Skip to content

Commit

Permalink
fs: buffer_head: remove kmem_cache constructor to reduce memory usage…
Browse files Browse the repository at this point in the history
… under slub

When using slub, having a kmem_cache constructor forces slub to add a free
pointer to the size of the cached object, which can have a significant
impact to the number of small objects that can fit into a slab.

As buffer_head is relatively small and we can have large numbers of them,
removing the constructor is a definite win.

On x86_64 removing the constructor gives me 39 objects/slab, 3 more than
without the patch.  And on x86_32 73 objects/slab, which is 9 more.

As alloc_buffer_head() already initializes each new object there is very
little difference in actual code run.

Signed-off-by: Richard Kennedy <richard@rsk.demon.co.uk>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Jens Axboe <jens.axboe@oracle.com>
Acked-by: Nick Piggin <npiggin@suse.de>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Richard Kennedy authored and Linus Torvalds committed Mar 12, 2010
1 parent 03affde commit 019b4d1
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions fs/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3265,7 +3265,7 @@ static void recalc_bh_state(void)

struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
{
struct buffer_head *ret = kmem_cache_alloc(bh_cachep, gfp_flags);
struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
if (ret) {
INIT_LIST_HEAD(&ret->b_assoc_buffers);
get_cpu_var(bh_accounting).nr++;
Expand Down Expand Up @@ -3352,15 +3352,6 @@ int bh_submit_read(struct buffer_head *bh)
}
EXPORT_SYMBOL(bh_submit_read);

static void
init_buffer_head(void *data)
{
struct buffer_head *bh = data;

memset(bh, 0, sizeof(*bh));
INIT_LIST_HEAD(&bh->b_assoc_buffers);
}

void __init buffer_init(void)
{
int nrpages;
Expand All @@ -3369,7 +3360,7 @@ void __init buffer_init(void)
sizeof(struct buffer_head), 0,
(SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
SLAB_MEM_SPREAD),
init_buffer_head);
NULL);

/*
* Limit the bh occupancy to 10% of ZONE_NORMAL
Expand Down

0 comments on commit 019b4d1

Please sign in to comment.