mm, slab: warn when increasing refcount on large kmalloc page
Subsystems (2)
RFC PATCH 1/1 mm, slab: warn when increasing refcount on large kmalloc page
Since slab pages are now frozen, increasing refcount on a page containing a kmalloc() allocation is not possible anymore. Large kmalloc pages should ideally behave the same, because the decision for which allocation size to use them is the slab allocator's implementation detail, and sizes passed to kmalloc() might depend on e.g. user input.
Because of some unexpected fallout in the slab pages case (see commit b9c0e49abfca ("mm: decline to manipulate the refcount on a slab page"), let's take a more cautious approach and before making large kmalloc pages actually frozen, start warning about code that would try to increase refcount on them.
---
I'd like to expose this via slab-next and see if there are any reports. If not for few weeks, maybe proceed immediately to freezing refcount and handling it in get_page/put_page exactly like folio_test_slab. Thoughts?
include/linux/mm.h | 1 + 1 file changed, 1 insertion(+)
include/linux/mm.h +1 -0
@@ -1532,6 +1532,7 @@ static inline void get_page(struct page *page)struct folio *folio =page_folio (page);if (WARN_ON_ONCE (folio_test_slab (folio)))return ; +WARN_ON_ONCE (folio_test_large_kmalloc (folio));folio_get (folio); }
Signature · 1 line
2.49.0
Quoted 5 lines · Vlastimil Babka
Since slab pages are now frozen, increasing refcount on a page containing a
kmalloc()allocation is not possible anymore. Large kmalloc pages should ideally behave the same, because the decision for which allocation size to use them is the slab allocator's implementation detail, and sizes passed tokmalloc()might depend on e.g. user input.
Agreed.
Quoted 11 lines
Because of some unexpected fallout in the slab pages case (see commit
b9c0e49abfca("mm: decline to manipulate the refcount on a slab page"), let's take a more cautious approach and before making large kmalloc pages actually frozen, start warning about code that would try to increase refcount on them.Signed-off-by Vlastimil Babka <[email protected]>---
I'd like to expose this via slab-next and see if there are any reports. If not for few weeks, maybe proceed immediately to freezing refcount and handling it in get_page/put_page exactly likefolio_test_slab. Thoughts?
+1
Let's give testing a try.
...at least it does not hit anything on my box.
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 17 lines
include/linux/mm.h | 1 + 1 file changed, 1 insertion(+)include/linux/mm.h +1
-0@@ -1532,6 +1532,7 @@ static inline void get_page(struct page *page)struct folio *folio =page_folio (page);if (WARN_ON_ONCE (folio_test_slab (folio)))return ; +WARN_ON_ONCE (folio_test_large_kmalloc (folio));folio_get (folio); }Signature · 1 line
2.49.0
Quoted 20 lines · Harry Yoo
Quoted 5 lines
Since slab pages are now frozen, increasing refcount on a page containing a
kmalloc()allocation is not possible anymore. Large kmalloc pages should ideally behave the same, because the decision for which allocation size to use them is the slab allocator's implementation detail, and sizes passed tokmalloc()might depend on e.g. user input.Agreed.
Quoted 11 lines
Because of some unexpected fallout in the slab pages case (see commit
b9c0e49abfca("mm: decline to manipulate the refcount on a slab page"), let's take a more cautious approach and before making large kmalloc pages actually frozen, start warning about code that would try to increase refcount on them.Signed-off-by Vlastimil Babka <[email protected]>---
I'd like to expose this via slab-next and see if there are any reports. If not for few weeks, maybe proceed immediately to freezing refcount and handling it in get_page/put_page exactly likefolio_test_slab. Thoughts?
Quoted 6 lines
+1
Let's give testing a try.
...at least it does not hit anything on my box.
Same, I ran this through a number of benchmarks on x86 and couldn't find any occurrences of the warning.
Quoted 22 lines · David Rientjes
Quoted 22 lines
Quoted 5 lines
Since slab pages are now frozen, increasing refcount on a page containing a
kmalloc()allocation is not possible anymore. Large kmalloc pages should ideally behave the same, because the decision for which allocation size to use them is the slab allocator's implementation detail, and sizes passed tokmalloc()might depend on e.g. user input.Agreed.
Quoted 11 lines
Because of some unexpected fallout in the slab pages case (see commit
b9c0e49abfca("mm: decline to manipulate the refcount on a slab page"), let's take a more cautious approach and before making large kmalloc pages actually frozen, start warning about code that would try to increase refcount on them.Signed-off-by Vlastimil Babka <[email protected]>---
I'd like to expose this via slab-next and see if there are any reports. If not for few weeks, maybe proceed immediately to freezing refcount and handling it in get_page/put_page exactly likefolio_test_slab. Thoughts?+1
Quoted 8 lines
Quoted 4 lines
Let's give testing a try.
...at least it does not hit anything on my box.
Same, I ran this through a number of benchmarks on x86 and couldn't find any occurrences of the warning.
Btw, the benchmarks that I normally run regularly on SLUB are kernbench, multichase, hackbench, specjbb, will-it-scale, redis, unixbench, netperf TCP_RR and UDP_STREAM, on both x86 and arm64. I haven't run on any other architectures recently, but perhaps others do.
Are there any other benchmarks that people normally run for slab allocator related changes?
Quoted 3 lines · Vlastimil Babka
I'd like to expose this via slab-next and see if there are any reports. If not for few weeks, maybe proceed immediately to freezing refcount and handling it in get_page/put_page exactly like
folio_test_slab. Thoughts?
I think you're being too cautious ;-) I had a bit of a play around to see if there's a way of getting gcc to optimise the generated code for this, but didn't come up with anything too clever.