alloc_tag: introduce clear_page_tag_ref() helper function
Subsystems (5)
Suren Baghdasaryan
maintainerPATCH v3 1/2 alloc_tag: introduce clear_page_tag_ref() helper function
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.
--- include/linux/pgalloc_tag.h | 13 +++++++++++++ mm/mm_init.c | 10 +--------- mm/page_alloc.c | 9 +-------- 3 files changed, 15 insertions(+), 17 deletions(-)
include/linux/pgalloc_tag.h +13 -0
@@ -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) {}
mm/mm_init.c +1 -9
@@ -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 ); }
mm/page_alloc.c +1 -8
@@ -5821,14 +5821,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const charvoid 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
Signature · 1 line
2.46.0.76.ge559c4bf1a-goog
Suren Baghdasaryan
maintainerPATCH v3 2/2 alloc_tag: mark pages reserved during CMA activation as not tagged
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.
---
Changes since v2 [1]:
- Add and use clear_page_tag_ref helper, per David Hildenbrand
https://lore.kernel.org/all/[email protected]/
mm/mm_init.c | 2 ++ 1 file changed, 2 insertions(+)
mm/mm_init.c +2 -0
@@ -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);
Signature · 1 line
2.46.0.76.ge559c4bf1a-goog
Re: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
Quoted 22 lines · Suren Baghdasaryan
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 <[email protected]>Cc [email protected] # v6.10---
Changes since v2 [1]:
- Add and useclear_page_tag_refhelper, per David Hildenbrandhttps://lore.kernel.org/all/[email protected]/
mm/mm_init.c | 2 ++ 1 file changed, 2 insertions(+)mm/mm_init.c +0
-0
mm/mm_init.c void __init init_cma_reserved_pageblock(struct page *page) · line 2252
Quoted 8 lines
mm/mm_init.c +2
-0@@ -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);
Signature · 3 lines
Cheers, David / dhildenb
Suren Baghdasaryan
maintainerRe: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
Quoted 31 lines · David Hildenbrand
Quoted 29 lines · Suren Baghdasaryan
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 <[email protected]>Cc [email protected] # v6.10---
Changes since v2 [1]:
- Add and useclear_page_tag_refhelper, per David Hildenbrandhttps://lore.kernel.org/all/[email protected]/
mm/mm_init.c | 2 ++ 1 file changed, 2 insertions(+)mm/mm_init.c +2
-0@@ -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);
Quoted 3 lines
mm/mm_init.c void __init init_cma_reserved_pageblock(struct page *page) · line 2252
Quoted 1 line
mm/mm_init.c +0
-0adjust_managed_page_count (page, pageblock_nr_pages);
Thanks!
Quoted 6 lines
--
Cheers,David / dhildenb
Andrew Morton
maintainerRe: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
In reply to Suren BaghdasaryanQuoted 1 line · On Tue, 13 Aug 2024 08:07:57 -0700 Suren Baghdasaryan <[email protected]> wrote:
Fixes d224eb0287fb ("codetag: debug: mark codetags for reserved pages as empty")
I copied this into [1/2] so everything lands nicely.
Suren Baghdasaryan
maintainerRe: [PATCH v3 2/2] alloc_tag: mark pages reserved during CMA activation as not tagged
Quoted 6 lines · Andrew Morton
Quoted 1 line · On Tue, 13 Aug 2024 08:07:57 -0700 Suren Baghdasaryan <[email protected]> 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.
Quoted 10 lines · Suren Baghdasaryan
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 <[email protected]>Signed-off-by Suren Baghdasaryan <[email protected]>Cc [email protected] # v6.10---
Signature · 3 lines
Cheers, David / dhildenb
Quoted 6 lines · Suren Baghdasaryan
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.