From: Wu Fengguang Introduce a pair of functions to probe the existence of file page. - int __probe_page(mapping, offset) - int probe_page(mapping, offset) Signed-off-by: Wu Fengguang Signed-off-by: Andrew Morton --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff -puN include/linux/pagemap.h~mm-introduce-probe_page include/linux/pagemap.h --- a/include/linux/pagemap.h~mm-introduce-probe_page +++ a/include/linux/pagemap.h @@ -72,6 +72,8 @@ static inline struct page *page_cache_al typedef int filler_t(void *, struct page *); +extern int __probe_page(struct address_space *mapping, pgoff_t offset); +extern int probe_page(struct address_space *mapping, pgoff_t offset); extern struct page * find_get_page(struct address_space *mapping, unsigned long index); extern struct page * find_lock_page(struct address_space *mapping, diff -puN mm/filemap.c~mm-introduce-probe_page mm/filemap.c --- a/mm/filemap.c~mm-introduce-probe_page +++ a/mm/filemap.c @@ -552,6 +552,28 @@ void fastcall unlock_page(struct page *p } EXPORT_SYMBOL(unlock_page); +/* + * Probing page existence. + */ +int __probe_page(struct address_space *mapping, pgoff_t offset) +{ + return !! radix_tree_lookup(&mapping->page_tree, offset); +} + +/* + * Here we just do not bother to grab the page, it's meaningless anyway. + */ +int probe_page(struct address_space *mapping, pgoff_t offset) +{ + int exists; + + read_lock_irq(&mapping->tree_lock); + exists = __probe_page(mapping, offset); + read_unlock_irq(&mapping->tree_lock); + + return exists; +} + /** * end_page_writeback - end writeback against a page * @page: the page _