Checking if a Buffer head is valid or not

Pranay Srivastava pranjas at
Sun Sep 29 00:46:54 EDT 2013


I've a question regarding how to check if a buffer head is valid.
Suppose that I've read  in a block using sb_bread and that buffer head
hasn't been touched in a while so that it's uptodate.

Now suppose that somebody drops the caches from user space. I looked
at the code and found the following,

Beginning from drop_caches_sysctl_handler


In the try_to_release_page there's call to try_to_free_buffers

Now since i would be having a pointer to the buffer head which is
already uptodate and nothing going on with it this would actually free
the buffer. There's a call to kmem_cache_free, so i would be left with
a pointer which is invalid [Correct?]

Now how do I check if i need to re-read this buffer from disk since
the pointer is actually not valid anymore so checking for bh_uptodate
doesn't make sense. Reading the buffer from disk always isn't
something i'm looking for so any advice on how to check it?

Pranay Kr. Srivastava

Pranay Srivastava

More information about the Kernelnewbies mailing list