Checking if a Buffer head is valid or not

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


Hi,

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

--->iterate_supers
     ---->drop_pagecache_sb
             --->invalidate_mapping_pages
                   ---->invalidate_inode_page
                          --->invalidate_complete_page
                               --->try_to_release_page

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?

Regards,
Pranay Kr. Srivastava

-- 
Pranay Srivastava



More information about the Kernelnewbies mailing list