Skip to content

Commit e6e8871

Browse files
Matthew Wilcox (Oracle)torvalds
authored andcommitted
mm: optimise madvise WILLNEED
Instead of calling find_get_entry() for every page index, use an XArray iterator to skip over NULL entries, and avoid calling get_page(), because we only want the swap entries. [willy@infradead.org: fix LTP soft lockups] Link: https://lkml.kernel.org/r/20200914165032.GS6583@casper.infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Huang Ying <ying.huang@intel.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Matthew Auld <matthew.auld@intel.com> Cc: William Kucharski <william.kucharski@oracle.com> Cc: Qian Cai <cai@redhat.com> Link: https://lkml.kernel.org/r/20200910183318.20139-4-willy@infradead.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f5df863 commit e6e8871

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

mm/madvise.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,25 +224,28 @@ static void force_shm_swapin_readahead(struct vm_area_struct *vma,
224224
unsigned long start, unsigned long end,
225225
struct address_space *mapping)
226226
{
227-
pgoff_t index;
227+
XA_STATE(xas, &mapping->i_pages, linear_page_index(vma, start));
228+
pgoff_t end_index = end / PAGE_SIZE;
228229
struct page *page;
229-
swp_entry_t swap;
230230

231-
for (; start < end; start += PAGE_SIZE) {
232-
index = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
231+
rcu_read_lock();
232+
xas_for_each(&xas, page, end_index) {
233+
swp_entry_t swap;
233234

234-
page = find_get_entry(mapping, index);
235-
if (!xa_is_value(page)) {
236-
if (page)
237-
put_page(page);
235+
if (!xa_is_value(page))
238236
continue;
239-
}
237+
xas_pause(&xas);
238+
rcu_read_unlock();
239+
240240
swap = radix_to_swp_entry(page);
241241
page = read_swap_cache_async(swap, GFP_HIGHUSER_MOVABLE,
242242
NULL, 0, false);
243243
if (page)
244244
put_page(page);
245+
246+
rcu_read_lock();
245247
}
248+
rcu_read_unlock();
246249

247250
lru_add_drain(); /* Push any new pages onto the LRU now */
248251
}

0 commit comments

Comments
 (0)