Skip to contentSkip to conversation

slab vs. slub kmem cache name inconsistency

DISCUSSION Johannes Berg 3 participants 4 messages Oct 2, 2012 Memory management

lore
Share & tools
lore
#0 lore raw

Hi,

I just noticed that slub's kmem_cache_create() will kstrdup() the name, while slab doesn't. That's a little confusing, since when you look at slub you can easily get away with passing a string you built on the stack, while that will then lead to very strange results (and possibly crashes?) with slab. The slab kernel-doc string always says this:

* @name must be valid until the cache is destroyed. This implies that
* the module calling this has to destroy the cache before getting unloaded.

Is there any reason for this difference, or should slab also kstrdup(), or should slub not do it? Or maybe slub should have a "oops, name is on stack" warning/check?

johannes

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

Hi, Johannes.

2012/10/2 Johannes Berg <[email protected]>:

Quoted 7 lines

Hi,

I just noticed that slub's kmem_cache_create() will kstrdup() the name, while slab doesn't. That's a little confusing, since when you look at slub you can easily get away with passing a string you built on the stack, while that will then lead to very strange results (and possibly crashes?) with slab.

As far as I know, this issue is already fixed. However, fix for this is not merged into mainline yet.
You can find the fix in common_for_cgroups branch of Pekka's git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/penberg/linux.git
slab/common-for-cgroups

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Hi,

Quoted 6 lines
Quoted 5 lines

I just noticed that slub's kmem_cache_create() will kstrdup() the name, while slab doesn't. That's a little confusing, since when you look at slub you can easily get away with passing a string you built on the stack, while that will then lead to very strange results (and possibly crashes?) with slab.

Quoted 6 lines

As far as I know, this issue is already fixed. However, fix for this is not merged into mainline yet.
You can find the fix in common_for_cgroups branch of Pekka's git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/penberg/linux.git
slab/common-for-cgroups

Cool, yes, we have a commit there which addresses this:

http://git.kernel.org/?p=linux/kernel/git/penberg/linux.git;a=commit;h=db265eca77000c5dafc5608975afe8dafb2a02d5

Thanks!

johannes

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to Johannes Berg

This should be fixed the merge window for 3.7. All allocators will do a kstrdup then.

Quoted 8 lines · Johannes Berg

Hi,

I just noticed that slub's kmem_cache_create() will kstrdup() the name, while slab doesn't. That's a little confusing, since when you look at slub you can easily get away with passing a string you built on the stack, while that will then lead to very strange results (and possibly crashes?) with slab. The slab kernel-doc string always says this:

Quoted 9 lines

* @name must be valid until the cache is destroyed. This implies that
* the module calling this has to destroy the cache before getting unloaded.

Is there any reason for this difference, or should slab also kstrdup(), or should slub not do it? Or maybe slub should have a "oops, name is on stack" warning/check?

johannes

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>