mm/hugetlb: convert hugetlbfs_pagecache_present() to folios
authorSidhartha Kumar <sidhartha.kumar@oracle.com>
Wed, 25 Jan 2023 17:05:31 +0000 (09:05 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 13 Feb 2023 23:54:28 +0000 (15:54 -0800)
Refactor hugetlbfs_pagecache_present() to avoid getting and dropping a
refcount on a page.  Use RCU and page_cache_next_miss() instead.

Link: https://lkml.kernel.org/r/20230125170537.96973-3-sidhartha.kumar@oracle.com
Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: kernel test robot <lkp@intel.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/hugetlb.c

index b246f2b4d0bde5455dccdae725417db4ed157bbc..a0d486ed541181947fcef586c27e572f4bf2622e 100644 (file)
@@ -5651,17 +5651,15 @@ out_release_old:
 static bool hugetlbfs_pagecache_present(struct hstate *h,
                        struct vm_area_struct *vma, unsigned long address)
 {
-       struct address_space *mapping;
-       pgoff_t idx;
-       struct page *page;
+       struct address_space *mapping = vma->vm_file->f_mapping;
+       pgoff_t idx = vma_hugecache_offset(h, vma, address);
+       bool present;
 
-       mapping = vma->vm_file->f_mapping;
-       idx = vma_hugecache_offset(h, vma, address);
+       rcu_read_lock();
+       present = page_cache_next_miss(mapping, idx, 1) != idx;
+       rcu_read_unlock();
 
-       page = find_get_page(mapping, idx);
-       if (page)
-               put_page(page);
-       return page != NULL;
+       return present;
 }
 
 int hugetlb_add_to_page_cache(struct page *page, struct address_space *mapping,