FAILED: patch "[PATCH] mm: kfence: fix objcgs vector allocation" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8f0b36497303487d5a32c75789c77859cc2ee895 Mon Sep 17 00:00:00 2001
From: Muchun Song <[email protected]>
Date: Fri, 1 Apr 2022 11:28:36 -0700
Subject: [PATCH] mm: kfence: fix objcgs vector allocation
If the kfence object is allocated to be used for objects vector, then this slot of the pool eventually being occupied permanently since the vector is never freed. The solutions could be (1) freeing vector when the kfence object is freed or (2) allocating all vectors statically.
Since the memory consumption of object vectors is low, it is better to chose (2) to fix the issue and it is also can reduce overhead of vectors allocating in the future.
mm/kfence/core.c +10 -1
@@ -566,6 +566,8 @@ static unsigned long kfence_init_pool(void)* enters __slab_free() slow-path. */ for (i =0 ; i <KFENCE_POOL_SIZE /PAGE_SIZE ; i++) { +struct slab *slab =page_slab (&pages[i]); +if (!i || (i %2 ))continue ;
@@ -573,7 +575,11 @@ static unsigned long kfence_init_pool(void)if (WARN_ON (compound_head (&pages[i]) != &pages[i]))return addr; -__SetPageSlab (&pages[i]); +__folio_set_slab (slab_folio (slab)); +#ifdef CONFIG_MEMCG + slab->memcg_data = (unsigned long )&kfence_metadata[i /2 -1 ].objcg | +MEMCG_DATA_OBJCGS ; +#endif }/*
@@ -1033,6 +1039,9 @@ void __kfence_free(void *addr) {struct kfence_metadata *meta =addr_to_metadata ((unsigned long )addr); +#ifdef CONFIG_MEMCG +KFENCE_WARN_ON (meta->objcg); +#endif /* * If the objects of the cache are SLAB_TYPESAFE_BY_RCU, defer freeing * the object, as the object page may be recycled for other-typed
mm/kfence/kfence.h +3 -0
@@ -89,6 +89,9 @@ struct kfence_metadata {struct kfence_track free_track;/* For updating alloc_covered on frees. */ u32 alloc_stack_hash; +#ifdef CONFIG_MEMCG +struct obj_cgroup *objcg; +#endif };extern struct kfence_metadata kfence_metadata[CONFIG_KFENCE_NUM_OBJECTS ];
Quoted 7 lines · On Thu, Apr 28, 2022 at 11:36 PM <[email protected]> wrote:
The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
I have fixed all conflicts and the attachment is the new patch for 5.15.
Thanks.
From 99e78b2e14ecbfedf3e9b1c6f47bc9587b129985 Mon Sep 17 00:00:00 2001
From: Muchun Song <[email protected]>
Date: Sun, 27 Mar 2022 10:39:04 +0800
Subject: [PATCH] mm: kfence: fix objcgs vector allocation
If the kfence object is allocated to be used for objects vector, then this slot of the pool eventually being occupied permanently since the vector is never freed. The solutions could be 1) freeing vector when the kfence object is freed or 2) allocating all vectors statically. Since the memory consumption of object vectors is low, it is better to chose 2) to fix the issue and it is also can reduce overhead of vectors allocating in the future.
--- mm/kfence/core.c | 11 ++++++++++- mm/kfence/kfence.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-)
mm/kfence/core.c +10 -1
@@ -448,6 +448,8 @@ static bool __init kfence_init_pool(void)* enters __slab_free() slow-path. */ for (i =0 ; i <KFENCE_POOL_SIZE /PAGE_SIZE ; i++) { +struct page *page = &pages[i]; +if (!i || (i %2 ))continue ;
@@ -455,7 +457,11 @@ static bool __init kfence_init_pool(void)if (WARN_ON (compound_head (&pages[i]) != &pages[i])) goto err; -__SetPageSlab (&pages[i]); +__SetPageSlab (page); +#ifdef CONFIG_MEMCG + page->memcg_data = (unsigned long )&kfence_metadata[i /2 -1 ].objcg | +MEMCG_DATA_OBJCGS ; +#endif }/*
@@ -804,6 +810,9 @@ void __kfence_free(void *addr) {struct kfence_metadata *meta =addr_to_metadata ((unsigned long )addr); +#ifdef CONFIG_MEMCG +KFENCE_WARN_ON (meta->objcg); +#endif /* * If the objects of the cache are SLAB_TYPESAFE_BY_RCU, defer freeing * the object, as the object page may be recycled for other-typed
mm/kfence/kfence.h +3 -0
@@ -87,6 +87,9 @@ struct kfence_metadata {/* Allocation and free stack information. */ struct kfence_track alloc_track;struct kfence_track free_track; +#ifdef CONFIG_MEMCG +struct obj_cgroup *objcg; +#endif };extern struct kfence_metadata kfence_metadata[CONFIG_KFENCE_NUM_OBJECTS ];
Signature · 1 line
2.11.0
Marco Elver
maintainerQuoted 9 lines · Muchun Song
Quoted 7 lines · On Thu, Apr 28, 2022 at 11:36 PM <[email protected]> wrote:
The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Quoted 3 lines
I have fixed all conflicts and the attachment is the new patch for 5.15.
Thanks.
I wanted to test, but unfortunately this doesn't apply to 5.15.36.
Quoted 11 lines · Marco Elver
Quoted 9 lines · Muchun Song
Quoted 7 lines · On Thu, Apr 28, 2022 at 11:36 PM <[email protected]> wrote:
The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Quoted 5 lines
Quoted 3 lines
I have fixed all conflicts and the attachment is the new patch for 5.15.
Thanks.
I wanted to test, but unfortunately this doesn't apply to 5.15.36.
My bad. I was based on v5.15.33. I have made a new version for v5.15.36 (see attachment) and tested it.
Thanks.
From 1b446e199c0392ee1f44b709365cee3bb09306cf Mon Sep 17 00:00:00 2001
From: Muchun Song <[email protected]>
Date: Sun, 27 Mar 2022 10:39:04 +0800
Subject: [PATCH] mm: kfence: fix objcgs vector allocation
If the kfence object is allocated to be used for objects vector, then this slot of the pool eventually being occupied permanently since the vector is never freed. The solutions could be 1) freeing vector when the kfence object is freed or 2) allocating all vectors statically. Since the memory consumption of object vectors is low, it is better to chose 2) to fix the issue and it is also can reduce overhead of vectors allocating in the future.
--- mm/kfence/core.c | 11 ++++++++++- mm/kfence/kfence.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-)
mm/kfence/core.c +10 -1
@@ -528,6 +528,8 @@ static bool __init kfence_init_pool(void)* enters __slab_free() slow-path. */ for (i =0 ; i <KFENCE_POOL_SIZE /PAGE_SIZE ; i++) { +struct page *page = &pages[i]; +if (!i || (i %2 ))continue ;
@@ -535,7 +537,11 @@ static bool __init kfence_init_pool(void)if (WARN_ON (compound_head (&pages[i]) != &pages[i])) goto err; -__SetPageSlab (&pages[i]); +__SetPageSlab (page); +#ifdef CONFIG_MEMCG + page->memcg_data = (unsigned long )&kfence_metadata[i /2 -1 ].objcg | +MEMCG_DATA_OBJCGS ; +#endif }/*
@@ -911,6 +917,9 @@ void __kfence_free(void *addr) {struct kfence_metadata *meta =addr_to_metadata ((unsigned long )addr); +#ifdef CONFIG_MEMCG +KFENCE_WARN_ON (meta->objcg); +#endif /* * If the objects of the cache are SLAB_TYPESAFE_BY_RCU, defer freeing * the object, as the object page may be recycled for other-typed
mm/kfence/kfence.h +3 -0
@@ -89,6 +89,9 @@ struct kfence_metadata {struct kfence_track free_track;/* For updating alloc_covered on frees. */ u32 alloc_stack_hash; +#ifdef CONFIG_MEMCG +struct obj_cgroup *objcg; +#endif };extern struct kfence_metadata kfence_metadata[CONFIG_KFENCE_NUM_OBJECTS ];
Signature · 1 line
2.11.0
Greg KH
maintainerQuoted 14 lines · Muchun Song
Quoted 13 lines · Marco Elver
Quoted 11 lines · Muchun Song
Quoted 7 lines · On Thu, Apr 28, 2022 at 11:36 PM <[email protected]> wrote:
The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.I have fixed all conflicts and the attachment is the new patch for 5.15.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Thanks.
I wanted to test, but unfortunately this doesn't apply to 5.15.36.
My bad. I was based on v5.15.33. I have made a new version for v5.15.36 (see attachment) and tested it.
Thanks.
Now queued up, thanks.
greg k-h