* [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo
@ 2024-09-03 21:36 Yu Zhao
2024-09-03 21:36 ` [PATCH mm-unstable v1 2/3] mm/codetag: fix pgalloc_tag_split() Yu Zhao
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Yu Zhao @ 2024-09-03 21:36 UTC (permalink / raw)
To: Andrew Morton, Kent Overstreet, Suren Baghdasaryan
Cc: Muchun Song, linux-mm, linux-kernel, Yu Zhao
Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
Signed-off-by: Yu Zhao <yuzhao@google.com>
---
include/linux/alloc_tag.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h
index 8c61ccd161ba..896491d9ebe8 100644
--- a/include/linux/alloc_tag.h
+++ b/include/linux/alloc_tag.h
@@ -70,7 +70,7 @@ static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct)
/*
* When percpu variables are required to be defined as weak, static percpu
* variables can't be used inside a function (see comments for DECLARE_PER_CPU_SECTION).
- * Instead we will accound all module allocations to a single counter.
+ * Instead we will account all module allocations to a single counter.
*/
DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag);
--
2.46.0.469.g59c65b2a67-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH mm-unstable v1 2/3] mm/codetag: fix pgalloc_tag_split()
2024-09-03 21:36 [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Yu Zhao
@ 2024-09-03 21:36 ` Yu Zhao
2024-09-06 3:00 ` Suren Baghdasaryan
2024-09-03 21:36 ` [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy() Yu Zhao
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Yu Zhao @ 2024-09-03 21:36 UTC (permalink / raw)
To: Andrew Morton, Kent Overstreet, Suren Baghdasaryan
Cc: Muchun Song, linux-mm, linux-kernel, Yu Zhao
Only tag the new head pages when splitting one large folio to multiple
ones of a lower order. Tagging tail pages can cause imbalanced "calls"
counters, since only head pages are untagged by pgalloc_tag_sub() and
reference counts on tail pages are leaked, e.g.,
# echo 2048kB >/sys/kernel/mm/hugepages/hugepages-1048576kB/demote_size
# echo 700 >/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
# time echo 700 >/sys/kernel/mm/hugepages/hugepages-1048576kB/demote
# grep alloc_gigantic_folio /proc/allocinfo
Before this patch:
0 549427200 mm/hugetlb.c:1549 func:alloc_gigantic_folio
real 0m2.057s
user 0m0.000s
sys 0m2.051s
After this patch:
0 0 mm/hugetlb.c:1549 func:alloc_gigantic_folio
real 0m1.711s
user 0m0.000s
sys 0m1.704s
Not tagging tail pages also improves the splitting time, e.g., by
about 15% when demoting 1GB hugeTLB folios to 2MB ones, as shown
above.
Fixes: be25d1d4e822 ("mm: create new codetag references during page splitting")
Signed-off-by: Yu Zhao <yuzhao@google.com>
---
include/linux/mm.h | 30 ++++++++++++++++++++++++++++++
include/linux/pgalloc_tag.h | 31 -------------------------------
mm/huge_memory.c | 2 +-
mm/hugetlb.c | 2 +-
mm/page_alloc.c | 4 ++--
5 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index b31d4bdd65ad..a07e93adb8ad 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4137,4 +4137,34 @@ void vma_pgtable_walk_end(struct vm_area_struct *vma);
int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *size);
+#ifdef CONFIG_MEM_ALLOC_PROFILING
+static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
+{
+ int i;
+ struct alloc_tag *tag;
+ unsigned int nr_pages = 1 << new_order;
+
+ if (!mem_alloc_profiling_enabled())
+ return;
+
+ tag = pgalloc_tag_get(&folio->page);
+ if (!tag)
+ return;
+
+ for (i = nr_pages; i < (1 << old_order); i += nr_pages) {
+ union codetag_ref *ref = get_page_tag_ref(folio_page(folio, i));
+
+ if (ref) {
+ /* Set new reference to point to the original tag */
+ alloc_tag_ref_set(ref, tag);
+ put_page_tag_ref(ref);
+ }
+ }
+}
+#else /* !CONFIG_MEM_ALLOC_PROFILING */
+static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
+{
+}
+#endif /* CONFIG_MEM_ALLOC_PROFILING */
+
#endif /* _LINUX_MM_H */
diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h
index 207f0c83c8e9..59a3deb792a8 100644
--- a/include/linux/pgalloc_tag.h
+++ b/include/linux/pgalloc_tag.h
@@ -80,36 +80,6 @@ static inline void pgalloc_tag_sub(struct page *page, unsigned int nr)
}
}
-static inline void pgalloc_tag_split(struct page *page, unsigned int nr)
-{
- int i;
- struct page_ext *first_page_ext;
- struct page_ext *page_ext;
- union codetag_ref *ref;
- struct alloc_tag *tag;
-
- if (!mem_alloc_profiling_enabled())
- return;
-
- first_page_ext = page_ext = page_ext_get(page);
- if (unlikely(!page_ext))
- return;
-
- ref = codetag_ref_from_page_ext(page_ext);
- if (!ref->ct)
- goto out;
-
- tag = ct_to_alloc_tag(ref->ct);
- page_ext = page_ext_next(page_ext);
- for (i = 1; i < nr; i++) {
- /* Set new reference to point to the original tag */
- alloc_tag_ref_set(codetag_ref_from_page_ext(page_ext), tag);
- page_ext = page_ext_next(page_ext);
- }
-out:
- page_ext_put(first_page_ext);
-}
-
static inline struct alloc_tag *pgalloc_tag_get(struct page *page)
{
struct alloc_tag *tag = NULL;
@@ -142,7 +112,6 @@ static inline void clear_page_tag_ref(struct page *page) {}
static inline void pgalloc_tag_add(struct page *page, struct task_struct *task,
unsigned int nr) {}
static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {}
-static inline void pgalloc_tag_split(struct page *page, unsigned int nr) {}
static inline struct alloc_tag *pgalloc_tag_get(struct page *page) { return NULL; }
static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) {}
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0993dfe9ae94..aa8a4c938ba9 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3244,7 +3244,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
/* Caller disabled irqs, so they are still disabled here */
split_page_owner(head, order, new_order);
- pgalloc_tag_split(head, 1 << order);
+ pgalloc_tag_split(folio, order, new_order);
/* See comment in __split_huge_page_tail() */
if (folio_test_anon(folio)) {
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 3faf5aad142d..a8624c07d8bf 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3778,7 +3778,7 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst,
list_del(&folio->lru);
split_page_owner(&folio->page, huge_page_order(src), huge_page_order(dst));
- pgalloc_tag_split(&folio->page, 1 << huge_page_order(src));
+ pgalloc_tag_split(folio, huge_page_order(src), huge_page_order(dst));
for (i = 0; i < pages_per_huge_page(src); i += pages_per_huge_page(dst)) {
struct page *page = folio_page(folio, i);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index c242d61fc4fd..13ce8e8899ed 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2822,7 +2822,7 @@ void split_page(struct page *page, unsigned int order)
for (i = 1; i < (1 << order); i++)
set_page_refcounted(page + i);
split_page_owner(page, order, 0);
- pgalloc_tag_split(page, 1 << order);
+ pgalloc_tag_split(page_folio(page), order, 0);
split_page_memcg(page, order, 0);
}
EXPORT_SYMBOL_GPL(split_page);
@@ -5020,7 +5020,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,
struct page *last = page + nr;
split_page_owner(page, order, 0);
- pgalloc_tag_split(page, 1 << order);
+ pgalloc_tag_split(page_folio(page), order, 0);
split_page_memcg(page, order, 0);
while (page < --last)
set_page_refcounted(last);
--
2.46.0.469.g59c65b2a67-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy()
2024-09-03 21:36 [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Yu Zhao
2024-09-03 21:36 ` [PATCH mm-unstable v1 2/3] mm/codetag: fix pgalloc_tag_split() Yu Zhao
@ 2024-09-03 21:36 ` Yu Zhao
2024-09-05 23:25 ` Andrew Morton
2024-09-06 2:41 ` [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Suren Baghdasaryan
2024-09-06 2:43 ` Muchun Song
3 siblings, 1 reply; 9+ messages in thread
From: Yu Zhao @ 2024-09-03 21:36 UTC (permalink / raw)
To: Andrew Morton, Kent Overstreet, Suren Baghdasaryan
Cc: Muchun Song, linux-mm, linux-kernel, Yu Zhao
Add pgalloc_tag_copy() to transfer the codetag from the old folio to
the new one during migration. This makes original allocation sites
persist cross migration rather than lump into compaction_alloc, e.g.,
# echo 1 >/proc/sys/vm/compact_memory
# grep compaction_alloc /proc/allocinfo
Before this patch:
132968448 32463 mm/compaction.c:1880 func:compaction_alloc
After this patch:
0 0 mm/compaction.c:1880 func:compaction_alloc
Signed-off-by: Yu Zhao <yuzhao@google.com>
---
include/linux/alloc_tag.h | 24 ++++++++++--------------
include/linux/mm.h | 25 +++++++++++++++++++++++++
mm/migrate.c | 1 +
3 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h
index 896491d9ebe8..1f0a9ff23a2c 100644
--- a/include/linux/alloc_tag.h
+++ b/include/linux/alloc_tag.h
@@ -137,7 +137,16 @@ static inline void alloc_tag_sub_check(union codetag_ref *ref) {}
/* Caller should verify both ref and tag to be valid */
static inline void __alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag)
{
+ alloc_tag_add_check(ref, tag);
+ if (!ref || !tag)
+ return;
+
ref->ct = &tag->ct;
+}
+
+static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag)
+{
+ __alloc_tag_ref_set(ref, tag);
/*
* We need in increment the call counter every time we have a new
* allocation or when we split a large allocation into smaller ones.
@@ -147,22 +156,9 @@ static inline void __alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag
this_cpu_inc(tag->counters->calls);
}
-static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag)
-{
- alloc_tag_add_check(ref, tag);
- if (!ref || !tag)
- return;
-
- __alloc_tag_ref_set(ref, tag);
-}
-
static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes)
{
- alloc_tag_add_check(ref, tag);
- if (!ref || !tag)
- return;
-
- __alloc_tag_ref_set(ref, tag);
+ alloc_tag_ref_set(ref, tag);
this_cpu_add(tag->counters->bytes, bytes);
}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index a07e93adb8ad..1b98d843a5e9 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4161,10 +4161,35 @@ static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new
}
}
}
+
+static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
+{
+ struct alloc_tag *tag;
+ union codetag_ref *ref;
+
+ tag = pgalloc_tag_get(&old->page);
+ if (!tag)
+ return;
+
+ ref = get_page_tag_ref(&new->page);
+ if (!ref)
+ return;
+
+ /* Clear the old ref to the original allocation site. */
+ clear_page_tag_ref(&old->page);
+ /* Decrement the counters of the tag on get_new_folio. */
+ alloc_tag_sub(ref, folio_nr_pages(new));
+ __alloc_tag_ref_set(ref, tag);
+ put_page_tag_ref(ref);
+}
#else /* !CONFIG_MEM_ALLOC_PROFILING */
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
{
}
+
+static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
+{
+}
#endif /* CONFIG_MEM_ALLOC_PROFILING */
#endif /* _LINUX_MM_H */
diff --git a/mm/migrate.c b/mm/migrate.c
index 35cc9d35064b..0b24021d5fee 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -750,6 +750,7 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)
folio_set_readahead(newfolio);
folio_copy_owner(newfolio, folio);
+ pgalloc_tag_copy(newfolio, folio);
mem_cgroup_migrate(folio, newfolio);
}
--
2.46.0.469.g59c65b2a67-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy()
2024-09-03 21:36 ` [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy() Yu Zhao
@ 2024-09-05 23:25 ` Andrew Morton
2024-09-06 0:03 ` Suren Baghdasaryan
0 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2024-09-05 23:25 UTC (permalink / raw)
To: Yu Zhao
Cc: Kent Overstreet, Suren Baghdasaryan, Muchun Song, linux-mm, linux-kernel
On Tue, 3 Sep 2024 15:36:49 -0600 Yu Zhao <yuzhao@google.com> wrote:
> Add pgalloc_tag_copy() to transfer the codetag from the old folio to
> the new one during migration. This makes original allocation sites
> persist cross migration rather than lump into compaction_alloc, e.g.,
> # echo 1 >/proc/sys/vm/compact_memory
> # grep compaction_alloc /proc/allocinfo
>
> Before this patch:
> 132968448 32463 mm/compaction.c:1880 func:compaction_alloc
>
> After this patch:
> 0 0 mm/compaction.c:1880 func:compaction_alloc
>
I'm thinking that [2/3] should be backported?
And possibly this one, but for that we should identify a Fixes:, please.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy()
2024-09-05 23:25 ` Andrew Morton
@ 2024-09-06 0:03 ` Suren Baghdasaryan
2024-09-06 3:27 ` Suren Baghdasaryan
0 siblings, 1 reply; 9+ messages in thread
From: Suren Baghdasaryan @ 2024-09-06 0:03 UTC (permalink / raw)
To: Andrew Morton
Cc: Yu Zhao, Kent Overstreet, Muchun Song, linux-mm, linux-kernel
On Thu, Sep 5, 2024 at 4:25 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Tue, 3 Sep 2024 15:36:49 -0600 Yu Zhao <yuzhao@google.com> wrote:
>
> > Add pgalloc_tag_copy() to transfer the codetag from the old folio to
> > the new one during migration. This makes original allocation sites
> > persist cross migration rather than lump into compaction_alloc, e.g.,
> > # echo 1 >/proc/sys/vm/compact_memory
> > # grep compaction_alloc /proc/allocinfo
> >
> > Before this patch:
> > 132968448 32463 mm/compaction.c:1880 func:compaction_alloc
> >
> > After this patch:
> > 0 0 mm/compaction.c:1880 func:compaction_alloc
> >
>
> I'm thinking that [2/3] should be backported?
Yes, should be CC'ed to stable #6.10
>
> And possibly this one, but for that we should identify a Fixes:, please.
I think for this one Fixes: dcfe378c81f7 ("lib: introduce support for
page allocation tagging") would be the most appropriate.
I'll review all 3 fixes later today.
Thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo
2024-09-03 21:36 [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Yu Zhao
2024-09-03 21:36 ` [PATCH mm-unstable v1 2/3] mm/codetag: fix pgalloc_tag_split() Yu Zhao
2024-09-03 21:36 ` [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy() Yu Zhao
@ 2024-09-06 2:41 ` Suren Baghdasaryan
2024-09-06 2:43 ` Muchun Song
3 siblings, 0 replies; 9+ messages in thread
From: Suren Baghdasaryan @ 2024-09-06 2:41 UTC (permalink / raw)
To: Yu Zhao
Cc: Andrew Morton, Kent Overstreet, Muchun Song, linux-mm, linux-kernel
On Tue, Sep 3, 2024 at 2:36 PM Yu Zhao <yuzhao@google.com> wrote:
>
> Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
> Signed-off-by: Yu Zhao <yuzhao@google.com>
Acked-by: Suren Baghdasaryan <surenb@google.com>
> ---
> include/linux/alloc_tag.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h
> index 8c61ccd161ba..896491d9ebe8 100644
> --- a/include/linux/alloc_tag.h
> +++ b/include/linux/alloc_tag.h
> @@ -70,7 +70,7 @@ static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct)
> /*
> * When percpu variables are required to be defined as weak, static percpu
> * variables can't be used inside a function (see comments for DECLARE_PER_CPU_SECTION).
> - * Instead we will accound all module allocations to a single counter.
> + * Instead we will account all module allocations to a single counter.
> */
> DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag);
>
> --
> 2.46.0.469.g59c65b2a67-goog
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo
2024-09-03 21:36 [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Yu Zhao
` (2 preceding siblings ...)
2024-09-06 2:41 ` [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Suren Baghdasaryan
@ 2024-09-06 2:43 ` Muchun Song
3 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2024-09-06 2:43 UTC (permalink / raw)
To: Yu Zhao
Cc: Andrew Morton, Kent Overstreet, Suren Baghdasaryan,
Linux Memory Management List, LKML
> On Sep 4, 2024, at 05:36, Yu Zhao <yuzhao@google.com> wrote:
>
> Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
> Signed-off-by: Yu Zhao <yuzhao@google.com>
Acked-by: Muchun Song <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH mm-unstable v1 2/3] mm/codetag: fix pgalloc_tag_split()
2024-09-03 21:36 ` [PATCH mm-unstable v1 2/3] mm/codetag: fix pgalloc_tag_split() Yu Zhao
@ 2024-09-06 3:00 ` Suren Baghdasaryan
0 siblings, 0 replies; 9+ messages in thread
From: Suren Baghdasaryan @ 2024-09-06 3:00 UTC (permalink / raw)
To: Yu Zhao
Cc: Andrew Morton, Kent Overstreet, Muchun Song, linux-mm, linux-kernel
On Tue, Sep 3, 2024 at 2:36 PM Yu Zhao <yuzhao@google.com> wrote:
>
> Only tag the new head pages when splitting one large folio to multiple
> ones of a lower order. Tagging tail pages can cause imbalanced "calls"
> counters, since only head pages are untagged by pgalloc_tag_sub() and
> reference counts on tail pages are leaked, e.g.,
> # echo 2048kB >/sys/kernel/mm/hugepages/hugepages-1048576kB/demote_size
> # echo 700 >/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
> # time echo 700 >/sys/kernel/mm/hugepages/hugepages-1048576kB/demote
> # grep alloc_gigantic_folio /proc/allocinfo
>
> Before this patch:
> 0 549427200 mm/hugetlb.c:1549 func:alloc_gigantic_folio
>
> real 0m2.057s
> user 0m0.000s
> sys 0m2.051s
>
> After this patch:
> 0 0 mm/hugetlb.c:1549 func:alloc_gigantic_folio
>
> real 0m1.711s
> user 0m0.000s
> sys 0m1.704s
>
> Not tagging tail pages also improves the splitting time, e.g., by
> about 15% when demoting 1GB hugeTLB folios to 2MB ones, as shown
> above.
>
> Fixes: be25d1d4e822 ("mm: create new codetag references during page splitting")
> Signed-off-by: Yu Zhao <yuzhao@google.com>
> ---
> include/linux/mm.h | 30 ++++++++++++++++++++++++++++++
> include/linux/pgalloc_tag.h | 31 -------------------------------
> mm/huge_memory.c | 2 +-
> mm/hugetlb.c | 2 +-
> mm/page_alloc.c | 4 ++--
> 5 files changed, 34 insertions(+), 35 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index b31d4bdd65ad..a07e93adb8ad 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -4137,4 +4137,34 @@ void vma_pgtable_walk_end(struct vm_area_struct *vma);
>
> int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *size);
>
> +#ifdef CONFIG_MEM_ALLOC_PROFILING
> +static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
> +{
> + int i;
> + struct alloc_tag *tag;
> + unsigned int nr_pages = 1 << new_order;
> +
> + if (!mem_alloc_profiling_enabled())
> + return;
> +
> + tag = pgalloc_tag_get(&folio->page);
> + if (!tag)
> + return;
> +
> + for (i = nr_pages; i < (1 << old_order); i += nr_pages) {
> + union codetag_ref *ref = get_page_tag_ref(folio_page(folio, i));
> +
> + if (ref) {
> + /* Set new reference to point to the original tag */
> + alloc_tag_ref_set(ref, tag);
> + put_page_tag_ref(ref);
> + }
> + }
> +}
> +#else /* !CONFIG_MEM_ALLOC_PROFILING */
> +static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
> +{
> +}
> +#endif /* CONFIG_MEM_ALLOC_PROFILING */
> +
> #endif /* _LINUX_MM_H */
> diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h
> index 207f0c83c8e9..59a3deb792a8 100644
> --- a/include/linux/pgalloc_tag.h
> +++ b/include/linux/pgalloc_tag.h
> @@ -80,36 +80,6 @@ static inline void pgalloc_tag_sub(struct page *page, unsigned int nr)
> }
> }
>
> -static inline void pgalloc_tag_split(struct page *page, unsigned int nr)
> -{
> - int i;
> - struct page_ext *first_page_ext;
> - struct page_ext *page_ext;
> - union codetag_ref *ref;
> - struct alloc_tag *tag;
> -
> - if (!mem_alloc_profiling_enabled())
> - return;
> -
> - first_page_ext = page_ext = page_ext_get(page);
> - if (unlikely(!page_ext))
> - return;
> -
> - ref = codetag_ref_from_page_ext(page_ext);
> - if (!ref->ct)
> - goto out;
> -
> - tag = ct_to_alloc_tag(ref->ct);
> - page_ext = page_ext_next(page_ext);
> - for (i = 1; i < nr; i++) {
> - /* Set new reference to point to the original tag */
> - alloc_tag_ref_set(codetag_ref_from_page_ext(page_ext), tag);
> - page_ext = page_ext_next(page_ext);
> - }
> -out:
> - page_ext_put(first_page_ext);
> -}
> -
> static inline struct alloc_tag *pgalloc_tag_get(struct page *page)
> {
> struct alloc_tag *tag = NULL;
> @@ -142,7 +112,6 @@ static inline void clear_page_tag_ref(struct page *page) {}
> static inline void pgalloc_tag_add(struct page *page, struct task_struct *task,
> unsigned int nr) {}
> static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {}
> -static inline void pgalloc_tag_split(struct page *page, unsigned int nr) {}
> static inline struct alloc_tag *pgalloc_tag_get(struct page *page) { return NULL; }
> static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) {}
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 0993dfe9ae94..aa8a4c938ba9 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -3244,7 +3244,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
> /* Caller disabled irqs, so they are still disabled here */
>
> split_page_owner(head, order, new_order);
> - pgalloc_tag_split(head, 1 << order);
> + pgalloc_tag_split(folio, order, new_order);
Looks like here and in the next diff you are fixing an additional bug.
I was assuming that we are always splitting into order-0 pages, which
is not the case anymore. It's worth mentioning that in the changelog.
With that added:
Acked-by: Suren Baghdasaryan <surenb@google.com>
>
> /* See comment in __split_huge_page_tail() */
> if (folio_test_anon(folio)) {
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 3faf5aad142d..a8624c07d8bf 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -3778,7 +3778,7 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst,
> list_del(&folio->lru);
>
> split_page_owner(&folio->page, huge_page_order(src), huge_page_order(dst));
> - pgalloc_tag_split(&folio->page, 1 << huge_page_order(src));
> + pgalloc_tag_split(folio, huge_page_order(src), huge_page_order(dst));
>
> for (i = 0; i < pages_per_huge_page(src); i += pages_per_huge_page(dst)) {
> struct page *page = folio_page(folio, i);
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index c242d61fc4fd..13ce8e8899ed 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2822,7 +2822,7 @@ void split_page(struct page *page, unsigned int order)
> for (i = 1; i < (1 << order); i++)
> set_page_refcounted(page + i);
> split_page_owner(page, order, 0);
> - pgalloc_tag_split(page, 1 << order);
> + pgalloc_tag_split(page_folio(page), order, 0);
> split_page_memcg(page, order, 0);
> }
> EXPORT_SYMBOL_GPL(split_page);
> @@ -5020,7 +5020,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,
> struct page *last = page + nr;
>
> split_page_owner(page, order, 0);
> - pgalloc_tag_split(page, 1 << order);
> + pgalloc_tag_split(page_folio(page), order, 0);
> split_page_memcg(page, order, 0);
> while (page < --last)
> set_page_refcounted(last);
> --
> 2.46.0.469.g59c65b2a67-goog
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy()
2024-09-06 0:03 ` Suren Baghdasaryan
@ 2024-09-06 3:27 ` Suren Baghdasaryan
0 siblings, 0 replies; 9+ messages in thread
From: Suren Baghdasaryan @ 2024-09-06 3:27 UTC (permalink / raw)
To: Andrew Morton
Cc: Yu Zhao, Kent Overstreet, Muchun Song, linux-mm, linux-kernel
On Thu, Sep 5, 2024 at 5:03 PM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Thu, Sep 5, 2024 at 4:25 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Tue, 3 Sep 2024 15:36:49 -0600 Yu Zhao <yuzhao@google.com> wrote:
> >
> > > Add pgalloc_tag_copy() to transfer the codetag from the old folio to
> > > the new one during migration. This makes original allocation sites
> > > persist cross migration rather than lump into compaction_alloc, e.g.,
> > > # echo 1 >/proc/sys/vm/compact_memory
> > > # grep compaction_alloc /proc/allocinfo
> > >
> > > Before this patch:
> > > 132968448 32463 mm/compaction.c:1880 func:compaction_alloc
> > >
> > > After this patch:
> > > 0 0 mm/compaction.c:1880 func:compaction_alloc
> > >
> >
> > I'm thinking that [2/3] should be backported?
>
> Yes, should be CC'ed to stable #6.10
>
> >
> > And possibly this one, but for that we should identify a Fixes:, please.
>
> I think for this one Fixes: dcfe378c81f7 ("lib: introduce support for
> page allocation tagging") would be the most appropriate.
>
> I'll review all 3 fixes later today.
Looks good to me. Both [2/3] and [3/3] should be sent to stable 6.10.
Acked-by: Suren Baghdasaryan <surenb@google.com>
> Thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-09-06 3:27 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-03 21:36 [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Yu Zhao
2024-09-03 21:36 ` [PATCH mm-unstable v1 2/3] mm/codetag: fix pgalloc_tag_split() Yu Zhao
2024-09-06 3:00 ` Suren Baghdasaryan
2024-09-03 21:36 ` [PATCH mm-unstable v1 3/3] mm/codetag: add pgalloc_tag_copy() Yu Zhao
2024-09-05 23:25 ` Andrew Morton
2024-09-06 0:03 ` Suren Baghdasaryan
2024-09-06 3:27 ` Suren Baghdasaryan
2024-09-06 2:41 ` [PATCH mm-unstable v1 1/3] mm/codetag: fix a typo Suren Baghdasaryan
2024-09-06 2:43 ` Muchun Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox