mm, slob: Drop usage of page->private for storing page-sized allocations
PATCH v2 1/1 mm, slob: Drop usage of page->private for storing page-sized allocations
This field was being used to store size allocation so it could be retrieved by ksize(). However, it is a bad practice to not mark a page as a slab page and then use fields for special purposes. There is no need to store the allocated size andksize() can simply return PAGE_SIZE << compound_order(page).
---
Changes from v1:
* Rebased on top of slab/next
mm/slob.c | 24 ++++++++++-------------- 1 files changed, 10 insertions(+), 14 deletions(-)
mm/slob.c +10 -14
@@ -28,9 +28,8 @@* from kmalloc are prepended with a 4-byte header with the kmalloc size. * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls * alloc_pages() directly, allocating compound pages so the page order -* does not have to be separately tracked, and also stores the exact -* allocation size in page->private so that it can be used to accurately -* provide ksize(). These objects are detected in kfree() because slob_page() +* does not have to be separately tracked. +* These objects are detected in kfree() because PageSlab() * is false for them. * * SLAB is emulated on top of SLOB by simply calling constructors and
@@ -454,11 +453,6 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)if (likely (order)) gfp |= __GFP_COMP; ret =slob_new_pages (gfp, order, node); -if (ret) { -struct page *page; - page =virt_to_page (ret); - page->private = size; - }trace_kmalloc_node (_RET_IP_, ret, size,PAGE_SIZE << order, gfp, node);
@@ -493,18 +487,20 @@ EXPORT_SYMBOL(kfree);size_t ksize (const void *block) {struct page *sp; +int align; +unsigned int *m;BUG_ON (!block);if (unlikely (block ==ZERO_SIZE_PTR ))return 0 ; sp =virt_to_page (block); -if (PageSlab (sp)) { -int align =max (ARCH_KMALLOC_MINALIGN ,ARCH_SLAB_MINALIGN ); -unsigned int *m = (unsigned int *)(block - align); -return SLOB_UNITS (*m) *SLOB_UNIT ; - }else -return sp->private; +if (unlikely (!PageSlab (sp))) +return PAGE_SIZE <<compound_order (sp); + + align =max (ARCH_KMALLOC_MINALIGN ,ARCH_SLAB_MINALIGN ); + m = (unsigned int *)(block - align); +return SLOB_UNITS (*m) *SLOB_UNIT ; }EXPORT_SYMBOL (ksize);
Signature · 7 lines
1.7.8.6 -- 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>
Quoted 5 lines · Ezequiel Garcia
This field was being used to store size allocation so it could be retrieved by
ksize(). However, it is a bad practice to not mark a page as a slab page and then use fields for special purposes. There is no need to store the allocated size andksize()can simply returnPAGE_SIZE<<compound_order(page).
What happens for allocations smaller than a page?
It seems you are breaking ksize for those.
--
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>
Hi Glauber,
Quoted 10 lines · Glauber Costa
Quoted 5 lines · Ezequiel Garcia
This field was being used to store size allocation so it could be retrieved by
ksize(). However, it is a bad practice to not mark a page as a slab page and then use fields for special purposes. There is no need to store the allocated size andksize()can simply returnPAGE_SIZE<<compound_order(page).What happens for allocations smaller than a page?
It seems you are breaking ksize for those.
Allocations smaller than a page save its own size on a header located at each returned pointer. This is documented at the beginning of slob:
"Above this is an implementation of kmalloc/kfree. Blocks returned from kmalloc are prepended with a 4-byte header with the kmalloc size."
For this objects (smaller than a page) ksize works fine:
size_t ksize(const void *block) {
[...]
unsigned int *m = (unsigned int *)(block - align); return SLOB_UNITS(*m) * SLOB_UNIT;
(see how ksize substract 'align' from block to find the header?)
Of course, it's possible I've overlooked something, but I think this should work.
Thanks!
Ezequiel.
--
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>
Quoted 27 lines · Ezequiel Garcia
Hi Glauber,
Quoted 10 lines · Glauber Costa
Quoted 5 lines · Ezequiel Garcia
This field was being used to store size allocation so it could be retrieved by
ksize(). However, it is a bad practice to not mark a page as a slab page and then use fields for special purposes. There is no need to store the allocated size andksize()can simply returnPAGE_SIZE<<compound_order(page).What happens for allocations smaller than a page?
It seems you are breaking ksize for those.Allocations smaller than a page save its own size on a header located at each returned pointer. This is documented at the beginning of slob:
"Above this is an implementation of kmalloc/kfree. Blocks returned from kmalloc are prepended with a 4-byte header with the kmalloc size."
For this objects (smaller than a page) ksize works fine:
size_tksize(const void *block){
[...]
unsigned int *m = (unsigned int *)(block - align); returnSLOB_UNITS(*m)*SLOB_UNIT;
Quoted 5 lines
(see how ksize substract 'align' from block to find the header?)
Of course, it's possible I've overlooked something, but I think this should work.
Ok. Slob also goes to the page allocator for higher order kmallocs, so it should work.
--
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>
Christoph Lameter
Acked-byI thought I acked it before?
--
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>
Quoted 4 lines · Christoph Lameter
I thought I acked it before?
Yes you did. This is a v2, that I rebased on top of slab/next for Pekka.
Thanks!
Ezequiel.
--
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>
Pekka,
Quoted 6 lines · Ezequiel Garcia
Quoted 4 lines · Christoph Lameter
I thought I acked it before?
Will you pick this for v3.7 pull request?
Or is there anything wrong with it?
--
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>
Pekka,
Quoted 4 lines · Ezequiel Garcia
Pekka,
Quoted 1 line · Ezequiel Garcia
On Tue, Sep 4, 2012 at 3:00 PM, Christoph Lameter <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
I thought I acked it before?
Will you pick this for v3.7 pull request?
Or is there anything wrong with it?
I think you've missed this for your pull request.
And I'm a bit puzzled, since it has been acked by Christoph, or are we still waiting to matt's ack?
Thanks!
Ezequiel
--
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>