* [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function
@ 2024-08-13 15:07 Suren Baghdasaryan
2024-08-13 15:07 ` [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged Suren Baghdasaryan
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Suren Baghdasaryan @ 2024-08-13 15:07 UTC (permalink / raw)
To: akpm
Cc: kent.overstreet, david, vbabka, pasha.tatashin, souravpanda,
keescook, linux-kernel, linux-mm, surenb, stable
In several cases we are freeing pages which were not allocated using
common page allocators. For such cases, in order to keep allocation
accounting correct, we should clear the page tag to indicate that the
page being freed is expected to not have a valid allocation tag.
Introduce clear_page_tag_ref() helper function to be used for this.
Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Cc: stable@vger.kernel.org # v6.10
---
include/linux/pgalloc_tag.h | 13 +++++++++++++
mm/mm_init.c | 10 +---------
mm/page_alloc.c | 9 +--------
3 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h
index 18cd0c0c73d9..207f0c83c8e9 100644
--- a/include/linux/pgalloc_tag.h
+++ b/include/linux/pgalloc_tag.h
@@ -43,6 +43,18 @@ static inline void put_page_tag_ref(union codetag_ref *ref)
page_ext_put(page_ext_from_codetag_ref(ref));
}
+static inline void clear_page_tag_ref(struct page *page)
+{
+ if (mem_alloc_profiling_enabled()) {
+ union codetag_ref *ref = get_page_tag_ref(page);
+
+ if (ref) {
+ set_codetag_empty(ref);
+ put_page_tag_ref(ref);
+ }
+ }
+}
+
static inline void pgalloc_tag_add(struct page *page, struct task_struct *task,
unsigned int nr)
{
@@ -126,6 +138,7 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
static inline union codetag_ref *get_page_tag_ref(struct page *page) { return NULL; }
static inline void put_page_tag_ref(union codetag_ref *ref) {}
+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) {}
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 75c3bd42799b..907c46b0773f 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -2460,15 +2460,7 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn,
}
/* pages were reserved and not allocated */
- if (mem_alloc_profiling_enabled()) {
- union codetag_ref *ref = get_page_tag_ref(page);
-
- if (ref) {
- set_codetag_empty(ref);
- put_page_tag_ref(ref);
- }
- }
-
+ clear_page_tag_ref(page);
__free_pages_core(page, order, MEMINIT_EARLY);
}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 28f80daf5c04..3f80e94a0b66 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5821,14 +5821,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
void free_reserved_page(struct page *page)
{
- if (mem_alloc_profiling_enabled()) {
- union codetag_ref *ref = get_page_tag_ref(page);
-
- if (ref) {
- set_codetag_empty(ref);
- put_page_tag_ref(ref);
- }
- }
+ clear_page_tag_ref(page);
ClearPageReserved(page);
init_page_count(page);
__free_page(page);
base-commit: d74da846046aeec9333e802f5918bd3261fb5509
--
2.46.0.76.ge559c4bf1a-goog
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
2024-08-13 15:07 [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function Suren Baghdasaryan
@ 2024-08-13 15:07 ` Suren Baghdasaryan
2024-08-13 15:09 ` David Hildenbrand
2024-08-13 18:40 ` Andrew Morton
2024-08-13 15:08 ` [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function David Hildenbrand
2024-08-14 18:42 ` Pasha Tatashin
2 siblings, 2 replies; 8+ messages in thread
From: Suren Baghdasaryan @ 2024-08-13 15:07 UTC (permalink / raw)
To: akpm
Cc: kent.overstreet, david, vbabka, pasha.tatashin, souravpanda,
keescook, linux-kernel, linux-mm, surenb, stable
During CMA activation, pages in CMA area are prepared and then freed
without being allocated. This triggers warnings when memory allocation
debug config (CONFIG_MEM_ALLOC_PROFILING_DEBUG) is enabled. Fix this
by marking these pages not tagged before freeing them.
Fixes: d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Cc: stable@vger.kernel.org # v6.10
---
Changes since v2 [1]:
- Add and use clear_page_tag_ref helper, per David Hildenbrand
https://lore.kernel.org/all/20240812192428.151825-1-surenb@google.com/
mm/mm_init.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 907c46b0773f..13c4060bb01a 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -2245,6 +2245,8 @@ void __init init_cma_reserved_pageblock(struct page *page)
set_pageblock_migratetype(page, MIGRATE_CMA);
set_page_refcounted(page);
+ /* pages were reserved and not allocated */
+ clear_page_tag_ref(page);
__free_pages(page, pageblock_order);
adjust_managed_page_count(page, pageblock_nr_pages);
--
2.46.0.76.ge559c4bf1a-goog
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
2024-08-13 15:07 ` [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged Suren Baghdasaryan
@ 2024-08-13 15:09 ` David Hildenbrand
2024-08-13 16:06 ` Suren Baghdasaryan
2024-08-13 18:40 ` Andrew Morton
1 sibling, 1 reply; 8+ messages in thread
From: David Hildenbrand @ 2024-08-13 15:09 UTC (permalink / raw)
To: Suren Baghdasaryan, akpm
Cc: kent.overstreet, vbabka, pasha.tatashin, souravpanda, keescook,
linux-kernel, linux-mm, stable
On 13.08.24 17:07, Suren Baghdasaryan wrote:
> During CMA activation, pages in CMA area are prepared and then freed
> without being allocated. This triggers warnings when memory allocation
> debug config (CONFIG_MEM_ALLOC_PROFILING_DEBUG) is enabled. Fix this
> by marking these pages not tagged before freeing them.
>
> Fixes: d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty")
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Cc: stable@vger.kernel.org # v6.10
> ---
> Changes since v2 [1]:
> - Add and use clear_page_tag_ref helper, per David Hildenbrand
>
> https://lore.kernel.org/all/20240812192428.151825-1-surenb@google.com/
>
> mm/mm_init.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index 907c46b0773f..13c4060bb01a 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -2245,6 +2245,8 @@ void __init init_cma_reserved_pageblock(struct page *page)
>
> set_pageblock_migratetype(page, MIGRATE_CMA);
> set_page_refcounted(page);
> + /* pages were reserved and not allocated */
> + clear_page_tag_ref(page);
> __free_pages(page, pageblock_order);
>
> adjust_managed_page_count(page, pageblock_nr_pages);
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
2024-08-13 15:09 ` David Hildenbrand
@ 2024-08-13 16:06 ` Suren Baghdasaryan
0 siblings, 0 replies; 8+ messages in thread
From: Suren Baghdasaryan @ 2024-08-13 16:06 UTC (permalink / raw)
To: David Hildenbrand
Cc: akpm, kent.overstreet, vbabka, pasha.tatashin, souravpanda,
keescook, linux-kernel, linux-mm, stable
On Tue, Aug 13, 2024 at 8:09 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 13.08.24 17:07, Suren Baghdasaryan wrote:
> > During CMA activation, pages in CMA area are prepared and then freed
> > without being allocated. This triggers warnings when memory allocation
> > debug config (CONFIG_MEM_ALLOC_PROFILING_DEBUG) is enabled. Fix this
> > by marking these pages not tagged before freeing them.
> >
> > Fixes: d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty")
> > Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> > Cc: stable@vger.kernel.org # v6.10
> > ---
> > Changes since v2 [1]:
> > - Add and use clear_page_tag_ref helper, per David Hildenbrand
> >
> > https://lore.kernel.org/all/20240812192428.151825-1-surenb@google.com/
> >
> > mm/mm_init.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/mm/mm_init.c b/mm/mm_init.c
> > index 907c46b0773f..13c4060bb01a 100644
> > --- a/mm/mm_init.c
> > +++ b/mm/mm_init.c
> > @@ -2245,6 +2245,8 @@ void __init init_cma_reserved_pageblock(struct page *page)
> >
> > set_pageblock_migratetype(page, MIGRATE_CMA);
> > set_page_refcounted(page);
> > + /* pages were reserved and not allocated */
> > + clear_page_tag_ref(page);
> > __free_pages(page, pageblock_order);
> >
> > adjust_managed_page_count(page, pageblock_nr_pages);
>
> Acked-by: David Hildenbrand <david@redhat.com>
Thanks!
>
> --
> Cheers,
>
> David / dhildenb
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
2024-08-13 15:07 ` [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged Suren Baghdasaryan
2024-08-13 15:09 ` David Hildenbrand
@ 2024-08-13 18:40 ` Andrew Morton
2024-08-13 19:37 ` Suren Baghdasaryan
1 sibling, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2024-08-13 18:40 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: kent.overstreet, david, vbabka, pasha.tatashin, souravpanda,
keescook, linux-kernel, linux-mm, stable
On Tue, 13 Aug 2024 08:07:57 -0700 Suren Baghdasaryan <surenb@google.com> wrote:
> Fixes: d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty")
I copied this into [1/2] so everything lands nicely.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
2024-08-13 18:40 ` Andrew Morton
@ 2024-08-13 19:37 ` Suren Baghdasaryan
0 siblings, 0 replies; 8+ messages in thread
From: Suren Baghdasaryan @ 2024-08-13 19:37 UTC (permalink / raw)
To: Andrew Morton
Cc: kent.overstreet, david, vbabka, pasha.tatashin, souravpanda,
keescook, linux-kernel, linux-mm, stable
On Tue, Aug 13, 2024 at 11:40 AM Andrew Morton
<akpm@linux-foundation.org> wrote:
>
> On Tue, 13 Aug 2024 08:07:57 -0700 Suren Baghdasaryan <surenb@google.com> wrote:
>
> > Fixes: d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty")
>
> I copied this into [1/2] so everything lands nicely.
Yeah, technically this does not "fix" that patch but since it's needed
for the next patch I think that's fine.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function
2024-08-13 15:07 [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function Suren Baghdasaryan
2024-08-13 15:07 ` [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged Suren Baghdasaryan
@ 2024-08-13 15:08 ` David Hildenbrand
2024-08-14 18:42 ` Pasha Tatashin
2 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand @ 2024-08-13 15:08 UTC (permalink / raw)
To: Suren Baghdasaryan, akpm
Cc: kent.overstreet, vbabka, pasha.tatashin, souravpanda, keescook,
linux-kernel, linux-mm, stable
On 13.08.24 17:07, Suren Baghdasaryan wrote:
> In several cases we are freeing pages which were not allocated using
> common page allocators. For such cases, in order to keep allocation
> accounting correct, we should clear the page tag to indicate that the
> page being freed is expected to not have a valid allocation tag.
> Introduce clear_page_tag_ref() helper function to be used for this.
>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Cc: stable@vger.kernel.org # v6.10
> ---
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function
2024-08-13 15:07 [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function Suren Baghdasaryan
2024-08-13 15:07 ` [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged Suren Baghdasaryan
2024-08-13 15:08 ` [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function David Hildenbrand
@ 2024-08-14 18:42 ` Pasha Tatashin
2 siblings, 0 replies; 8+ messages in thread
From: Pasha Tatashin @ 2024-08-14 18:42 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: akpm, kent.overstreet, david, vbabka, souravpanda, keescook,
linux-kernel, linux-mm, stable
On Tue, Aug 13, 2024 at 3:08 PM Suren Baghdasaryan <surenb@google.com> wrote:
>
> In several cases we are freeing pages which were not allocated using
> common page allocators. For such cases, in order to keep allocation
> accounting correct, we should clear the page tag to indicate that the
> page being freed is expected to not have a valid allocation tag.
> Introduce clear_page_tag_ref() helper function to be used for this.
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-08-14 18:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-13 15:07 [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function Suren Baghdasaryan
2024-08-13 15:07 ` [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged Suren Baghdasaryan
2024-08-13 15:09 ` David Hildenbrand
2024-08-13 16:06 ` Suren Baghdasaryan
2024-08-13 18:40 ` Andrew Morton
2024-08-13 19:37 ` Suren Baghdasaryan
2024-08-13 15:08 ` [PATCH v3 1/2] alloc_tag: introduce clear_page_tag_ref() helper function David Hildenbrand
2024-08-14 18:42 ` Pasha Tatashin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox