* [PATCH v2 1/7] fs/proc/page: remove unneeded PageTail && PageSlab check
2023-11-10 3:33 [PATCH v2 0/7] mm: remove page idle and young wrapper Kefeng Wang
@ 2023-11-10 3:33 ` Kefeng Wang
2023-11-10 18:11 ` Matthew Wilcox
2023-11-10 3:33 ` [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
` (5 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Kefeng Wang @ 2023-11-10 3:33 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand,
Gregory Price, Kefeng Wang
After commit dcb351cd095a ("page-flags: define behavior SL*B-related
flags on compound pages"), the slab could not be a tail, remove unneeded
PageTail && PageSlab check.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
fs/proc/page.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 195b077c0fac..466efb0dadf7 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -184,9 +184,6 @@ u64 stable_page_flags(struct page *page)
u |= kpf_copy_bit(k, KPF_LOCKED, PG_locked);
u |= kpf_copy_bit(k, KPF_SLAB, PG_slab);
- if (PageTail(page) && PageSlab(page))
- u |= 1 << KPF_SLAB;
-
u |= kpf_copy_bit(k, KPF_ERROR, PG_error);
u |= kpf_copy_bit(k, KPF_DIRTY, PG_dirty);
u |= kpf_copy_bit(k, KPF_UPTODATE, PG_uptodate);
--
2.27.0
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v2 1/7] fs/proc/page: remove unneeded PageTail && PageSlab check
2023-11-10 3:33 ` [PATCH v2 1/7] fs/proc/page: remove unneeded PageTail && PageSlab check Kefeng Wang
@ 2023-11-10 18:11 ` Matthew Wilcox
0 siblings, 0 replies; 18+ messages in thread
From: Matthew Wilcox @ 2023-11-10 18:11 UTC (permalink / raw)
To: Kefeng Wang
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On Fri, Nov 10, 2023 at 11:33:18AM +0800, Kefeng Wang wrote:
> After commit dcb351cd095a ("page-flags: define behavior SL*B-related
> flags on compound pages"), the slab could not be a tail, remove unneeded
> PageTail && PageSlab check.
No, that's completely wrong.
* PF_NO_TAIL:
* modifications of the page flag must be done on small or head pages,
* checks can be done on tail pages too.
That's backed up by the code:
#define PF_NO_TAIL(page, enforce) ({ \
VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \
PF_POISONED_CHECK(compound_head(page)); })
(enforce is set to 0 for the 'test')
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
NAK
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags()
2023-11-10 3:33 [PATCH v2 0/7] mm: remove page idle and young wrapper Kefeng Wang
2023-11-10 3:33 ` [PATCH v2 1/7] fs/proc/page: remove unneeded PageTail && PageSlab check Kefeng Wang
@ 2023-11-10 3:33 ` Kefeng Wang
2023-11-10 18:15 ` Matthew Wilcox
2023-11-10 21:50 ` Gregory Price
2023-11-10 3:33 ` [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement Kefeng Wang
` (4 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Kefeng Wang @ 2023-11-10 3:33 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand,
Gregory Price, Kefeng Wang
Replace nine compound_head() calls with one page_folio().
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
fs/proc/page.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 466efb0dadf7..dcef02471f91 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -109,6 +109,7 @@ static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
u64 stable_page_flags(struct page *page)
{
+ struct folio *folio;
u64 k;
u64 u;
@@ -119,6 +120,7 @@ u64 stable_page_flags(struct page *page)
if (!page)
return 1 << KPF_NOPAGE;
+ folio = page_folio(page);
k = page->flags;
u = 0;
@@ -128,11 +130,11 @@ u64 stable_page_flags(struct page *page)
* Note that page->_mapcount is overloaded in SLAB, so the
* simple test in page_mapped() is not enough.
*/
- if (!PageSlab(page) && page_mapped(page))
+ if (!folio_test_slab(folio) && folio_mapped(folio))
u |= 1 << KPF_MMAP;
- if (PageAnon(page))
+ if (folio_test_anon(folio))
u |= 1 << KPF_ANON;
- if (PageKsm(page))
+ if (folio_test_ksm(folio))
u |= 1 << KPF_KSM;
/*
@@ -152,11 +154,9 @@ u64 stable_page_flags(struct page *page)
* to make sure a given page is a thp, not a non-huge compound page.
*/
else if (PageTransCompound(page)) {
- struct page *head = compound_head(page);
-
- if (PageLRU(head) || PageAnon(head))
+ if (folio_test_lru(folio) || folio_test_anon(folio))
u |= 1 << KPF_THP;
- else if (is_huge_zero_page(head)) {
+ else if (is_huge_zero_page(&folio->page)) {
u |= 1 << KPF_ZERO_PAGE;
u |= 1 << KPF_THP;
}
@@ -170,7 +170,7 @@ u64 stable_page_flags(struct page *page)
*/
if (PageBuddy(page))
u |= 1 << KPF_BUDDY;
- else if (page_count(page) == 0 && is_free_buddy_page(page))
+ else if (folio_ref_count(folio) == 0 && is_free_buddy_page(page))
u |= 1 << KPF_BUDDY;
if (PageOffline(page))
@@ -178,7 +178,7 @@ u64 stable_page_flags(struct page *page)
if (PageTable(page))
u |= 1 << KPF_PGTABLE;
- if (page_is_idle(page))
+ if (folio_test_idle(folio))
u |= 1 << KPF_IDLE;
u |= kpf_copy_bit(k, KPF_LOCKED, PG_locked);
@@ -194,7 +194,7 @@ u64 stable_page_flags(struct page *page)
u |= kpf_copy_bit(k, KPF_ACTIVE, PG_active);
u |= kpf_copy_bit(k, KPF_RECLAIM, PG_reclaim);
- if (PageSwapCache(page))
+ if (folio_test_swapcache(folio))
u |= 1 << KPF_SWAPCACHE;
u |= kpf_copy_bit(k, KPF_SWAPBACKED, PG_swapbacked);
--
2.27.0
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags()
2023-11-10 3:33 ` [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
@ 2023-11-10 18:15 ` Matthew Wilcox
2023-11-11 3:21 ` Kefeng Wang
2023-11-10 21:50 ` Gregory Price
1 sibling, 1 reply; 18+ messages in thread
From: Matthew Wilcox @ 2023-11-10 18:15 UTC (permalink / raw)
To: Kefeng Wang
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On Fri, Nov 10, 2023 at 11:33:19AM +0800, Kefeng Wang wrote:
> Replace nine compound_head() calls with one page_folio().
But that's not all it does. Honestly, when you write these kind of
things, I wonder if you understand what you're doing.
After this patch, if we report on a tail page, we set (some of) the
flags according to how its head page is set. Before, we would have not
reported on it at all.
This was THE ENTIRE POINT of Greg's patch. And why his patch made sense
and yours is nonsense. Andrew, please drop this patch series.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags()
2023-11-10 18:15 ` Matthew Wilcox
@ 2023-11-11 3:21 ` Kefeng Wang
0 siblings, 0 replies; 18+ messages in thread
From: Kefeng Wang @ 2023-11-11 3:21 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On 2023/11/11 2:15, Matthew Wilcox wrote:
> On Fri, Nov 10, 2023 at 11:33:19AM +0800, Kefeng Wang wrote:
>> Replace nine compound_head() calls with one page_folio().
>
> But that's not all it does. Honestly, when you write these kind of
> things, I wonder if you understand what you're doing.
Oh, yes, I total wrong for some change, the kpagelfags should report
per-page.
>
> After this patch, if we report on a tail page, we set (some of) the
> flags according to how its head page is set. Before, we would have not
> reported on it at all.
I should force on the following specific flags in this patch
1) PageKsm
- KSM only normal anon page, also it is wrapper of folio_test_ksm()
2) struct page *head = compound_head(page); PageLRU(head) PageAnon(head)
- they expect to check the head page flags
3) page_count(page) == 0 && is_free_buddy_page(page)
- this is to identify free buddy page, also page_count is a wrapper
of folio_ref_count
4) page_is_idle
- a wrapper of folio_test_idle
Matthew and Gregory, correct me if I am still misunderstanding, man thanks.
>
> This was THE ENTIRE POINT of Greg's patch. And why his patch made sense
> and yours is nonsense. Andrew, please drop this patch series.
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags()
2023-11-10 3:33 ` [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
2023-11-10 18:15 ` Matthew Wilcox
@ 2023-11-10 21:50 ` Gregory Price
1 sibling, 0 replies; 18+ messages in thread
From: Gregory Price @ 2023-11-10 21:50 UTC (permalink / raw)
To: Kefeng Wang
Cc: Andrew Morton, linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand
On Fri, Nov 10, 2023 at 11:33:19AM +0800, Kefeng Wang wrote:
> Replace nine compound_head() calls with one page_folio().
>
Sorry to echo Matthew, but this commit message is extremely
insufficient and just outright wrong.
Single pass through, here's the real change list:
1) changes PageFLAG() calls to folio_test_FLAG calls
2) changes compound_head() flag checks to folio_test_FLAG checks
3) change page count to folio ref count
-- without even looking... is this even correct? Need more
explanation here. Is page count === folio ref count?
So there are really 3 changes in this patch set that should be broken
out separately, even if they all depend on folio flags, because they
need separate explanation and validation for correctness.
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> fs/proc/page.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement
2023-11-10 3:33 [PATCH v2 0/7] mm: remove page idle and young wrapper Kefeng Wang
2023-11-10 3:33 ` [PATCH v2 1/7] fs/proc/page: remove unneeded PageTail && PageSlab check Kefeng Wang
2023-11-10 3:33 ` [PATCH v2 2/7] fs/proc/page: use a folio in stable_page_flags() Kefeng Wang
@ 2023-11-10 3:33 ` Kefeng Wang
2023-11-10 18:19 ` Matthew Wilcox
2023-11-10 3:33 ` [PATCH v2 4/7] mm: huge_memory: use more folio api in __split_huge_page_tail() Kefeng Wang
` (3 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Kefeng Wang @ 2023-11-10 3:33 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand,
Gregory Price, Kefeng Wang
kpageflags reads page-flags directly from the page, even when the
respective flag is only updated on the headpage of a folio.
Since most flags are stored in head flags, make k = folio->flags,
and add new p = page->flags used for per-page flags.
Originally-from: Gregory Price <gregory.price@memverge.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
fs/proc/page.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index dcef02471f91..553a7c921cb4 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -110,8 +110,7 @@ static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
u64 stable_page_flags(struct page *page)
{
struct folio *folio;
- u64 k;
- u64 u;
+ u64 k, p, u;
/*
* pseudo flag: KPF_NOPAGE
@@ -121,7 +120,8 @@ u64 stable_page_flags(struct page *page)
return 1 << KPF_NOPAGE;
folio = page_folio(page);
- k = page->flags;
+ k = folio->flags;
+ p = page->flags;
u = 0;
/*
@@ -202,7 +202,7 @@ u64 stable_page_flags(struct page *page)
u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked);
#ifdef CONFIG_MEMORY_FAILURE
- u |= kpf_copy_bit(k, KPF_HWPOISON, PG_hwpoison);
+ u |= kpf_copy_bit(p, KPF_HWPOISON, PG_hwpoison);
#endif
#ifdef CONFIG_ARCH_USES_PG_UNCACHED
@@ -211,13 +211,13 @@ u64 stable_page_flags(struct page *page)
u |= kpf_copy_bit(k, KPF_RESERVED, PG_reserved);
u |= kpf_copy_bit(k, KPF_MAPPEDTODISK, PG_mappedtodisk);
- u |= kpf_copy_bit(k, KPF_PRIVATE, PG_private);
- u |= kpf_copy_bit(k, KPF_PRIVATE_2, PG_private_2);
- u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE, PG_owner_priv_1);
+ u |= kpf_copy_bit(p, KPF_PRIVATE, PG_private);
+ u |= kpf_copy_bit(p, KPF_PRIVATE_2, PG_private_2);
+ u |= kpf_copy_bit(p, KPF_OWNER_PRIVATE, PG_owner_priv_1);
u |= kpf_copy_bit(k, KPF_ARCH, PG_arch_1);
#ifdef CONFIG_ARCH_USES_PG_ARCH_X
- u |= kpf_copy_bit(k, KPF_ARCH_2, PG_arch_2);
- u |= kpf_copy_bit(k, KPF_ARCH_3, PG_arch_3);
+ u |= kpf_copy_bit(p, KPF_ARCH_2, PG_arch_2);
+ u |= kpf_copy_bit(p, KPF_ARCH_3, PG_arch_3);
#endif
return u;
--
2.27.0
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement
2023-11-10 3:33 ` [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement Kefeng Wang
@ 2023-11-10 18:19 ` Matthew Wilcox
2023-11-11 9:49 ` Kefeng Wang
0 siblings, 1 reply; 18+ messages in thread
From: Matthew Wilcox @ 2023-11-10 18:19 UTC (permalink / raw)
To: Kefeng Wang
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On Fri, Nov 10, 2023 at 11:33:20AM +0800, Kefeng Wang wrote:
> kpageflags reads page-flags directly from the page, even when the
> respective flag is only updated on the headpage of a folio.
>
> Since most flags are stored in head flags, make k = folio->flags,
> and add new p = page->flags used for per-page flags.
You'd do better to steal Greg's commit message.
> Originally-from: Gregory Price <gregory.price@memverge.com>
> Suggested-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> @@ -202,7 +202,7 @@ u64 stable_page_flags(struct page *page)
> u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked);
>
> #ifdef CONFIG_MEMORY_FAILURE
> - u |= kpf_copy_bit(k, KPF_HWPOISON, PG_hwpoison);
> + u |= kpf_copy_bit(p, KPF_HWPOISON, PG_hwpoison);
This is correct.
> @@ -211,13 +211,13 @@ u64 stable_page_flags(struct page *page)
>
> u |= kpf_copy_bit(k, KPF_RESERVED, PG_reserved);
> u |= kpf_copy_bit(k, KPF_MAPPEDTODISK, PG_mappedtodisk);
> - u |= kpf_copy_bit(k, KPF_PRIVATE, PG_private);
> - u |= kpf_copy_bit(k, KPF_PRIVATE_2, PG_private_2);
> - u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE, PG_owner_priv_1);
> + u |= kpf_copy_bit(p, KPF_PRIVATE, PG_private);
> + u |= kpf_copy_bit(p, KPF_PRIVATE_2, PG_private_2);
> + u |= kpf_copy_bit(p, KPF_OWNER_PRIVATE, PG_owner_priv_1);
This is not. PG_private is not, I believe, set on tail pages.
Ditto the other two. If you know differently ... ?
> #ifdef CONFIG_ARCH_USES_PG_ARCH_X
> - u |= kpf_copy_bit(k, KPF_ARCH_2, PG_arch_2);
> - u |= kpf_copy_bit(k, KPF_ARCH_3, PG_arch_3);
> + u |= kpf_copy_bit(p, KPF_ARCH_2, PG_arch_2);
> + u |= kpf_copy_bit(p, KPF_ARCH_3, PG_arch_3);
> #endif
I also don't think this is correct, but there are many uses of
PG_arch* and I may have missed something.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement
2023-11-10 18:19 ` Matthew Wilcox
@ 2023-11-11 9:49 ` Kefeng Wang
0 siblings, 0 replies; 18+ messages in thread
From: Kefeng Wang @ 2023-11-11 9:49 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On 2023/11/11 2:19, Matthew Wilcox wrote:
> On Fri, Nov 10, 2023 at 11:33:20AM +0800, Kefeng Wang wrote:
>> kpageflags reads page-flags directly from the page, even when the
>> respective flag is only updated on the headpage of a folio.
>>
>> Since most flags are stored in head flags, make k = folio->flags,
>> and add new p = page->flags used for per-page flags.
>
> You'd do better to steal Greg's commit message.
Sure
>
>> Originally-from: Gregory Price <gregory.price@memverge.com>
>> Suggested-by: Matthew Wilcox <willy@infradead.org>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>
>> @@ -202,7 +202,7 @@ u64 stable_page_flags(struct page *page)
>> u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked);
>>
>> #ifdef CONFIG_MEMORY_FAILURE
>> - u |= kpf_copy_bit(k, KPF_HWPOISON, PG_hwpoison);
>> + u |= kpf_copy_bit(p, KPF_HWPOISON, PG_hwpoison);
>
> This is correct.
>
>> @@ -211,13 +211,13 @@ u64 stable_page_flags(struct page *page)
>>
>> u |= kpf_copy_bit(k, KPF_RESERVED, PG_reserved);
>> u |= kpf_copy_bit(k, KPF_MAPPEDTODISK, PG_mappedtodisk);
>> - u |= kpf_copy_bit(k, KPF_PRIVATE, PG_private);
>> - u |= kpf_copy_bit(k, KPF_PRIVATE_2, PG_private_2);
>> - u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE, PG_owner_priv_1);
>> + u |= kpf_copy_bit(p, KPF_PRIVATE, PG_private);
>> + u |= kpf_copy_bit(p, KPF_PRIVATE_2, PG_private_2);
>> + u |= kpf_copy_bit(p, KPF_OWNER_PRIVATE, PG_owner_priv_1);
>
> This is not. PG_private is not, I believe, set on tail pages.
> Ditto the other two. If you know differently ... ?
k = folio->flags, p = page->flags
as PG_private/private_2/owner_priv_1 use PF_ANY page policy,
so they should per-page check, confused...
See checked page flags,
PG_error PF_NO_TAIL
PG_dirty PF_HEAD
PG_uptodate PF_NO_TAIL
PG_writeback PF_NO_TAIL
PG_lru PF_HEAD
PG_referenced PF_HEAD
PG_active PF_HEAD
PG_reclaim PF_NO_TAIL
PG_swapbacked PF_NO_TAIL
PG_unevictable PF_HEAD
PG_mlocked PF_NO_TAIL
PG_hwpoison PF_ANY
PG_uncached PF_NO_COMPOUND
PG_reserved PF_NO_COMPOUND
PG_mappedtodisk PF_NO_TAIL
PG_private PF_ANY
PG_private_2 PF_ANY
PG_owner_priv_1 PF_ANY
above part has 4 types,
1) PF_HEAD - should use k
2) PF_ANY - should use p
3) PF_NO_TAIL
- PageXXX will check head page flags, so suppose to use k,
but here use bit check, I wonder it should use p?
4) PF_NO_COMPOUND
- should per-page check
>
>> #ifdef CONFIG_ARCH_USES_PG_ARCH_X
>> - u |= kpf_copy_bit(k, KPF_ARCH_2, PG_arch_2);
>> - u |= kpf_copy_bit(k, KPF_ARCH_3, PG_arch_3);
>> + u |= kpf_copy_bit(p, KPF_ARCH_2, PG_arch_2);
>> + u |= kpf_copy_bit(p, KPF_ARCH_3, PG_arch_3);
>> #endif
>
> I also don't think this is correct, but there are many uses of
> PG_arch* and I may have missed something.
>
And 3 arch page flags,
PG_arch_1
- PG_dcache_clean, from achetlb.rst, I think it is per-folio, use k
PG_arch_2
- only arm64 mte, PG_mte_tagged
PG_arch_3
- only arm64 mte, PG_mte_lock
the two PG_arch only used by arm64 mte, they are per-page flag, use p
Correct me if I am wrong, thanks.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 4/7] mm: huge_memory: use more folio api in __split_huge_page_tail()
2023-11-10 3:33 [PATCH v2 0/7] mm: remove page idle and young wrapper Kefeng Wang
` (2 preceding siblings ...)
2023-11-10 3:33 ` [PATCH v2 3/7] fs/proc/page: respect folio head-page flag placement Kefeng Wang
@ 2023-11-10 3:33 ` Kefeng Wang
2023-11-10 18:20 ` Matthew Wilcox
2023-11-10 3:33 ` [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account() Kefeng Wang
` (2 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Kefeng Wang @ 2023-11-10 3:33 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand,
Gregory Price, Kefeng Wang
Use more folio APIs to save six compound_head() calls in
__split_huge_page_tail().
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
mm/huge_memory.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 3f74a063f7d1..2b03c55ea425 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2509,13 +2509,13 @@ static void __split_huge_page_tail(struct folio *folio, int tail,
clear_compound_head(page_tail);
/* Finally unfreeze refcount. Additional reference from page cache. */
- page_ref_unfreeze(page_tail, 1 + (!PageAnon(head) ||
- PageSwapCache(head)));
+ page_ref_unfreeze(page_tail, 1 + (!folio_test_anon(folio) ||
+ folio_test_swapcache(folio)));
- if (page_is_young(head))
- set_page_young(page_tail);
- if (page_is_idle(head))
- set_page_idle(page_tail);
+ if (folio_test_young(folio))
+ folio_set_young(new_folio);
+ if (folio_test_idle(folio))
+ folio_set_idle(new_folio);
folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio));
--
2.27.0
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v2 4/7] mm: huge_memory: use more folio api in __split_huge_page_tail()
2023-11-10 3:33 ` [PATCH v2 4/7] mm: huge_memory: use more folio api in __split_huge_page_tail() Kefeng Wang
@ 2023-11-10 18:20 ` Matthew Wilcox
2023-11-11 10:00 ` Kefeng Wang
0 siblings, 1 reply; 18+ messages in thread
From: Matthew Wilcox @ 2023-11-10 18:20 UTC (permalink / raw)
To: Kefeng Wang
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On Fri, Nov 10, 2023 at 11:33:21AM +0800, Kefeng Wang wrote:
> Use more folio APIs to save six compound_head() calls in
> __split_huge_page_tail().
>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 4/7] mm: huge_memory: use more folio api in __split_huge_page_tail()
2023-11-10 18:20 ` Matthew Wilcox
@ 2023-11-11 10:00 ` Kefeng Wang
0 siblings, 0 replies; 18+ messages in thread
From: Kefeng Wang @ 2023-11-11 10:00 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On 2023/11/11 2:20, Matthew Wilcox wrote:
> On Fri, Nov 10, 2023 at 11:33:21AM +0800, Kefeng Wang wrote:
>> Use more folio APIs to save six compound_head() calls in
>> __split_huge_page_tail().
>>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>
> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>
Thanks, Hi Andrew, please consider only take this one,
I will think more about other part as Matthew suggested.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account()
2023-11-10 3:33 [PATCH v2 0/7] mm: remove page idle and young wrapper Kefeng Wang
` (3 preceding siblings ...)
2023-11-10 3:33 ` [PATCH v2 4/7] mm: huge_memory: use more folio api in __split_huge_page_tail() Kefeng Wang
@ 2023-11-10 3:33 ` Kefeng Wang
2023-11-10 18:29 ` Matthew Wilcox
2023-11-10 3:33 ` [PATCH v2 6/7] mm: task_mmu: use a folio in clear_refs_pte_range() Kefeng Wang
2023-11-10 3:33 ` [PATCH v2 7/7] page_idle: kill page idle and young wrapper Kefeng Wang
6 siblings, 1 reply; 18+ messages in thread
From: Kefeng Wang @ 2023-11-10 3:33 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand,
Gregory Price, Kefeng Wang
Replace seven implicit calls to compound_head() with one page_folio().
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
fs/proc/task_mmu.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 51e0ec658457..fe15f99a4908 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
{
int i, nr = compound ? compound_nr(page) : 1;
unsigned long size = nr * PAGE_SIZE;
+ struct folio *folio = page_folio(page);
/*
* First accumulate quantities that depend only on |size| and the type
* of the compound page.
*/
- if (PageAnon(page)) {
+ if (folio_test_anon(folio)) {
mss->anonymous += size;
- if (!PageSwapBacked(page) && !dirty && !PageDirty(page))
+ if (!folio_test_swapbacked(folio) && !dirty &&
+ !folio_test_dirty(folio))
mss->lazyfree += size;
}
- if (PageKsm(page))
+ if (folio_test_ksm(folio))
mss->ksm += size;
mss->resident += size;
/* Accumulate the size in pages that have been accessed. */
- if (young || page_is_young(page) || PageReferenced(page))
+ if (young || folio_test_young(folio) || folio_test_referenced(folio))
mss->referenced += size;
/*
@@ -479,7 +481,7 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
* especially for migration entries. Treat regular migration entries
* as mapcount == 1.
*/
- if ((page_count(page) == 1) || migration) {
+ if ((folio_ref_count(folio) == 1) || migration) {
smaps_page_accumulate(mss, page, size, size << PSS_SHIFT, dirty,
locked, true);
return;
--
2.27.0
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account()
2023-11-10 3:33 ` [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account() Kefeng Wang
@ 2023-11-10 18:29 ` Matthew Wilcox
2023-11-11 10:57 ` Kefeng Wang
0 siblings, 1 reply; 18+ messages in thread
From: Matthew Wilcox @ 2023-11-10 18:29 UTC (permalink / raw)
To: Kefeng Wang
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On Fri, Nov 10, 2023 at 11:33:22AM +0800, Kefeng Wang wrote:
> Replace seven implicit calls to compound_head() with one page_folio().
You're so focused on trying to accomplish your goal (killing off the
page_idle and page_young functions) that you're doing a poor job thinkig
about the conversions you're doing along the way.
> +++ b/fs/proc/task_mmu.c
> @@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
> {
> int i, nr = compound ? compound_nr(page) : 1;
> unsigned long size = nr * PAGE_SIZE;
> + struct folio *folio = page_folio(page);
Stop right here. The use of compound_nr() should give you pause.
After looking at how smaps_account() is used, it seems to me that the
two callers should each pass in PAGE_SIZE or PMD_SIZE instead of doing
this calculation.
More generally, step back from this series. Do a good job of
transforming fs/proc/task_mmu.c to use folios. Once you've done
that, you can approach the young/idle work again.
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account()
2023-11-10 18:29 ` Matthew Wilcox
@ 2023-11-11 10:57 ` Kefeng Wang
0 siblings, 0 replies; 18+ messages in thread
From: Kefeng Wang @ 2023-11-11 10:57 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Andrew Morton, linux-kernel, linux-mm, David Hildenbrand, Gregory Price
On 2023/11/11 2:29, Matthew Wilcox wrote:
> On Fri, Nov 10, 2023 at 11:33:22AM +0800, Kefeng Wang wrote:
>> Replace seven implicit calls to compound_head() with one page_folio().
>
> You're so focused on trying to accomplish your goal (killing off the
> page_idle and page_young functions) that you're doing a poor job thinkig
> about the conversions you're doing along the way.
>
>> +++ b/fs/proc/task_mmu.c
>> @@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
>> {
>> int i, nr = compound ? compound_nr(page) : 1;
>> unsigned long size = nr * PAGE_SIZE;
>> + struct folio *folio = page_folio(page);
>
> Stop right here. The use of compound_nr() should give you pause.
>
> After looking at how smaps_account() is used, it seems to me that the
> two callers should each pass in PAGE_SIZE or PMD_SIZE instead of doing
> this calculation.
Yes,this will save extra calculation
>
> More generally, step back from this series. Do a good job of
> transforming fs/proc/task_mmu.c to use folios. Once you've done
> that, you can approach the young/idle work again.
>
Thanks for you advise,will try this firstly.
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 6/7] mm: task_mmu: use a folio in clear_refs_pte_range()
2023-11-10 3:33 [PATCH v2 0/7] mm: remove page idle and young wrapper Kefeng Wang
` (4 preceding siblings ...)
2023-11-10 3:33 ` [PATCH v2 5/7] mm: task_mmu: use a folio in smaps_account() Kefeng Wang
@ 2023-11-10 3:33 ` Kefeng Wang
2023-11-10 3:33 ` [PATCH v2 7/7] page_idle: kill page idle and young wrapper Kefeng Wang
6 siblings, 0 replies; 18+ messages in thread
From: Kefeng Wang @ 2023-11-10 3:33 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand,
Gregory Price, Kefeng Wang
Use a folio to save two compound_head() calls in clear_refs_pte_range().
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
fs/proc/task_mmu.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index fe15f99a4908..740d5c4fa33c 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1161,7 +1161,7 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
struct vm_area_struct *vma = walk->vma;
pte_t *pte, ptent;
spinlock_t *ptl;
- struct page *page;
+ struct folio *folio;
ptl = pmd_trans_huge_lock(pmd, vma);
if (ptl) {
@@ -1173,12 +1173,12 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
if (!pmd_present(*pmd))
goto out;
- page = pmd_page(*pmd);
+ folio = page_folio(pmd_page(*pmd));
/* Clear accessed and referenced bits. */
pmdp_test_and_clear_young(vma, addr, pmd);
- test_and_clear_page_young(page);
- ClearPageReferenced(page);
+ folio_test_clear_young(folio);
+ folio_clear_referenced(folio);
out:
spin_unlock(ptl);
return 0;
@@ -1200,14 +1200,14 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
if (!pte_present(ptent))
continue;
- page = vm_normal_page(vma, addr, ptent);
- if (!page)
+ folio = vm_normal_folio(vma, addr, ptent);
+ if (!folio)
continue;
/* Clear accessed and referenced bits. */
ptep_test_and_clear_young(vma, addr, pte);
- test_and_clear_page_young(page);
- ClearPageReferenced(page);
+ folio_test_clear_young(folio);
+ folio_clear_referenced(folio);
}
pte_unmap_unlock(pte - 1, ptl);
cond_resched();
--
2.27.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 7/7] page_idle: kill page idle and young wrapper
2023-11-10 3:33 [PATCH v2 0/7] mm: remove page idle and young wrapper Kefeng Wang
` (5 preceding siblings ...)
2023-11-10 3:33 ` [PATCH v2 6/7] mm: task_mmu: use a folio in clear_refs_pte_range() Kefeng Wang
@ 2023-11-10 3:33 ` Kefeng Wang
6 siblings, 0 replies; 18+ messages in thread
From: Kefeng Wang @ 2023-11-10 3:33 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, linux-mm, Matthew Wilcox, David Hildenbrand,
Gregory Price, Kefeng Wang
Since all the calls of page idle and young functions are gone,
let's remove all the wrapper.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
include/linux/page_idle.h | 25 -------------------------
1 file changed, 25 deletions(-)
diff --git a/include/linux/page_idle.h b/include/linux/page_idle.h
index d8f344840643..1168d5f58ff2 100644
--- a/include/linux/page_idle.h
+++ b/include/linux/page_idle.h
@@ -119,29 +119,4 @@ static inline void folio_clear_idle(struct folio *folio)
}
#endif /* CONFIG_PAGE_IDLE_FLAG */
-
-static inline bool page_is_young(struct page *page)
-{
- return folio_test_young(page_folio(page));
-}
-
-static inline void set_page_young(struct page *page)
-{
- folio_set_young(page_folio(page));
-}
-
-static inline bool test_and_clear_page_young(struct page *page)
-{
- return folio_test_clear_young(page_folio(page));
-}
-
-static inline bool page_is_idle(struct page *page)
-{
- return folio_test_idle(page_folio(page));
-}
-
-static inline void set_page_idle(struct page *page)
-{
- folio_set_idle(page_folio(page));
-}
#endif /* _LINUX_MM_PAGE_IDLE_H */
--
2.27.0
^ permalink raw reply [flat|nested] 18+ messages in thread