1

When we do a find in linux, I am guessing the kernel will store the result into buffer/cache. Let say after an hour, some changes of the folder and files happened, so my question is, when we do the next find:

i) Will the kernel get the wrong old result stored in buffer/cache ?

ii) How does kernel know there already some changes of the folder and files and it can't use back the result from the buffer/cache ? Is it doing a comparison between the new result and old result ? Wouldn't this even take up more time ? If not, how the kernel achieve such intelligent choice ?

iii) Do we ever need to worry about dropping the cache (i.e. : echo 3 > /proc/sys/vm/drop_caches) to get the latest result of our operation let say find ? or there are some scenario where we need to do such thing ? (although I feel we shouldn't need to, but just want to make sure)

iv) Let say there is a scenario where some cron script run a command (may be grep a very huge file) that causing to taken up most of the resource of the server. We kill that process and truncate that huge file. That cron job then run again after few minutes. Do we need to drop the buffer/cache in order to avoid the next grep getting the huge file content result stored in it to avoid it hang the server again ? (sorry if this question sound too silly to you)

9
  • The system maps buffers directly to their corresponding cache entry. The cached version is always accurate, sometimes more than the disk's version if the buffer hasn't yet been flushed. It is a common mistake to think that the amount of memory taken by the cache could slow down their machine or cause out of memory problems, but that's not the case. The kernel will always prioritize any request to memory and flush the required amount of cache to balance the system. Feb 4 '17 at 5:57
  • A grep should normally not be able to hang a server. The only case I could imagine is if you have a single core CPU and a complex regular expression. The solution if that's similar to your case, is to run it on low priority with nice. Feb 4 '17 at 5:59
  • @julie: "sometimes more than the disk's version if the buffer hasn't yet been flushed" -> what does the 'more' here mean ?
    – sylye
    Feb 4 '17 at 16:55
  • @julie: " It is a common mistake to think that the amount of memory taken by the cache could slow down their machine or cause out of memory problems"-> I understand about this :) My question is not concern about out of memory, but the integrity of the data stored in buffer/cache. Thanks for reminding us about it though,appreciated :)
    – sylye
    Feb 4 '17 at 16:56
  • The system cache is at the core of the filesystem IO. The buffers allocated there are used directly for read and write operations to the disk. So there's no question about integrity since what is in the cache is exactly what should be there at any moment. Feb 4 '17 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.