mm/ksm: convert get_mergeable_page() from follow_page() to folio_walk
Let's use folio_walk instead, for example avoiding taking temporary folio references if the folio does not even apply and getting rid of one more follow_page() user. Note that zeropages obviously don't apply: old code could just have specified FOLL_DUMP. Anon folios are never secretmem, so we don't care about losing the check in follow_page(). Link: https://lkml.kernel.org/r/20240802155524.517137-6-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Claudio Imbrenda <imbrenda@linux.ibm.com> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Janosch Frank <frankja@linux.ibm.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Matthew Wilcox <willy@infradead.org> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
7dff875c94
commit
184e916c62
26
mm/ksm.c
26
mm/ksm.c
@ -767,26 +767,28 @@ static struct page *get_mergeable_page(struct ksm_rmap_item *rmap_item)
|
|||||||
struct mm_struct *mm = rmap_item->mm;
|
struct mm_struct *mm = rmap_item->mm;
|
||||||
unsigned long addr = rmap_item->address;
|
unsigned long addr = rmap_item->address;
|
||||||
struct vm_area_struct *vma;
|
struct vm_area_struct *vma;
|
||||||
struct page *page;
|
struct page *page = NULL;
|
||||||
|
struct folio_walk fw;
|
||||||
|
struct folio *folio;
|
||||||
|
|
||||||
mmap_read_lock(mm);
|
mmap_read_lock(mm);
|
||||||
vma = find_mergeable_vma(mm, addr);
|
vma = find_mergeable_vma(mm, addr);
|
||||||
if (!vma)
|
if (!vma)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
page = follow_page(vma, addr, FOLL_GET);
|
folio = folio_walk_start(&fw, vma, addr, 0);
|
||||||
if (IS_ERR_OR_NULL(page))
|
if (folio) {
|
||||||
goto out;
|
if (!folio_is_zone_device(folio) &&
|
||||||
if (is_zone_device_page(page))
|
folio_test_anon(folio)) {
|
||||||
goto out_putpage;
|
folio_get(folio);
|
||||||
if (PageAnon(page)) {
|
page = fw.page;
|
||||||
|
}
|
||||||
|
folio_walk_end(&fw, vma);
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
if (page) {
|
||||||
flush_anon_page(vma, page, addr);
|
flush_anon_page(vma, page, addr);
|
||||||
flush_dcache_page(page);
|
flush_dcache_page(page);
|
||||||
} else {
|
|
||||||
out_putpage:
|
|
||||||
put_page(page);
|
|
||||||
out:
|
|
||||||
page = NULL;
|
|
||||||
}
|
}
|
||||||
mmap_read_unlock(mm);
|
mmap_read_unlock(mm);
|
||||||
return page;
|
return page;
|
||||||
|
Loading…
Reference in New Issue
Block a user