Commit 8dd1e896 authored by Vishal Moola (Oracle)'s avatar Vishal Moola (Oracle) Committed by Andrew Morton

mm/khugepaged: convert __collapse_huge_page_isolate() to use folios

Patch series "Some khugepaged folio conversions", v3.

This patchset converts a number of functions to use folios.  This cleans
up some khugepaged code and removes a large number of hidden
compound_head() calls.


This patch (of 5):

Replaces 11 calls to compound_head() with 1, and removes 1348 bytes of
kernel text.

Link: https://lkml.kernel.org/r/20231020183331.10770-1-vishal.moola@gmail.com
Link: https://lkml.kernel.org/r/20231020183331.10770-2-vishal.moola@gmail.comSigned-off-by: default avatarVishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarYang Shi <shy828301@gmail.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent b7812c86
...@@ -542,6 +542,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -542,6 +542,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
struct list_head *compound_pagelist) struct list_head *compound_pagelist)
{ {
struct page *page = NULL; struct page *page = NULL;
struct folio *folio = NULL;
pte_t *_pte; pte_t *_pte;
int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0; int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0;
bool writable = false; bool writable = false;
...@@ -576,7 +577,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -576,7 +577,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
goto out; goto out;
} }
VM_BUG_ON_PAGE(!PageAnon(page), page); folio = page_folio(page);
VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio);
if (page_mapcount(page) > 1) { if (page_mapcount(page) > 1) {
++shared; ++shared;
...@@ -588,16 +590,15 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -588,16 +590,15 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
} }
} }
if (PageCompound(page)) { if (folio_test_large(folio)) {
struct page *p; struct folio *f;
page = compound_head(page);
/* /*
* Check if we have dealt with the compound page * Check if we have dealt with the compound page
* already * already
*/ */
list_for_each_entry(p, compound_pagelist, lru) { list_for_each_entry(f, compound_pagelist, lru) {
if (page == p) if (folio == f)
goto next; goto next;
} }
} }
...@@ -608,7 +609,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -608,7 +609,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
* is needed to serialize against split_huge_page * is needed to serialize against split_huge_page
* when invoked from the VM. * when invoked from the VM.
*/ */
if (!trylock_page(page)) { if (!folio_trylock(folio)) {
result = SCAN_PAGE_LOCK; result = SCAN_PAGE_LOCK;
goto out; goto out;
} }
...@@ -624,8 +625,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -624,8 +625,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
* but not from this process. The other process cannot write to * but not from this process. The other process cannot write to
* the page, only trigger CoW. * the page, only trigger CoW.
*/ */
if (!is_refcount_suitable(page)) { if (!is_refcount_suitable(&folio->page)) {
unlock_page(page); folio_unlock(folio);
result = SCAN_PAGE_COUNT; result = SCAN_PAGE_COUNT;
goto out; goto out;
} }
...@@ -634,27 +635,27 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -634,27 +635,27 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
* Isolate the page to avoid collapsing an hugepage * Isolate the page to avoid collapsing an hugepage
* currently in use by the VM. * currently in use by the VM.
*/ */
if (!isolate_lru_page(page)) { if (!folio_isolate_lru(folio)) {
unlock_page(page); folio_unlock(folio);
result = SCAN_DEL_PAGE_LRU; result = SCAN_DEL_PAGE_LRU;
goto out; goto out;
} }
mod_node_page_state(page_pgdat(page), node_stat_mod_folio(folio,
NR_ISOLATED_ANON + page_is_file_lru(page), NR_ISOLATED_ANON + folio_is_file_lru(folio),
compound_nr(page)); folio_nr_pages(folio));
VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
VM_BUG_ON_PAGE(PageLRU(page), page); VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
if (PageCompound(page)) if (folio_test_large(folio))
list_add_tail(&page->lru, compound_pagelist); list_add_tail(&folio->lru, compound_pagelist);
next: next:
/* /*
* If collapse was initiated by khugepaged, check that there is * If collapse was initiated by khugepaged, check that there is
* enough young pte to justify collapsing the page * enough young pte to justify collapsing the page
*/ */
if (cc->is_khugepaged && if (cc->is_khugepaged &&
(pte_young(pteval) || page_is_young(page) || (pte_young(pteval) || folio_test_young(folio) ||
PageReferenced(page) || mmu_notifier_test_young(vma->vm_mm, folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm,
address))) address)))
referenced++; referenced++;
...@@ -668,13 +669,13 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, ...@@ -668,13 +669,13 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
result = SCAN_LACK_REFERENCED_PAGE; result = SCAN_LACK_REFERENCED_PAGE;
} else { } else {
result = SCAN_SUCCEED; result = SCAN_SUCCEED;
trace_mm_collapse_huge_page_isolate(page, none_or_zero, trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero,
referenced, writable, result); referenced, writable, result);
return result; return result;
} }
out: out:
release_pte_pages(pte, _pte, compound_pagelist); release_pte_pages(pte, _pte, compound_pagelist);
trace_mm_collapse_huge_page_isolate(page, none_or_zero, trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero,
referenced, writable, result); referenced, writable, result);
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment