page allocation tag compression
Subsystems (12)
Suren Baghdasaryan
maintainerv3 cover page allocation tag compression
This patchset implements several improvements:
1. Gracefully handles module unloading while there are used allocations allocated from that module;
2. Provides an option to store page allocation tag references in the page flags, removing dependency on page extensions and eliminating the memory overhead from storing page allocation references (~0.2% of total system memory). This also improves page allocation performance when CONFIG_MEM_ALLOC_PROFILING is enabled by eliminating page extension lookup. Page allocation performance overhead is reduced from 41% to 5.5%.
Patch #1 introduces mas_for_each_rev() helper function.
Patch #2 copies module tags into virtually contiguous memory which serves two purposes:
- Lets us deal with the situation when module is unloaded while there are still live allocations from that module. Since we are using a copy version of the tags we can safely unload the module. Space and gaps in this contiguous memory are managed using a maple tree.
- Enables simple indexing of the tags in the later patches.
Patch #3 changes the way we allocate virtually contiguous memory for module tags to reserve only vitrual area and populate physical pages only as needed at module load time.
Patch #4 abstracts page allocation tag reference to simplify later changes.
Patch #5 adds a config to store page allocation tag references inside page flags if they fit. If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning.
Patchset applies to mm-unstable.
Changes since v2 [1]:
- removed extra configs, leaving only CONFIG_PGALLOC_TAG_USE_PAGEFLAGS yes/no option, per Andrew Morton
- populate physical memory for module tags only as needed, per Pasha Tatashin
[1] https://lore.kernel.org/all/[email protected]/
Suren Baghdasaryan (5):
maple_tree: add mas_for_each_rev() helper
alloc_tag: load module tags into separate contiguous memory
alloc_tag: populate memory for module tags as needed
alloc_tag: introduce pgalloc_tag_ref to abstract page tag references
alloc_tag: config to store page allocation tag refs in page flags
include/asm-generic/codetag.lds.h | 19 ++ include/linux/alloc_tag.h | 21 +- include/linux/codetag.h | 40 ++- include/linux/execmem.h | 11 + include/linux/maple_tree.h | 14 ++ include/linux/mm.h | 25 +- include/linux/page-flags-layout.h | 7 + include/linux/pgalloc_tag.h | 278 ++++++++++++++++++--- include/linux/vmalloc.h | 9 + kernel/module/main.c | 74 ++++-- lib/Kconfig.debug | 19 ++ lib/alloc_tag.c | 394 ++++++++++++++++++++++++++++-- lib/codetag.c | 104 +++++++- mm/execmem.c | 16 ++ mm/mm_init.c | 5 +- mm/vmalloc.c | 4 +- scripts/module.lds.S | 5 +- 17 files changed, 931 insertions(+), 114 deletions(-)
base-commit: 828d7267c42c2aab3877c08b4bb00b1e56769557
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Suren Baghdasaryan
maintainerPATCH v3 1/5 maple_tree: add mas_for_each_rev() helper
Add mas_for_each_rev() function to iterate maple tree nodes in reverse order.
--- include/linux/maple_tree.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/maple_tree.h +14 -0
@@ -592,6 +592,20 @@ static __always_inline void mas_reset(struct ma_state *mas)#define mas_for_each (__mas, __entry, __max) \ while (((__entry) = mas_find((__mas), (__max))) != NULL) +/** +* mas_for_each_rev() - Iterate over a range of the maple tree in reverse order. +* @__mas: Maple Tree operation state (maple_state) +* @__entry: Entry retrieved from the tree +* @__min: minimum index to retrieve from the tree +* +* When returned, mas->index and mas->last will hold the entire range for the +* entry. +* +* Note: may return the zero entry. +*/ +#define mas_for_each_rev (__mas, __entry, __min) \ + while (((__entry) = mas_find_rev((__mas), (__min))) != NULL) +#ifdef CONFIG_DEBUG_MAPLE_TREE enum mt_dump_format { mt_dump_dec,
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Re: [PATCH v3 1/5] maple_tree: add mas_for_each_rev() helper
Quoted 5 lines · Suren Baghdasaryan
Add
mas_for_each_rev()function to iterate maple tree nodes in reverse order.Suggested-by Liam R. Howlett <[email protected]>Signed-off-by Suren Baghdasaryan <[email protected]>
I am now sure I added a R-B in a reply to this :)
Quoted 32 lines
--- include/linux/maple_tree.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/maple_tree.h +14
-0@@ -592,6 +592,20 @@ static __always_inline void mas_reset(struct ma_state *mas)#define mas_for_each (__mas, __entry, __max) \ while (((__entry) = mas_find((__mas), (__max))) != NULL) +/** +* mas_for_each_rev() - Iterate over a range of the maple tree in reverse order. +* @__mas: Maple Tree operation state (maple_state) +* @__entry: Entry retrieved from the tree +* @__min: minimum index to retrieve from the tree +* +* When returned, mas->index and mas->last will hold the entire range for the +* entry. +* +* Note: may return the zero entry. +*/ +#define mas_for_each_rev (__mas, __entry, __min) \ + while (((__entry) = mas_find_rev((__mas), (__min))) != NULL) +#ifdef CONFIG_DEBUG_MAPLE_TREE enum mt_dump_format { mt_dump_dec,Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Suren Baghdasaryan
maintainerRe: [PATCH v3 1/5] maple_tree: add mas_for_each_rev() helper
Quoted 9 lines · Liam R. Howlett' via kernel-team
Quoted 5 lines · Suren Baghdasaryan
Add
mas_for_each_rev()function to iterate maple tree nodes in reverse order.Suggested-by Liam R. Howlett <[email protected]>Signed-off-by Suren Baghdasaryan <[email protected]>I am now sure I added a R-B in a reply to this :)
Sorry, I missed it. Will add in the next version. Thanks!
Quoted 36 lines
Quoted 31 lines
--- include/linux/maple_tree.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/maple_tree.h +14
-1@@ -592,6 +592,20 @@ static __always_inline void mas_reset(struct ma_state *mas)#define mas_for_each (__mas, __entry, __max) \ while (((__entry) = mas_find((__mas), (__max))) != NULL) +/** +* mas_for_each_rev() - Iterate over a range of the maple tree in reverse order. +* @__mas: Maple Tree operation state (maple_state) +* @__entry: Entry retrieved from the tree +* @__min: minimum index to retrieve from the tree +* +* When returned, mas->index and mas->last will hold the entire range for the +* entry. +* +* Note: may return the zero entry. +*/ +#define mas_for_each_rev (__mas, __entry, __min) \ + while (((__entry) = mas_find_rev((__mas), (__min))) != NULL) +#ifdef CONFIG_DEBUG_MAPLE_TREE enum mt_dump_format { mt_dump_dec, --Quoted 2 lines
2.47.0.rc1.288.g06298d1525-goog
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
Suren Baghdasaryan
maintainerPATCH v3 2/5 alloc_tag: load module tags into separate contiguous memory
In reply to Suren BaghdasaryanWhen a module gets unloaded there is a possibility that some of the allocations it made are still used and therefore the allocation tags corresponding to these allocations are still referenced. As such, the memory for these tags can't be freed. This is currently handled as an abnormal situation and module's data section is not being unloaded. To handle this situation without keeping module's data in memory, allow codetags with longer lifespan than the module to be loaded into their own separate memory. The in-use memory areas and gaps after module unloading in this separate memory are tracked using maple trees. Allocation tags arrange their separate memory so that it is virtually contiguous and that will allow simple allocation tag indexing later on in this patchset. The size of this virtually contiguous memory is set to store up to 100000 allocation tags.
--- include/asm-generic/codetag.lds.h | 19 +++ include/linux/alloc_tag.h | 13 +- include/linux/codetag.h | 37 ++++- kernel/module/main.c | 74 +++++---- lib/alloc_tag.c | 251 +++++++++++++++++++++++++++--- lib/codetag.c | 100 +++++++++++- scripts/module.lds.S | 5 +- 7 files changed, 438 insertions(+), 61 deletions(-)
include/asm-generic/codetag.lds.h +19 -0
@@ -11,4 +11,23 @@#define CODETAG_SECTIONS () \ SECTION_WITH_BOUNDARIES(alloc_tags) +/* +* Module codetags which aren't used after module unload, therefore have the +* same lifespan as the module and can be safely unloaded with the module. +*/ +#define MOD_CODETAG_SECTIONS () + +#define MOD_SEPARATE_CODETAG_SECTION (_name) \ + .codetag.##_name : { \ + SECTION_WITH_BOUNDARIES(_name) \ + } + +/* +* For codetags which might be used after module unload, therefore might stay +* longer in memory. Each such codetag type has its own section so that we can +* unload them individually once unused. +*/ +#define MOD_SEPARATE_CODETAG_SECTIONS () \ + MOD_SEPARATE_CODETAG_SECTION(alloc_tags) +#endif /* __ASM_GENERIC_CODETAG_LDS_H */
include/linux/alloc_tag.h +11 -2
@@ -30,6 +30,13 @@ struct alloc_tag {struct alloc_tag_counters __percpu *counters; }__aligned(8) ; +struct alloc_tag_module_section { +unsigned long start_addr; +unsigned long end_addr; +/* used size */ +unsigned long size; +}; +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG #define CODETAG_EMPTY ((void *)1)
@@ -54,6 +61,8 @@ static inline void set_codetag_empty(union codetag_ref *ref) {} #ifdef CONFIG_MEM_ALLOC_PROFILING +#define ALLOC_TAG_SECTION_NAME "alloc_tags" + struct codetag_bytes { struct codetag *ct; s64 bytes;
@@ -76,7 +85,7 @@ DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag);#define DEFINE_ALLOC_TAG (_alloc_tag) \ static struct alloc_tag _alloc_tag __used __aligned(8) \ - __section("alloc_tags") = { \ + __section(ALLOC_TAG_SECTION_NAME) = { \ .ct = CODE_TAG_INIT, \ .counters = &_shared_alloc_tag };
@@ -85,7 +94,7 @@ DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag);#define DEFINE_ALLOC_TAG (_alloc_tag) \ static DEFINE_PER_CPU(struct alloc_tag_counters, _alloc_tag_cntr); \ static struct alloc_tag _alloc_tag __used __aligned(8) \ - __section("alloc_tags") = { \ + __section(ALLOC_TAG_SECTION_NAME) = { \ .ct = CODE_TAG_INIT, \ .counters = &_alloc_tag_cntr };
include/linux/codetag.h +32 -5
@@ -35,8 +35,15 @@ struct codetag_type_desc {size_t tag_size;void (*module_load)(struct codetag_type *cttype,struct codetag_module *cmod); -bool (*module_unload)(struct codetag_type *cttype, +void (*module_unload)(struct codetag_type *cttype,struct codetag_module *cmod); +#ifdef CONFIG_MODULES +void (*module_replaced)(struct module *mod,struct module *new_mod); +bool (*needs_section_mem)(struct module *mod,unsigned long size); +void *(*alloc_section_mem)(struct module *mod,unsigned long size, +unsigned int prepend,unsigned long align); +void (*free_section_mem)(struct module *mod,bool unused); +#endif };struct codetag_iterator {
@@ -71,11 +78,31 @@ struct codetag_type * codetag_register_type(const struct codetag_type_desc *desc);#if defined(CONFIG_CODE_TAGGING ) && defined(CONFIG_MODULES ) + +bool codetag_needs_module_section (struct module *mod,const char *name, +unsigned long size); +void *codetag_alloc_module_section (struct module *mod,const char *name, +unsigned long size,unsigned int prepend, +unsigned long align); +void codetag_free_module_sections (struct module *mod); +void codetag_module_replaced (struct module *mod,struct module *new_mod);void codetag_load_module (struct module *mod); -bool codetag_unload_module (struct module *mod); -#else +void codetag_unload_module (struct module *mod); + +#else /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */ + +static inline bool +codetag_needs_module_section (struct module *mod,const char *name, +unsigned long size) {return false; } +static inline void * +codetag_alloc_module_section (struct module *mod,const char *name, +unsigned long size,unsigned int prepend, +unsigned long align) {return NULL ; } +static inline void codetag_free_module_sections (struct module *mod) {} +static inline void codetag_module_replaced (struct module *mod,struct module *new_mod) {}static inline void codetag_load_module (struct module *mod) {} -static inline bool codetag_unload_module (struct module *mod) {return true; } -#endif +static inline void codetag_unload_module (struct module *mod) {} + +#endif /* defined(CONFIG_CODE_TAGGING) && defined(CONFIG_MODULES) */ #endif /* _LINUX_CODETAG_H */
kernel/module/main.c +48 -26
165 lines not on this page · raw message
lib/alloc_tag.c +232 -19
282 lines not on this page · raw message
lib/codetag.c +93 -7
130 lines not on this page · raw message
scripts/module.lds.S +3 -2
@@ -50,7 +50,7 @@ SECTIONS { .data : { *(.data .data.[0-9a-zA-Z_]*) *(.data..L*) - CODETAG_SECTIONS() + MOD_CODETAG_SECTIONS() } .rodata : {
@@ -59,9 +59,10 @@ SECTIONS { } #else .data : { - CODETAG_SECTIONS() + MOD_CODETAG_SECTIONS() } #endif + MOD_SEPARATE_CODETAG_SECTIONS() } /* bring in arch-specific sections */
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Andrew Morton
maintainerRe: [PATCH v3 2/5] alloc_tag: load module tags into separate contiguous memory
Quoted 28 lines · On Mon, 14 Oct 2024 13:36:43 -0700 Suren Baghdasaryan <[email protected]> wrote:
When a module gets unloaded there is a possibility that some of the allocations it made are still used and therefore the allocation tags corresponding to these allocations are still referenced. As such, the memory for these tags can't be freed. This is currently handled as an abnormal situation and module's data section is not being unloaded. To handle this situation without keeping module's data in memory, allow codetags with longer lifespan than the module to be loaded into their own separate memory. The in-use memory areas and gaps after module unloading in this separate memory are tracked using maple trees. Allocation tags arrange their separate memory so that it is virtually contiguous and that will allow simple allocation tag indexing later on in this patchset. The size of this virtually contiguous memory is set to store up to 100000 allocation tags.
...
kernel/module/main.c +1
-3@@ -1254,22 +1254,17 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)return 0 ; } -static void module_memory_free (struct module *mod,enum mod_mem_type type, -bool unload_codetags) +static void module_memory_free (struct module *mod,enum mod_mem_type type) {struct module_memory *mem = &mod->mem[type]; -void *ptr = mem->base;
kernel/module/main.c static int module_memory_alloc(struct module *mod, enum mod_mem_type type) · line 1265
Quoted 10 lines
kernel/module/main.c +1
-4if (mem->is_rox)vfree (mem->rw_copy); -if (!unload_codetags &&mod_mem_type_is_core_data (type)) -return ; - -execmem_free (ptr); +execmem_free (mem->base); }
The changes around here are dependent upon Mike's "module: make module_memory_{alloc,free} more self-contained", which is no longer in mm-unstable. I assume Mike is working on a v2 so I'll park this series for now.
Suren Baghdasaryan
maintainerRe: [PATCH v3 2/5] alloc_tag: load module tags into separate contiguous memory
Quoted 35 lines · Andrew Morton
Quoted 32 lines · On Mon, 14 Oct 2024 13:36:43 -0700 Suren Baghdasaryan <[email protected]> wrote:
When a module gets unloaded there is a possibility that some of the allocations it made are still used and therefore the allocation tags corresponding to these allocations are still referenced. As such, the memory for these tags can't be freed. This is currently handled as an abnormal situation and module's data section is not being unloaded. To handle this situation without keeping module's data in memory, allow codetags with longer lifespan than the module to be loaded into their own separate memory. The in-use memory areas and gaps after module unloading in this separate memory are tracked using maple trees. Allocation tags arrange their separate memory so that it is virtually contiguous and that will allow simple allocation tag indexing later on in this patchset. The size of this virtually contiguous memory is set to store up to 100000 allocation tags.
...
kernel/module/main.c +1
-3@@ -1254,22 +1254,17 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)return 0 ; } -static void module_memory_free (struct module *mod,enum mod_mem_type type, -bool unload_codetags) +static void module_memory_free (struct module *mod,enum mod_mem_type type) {struct module_memory *mem = &mod->mem[type]; -void *ptr = mem->base;if (mem->is_rox)vfree (mem->rw_copy);
Quoted 11 lines
kernel/module/main.c static int module_memory_alloc(struct module *mod, enum mod_mem_type type) · line 1265
Quoted 6 lines
kernel/module/main.c +1
-4-if (!unload_codetags &&mod_mem_type_is_core_data (type)) -return ; - -execmem_free (ptr); +execmem_free (mem->base); }The changes around here are dependent upon Mike's "module: make module_memory_{alloc,free} more self-contained", which is no longer in mm-unstable. I assume Mike is working on a v2 so I'll park this series for now.
Looks like the last update on Mike's patchset was back in May. Let me check with Mike if he is planning to get it out soon. I would like my patchset to get into 6.12 if possible.
Thanks,
Suren.
Re: [PATCH v3 2/5] alloc_tag: load module tags into separate contiguous memory
Quoted 48 lines · Suren Baghdasaryan
Quoted 35 lines · Andrew Morton
Quoted 32 lines · On Mon, 14 Oct 2024 13:36:43 -0700 Suren Baghdasaryan <[email protected]> wrote:
When a module gets unloaded there is a possibility that some of the allocations it made are still used and therefore the allocation tags corresponding to these allocations are still referenced. As such, the memory for these tags can't be freed. This is currently handled as an abnormal situation and module's data section is not being unloaded. To handle this situation without keeping module's data in memory, allow codetags with longer lifespan than the module to be loaded into their own separate memory. The in-use memory areas and gaps after module unloading in this separate memory are tracked using maple trees. Allocation tags arrange their separate memory so that it is virtually contiguous and that will allow simple allocation tag indexing later on in this patchset. The size of this virtually contiguous memory is set to store up to 100000 allocation tags.
...
kernel/module/main.c +1
-3@@ -1254,22 +1254,17 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)return 0 ; } -static void module_memory_free (struct module *mod,enum mod_mem_type type, -bool unload_codetags) +static void module_memory_free (struct module *mod,enum mod_mem_type type) {struct module_memory *mem = &mod->mem[type]; -void *ptr = mem->base;if (mem->is_rox)vfree (mem->rw_copy);Quoted 11 lines
kernel/module/main.c static int module_memory_alloc(struct module *mod, enum mod_mem_type type) · line 1265
Quoted 6 lines
kernel/module/main.c +1
-4-if (!unload_codetags &&mod_mem_type_is_core_data (type)) -return ; - -execmem_free (ptr); +execmem_free (mem->base); }The changes around here are dependent upon Mike's "module: make module_memory_{alloc,free} more self-contained", which is no longer in mm-unstable. I assume Mike is working on a v2 so I'll park this series for now.
Quoted 3 lines
Looks like the last update on Mike's patchset was back in May. Let me check with Mike if he is planning to get it out soon. I would like my patchset to get into 6.12 if possible.
6.12 or 6.13?
Suren Baghdasaryan
maintainerRe: [PATCH v3 2/5] alloc_tag: load module tags into separate contiguous memory
Quoted 50 lines · Shakeel Butt
Quoted 48 lines · Suren Baghdasaryan
Quoted 46 lines · Andrew Morton
Quoted 28 lines · On Mon, 14 Oct 2024 13:36:43 -0700 Suren Baghdasaryan <[email protected]> wrote:
When a module gets unloaded there is a possibility that some of the allocations it made are still used and therefore the allocation tags corresponding to these allocations are still referenced. As such, the memory for these tags can't be freed. This is currently handled as an abnormal situation and module's data section is not being unloaded. To handle this situation without keeping module's data in memory, allow codetags with longer lifespan than the module to be loaded into their own separate memory. The in-use memory areas and gaps after module unloading in this separate memory are tracked using maple trees. Allocation tags arrange their separate memory so that it is virtually contiguous and that will allow simple allocation tag indexing later on in this patchset. The size of this virtually contiguous memory is set to store up to 100000 allocation tags.
...
kernel/module/main.c +1
-3@@ -1254,22 +1254,17 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)return 0 ; } -static void module_memory_free (struct module *mod,enum mod_mem_type type, -bool unload_codetags) +static void module_memory_free (struct module *mod,enum mod_mem_type type) {struct module_memory *mem = &mod->mem[type]; -void *ptr = mem->base;kernel/module/main.c static int module_memory_alloc(struct module *mod, enum mod_mem_type type) · line 1265
Quoted 10 lines
kernel/module/main.c +1
-4if (mem->is_rox)vfree (mem->rw_copy); -if (!unload_codetags &&mod_mem_type_is_core_data (type)) -return ; - -execmem_free (ptr); +execmem_free (mem->base); }The changes around here are dependent upon Mike's "module: make module_memory_{alloc,free} more self-contained", which is no longer in mm-unstable. I assume Mike is working on a v2 so I'll park this series for now.
Quoted 5 lines
Quoted 3 lines
Looks like the last update on Mike's patchset was back in May. Let me check with Mike if he is planning to get it out soon. I would like my patchset to get into 6.12 if possible.
6.12 or 6.13?
Right, it's 6.13 at this point.
Suren Baghdasaryan
maintainerPATCH v3 3/5 alloc_tag: populate memory for module tags as needed
In reply to Suren BaghdasaryanThe memory reserved for module tags does not need to be backed by physical pages until there are tags to store there. Change the way we reserve this memory to allocate only virtual area for the tags and populate it with physical pages as needed when we load a module.
--- include/linux/execmem.h | 11 ++++++ include/linux/vmalloc.h | 9 +++++ lib/alloc_tag.c | 84 +++++++++++++++++++++++++++++++++-------- mm/execmem.c | 16 ++++++++ mm/vmalloc.c | 4 +- 5 files changed, 106 insertions(+), 18 deletions(-)
include/linux/execmem.h +11 -0
@@ -127,6 +127,17 @@ void *execmem_alloc(enum execmem_type type, size_t size);*/ void execmem_free (void *ptr); +/** +* execmem_vmap - create virtual mapping for executable memory +* @type: type of the allocation +* @size: size of the virtual mapping in bytes +* +* Maps virtually contiguous area that can be populated with executable code. +* +* Return: the area descriptor on success or %NULL on failure. +*/ +struct vm_struct *execmem_vmap (enum execmem_type type,size_t size); +/** * execmem_update_copy - copy an update to executable memory * @dst: destination address to update
include/linux/vmalloc.h +9 -0
@@ -202,6 +202,9 @@ extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,extern int remap_vmalloc_range (struct vm_area_struct *vma,void *addr,unsigned long pgoff); +int vmap_pages_range (unsigned long addr,unsigned long end, +pgprot_t prot,struct page **pages,unsigned int page_shift); +/* * Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values * and let generic vmalloc and ioremap code know when arch_sync_kernel_mappings()
@@ -239,6 +242,12 @@ extern struct vm_struct *__get_vm_area_caller(unsigned long size,unsigned long flags, unsigned long start, unsigned long end, const void *caller); +struct vm_struct *__get_vm_area_node (unsigned long size, +unsigned long align,unsigned long shift, +unsigned long flags,unsigned long start, +unsigned long end,int node,gfp_t gfp_mask, +const void *caller); +void free_vm_area (struct vm_struct *area);extern struct vm_struct *remove_vm_area (const void *addr);extern struct vm_struct *find_vm_area (const void *addr);
lib/alloc_tag.c +68 -16
152 lines not on this page · raw message
mm/execmem.c +16 -0
@@ -366,6 +366,22 @@ void execmem_free(void *ptr)vfree (ptr); } +struct vm_struct *execmem_vmap (enum execmem_type type,size_t size) +{ +struct execmem_range *range = &execmem_info->ranges[type]; +struct vm_struct *area; + + area =__get_vm_area_node (size, range->alignment,PAGE_SHIFT ,VM_ALLOC , + range->start, range->end,NUMA_NO_NODE , +GFP_KERNEL ,__builtin_return_address (0 )); +if (!area && range->fallback_start) + area =__get_vm_area_node (size, range->alignment,PAGE_SHIFT ,VM_ALLOC , + range->fallback_start, range->fallback_end, +NUMA_NO_NODE ,GFP_KERNEL ,__builtin_return_address (0 )); + +return area; +} +void *execmem_update_copy (void *dst,const void *src,size_t size) {return text_poke_copy (dst, src, size);
mm/vmalloc.c +2 -2
@@ -653,7 +653,7 @@ int vmap_pages_range_noflush(unsigned long addr, unsigned long end,* RETURNS: * 0 on success, -errno on failure. */ -static int vmap_pages_range (unsigned long addr,unsigned long end, +int vmap_pages_range (unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,unsigned int page_shift) {int err;
@@ -3106,7 +3106,7 @@ static void clear_vm_uninitialized_flag(struct vm_struct *vm) vm->flags &= ~VM_UNINITIALIZED ; } -static struct vm_struct *__get_vm_area_node (unsigned long size, +struct vm_struct *__get_vm_area_node (unsigned long size,unsigned long align,unsigned long shift,unsigned long flags,unsigned long start,unsigned long end,int node,gfp_t gfp_mask,const void *caller)
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Mike Rapoport
maintainerRe: [PATCH v3 3/5] alloc_tag: populate memory for module tags as needed
Quoted 23 lines · Suren Baghdasaryan
The memory reserved for module tags does not need to be backed by physical pages until there are tags to store there. Change the way we reserve this memory to allocate only virtual area for the tags and populate it with physical pages as needed when we load a module.
Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/execmem.h | 11 ++++++ include/linux/vmalloc.h | 9 +++++ lib/alloc_tag.c | 84 +++++++++++++++++++++++++++++++++-------- mm/execmem.c | 16 ++++++++ mm/vmalloc.c | 4 +- 5 files changed, 106 insertions(+), 18 deletions(-)include/linux/execmem.h +1
-0@@ -127,6 +127,17 @@ void *execmem_alloc(enum execmem_type type, size_t size);*/ void execmem_free (void *ptr); +/**
include/linux/execmem.h void *execmem_alloc(enum execmem_type type, size_t size); · line 140
Quoted 10 lines
include/linux/execmem.h +10
-0+* execmem_vmap - create virtual mapping for executable memory +* @type: type of the allocation +* @size: size of the virtual mapping in bytes +* +* Maps virtually contiguous area that can be populated with executable code. +* +* Return: the area descriptor on success or %NULL on failure. +*/ +struct vm_struct *execmem_vmap (enum execmem_type type,size_t size); +
I think it's better limit it to EXECMEM_MODULE_DATA
Quoted 19 lines
include/linux/execmem.h +0
-0/** * execmem_update_copy - copy an update to executable memory * @dst: destination address to update include/linux/vmalloc.h +3
-0@@ -202,6 +202,9 @@ extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,extern int remap_vmalloc_range (struct vm_area_struct *vma,void *addr,unsigned long pgoff); +int vmap_pages_range (unsigned long addr,unsigned long end, +pgprot_t prot,struct page **pages,unsigned int page_shift); +/* * Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values * and let generic vmalloc and ioremap code know when
arch_sync_kernel_mappings()
include/linux/vmalloc.h extern struct vm_struct *__get_vm_area_caller(unsigned long size, · line 250
Quoted 9 lines
include/linux/vmalloc.h +6
-0@@ -239,6 +242,12 @@ extern struct vm_struct *__get_vm_area_caller(unsigned long size,unsigned long flags, unsigned long start, unsigned long end, const void *caller); +struct vm_struct *__get_vm_area_node (unsigned long size, +unsigned long align,unsigned long shift, +unsigned long flags,unsigned long start, +unsigned long end,int node,gfp_t gfp_mask, +const void *caller); +
This is not used outside mm/, let's put it into mm/internal.h
Quoted 110 lines
include/linux/vmalloc.h +0
-0void free_vm_area (struct vm_struct *area);extern struct vm_struct *remove_vm_area (const void *addr);extern struct vm_struct *find_vm_area (const void *addr);lib/alloc_tag.c +36
-10@@ -8,6 +8,7 @@#include <linux/proc_fs.h> #include <linux/seq_buf.h> #include <linux/seq_file.h> +#include <linux/vmalloc.h> static struct codetag_type *alloc_tag_cttype;@@ -153,6 +154,7 @@ static void __init procfs_init(void)#ifdef CONFIG_MODULES static struct maple_tree mod_area_mt =MTREE_INIT (mod_area_mt,MT_FLAGS_ALLOC_RANGE ); +static struct vm_struct *vm_module_tags;/* A dummy object used to indicate an unloaded module */ static struct module unloaded_mod;/* A dummy object used to indicate a module prepended area */ @@ -195,6 +197,25 @@ static void clean_unused_module_areas_locked(void) } } +static int vm_module_tags_grow (unsigned long addr,unsigned long bytes) +{ +struct page **next_page = vm_module_tags->pages + vm_module_tags->nr_pages; +unsigned long more_pages =ALIGN (bytes,PAGE_SIZE ) >>PAGE_SHIFT ; +unsigned long nr; + + nr =alloc_pages_bulk_array_node (GFP_KERNEL | __GFP_NOWARN, +NUMA_NO_NODE , more_pages, next_page); +if (nr != more_pages) +return -ENOMEM ; + + vm_module_tags->nr_pages += nr; +if (vmap_pages_range (addr, addr + (nr <<PAGE_SHIFT ), +PAGE_KERNEL , next_page,PAGE_SHIFT ) <0 ) +return -ENOMEM ; + +return 0 ; +} +static void *reserve_module_tags (struct module *mod,unsigned long size,unsigned int prepend,unsigned long align) {@@ -202,7 +223,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,MA_STATE (mas, &mod_area_mt,0 , section_size -1 );bool cleanup_done = false;unsigned long offset; -void *ret; +void *ret =NULL ;/* If no tags return NULL */ if (size <sizeof (struct alloc_tag ))@@ -239,7 +260,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size, goto repeat; }else { ret =ERR_PTR (-ENOMEM ); - goto out; + goto unlock; } found:@@ -254,7 +275,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,mas_store (&mas, &prepend_mod);if (mas_is_err (&mas)) { ret =ERR_PTR (xa_err (mas.node)); - goto out; + goto unlock; } mas.index = offset; mas.last = offset + size -1 ;@@ -263,7 +284,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size, ret =ERR_PTR (xa_err (mas.node)); mas.index = pad_start;mas_erase (&mas); - goto out; + goto unlock; } }else {@@ -271,18 +292,33 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,mas_store (&mas, mod);if (mas_is_err (&mas)) { ret =ERR_PTR (xa_err (mas.node)); - goto out; + goto unlock; } } +unlock: +mas_unlock (&mas); +if (IS_ERR (ret)) +return ret; -if (module_tags.size < offset + size) - module_tags.size = offset + size; +if (module_tags.size < offset + size) { +unsigned long phys_size = vm_module_tags->nr_pages <<PAGE_SHIFT ; - ret = (struct alloc_tag *)(module_tags.start_addr + offset); -out: -mas_unlock (&mas); + module_tags.size = offset + size; +if (phys_size < module_tags.size) { +int grow_res; +
lib/alloc_tag.c static void *reserve_module_tags(struct module *mod, unsigned long size, · line 319
Quoted 10 lines
lib/alloc_tag.c +10
-0+ grow_res =vm_module_tags_grow (module_tags.start_addr + phys_size, + module_tags.size - phys_size); +if (grow_res) { +static_branch_disable (&mem_alloc_profiling_key); +pr_warn ("Failed to allocate tags memory for module %s. Memory profiling is disabled!\n" , + mod->name); +return ERR_PTR (grow_res); + } + } + }
The diff for reserve_module_tags() is hard to read, and the function itself becomes really complex to follow with all the gotos back and forth. Maybe it's possible to split out some parts of it as helpers?
Quoted 4 lines
lib/alloc_tag.c +1
-1-return ret; +return (struct alloc_tag *)(module_tags.start_addr + offset); }
Signature · 2 lines
Sincerely yours, Mike.
Suren Baghdasaryan
maintainerRe: [PATCH v3 3/5] alloc_tag: populate memory for module tags as needed
Quoted 24 lines · Mike Rapoport' via kernel-team
Quoted 22 lines · Suren Baghdasaryan
The memory reserved for module tags does not need to be backed by physical pages until there are tags to store there. Change the way we reserve this memory to allocate only virtual area for the tags and populate it with physical pages as needed when we load a module.
Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/execmem.h | 11 ++++++ include/linux/vmalloc.h | 9 +++++ lib/alloc_tag.c | 84 +++++++++++++++++++++++++++++++++-------- mm/execmem.c | 16 ++++++++ mm/vmalloc.c | 4 +- 5 files changed, 106 insertions(+), 18 deletions(-)include/linux/execmem.h +0
-0@@ -127,6 +127,17 @@ void *execmem_alloc(enum execmem_type type, size_t size);*/ void execmem_free (void *ptr);
Quoted 13 lines
include/linux/execmem.h void *execmem_alloc(enum execmem_type type, size_t size); · line 140
Quoted 11 lines
include/linux/execmem.h +11
-0+/** +* execmem_vmap - create virtual mapping for executable memory +* @type: type of the allocation +* @size: size of the virtual mapping in bytes +* +* Maps virtually contiguous area that can be populated with executable code. +* +* Return: the area descriptor on success or %NULL on failure. +*/ +struct vm_struct *execmem_vmap (enum execmem_type type,size_t size); +I think it's better limit it to
EXECMEM_MODULE_DATA
Ack.
Quoted 16 lines
Quoted 16 lines
include/linux/execmem.h +0
-0/** * execmem_update_copy - copy an update to executable memory * @dst: destination address to update include/linux/vmalloc.h +3
-0@@ -202,6 +202,9 @@ extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,extern int remap_vmalloc_range (struct vm_area_struct *vma,void *addr,unsigned long pgoff); +int vmap_pages_range (unsigned long addr,unsigned long end, +pgprot_t prot,struct page **pages,unsigned int page_shift); +
Quoted 15 lines
include/linux/vmalloc.h extern struct vm_struct *__get_vm_area_caller(unsigned long size, · line 250
Quoted 13 lines
include/linux/vmalloc.h +0
-0/* * Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values * and let generic vmalloc and ioremap code know when
arch_sync_kernel_mappings()include/linux/vmalloc.h +6
-0@@ -239,6 +242,12 @@ extern struct vm_struct *__get_vm_area_caller(unsigned long size,unsigned long flags, unsigned long start, unsigned long end, const void *caller); +struct vm_struct *__get_vm_area_node (unsigned long size, +unsigned long align,unsigned long shift, +unsigned long flags,unsigned long start, +unsigned long end,int node,gfp_t gfp_mask, +const void *caller); +This is not used outside
mm/, let's put it intomm/internal.h
Ack.
Quoted 117 lines
Quoted 117 lines
include/linux/vmalloc.h +0
-0void free_vm_area (struct vm_struct *area);extern struct vm_struct *remove_vm_area (const void *addr);extern struct vm_struct *find_vm_area (const void *addr);lib/alloc_tag.c +42
-10@@ -8,6 +8,7 @@#include <linux/proc_fs.h> #include <linux/seq_buf.h> #include <linux/seq_file.h> +#include <linux/vmalloc.h> static struct codetag_type *alloc_tag_cttype;@@ -153,6 +154,7 @@ static void __init procfs_init(void)#ifdef CONFIG_MODULES static struct maple_tree mod_area_mt =MTREE_INIT (mod_area_mt,MT_FLAGS_ALLOC_RANGE ); +static struct vm_struct *vm_module_tags;/* A dummy object used to indicate an unloaded module */ static struct module unloaded_mod;/* A dummy object used to indicate a module prepended area */ @@ -195,6 +197,25 @@ static void clean_unused_module_areas_locked(void) } } +static int vm_module_tags_grow (unsigned long addr,unsigned long bytes) +{ +struct page **next_page = vm_module_tags->pages + vm_module_tags->nr_pages; +unsigned long more_pages =ALIGN (bytes,PAGE_SIZE ) >>PAGE_SHIFT ; +unsigned long nr; + + nr =alloc_pages_bulk_array_node (GFP_KERNEL | __GFP_NOWARN, +NUMA_NO_NODE , more_pages, next_page); +if (nr != more_pages) +return -ENOMEM ; + + vm_module_tags->nr_pages += nr; +if (vmap_pages_range (addr, addr + (nr <<PAGE_SHIFT ), +PAGE_KERNEL , next_page,PAGE_SHIFT ) <0 ) +return -ENOMEM ; + +return 0 ; +} +static void *reserve_module_tags (struct module *mod,unsigned long size,unsigned int prepend,unsigned long align) {@@ -202,7 +223,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,MA_STATE (mas, &mod_area_mt,0 , section_size -1 );bool cleanup_done = false;unsigned long offset; -void *ret; +void *ret =NULL ;/* If no tags return NULL */ if (size <sizeof (struct alloc_tag ))@@ -239,7 +260,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size, goto repeat; }else { ret =ERR_PTR (-ENOMEM ); - goto out; + goto unlock; } found:@@ -254,7 +275,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,mas_store (&mas, &prepend_mod);if (mas_is_err (&mas)) { ret =ERR_PTR (xa_err (mas.node)); - goto out; + goto unlock; } mas.index = offset; mas.last = offset + size -1 ;@@ -263,7 +284,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size, ret =ERR_PTR (xa_err (mas.node)); mas.index = pad_start;mas_erase (&mas); - goto out; + goto unlock; } }else {@@ -271,18 +292,33 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,mas_store (&mas, mod);if (mas_is_err (&mas)) { ret =ERR_PTR (xa_err (mas.node)); - goto out; + goto unlock; } } +unlock: +mas_unlock (&mas); +if (IS_ERR (ret)) +return ret; -if (module_tags.size < offset + size) - module_tags.size = offset + size; +if (module_tags.size < offset + size) { +unsigned long phys_size = vm_module_tags->nr_pages <<PAGE_SHIFT ; - ret = (struct alloc_tag *)(module_tags.start_addr + offset); -out: -mas_unlock (&mas); + module_tags.size = offset + size; +if (phys_size < module_tags.size) { +int grow_res; + + grow_res =vm_module_tags_grow (module_tags.start_addr + phys_size, + module_tags.size - phys_size); +if (grow_res) { +static_branch_disable (&mem_alloc_profiling_key); +pr_warn ("Failed to allocate tags memory for module %s. Memory profiling is disabled!\n" , + mod->name);
Quoted 8 lines
lib/alloc_tag.c static void *reserve_module_tags(struct module *mod, unsigned long size, · line 319
Quoted 4 lines
lib/alloc_tag.c +4
-0+return ERR_PTR (grow_res); + } + } + }The diff for
reserve_module_tags()is hard to read, and the function itself becomes really complex to follow with all the gotos back and forth. Maybe it's possible to split out some parts of it as helpers?
Got it. Will refactor this function to make it easier to review.
Thanks for the prompt review, Mike!
Quoted 12 lines
lib/alloc_tag.c static void *reserve_module_tags(struct module *mod, unsigned long size, · line 323
Quoted 5 lines
lib/alloc_tag.c +1
-1-return ret; +return (struct alloc_tag *)(module_tags.start_addr + offset); }--
Sincerely yours,
Mike.To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
kernel test robot
build botRe: [PATCH v3 3/5] alloc_tag: populate memory for module tags as needed
In reply to Suren Baghdasaryankernel test robot noticed the following build warnings:
Hi Suren,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 828d7267c42c2aab3877c08b4bb00b1e56769557]
url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/maple_tree-add-mas_for_each_rev-helper/20241015-044156 base: 828d7267c42c2aab3877c08b4bb00b1e56769557 patch link: https://lore.kernel.org/r/20241014203646.1952505-4-surenb%40google.com patch subject: [PATCH v3 3/5] alloc_tag: populate memory for module tags as needed config: i386-randconfig-006-20241018 (https://download.01.org/0day-ci/archive/20241018/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241018/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> lib/alloc_tag.c:394:4: warning: format specifies type 'unsigned long' but the argument has type 'unsigned int' [-Wformat]
393 | pr_err("Failed to map %lu bytes for module allocation tags\n",
| ~~~
| %u
394 | MODULE_ALLOC_TAG_VMAP_SIZE);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/printk.h:533:33: note: expanded from macro 'pr_err'
533 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ~~~ ^~~~~~~~~~~
include/linux/printk.h:490:60: note: expanded from macro 'printk'
490 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
| ~~~ ^~~~~~~~~~~
include/linux/printk.h:462:19: note: expanded from macro 'printk_index_wrap'
462 | _p_func(_fmt, ##__VA_ARGS__); \
| ~~~~ ^~~~~~~~~~~
lib/alloc_tag.c:386:36: note: expanded from macro 'MODULE_ALLOC_TAG_VMAP_SIZE'
386 | #define MODULE_ALLOC_TAG_VMAP_SIZE (100000 * sizeof(struct alloc_tag))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1 warning generated.
vim +394 lib/alloc_tag.c
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 387
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 388 static int __init alloc_mod_tags_mem(void)
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 389 {
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 390 /* Map space to copy allocation tags */
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 391 vm_module_tags = execmem_vmap(EXECMEM_MODULE_DATA, MODULE_ALLOC_TAG_VMAP_SIZE);
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 392 if (!vm_module_tags) {
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 393 pr_err("Failed to map %lu bytes for module allocation tags\n",
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 @394 MODULE_ALLOC_TAG_VMAP_SIZE);
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 395 module_tags.start_addr = 0;
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 396 return -ENOMEM;
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 397 }
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 398
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 399 vm_module_tags->pages = kmalloc_array(get_vm_area_size(vm_module_tags) >> PAGE_SHIFT,
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 400 sizeof(struct page *), GFP_KERNEL | __GFP_ZERO);
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 401 if (!vm_module_tags->pages) {
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 402 free_vm_area(vm_module_tags);
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 403 return -ENOMEM;
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 404 }
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 405
f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 406 module_tags.start_addr = (unsigned long)vm_module_tags->addr;
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 407 module_tags.end_addr = module_tags.start_addr + MODULE_ALLOC_TAG_VMAP_SIZE;
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 408
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 409 return 0;
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 410 }
5b662b363f38b01 Suren Baghdasaryan 2024-10-14 411 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Suren Baghdasaryan
maintainerRe: [PATCH v3 3/5] alloc_tag: populate memory for module tags as needed
Quoted 20 lines · kernel test robot
Hi Suren,
kernel test robot noticed the following build warnings:
[auto build test WARNING on
828d7267c42c2aab3877c08b4bb00b1e56769557]url: https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/maple_tree-add-mas_for_each_rev-helper/20241015-044156 base: 828d7267c42c2aab3877c08b4bb00b1e56769557 patch link: https://lore.kernel.org/r/20241014203646.1952505-4-surenb%40google.com patch subject: [PATCH v3 3/5] alloc_tag: populate memory for module tags as needed config: i386-randconfig-006-20241018 (https://download.01.org/0day-ci/archive/20241018/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241018/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 8 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
lib/alloc_tag.c:394:4: warning: format specifies type 'unsigned long' but the argument has type 'unsigned int' [-Wformat]393 | pr_err("Failed to map %lu bytes for module allocation tags\n", | ~~~ | %u 394 | MODULE_ALLOC_TAG_VMAP_SIZE); | ^~~~~~~~~~~~~~~~~~~~~~~~~~
I'll fix this warning in the next version. Thanks!
Quoted 46 lines
include/linux/printk.h:533:33: note: expanded from macro 'pr_err' 533 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | ~~~ ^~~~~~~~~~~ include/linux/printk.h:490:60: note: expanded from macro 'printk' 490 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) | ~~~ ^~~~~~~~~~~ include/linux/printk.h:462:19: note: expanded from macro 'printk_index_wrap' 462 | _p_func(_fmt, ##__VA_ARGS__); \ | ~~~~ ^~~~~~~~~~~ lib/alloc_tag.c:386:36: note: expanded from macro 'MODULE_ALLOC_TAG_VMAP_SIZE' 386 | #define MODULE_ALLOC_TAG_VMAP_SIZE (100000 * sizeof(struct alloc_tag)) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated.vim +394
lib/alloc_tag.c5b662b363f38b01 Suren Baghdasaryan 2024-10-14 387 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 388 static int __init alloc_mod_tags_mem(void) 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 389 { f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 390 /* Map space to copy allocation tags */ f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 391 vm_module_tags = execmem_vmap(EXECMEM_MODULE_DATA, MODULE_ALLOC_TAG_VMAP_SIZE); f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 392 if (!vm_module_tags) { f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 393 pr_err("Failed to map %lu bytes for module allocation tags\n", 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 @394 MODULE_ALLOC_TAG_VMAP_SIZE); f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 395 module_tags.start_addr = 0; 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 396 return -ENOMEM; f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 397 } 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 398 f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 399 vm_module_tags->pages = kmalloc_array(get_vm_area_size(vm_module_tags) >> PAGE_SHIFT, f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 400 sizeof(struct page *), GFP_KERNEL | __GFP_ZERO); f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 401 if (!vm_module_tags->pages) { f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 402 free_vm_area(vm_module_tags); f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 403 return -ENOMEM; f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 404 } f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 405 f0d7ffe60ce5cf0 Suren Baghdasaryan 2024-10-14 406 module_tags.start_addr = (unsigned long)vm_module_tags->addr; 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 407 module_tags.end_addr = module_tags.start_addr + MODULE_ALLOC_TAG_VMAP_SIZE; 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 408 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 409 return 0; 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 410 } 5b662b363f38b01 Suren Baghdasaryan 2024-10-14 411--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Suren Baghdasaryan
maintainerPATCH v3 4/5 alloc_tag: introduce pgalloc_tag_ref to abstract page tag references
In reply to Suren BaghdasaryanTo simplify later changes to page tag references, introduce new pgalloc_tag_ref and pgtag_ref_handle types. This allows easy replacement of page_ext as a storage of page allocation tags.
--- include/linux/mm.h | 25 +++++---- include/linux/pgalloc_tag.h | 108 ++++++++++++++++++++++++------------ lib/alloc_tag.c | 3 +- 3 files changed, 88 insertions(+), 48 deletions(-)
include/linux/mm.h +13 -12
@@ -4180,37 +4180,38 @@ static inline void pgalloc_tag_split(struct folio *folio, int old_order, int newreturn ;for (i = nr_pages; i < (1 << old_order); i += nr_pages) { -union codetag_ref *ref =get_page_tag_ref (folio_page (folio, i)); +union pgtag_ref_handle handle; +union codetag_ref ref; -if (ref) { +if (get_page_tag_ref (folio_page (folio, i), &ref, &handle)) {/* Set new reference to point to the original tag */ -alloc_tag_ref_set (ref, tag); -put_page_tag_ref (ref); +alloc_tag_ref_set (&ref, tag); +update_page_tag_ref (handle, &ref); +put_page_tag_ref (handle); } } }static inline void pgalloc_tag_copy (struct folio *new,struct folio *old) { +union pgtag_ref_handle handle; +union codetag_ref ref;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) +if (!get_page_tag_ref (&new->page, &ref, &handle))return ;/* Clear the old ref to the original allocation tag. */ 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); +alloc_tag_sub (&ref,folio_nr_pages (new)); +__alloc_tag_ref_set (&ref, tag); +update_page_tag_ref (handle, &ref); +put_page_tag_ref (handle); }#else /* !CONFIG_MEM_ALLOC_PROFILING */ static inline void pgalloc_tag_split (struct folio *folio,int old_order,int new_order)
include/linux/pgalloc_tag.h +73 -35
164 lines not on this page · raw message
lib/alloc_tag.c +2 -1
@@ -5,6 +5,7 @@#include <linux/gfp.h> #include <linux/module.h> #include <linux/page_ext.h> +#include <linux/pgalloc_tag.h> #include <linux/proc_fs.h> #include <linux/seq_buf.h> #include <linux/seq_file.h>
@@ -474,7 +475,7 @@ static __init void init_page_alloc_tagging(void) }struct page_ext_operations page_alloc_tagging_ops = { - .size =sizeof (union codetag_ref ), + .size =sizeof (pgalloc_tag_ref), .need = need_page_alloc_tagging, .init = init_page_alloc_tagging, };
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Suren Baghdasaryan
maintainerPATCH v3 5/5 alloc_tag: config to store page allocation tag refs in page flags
In reply to Suren BaghdasaryanAdd CONFIG_PGALLOC_TAG_USE_PAGEFLAGS to store allocation tag references directly in the page flags. This eliminates memory overhead caused by page_ext and results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.
--- include/linux/alloc_tag.h | 10 +- include/linux/codetag.h | 3 + include/linux/page-flags-layout.h | 7 ++ include/linux/pgalloc_tag.h | 184 +++++++++++++++++++++++++++++- lib/Kconfig.debug | 19 +++ lib/alloc_tag.c | 90 ++++++++++++++- lib/codetag.c | 4 +- mm/mm_init.c | 5 +- 8 files changed, 310 insertions(+), 12 deletions(-)
include/linux/alloc_tag.h +9 -1
@@ -30,8 +30,16 @@ struct alloc_tag {struct alloc_tag_counters __percpu *counters; }__aligned(8) ; +struct alloc_tag_kernel_section { +struct alloc_tag *first_tag; +unsigned long count; +}; +struct alloc_tag_module_section { -unsigned long start_addr; +union { +unsigned long start_addr; +struct alloc_tag *first_tag; + };unsigned long end_addr;/* used size */ unsigned long size;
include/linux/codetag.h +3 -0
@@ -13,6 +13,9 @@ struct codetag_module;struct seq_buf ;struct module ; +#define CODETAG_SECTION_START_PREFIX "__start_" +#define CODETAG_SECTION_STOP_PREFIX "__stop_" +/* * An instance of this structure is created in a special ELF section at every * code location being tagged. At runtime, the special section is treated as
include/linux/page-flags-layout.h +7 -0
@@ -111,5 +111,12 @@ ZONES_WIDTH - LRU_GEN_WIDTH - SECTIONS_WIDTH - \ NODES_WIDTH - KASAN_TAG_WIDTH - LAST_CPUPID_WIDTH) +#define NR_NON_PAGEFLAG_BITS (SECTIONS_WIDTH + NODES_WIDTH + ZONES_WIDTH + \ + LAST_CPUPID_SHIFT + KASAN_TAG_WIDTH + \ + LRU_GEN_WIDTH + LRU_REFS_WIDTH) + +#define NR_UNUSED_PAGEFLAG_BITS (BITS_PER_LONG - \ + (NR_NON_PAGEFLAG_BITS + NR_PAGEFLAGS)) +#endif #endif /* _LINUX_PAGE_FLAGS_LAYOUT */
include/linux/pgalloc_tag.h +179 -5
228 lines not on this page · raw message
lib/Kconfig.debug +19 -0
@@ -1017,6 +1017,25 @@ config MEM_ALLOC_PROFILING_DEBUG Adds warnings with helpful error messages for memory allocation profiling. +config PGALLOC_TAG_USE_PAGEFLAGS + bool "Use pageflags to encode page allocation tag reference" + default n + depends on MEM_ALLOC_PROFILING + help + When set, page allocation tag references are encoded inside page + flags if they fit, otherwise they are encoded in page extensions. + + Setting this flag reduces memory and performance overhead of memory + allocation profiling but it requires enough unused page flag bits to + address all kernel allocations. If enabled but there are not enough + unused page flag bits, profiling will fall back to using page + extensions and a warning will be issued to disable this config. + If dynamically loaded modules add enough tags that they can't be + addressed anymore with available page flag bits, profiling for such + modules will be disabled and a warning will be issued. + + Say N if unsure. + source "lib/Kconfig.kasan" source "lib/Kconfig.kfence" source "lib/Kconfig.kmsan"
lib/alloc_tag.c +89 -1
132 lines not on this page · raw message
lib/codetag.c +2 -2
@@ -149,8 +149,8 @@ static struct codetag_range get_section_range(struct module *mod, const char *section) {return (struct codetag_range ) { -get_symbol (mod,"__start_" , section), -get_symbol (mod,"__stop_" , section), +get_symbol (mod,CODETAG_SECTION_START_PREFIX , section), +get_symbol (mod,CODETAG_SECTION_STOP_PREFIX , section), }; }
mm/mm_init.c +2 -3
@@ -83,8 +83,7 @@ void __init mminit_verify_pageflags_layout(void)unsigned long or_mask, add_mask; shift =BITS_PER_LONG ; - width = shift -SECTIONS_WIDTH -NODES_WIDTH -ZONES_WIDTH - -LAST_CPUPID_SHIFT -KASAN_TAG_WIDTH -LRU_GEN_WIDTH -LRU_REFS_WIDTH ; + width = shift -NR_NON_PAGEFLAG_BITS ; mminit_dprintk(MMINIT_TRACE, "pageflags_layout_widths", "Section %d Node %d Zone %d Lastcpupid %d Kasantag %d Gen %d Tier %d Flags %d\n", SECTIONS_WIDTH,
@@ -2639,7 +2638,7 @@ void __init mm_core_init(void)BUILD_BUG_ON (MAX_ZONELISTS >2 );build_all_zonelists (NULL );page_alloc_init_cpuhp (); - +alloc_tag_sec_init ();/* * page_ext requires contiguous pages, * bigger than MAX_PAGE_ORDER unless SPARSEMEM.
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to page_ext otherwise?
Is the reason that dynamically loadable modules, where the user may know in advance that the page flags won't be enough with the modules loaded?
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.
Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?
Or better yet, *always* fall back to page_ext, thus leaving the scarce and valuable page flags available for other features?
Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
thanks,
Signature · 1 line
John Hubbard
Quoted 4 lines
Is the reason that dynamically loadable modules, where the user may know in advance that the page flags won't be enough with the modules loaded?
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 20 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?
Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
I think we already always use page_ext today. My understanding is that the purpose of this series is to give the option to avoid using page_ext if there are enough unused page flags anyway, which reduces memory waste and improves performance.
My question is just why not have that be the default behavior with a config option, use page flags if there are enough unused bits, otherwise use page_ext.
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 29 lines · Yosry Ahmed
Quoted 20 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
Quoted 8 lines
I think we already always use
page_exttoday. My understanding is that the purpose of this series is to give the option to avoid usingpage_extif there are enough unused page flags anyway, which reduces memory waste and improves performance.My question is just why not have that be the default behavior with a config option, use page flags if there are enough unused bits, otherwise use
page_ext.
I agree that if you're going to implement this feature at all, then keying off of CONFIG_MEM_ALLOC_PROFILING seems sufficient, and no need to add CONFIG_PGALLOC_TAG_USE_PAGEFLAGS on top of that.
thanks,
Signature · 1 line
John Hubbard
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 13 lines · John Hubbard
Quoted 13 lines
Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
I think we already always use
page_exttoday. My understanding is that the purpose of this series is to give the option to avoid usingpage_extif there are enough unused page flags anyway, which reduces memory waste and improves performance.
Quoted 7 lines
Quoted 3 lines
My question is just why not have that be the default behavior with a config option, use page flags if there are enough unused bits, otherwise use
page_ext.I agree that if you're going to implement this feature at all, then keying off of
CONFIG_MEM_ALLOC_PROFILINGseems sufficient, and no need to addCONFIG_PGALLOC_TAG_USE_PAGEFLAGSon top of that.
Maybe the right idea is to use all the bits which are unused in this configuration for the first N callsites, then use page_ext for all the ones larger than N. It doesn't save any memory, but it does have the performance improvement.
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 19 lines · Matthew Wilcox
Quoted 17 lines · John Hubbard
Quoted 16 lines
Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
I think we already always use
page_exttoday. My understanding is that the purpose of this series is to give the option to avoid usingpage_extif there are enough unused page flags anyway, which reduces memory waste and improves performance.My question is just why not have that be the default behavior with a config option, use page flags if there are enough unused bits, otherwise use
page_ext.
Quoted 8 lines
Quoted 3 lines
I agree that if you're going to implement this feature at all, then keying off of
CONFIG_MEM_ALLOC_PROFILINGseems sufficient, and no need to addCONFIG_PGALLOC_TAG_USE_PAGEFLAGSon top of that.Maybe the right idea is to use all the bits which are unused in this configuration for the first N callsites, then use
page_extfor all the ones larger than N. It doesn't save any memory, but it does have the performance improvement.
Thanks for the idea! This would be more complicated and likely would require additional branching instructions in the allocation path. I'll think more about details but would prefer to get the simple solution first before adding more complexity.
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
In reply to John HubbardQuoted 36 lines · John Hubbard' via kernel-team
Quoted 34 lines · Yosry Ahmed
Quoted 20 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
I think we already always use
page_exttoday. My understanding is that the purpose of this series is to give the option to avoid usingpage_extif there are enough unused page flags anyway, which reduces memory waste and improves performance.
Quoted 7 lines
Quoted 3 lines
My question is just why not have that be the default behavior with a config option, use page flags if there are enough unused bits, otherwise use
page_ext.I agree that if you're going to implement this feature at all, then keying off of
CONFIG_MEM_ALLOC_PROFILINGseems sufficient, and no need to addCONFIG_PGALLOC_TAG_USE_PAGEFLAGSon top of that.
Yosry's original guess was correct. If not for loadable modules we could get away with having no CONFIG_PGALLOC_TAG_USE_PAGEFLAGS. We could try to fit codetag references into page flags and if they do not fit we could fall back to page_ext. That works fine when we have a predetermined number of tags. But loadable modules make this number variable at runtime and there is a possibility we run out of page flag bits at runtime. In that case, the current patchset disables memory profiling and issues a warning that the user should disable CONFIG_PGALLOC_TAG_USE_PAGEFLAGS to avoid this situation. I expect this to be a rare case but it can happen and we have to provide a way for a user to avoid running out of bits, which is where CONFIG_PGALLOC_TAG_USE_PAGEFLAGS would be used.
Thanks,
Suren.
Quoted 7 lines
thanks,
--
John HubbardTo unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 47 lines · Suren Baghdasaryan
Quoted 36 lines · John Hubbard' via kernel-team
Quoted 34 lines · Yosry Ahmed
Quoted 20 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
I think we already always use
page_exttoday. My understanding is that the purpose of this series is to give the option to avoid usingpage_extif there are enough unused page flags anyway, which reduces memory waste and improves performance.Quoted 7 lines
Quoted 3 lines
My question is just why not have that be the default behavior with a config option, use page flags if there are enough unused bits, otherwise use
page_ext.I agree that if you're going to implement this feature at all, then keying off of
CONFIG_MEM_ALLOC_PROFILINGseems sufficient, and no need to addCONFIG_PGALLOC_TAG_USE_PAGEFLAGSon top of that.
Quoted 12 lines
Yosry's original guess was correct. If not for loadable modules we could get away with having no
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS. We could try to fit codetag references into page flags and if they do not fit we could fall back topage_ext. That works fine when we have a predetermined number of tags. But loadable modules make this number variable at runtime and there is a possibility we run out of page flag bits at runtime. In that case, the current patchset disables memory profiling and issues a warning that the user should disableCONFIG_PGALLOC_TAG_USE_PAGEFLAGSto avoid this situation. I expect this to be a rare case but it can happen and we have to provide a way for a user to avoid running out of bits, which is whereCONFIG_PGALLOC_TAG_USE_PAGEFLAGSwould be used.
If this is in fact a rare case, I think it may make more sense for the config to be on by default, and the config description would clearly state that it is intended to be turned off only if the loadable modules warning fires.
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 62 lines · Yosry Ahmed
Quoted 47 lines · Suren Baghdasaryan
Quoted 36 lines · John Hubbard' via kernel-team
Quoted 34 lines · Yosry Ahmed
Quoted 20 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
I think we already always use
page_exttoday. My understanding is that the purpose of this series is to give the option to avoid usingpage_extif there are enough unused page flags anyway, which reduces memory waste and improves performance.Quoted 7 lines
Quoted 3 lines
My question is just why not have that be the default behavior with a config option, use page flags if there are enough unused bits, otherwise use
page_ext.I agree that if you're going to implement this feature at all, then keying off of
CONFIG_MEM_ALLOC_PROFILINGseems sufficient, and no need to addCONFIG_PGALLOC_TAG_USE_PAGEFLAGSon top of that.Quoted 12 lines
Yosry's original guess was correct. If not for loadable modules we could get away with having no
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS. We could try to fit codetag references into page flags and if they do not fit we could fall back topage_ext. That works fine when we have a predetermined number of tags. But loadable modules make this number variable at runtime and there is a possibility we run out of page flag bits at runtime. In that case, the current patchset disables memory profiling and issues a warning that the user should disableCONFIG_PGALLOC_TAG_USE_PAGEFLAGSto avoid this situation. I expect this to be a rare case but it can happen and we have to provide a way for a user to avoid running out of bits, which is whereCONFIG_PGALLOC_TAG_USE_PAGEFLAGSwould be used.
Quoted 4 lines
If this is in fact a rare case, I think it may make more sense for the config to be on by default, and the config description would clearly state that it is intended to be turned off only if the loadable modules warning fires.
Just to be clear, I think running out of pageflag bits at runtime (as a result of module loading) will be a rare case. That's because the core kernel has many more allocations than a typical module. Not having enough bits for the core kernel might be the most prevalent case, at least for large systems.
That said, your suggestion makes sense. Since we have to keep CONFIG_PAGE_EXTENSION dependency (for the cases when we have to fall back to page_ext), there is no advantage of keeping CONFIG_PGALLOC_TAG_USE_PAGEFLAGS disabled. I'll change the default in the next version. Thanks for the suggestion!
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
In reply to John HubbardQuoted 19 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?
Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
My 2 cents: there is nothing wrong about consuming unused page flags in a configuration. No need to let them stay unused in a configuration :)
The real issue starts once another feature wants to make use of some of them ... in such configuration there would be less available for allocation tags and the performance of allocations tags might consequently get worse again.
Signature · 3 lines
Cheers, David / dhildenb
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 29 lines · David Hildenbrand
Quoted 19 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
Quoted 7 lines
My 2 cents: there is nothing wrong about consuming unused page flags in a configuration. No need to let them stay unused in a configuration :)
The real issue starts once another feature wants to make use of some of them ... in such configuration there would be less available for allocation tags and the performance of allocations tags might consequently get worse again.
Thanks for the input and indeed this is the case. If this happens, we will get a warning telling us that page flags could not be used and page_ext will be used instead. I think that's the best I can do given that page flag bits is a limited resource.
Quoted 6 lines
--
Cheers,David / dhildenb
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 38 lines · Suren Baghdasaryan
Quoted 29 lines · David Hildenbrand
Quoted 19 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
Quoted 7 lines
My 2 cents: there is nothing wrong about consuming unused page flags in a configuration. No need to let them stay unused in a configuration :)
The real issue starts once another feature wants to make use of some of them ... in such configuration there would be less available for allocation tags and the performance of allocations tags might consequently get worse again.
Quoted 4 lines
Thanks for the input and indeed this is the case. If this happens, we will get a warning telling us that page flags could not be used and
page_extwill be used instead. I think that's the best I can do given that page flag bits is a limited resource.
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
So a "The Lord has given, and the Lord has taken away!" mentality might be required when consuming that many scarce resources, meaning, as long as they are actually unused, use them, but it should not block other features that really need them.
Does that make sense?
Signature · 3 lines
Cheers, David / dhildenb
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 45 lines · David Hildenbrand
Quoted 38 lines · Suren Baghdasaryan
Quoted 29 lines · David Hildenbrand
Quoted 19 lines · John Hubbard
Quoted 14 lines · Yosry Ahmed
Quoted 12 lines · Suren Baghdasaryan
Add
CONFIG_PGALLOC_TAG_USE_PAGEFLAGSto store allocation tag references directly in the page flags. This eliminates memory overhead caused bypage_extand results in better performance for page allocations.
If the number of available page flag bits is insufficient to address all kernel allocations, profiling falls back to using page extensions with an appropriate warning to disable this config.
If dynamically loaded modules add enough tags that they can't be addressed anymore with available page flag bits, memory profiling gets disabled and a warning is issued.Quoted 3 lines
Just curious, why do we need a config option? If there are enough bits in page flags, why not use them automatically or fallback to
page_extotherwise?Quoted 7 lines
Or better yet, *always* fall back to
page_ext, thus leaving the scarce and valuable page flags available for other features?Sorry Suren, to keep coming back to this suggestion, I know I'm driving you crazy here! But I just keep thinking it through and failing to see why this feature deserves to consume so many page flags.
Quoted 7 lines
My 2 cents: there is nothing wrong about consuming unused page flags in a configuration. No need to let them stay unused in a configuration :)
The real issue starts once another feature wants to make use of some of them ... in such configuration there would be less available for allocation tags and the performance of allocations tags might consequently get worse again.
Quoted 4 lines
Thanks for the input and indeed this is the case. If this happens, we will get a warning telling us that page flags could not be used and
page_extwill be used instead. I think that's the best I can do given that page flag bits is a limited resource.
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=n and keep what we have today. That's why I'm strongly advocating that we do need CONFIG_PGALLOC_TAG_USE_PAGEFLAGS so that the user has control over how this scarce resource is used.
Quoted 5 lines
So a "The Lord has given, and the Lord has taken away!" mentality might be required when consuming that many scarce resources, meaning, as long as they are actually unused, use them, but it should not block other features that really need them.
I agree and I think that's what I implemented here. If there are enough page flag bits we use them, otherwise we automatically fall back to page_ext.
Quoted 2 lines
Does that make sense?
Absolutely and thank you all for the feedback.
Quoted 6 lines
--
Cheers,David / dhildenb
Michal Hocko
reviewerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 1 line · Suren Baghdasaryan
On Tue, Oct 15, 2024 at 8:42 AM David Hildenbrand <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
Quoted 8 lines
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=nand keep what we have today. That's why I'm strongly advocating that we do needCONFIG_PGALLOC_TAG_USE_PAGEFLAGSso that the user has control over how this scarce resource is used.
I really do not think users will know how/why to setup this and I wouldn't even bother them thinking about that at all TBH.
This is an implementation detail. It is fine to reuse unused flags space as a storage as a performance optimization but why do you want users to bother with that? Why would they ever want to say N here?
Signature · 2 lines
Michal Hocko SUSE Labs
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 18 lines · Michal Hocko
Quoted 1 line · Suren Baghdasaryan
On Tue, Oct 15, 2024 at 8:42 AM David Hildenbrand <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
Quoted 8 lines
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=nand keep what we have today. That's why I'm strongly advocating that we do needCONFIG_PGALLOC_TAG_USE_PAGEFLAGSso that the user has control over how this scarce resource is used.
Quoted 6 lines
I really do not think users will know how/why to setup this and I wouldn't even bother them thinking about that at all TBH.
This is an implementation detail. It is fine to reuse unused flags space as a storage as a performance optimization but why do you want users to bother with that? Why would they ever want to say N here?
In this patch you can find a couple of warnings that look like this:
pr_warn("With module %s there are too many tags to fit in %d page flag bits. Memory profiling is disabled!\n", mod->name, NR_UNUSED_PAGEFLAG_BITS);
emitted when we run out of page flag bits during a module loading,
pr_err("%s: alignment %lu is incompatible with allocation tag indexing, disable CONFIG_PGALLOC_TAG_USE_PAGEFLAGS", mod->name, align);
emitted when the arch-specific section alignment is incompatible with alloc_tag indexing.
I'll change the first one to also specifically guide the user to disable CONFIG_PGALLOC_TAG_USE_PAGEFLAGS.
When these happen, memory profiling gets disabled automatically. These two cases would be the main ones when the user would want to disable CONFIG_PGALLOC_TAG_USE_PAGEFLAGS to keep memory profiling enabled. I also think when we auto-disable memory profiling at runtime like that, I should make /proc/allocinfo empty so that it's apparent it is disabled and the user does not use stale data.
Quoted 3 lines
--
Michal Hocko
SUSE Labs
Michal Hocko
reviewerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 33 lines · Suren Baghdasaryan
Quoted 18 lines · Michal Hocko
Quoted 1 line · Suren Baghdasaryan
On Tue, Oct 15, 2024 at 8:42 AM David Hildenbrand <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
Quoted 8 lines
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=nand keep what we have today. That's why I'm strongly advocating that we do needCONFIG_PGALLOC_TAG_USE_PAGEFLAGSso that the user has control over how this scarce resource is used.Quoted 6 lines
I really do not think users will know how/why to setup this and I wouldn't even bother them thinking about that at all TBH.
This is an implementation detail. It is fine to reuse unused flags space as a storage as a performance optimization but why do you want users to bother with that? Why would they ever want to say N here?
In this patch you can find a couple of warnings that look like this:
pr_warn("With module %s there are too many tags to fit in %d page flag bits. Memory profiling is disabled!\n",
mod->name,NR_UNUSED_PAGEFLAG_BITS);
emitted when we run out of page flag bits during a module loading,
Quoted 5 lines
pr_err("%s: alignment %lu is incompatible with allocation tag indexing, disable
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS",mod->name, align);
emitted when the arch-specific section alignment is incompatible withalloc_tagindexing.
You are asking users to workaround implementation issue by configuration which sounds like a really bad idea. Why cannot you make the fallback automatic?
Signature · 2 lines
Michal Hocko SUSE Labs
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 41 lines · Michal Hocko
Quoted 33 lines · Suren Baghdasaryan
Quoted 18 lines · Michal Hocko
Quoted 1 line · Suren Baghdasaryan
On Tue, Oct 15, 2024 at 8:42 AM David Hildenbrand <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
Quoted 8 lines
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=nand keep what we have today. That's why I'm strongly advocating that we do needCONFIG_PGALLOC_TAG_USE_PAGEFLAGSso that the user has control over how this scarce resource is used.Quoted 6 lines
I really do not think users will know how/why to setup this and I wouldn't even bother them thinking about that at all TBH.
This is an implementation detail. It is fine to reuse unused flags space as a storage as a performance optimization but why do you want users to bother with that? Why would they ever want to say N here?
In this patch you can find a couple of warnings that look like this:
pr_warn("With module %s there are too many tags to fit in %d page flag bits. Memory profiling is disabled!\n",
mod->name,NR_UNUSED_PAGEFLAG_BITS);
emitted when we run out of page flag bits during a module loading,Quoted 5 lines
pr_err("%s: alignment %lu is incompatible with allocation tag indexing, disable
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS",mod->name, align);
emitted when the arch-specific section alignment is incompatible withalloc_tagindexing.
Quoted 3 lines
You are asking users to workaround implementation issue by configuration which sounds like a really bad idea. Why cannot you make the fallback automatic?
Automatic fallback is possible during boot, when we decide whether to enable page extensions or not. So, if during boot we decide to disable page extensions and use page flags, we can't go back and re-enable page extensions after boot is complete. Since there is a possibility that we run out of page flags at runtime when we load a new module, this leaves this case when we can't reference the module tags and we can't fall back to page extensions, so we have to disable memory profiling.
I could keep page extensions always on just in case this happens but that's a lot of memory waste to handle a rare case...
Quoted 4 lines
--
Michal Hocko
SUSE Labs
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 47 lines · Suren Baghdasaryan
Quoted 41 lines · Michal Hocko
Quoted 33 lines · Suren Baghdasaryan
Quoted 18 lines · Michal Hocko
Quoted 1 line · Suren Baghdasaryan
On Tue, Oct 15, 2024 at 8:42 AM David Hildenbrand <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
Quoted 8 lines
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=nand keep what we have today. That's why I'm strongly advocating that we do needCONFIG_PGALLOC_TAG_USE_PAGEFLAGSso that the user has control over how this scarce resource is used.Quoted 6 lines
I really do not think users will know how/why to setup this and I wouldn't even bother them thinking about that at all TBH.
This is an implementation detail. It is fine to reuse unused flags space as a storage as a performance optimization but why do you want users to bother with that? Why would they ever want to say N here?
In this patch you can find a couple of warnings that look like this:
pr_warn("With module %s there are too many tags to fit in %d page flag bits. Memory profiling is disabled!\n",
mod->name,NR_UNUSED_PAGEFLAG_BITS);
emitted when we run out of page flag bits during a module loading,Quoted 5 lines
pr_err("%s: alignment %lu is incompatible with allocation tag indexing, disable
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS",mod->name, align);
emitted when the arch-specific section alignment is incompatible withalloc_tagindexing.Quoted 3 lines
You are asking users to workaround implementation issue by configuration which sounds like a really bad idea. Why cannot you make the fallback automatic?
Quoted 10 lines
Automatic fallback is possible during boot, when we decide whether to enable page extensions or not. So, if during boot we decide to disable page extensions and use page flags, we can't go back and re-enable page extensions after boot is complete. Since there is a possibility that we run out of page flags at runtime when we load a new module, this leaves this case when we can't reference the module tags and we can't fall back to page extensions, so we have to disable memory profiling.
I could keep page extensions always on just in case this happens but that's a lot of memory waste to handle a rare case...
After thinking more about this, I suggest a couple of changes that IMHO would make configuration simpler:
1. Change the CONFIG_PGALLOC_TAG_USE_PAGEFLAGS to an early boot parameter. Today we have a "mem_profiling" parameter to enable/disable memory profiling. I suggest adding "mem_profiling_use_pgflags" to switch the current behavior of using page extensions to use page flags. We keep the current behavior of using page extensions as default (mem_profiling_use_pgflags=0) because it always works even though it has higher overhead.
2. No auto-fallback. If mem_profiling_use_pgflags=1 and we don't have enough page flags (at boot time or later when we load a module), we simply disable memory profiling with a warning.
I think this would be less confusing for users and will avoid David's example when performance is unexpectedly degraded. The default option will work for everyone as it does today and advanced users who want to minimize the overhead can set mem_profiling_use_pgflags=1 to check if that works for their system.
WDYT?
Quoted 5 lines
Quoted 5 lines
--
Michal Hocko
SUSE Labs
Michal Hocko
reviewerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 59 lines · Suren Baghdasaryan
Quoted 47 lines · Suren Baghdasaryan
Quoted 41 lines · Michal Hocko
Quoted 33 lines · Suren Baghdasaryan
Quoted 18 lines · Michal Hocko
Quoted 1 line · Suren Baghdasaryan
On Tue, Oct 15, 2024 at 8:42 AM David Hildenbrand <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
Quoted 8 lines
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=nand keep what we have today. That's why I'm strongly advocating that we do needCONFIG_PGALLOC_TAG_USE_PAGEFLAGSso that the user has control over how this scarce resource is used.Quoted 6 lines
I really do not think users will know how/why to setup this and I wouldn't even bother them thinking about that at all TBH.
This is an implementation detail. It is fine to reuse unused flags space as a storage as a performance optimization but why do you want users to bother with that? Why would they ever want to say N here?
In this patch you can find a couple of warnings that look like this:
pr_warn("With module %s there are too many tags to fit in %d page flag bits. Memory profiling is disabled!\n",
mod->name,NR_UNUSED_PAGEFLAG_BITS);
emitted when we run out of page flag bits during a module loading,Quoted 5 lines
pr_err("%s: alignment %lu is incompatible with allocation tag indexing, disable
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS",mod->name, align);
emitted when the arch-specific section alignment is incompatible withalloc_tagindexing.Quoted 3 lines
You are asking users to workaround implementation issue by configuration which sounds like a really bad idea. Why cannot you make the fallback automatic?
Quoted 10 lines
Automatic fallback is possible during boot, when we decide whether to enable page extensions or not. So, if during boot we decide to disable page extensions and use page flags, we can't go back and re-enable page extensions after boot is complete. Since there is a possibility that we run out of page flags at runtime when we load a new module, this leaves this case when we can't reference the module tags and we can't fall back to page extensions, so we have to disable memory profiling.
I could keep page extensions always on just in case this happens but that's a lot of memory waste to handle a rare case...
Quoted 4 lines
After thinking more about this, I suggest a couple of changes that IMHO would make configuration simpler:
1. Change theCONFIG_PGALLOC_TAG_USE_PAGEFLAGSto an early boot parameter.
This makes much more sense!
Quoted 4 lines
Today we have a "
mem_profiling" parameter to enable/disable memory profiling. I suggest adding "mem_profiling_use_pgflags" to switch the current behavior of using page extensions to use page flags.
I do not want to bikeshed about this but to me it would make more sense to have an extension paramater to mem_profiling and call it something like compress or similar so that page flags are not really carved into naming. The docuemntation then can explain that the copression cannot be always guaranteed and it might fail so this is more of a optimistic and potentially failing optimization that might need to be dropped in some usege scenarios.
Quoted 3 lines
We keep the current behavior of using page extensions as default (mem_profiling_use_pgflags=0) because it always works even though it has higher overhead.
Yes this seems to be a safe default.
Quoted 3 lines
2. No auto-fallback. If mem_profiling_use_pgflags=1 and we don't have enough page flags (at boot time or later when we load a module), we simply disable memory profiling with a warning.
No strong opinion on this.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Am 21.10.24 um 09:26 schrieb Michal Hocko:
Quoted 28 lines · Suren Baghdasaryan
Quoted 15 lines · Suren Baghdasaryan
Quoted 13 lines · Michal Hocko
Automatic fallback is possible during boot, when we decide whether to enable page extensions or not. So, if during boot we decide to disable page extensions and use page flags, we can't go back and re-enable page extensions after boot is complete. Since there is a possibility that we run out of page flags at runtime when we load a new module, this leaves this case when we can't reference the module tags and we can't fall back to page extensions, so we have to disable memory profiling.
I could keep page extensions always on just in case this happens but that's a lot of memory waste to handle a rare case...Quoted 4 lines
After thinking more about this, I suggest a couple of changes that IMHO would make configuration simpler:
1. Change theCONFIG_PGALLOC_TAG_USE_PAGEFLAGSto an early boot parameter.This makes much more sense!
Quoted 4 lines
Today we have a "
mem_profiling" parameter to enable/disable memory profiling. I suggest adding "mem_profiling_use_pgflags" to switch the current behavior of using page extensions to use page flags.
Quoted 7 lines
I do not want to bikeshed about this but to me it would make more sense to have an extension paramater to
mem_profilingand call it something like compress or similar so that page flags are not really carved into naming. The docuemntation then can explain that the copression cannot be always guaranteed and it might fail so this is more of a optimistic and potentially failing optimization that might need to be dropped in some usege scenarios.
Maybe we can reuse the existing parameter (e.g., tristate). Only makes sense if we don't expect too many other modes though :)
Quoted 6 lines
Quoted 4 lines
We keep the current behavior of using page extensions as default (mem_profiling_use_pgflags=0) because it always works even though it has higher overhead.
Yes this seems to be a safe default.
Agreed.
Quoted 4 lines
Quoted 4 lines
2. No auto-fallback. If mem_profiling_use_pgflags=1 and we don't have enough page flags (at boot time or later when we load a module), we simply disable memory profiling with a warning.
Sounds reasonable to me.
Signature · 3 lines
Cheers, David / dhildenb
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 40 lines · David Hildenbrand
Am 21.10.24 um 09:26 schrieb Michal Hocko:
Quoted 28 lines · Suren Baghdasaryan
Quoted 15 lines · Suren Baghdasaryan
Quoted 13 lines · Michal Hocko
Automatic fallback is possible during boot, when we decide whether to enable page extensions or not. So, if during boot we decide to disable page extensions and use page flags, we can't go back and re-enable page extensions after boot is complete. Since there is a possibility that we run out of page flags at runtime when we load a new module, this leaves this case when we can't reference the module tags and we can't fall back to page extensions, so we have to disable memory profiling.
I could keep page extensions always on just in case this happens but that's a lot of memory waste to handle a rare case...Quoted 4 lines
After thinking more about this, I suggest a couple of changes that IMHO would make configuration simpler:
1. Change theCONFIG_PGALLOC_TAG_USE_PAGEFLAGSto an early boot parameter.This makes much more sense!
Quoted 4 lines
Today we have a "
mem_profiling" parameter to enable/disable memory profiling. I suggest adding "mem_profiling_use_pgflags" to switch the current behavior of using page extensions to use page flags.Quoted 7 lines
I do not want to bikeshed about this but to me it would make more sense to have an extension paramater to
mem_profilingand call it something like compress or similar so that page flags are not really carved into naming. The docuemntation then can explain that the copression cannot be always guaranteed and it might fail so this is more of a optimistic and potentially failing optimization that might need to be dropped in some usege scenarios.
Quoted 2 lines
Maybe we can reuse the existing parameter (e.g., tristate). Only makes sense if we don't expect too many other modes though :)
Yeah, I thought about adding new values to "mem_profiling" but it's a bit complicated. Today it's a tristate:
mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable page_ext at boot even when it's set to 0.
"never" means we do not enable page_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution has CONFIG_MEM_ALLOC_PROFILING=y but the user does not use it and does not want to waste memory on enabling page_ext.
I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for page_ext mode). IOW we will need to encode also the default state we want. Something like this:
mem_profiling=0|1|never|pgflags_on|pgflags_off
Would this be acceptable?
Quoted 22 lines
Quoted 7 lines
Quoted 5 lines
We keep the current behavior of using page extensions as default (mem_profiling_use_pgflags=0) because it always works even though it has higher overhead.
Yes this seems to be a safe default.
Agreed.
Quoted 4 lines
Quoted 4 lines
2. No auto-fallback. If mem_profiling_use_pgflags=1 and we don't have enough page flags (at boot time or later when we load a module), we simply disable memory profiling with a warning.
Sounds reasonable to me.
--
Cheers,David / dhildenb
Michal Hocko
reviewerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]
Quoted 13 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.
Quoted 8 lines
I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Signature · 2 lines
Michal Hocko SUSE Labs
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 23 lines · Michal Hocko
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]Quoted 20 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Quoted 7 lines
Quoted 1 line
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Oh, you mean having 2 parts in the parameter with supported options being:
mem_profiling=never
mem_profiling=0
mem_profiling=1
mem_profiling=0,pgflags
mem_profiling=1,pgflags
Did I understand correctly? If so then yes, this should work.
Quoted 3 lines
--
Michal Hocko
SUSE Labs
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 32 lines · Suren Baghdasaryan
Quoted 23 lines · Michal Hocko
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]Quoted 20 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Quoted 7 lines
Quoted 1 line
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Quoted 8 lines
Oh, you mean having 2 parts in the parameter with supported options being:
mem_profiling=never
mem_profiling=0
mem_profiling=1
mem_profiling=0,pgflags
mem_profiling=1,pgflags
That's also a viable solution indeed.
Signature · 3 lines
Cheers, David / dhildenb
Michal Hocko
reviewerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
In reply to Suren BaghdasaryanQuoted 34 lines · Suren Baghdasaryan
Quoted 23 lines · Michal Hocko
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]Quoted 20 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Quoted 7 lines
Quoted 1 line
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Oh, you mean having 2 parts in the parameter with supported options being:
Quoted 7 lines
mem_profiling=never
mem_profiling=0
mem_profiling=1
mem_profiling=0,pgflags
mem_profiling=1,pgflagsDid I understand correctly? If so then yes, this should work.
yes. I would just not call it pgflags because that just doesn't really tell what the option is to anybody but kernel developers. You could also have an option to override the default (disable profiling) failure strategy.
Signature · 2 lines
Michal Hocko SUSE Labs
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 42 lines · Michal Hocko
Quoted 40 lines · Suren Baghdasaryan
Quoted 23 lines · Michal Hocko
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]Quoted 20 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Quoted 7 lines
Quoted 1 line
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Oh, you mean having 2 parts in the parameter with supported options being:
mem_profiling=never
mem_profiling=0
mem_profiling=1
mem_profiling=0,pgflags
mem_profiling=1,pgflags
Quoted 5 lines
Quoted 1 line
Did I understand correctly? If so then yes, this should work.
yes. I would just not call it pgflags because that just doesn't really tell what the option is to anybody but kernel developers. You could also have an option to override the default (disable profiling) failure strategy.
Ok, how about "compressed" instead? Like this:
mem_profiling=0,compressed
Quoted 3 lines
--
Michal Hocko
SUSE Labs
Michal Hocko
reviewerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 45 lines · Suren Baghdasaryan
Quoted 44 lines · Michal Hocko
Quoted 41 lines · Suren Baghdasaryan
Quoted 23 lines · Michal Hocko
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]Quoted 20 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Quoted 7 lines
Quoted 1 line
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Oh, you mean having 2 parts in the parameter with supported options being:
mem_profiling=never
mem_profiling=0
mem_profiling=1
mem_profiling=0,pgflags
mem_profiling=1,pgflagsDid I understand correctly? If so then yes, this should work.
Quoted 7 lines
Quoted 3 lines
yes. I would just not call it pgflags because that just doesn't really tell what the option is to anybody but kernel developers. You could also have an option to override the default (disable profiling) failure strategy.
Ok, how about "compressed" instead? Like this:
mem_profiling=0,compressed
Sounds good to me. And just to repeat, I do not really care about specific name but let's just stay away from something as specific as page flags because that is really not helping to understand the purpose but rather the underlying mechanism which is not telling much to most users outside of kernel developers.
Signature · 2 lines
Michal Hocko SUSE Labs
Suren Baghdasaryan
maintainerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 53 lines · Michal Hocko
Quoted 51 lines · Suren Baghdasaryan
Quoted 42 lines · Michal Hocko
Quoted 40 lines · Suren Baghdasaryan
Quoted 23 lines · Michal Hocko
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]Quoted 20 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Quoted 7 lines
Quoted 1 line
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Oh, you mean having 2 parts in the parameter with supported options being:
mem_profiling=never
mem_profiling=0
mem_profiling=1
mem_profiling=0,pgflags
mem_profiling=1,pgflagsQuoted 5 lines
Quoted 1 line
Did I understand correctly? If so then yes, this should work.
yes. I would just not call it pgflags because that just doesn't really tell what the option is to anybody but kernel developers. You could also have an option to override the default (disable profiling) failure strategy.
Ok, how about "compressed" instead? Like this:
Quoted 7 lines
Quoted 1 line
mem_profiling=0,compressed
Sounds good to me. And just to repeat, I do not really care about specific name but let's just stay away from something as specific as page flags because that is really not helping to understand the purpose but rather the underlying mechanism which is not telling much to most users outside of kernel developers.
Understood. Ok, I'll start changing my patchset to incorporate this feedback and will post the new version this week.
Thanks for the input everyone!
Quoted 4 lines
--
Michal Hocko
SUSE Labs
Re: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
Quoted 45 lines · Suren Baghdasaryan
Quoted 44 lines · Michal Hocko
Quoted 43 lines · Suren Baghdasaryan
Quoted 42 lines · Michal Hocko
Quoted 40 lines · Suren Baghdasaryan
Quoted 22 lines · Michal Hocko
On Mon 21-10-24 08:05:16, Suren Baghdasaryan wrote:
[...]Quoted 20 lines
Yeah, I thought about adding new values to "
mem_profiling" but it's a bit complicated. Today it's a tristate:mem_profiling=0|1|never
0/1 means we disable/enable memory profiling by default but the user can enable it at runtime using a sysctl. This means that we enable
page_extat boot even when it's set to 0.
"never" means we do not enablepage_ext, memory profiling is disabled and sysctl to enable it will not be exposed. Used when a distribution hasCONFIG_MEM_ALLOC_PROFILING=ybut the user does not use it and does not want to waste memory on enablingpage_ext.I can add another option like "pgflags" but then it also needs to specify whether we should enable or disable profiling by default (similar to 0|1 for
page_extmode). IOW we will need to encode also the default state we want. Something like this:mem_profiling=0|1|never|pgflags_on|pgflags_off
Quoted 7 lines
Quoted 1 line
Would this be acceptable?
Isn't this overcomplicating it? Why cannot you simply go with mem_profiling={0|never|1}[,$YOUR_OPTIONS]
While $YOUR_OPTIONS could be compress,fallback,ponies and it would apply or just be ignored if that is not applicable.
Oh, you mean having 2 parts in the parameter with supported options being:
mem_profiling=never
mem_profiling=0
mem_profiling=1
mem_profiling=0,pgflags
mem_profiling=1,pgflagsDid I understand correctly? If so then yes, this should work.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
yes. I would just not call it pgflags because that just doesn't really tell what the option is to anybody but kernel developers. You could also have an option to override the default (disable profiling) failure strategy.
Ok, how about "compressed" instead? Like this:
mem_profiling=0,compressed
Yes. The configuration options all fit together nicely now, and the naming seems exactly right as well. And no more "you must rebuild your kernel" messages. Great!
thanks,
Signature · 1 line
John Hubbard
Quoted 15 lines
Quoted 6 lines
Sounds good to me. And just to repeat, I do not really care about specific name but let's just stay away from something as specific as page flags because that is really not helping to understand the purpose but rather the underlying mechanism which is not telling much to most users outside of kernel developers.
Understood. Ok, I'll start changing my patchset to incorporate this feedback and will post the new version this week.
Thanks for the input everyone!Quoted 4 lines
--
Michal Hocko
SUSE Labs
Michal Hocko
reviewerRe: [PATCH v3 5/5] alloc_tag: config to store page allocation tag refs in page flags
In reply to Suren BaghdasaryanQuoted 46 lines · Suren Baghdasaryan
Quoted 41 lines · Michal Hocko
Quoted 33 lines · Suren Baghdasaryan
Quoted 18 lines · Michal Hocko
Quoted 1 line · Suren Baghdasaryan
On Tue, Oct 15, 2024 at 8:42 AM David Hildenbrand <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 4 lines
Right, I think what John is concerned about (and me as well) is that once a new feature really needs a page flag, there will be objection like "no you can't, we need them for allocation tags otherwise that feature will be degraded".
Quoted 8 lines
I do understand your concern but IMHO the possibility of degrading a feature should not be a reason to always operate at degraded capacity (which is what we have today). If one is really concerned about possible future regression they can set
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=nand keep what we have today. That's why I'm strongly advocating that we do needCONFIG_PGALLOC_TAG_USE_PAGEFLAGSso that the user has control over how this scarce resource is used.Quoted 6 lines
I really do not think users will know how/why to setup this and I wouldn't even bother them thinking about that at all TBH.
This is an implementation detail. It is fine to reuse unused flags space as a storage as a performance optimization but why do you want users to bother with that? Why would they ever want to say N here?
In this patch you can find a couple of warnings that look like this:
pr_warn("With module %s there are too many tags to fit in %d page flag bits. Memory profiling is disabled!\n",
mod->name,NR_UNUSED_PAGEFLAG_BITS);
emitted when we run out of page flag bits during a module loading,Quoted 5 lines
pr_err("%s: alignment %lu is incompatible with allocation tag indexing, disable
CONFIG_PGALLOC_TAG_USE_PAGEFLAGS",mod->name, align);
emitted when the arch-specific section alignment is incompatible withalloc_tagindexing.Quoted 3 lines
You are asking users to workaround implementation issue by configuration which sounds like a really bad idea. Why cannot you make the fallback automatic?
Quoted 8 lines
Automatic fallback is possible during boot, when we decide whether to enable page extensions or not. So, if during boot we decide to disable page extensions and use page flags, we can't go back and re-enable page extensions after boot is complete. Since there is a possibility that we run out of page flags at runtime when we load a new module, this leaves this case when we can't reference the module tags and we can't fall back to page extensions, so we have to disable memory profiling.
Right, I do understand (I guess) the challenge. I am just arguing that it makes really no sense to tell user to recompile the kernel with a CONFIG_FOO to workaround this limitation. Please note that many users of this feature will simply use a precompiled (e.g. distribution) kernels. Once you force somebody to recompile with CONFIG_PGALLOC_TAG_USE_PAGEFLAGS=n they are not going back to a more memory optimal implementation.
Just my 2cents
Signature · 2 lines
Michal Hocko SUSE Labs
Andrew Morton
maintainerQuoted 6 lines · On Mon, 14 Oct 2024 13:36:41 -0700 Suren Baghdasaryan <[email protected]> wrote:
Patch #2 copies module tags into virtually contiguous memory which serves two purposes:
- Lets us deal with the situation when module is unloaded while there are still live allocations from that module. Since we are using a copy version of the tags we can safely unload the module. Space and gaps in this contiguous memory are managed using a maple tree.
Does this make "lib: alloc_tag_module_unload must wait for pending kfree_rcu calls" unneeded? If so, that patch was cc:stable (justifyably), so what to do about that?
Suren Baghdasaryan
maintainerQuoted 10 lines · Andrew Morton
Quoted 6 lines · On Mon, 14 Oct 2024 13:36:41 -0700 Suren Baghdasaryan <[email protected]> wrote:
Patch #2 copies module tags into virtually contiguous memory which serves two purposes:
- Lets us deal with the situation when module is unloaded while there are still live allocations from that module. Since we are using a copy version of the tags we can safely unload the module. Space and gaps in this contiguous memory are managed using a maple tree.
Quoted 2 lines
Does this make "lib:
alloc_tag_module_unloadmust wait for pendingkfree_rcucalls" unneeded?
With this change we can unload a module even when tags from that module are still in use. However "lib: alloc_tag_module_unload must wait for pending kfree_rcu calls" would still be useful because it will allow us to release the memory occupied by module's tags and let other modules use that memory.
Quoted 1 line
If so, that patch was cc:stable (justifyably), so what to do about that?
Now that I posted this patchset I'll work on backporting "lib:alloc_tag_module_unload must wait for pending kfree_rcu calls" and its prerequisites to 6.10 and 6.11. I'll try to get backports out tomorrow.
I don't think we need to backport this patchset to pre-6.12 kernels since this is an improvement and not a bug fix. But if it's needed I can backport it as well.
Thanks,
Suren.
Suren Baghdasaryan
maintainerQuoted 21 lines · Suren Baghdasaryan
Quoted 10 lines · Andrew Morton
Quoted 6 lines · On Mon, 14 Oct 2024 13:36:41 -0700 Suren Baghdasaryan <[email protected]> wrote:
Patch #2 copies module tags into virtually contiguous memory which serves two purposes:
- Lets us deal with the situation when module is unloaded while there are still live allocations from that module. Since we are using a copy version of the tags we can safely unload the module. Space and gaps in this contiguous memory are managed using a maple tree.Quoted 2 lines
Does this make "lib:
alloc_tag_module_unloadmust wait for pendingkfree_rcucalls" unneeded?With this change we can unload a module even when tags from that module are still in use. However "lib:
alloc_tag_module_unloadmust wait for pendingkfree_rcucalls" would still be useful because it will allow us to release the memory occupied by module's tags and let other modules use that memory.
Quoted 6 lines
Quoted 1 line
If so, that patch was cc:stable (justifyably), so what to do about that?
Now that I posted this patchset I'll work on backporting "lib:
alloc_tag_module_unloadmust wait for pendingkfree_rcucalls" and its prerequisites to 6.10 and 6.11. I'll try to get backports out tomorrow.
I prepared 6.10 and 6.11 backports for
https://lore.kernel.org/all/[email protected] but will wait for it to get merged into Linus' tree before posting them to stable.
Thanks,
Suren.
Quoted 5 lines
I don't think we need to backport this patchset to pre-6.12 kernels since this is an improvement and not a bug fix. But if it's needed I can backport it as well.
Thanks,
Suren.