mm, sl[ou]b: improve memory accounting

Patch series "guarantee natural alignment for kmalloc()", v2.

This patch (of 2):

SLOB currently doesn't account its pages at all, so in /proc/meminfo the
Slab field shows zero.  Modifying a counter on page allocation and
freeing should be acceptable even for the small system scenarios SLOB is
intended for.  Since reclaimable caches are not separated in SLOB,
account everything as unreclaimable.

SLUB currently doesn't account kmalloc() and kmalloc_node() allocations
larger than order-1 page, that are passed directly to the page
allocator.  As they also don't appear in /proc/slabinfo, it might look
like a memory leak.  For consistency, account them as well.  (SLAB
doesn't actually use page allocator directly, so no change there).

Ideally SLOB and SLUB would be handled in separate patches, but due to
the shared kmalloc_order() function and different kfree()
implementations, it's easier to patch both at once to prevent

Signed-off-by: Vlastimil Babka <>
Cc: Christoph Lameter <>
Cc: Pekka Enberg <>
Cc: David Rientjes <>
Cc: Ming Lei <>
Cc: Dave Chinner <>
Cc: Matthew Wilcox <>
Cc: "Darrick J . Wong" <>
Cc: Christoph Hellwig <>
Cc: James Bottomley <>
Cc: Vlastimil Babka <>
Cc: Joonsoo Kim <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
3 files changed