From patchwork Fri Nov 14 09:17:54 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 8735 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 94874DDDED for ; Fri, 14 Nov 2008 20:18:01 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751126AbYKNJR7 (ORCPT ); Fri, 14 Nov 2008 04:17:59 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751204AbYKNJR7 (ORCPT ); Fri, 14 Nov 2008 04:17:59 -0500 Received: from courier.cs.helsinki.fi ([128.214.9.1]:35104 "EHLO mail.cs.helsinki.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751126AbYKNJR4 (ORCPT ); Fri, 14 Nov 2008 04:17:56 -0500 Received: from melkki.cs.helsinki.fi (melkki.cs.helsinki.fi [128.214.9.98]) (AUTH: PLAIN cs-relay, TLS: TLSv1/SSLv3,256bits,AES256-SHA) by mail.cs.helsinki.fi with esmtp; Fri, 14 Nov 2008 11:17:54 +0200 id 000B024C.491D4242.0000109E Received: by melkki.cs.helsinki.fi (Postfix, from userid 54704) id 758331815E; Fri, 14 Nov 2008 11:17:54 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by melkki.cs.helsinki.fi (Postfix) with ESMTP id 6609417F48; Fri, 14 Nov 2008 11:17:54 +0200 (EET) Date: Fri, 14 Nov 2008 11:17:54 +0200 (EET) From: Pekka J Enberg To: akpm@linux-foundation.org cc: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, cl@linux-foundation.org, mpm@selenic.com, eduard.munteanu@linux360.ro Subject: [PATCH] ext2/ext3: allocate ->s_blockgroup_lock separately to avoid wasting space Message-ID: Mime-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Pekka Enberg As spotted by kmemtrace, struct ext2_sb_info is 17024 bytes and ext3_sb_info is 17152 bytes on 64-bit which makes them a very bad fit for SLAB allocators. In fact, both allocations are round up to the next available page size of order 3 which is 32 KB. The culprit if the wasted memory is the ->s_blockgroup_lock which can be as big as 16 KB when CONFIG_NR_CPUS is set to 32. As struct blockgroup_lock is a perfect fit for order 2 page in the worst case, allocate ->s_blockgroup_lock separately to avoid wasting space. The change shrinks struct ext2_sb_info to 592 bytes and struct ext3_sb_info to 640 bytes which fits into a 1024 byte slab cache so now we allocate 16 KB + 1 KB instead of 32 KB saving 15 KB of memory! Signed-off-by: Pekka Enberg --- fs/ext2/super.c | 10 +++++++++- fs/ext3/super.c | 10 +++++++++- include/linux/blockgroup_lock.h | 2 +- include/linux/ext2_fs_sb.h | 2 +- include/linux/ext3_fs_sb.h | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/fs/ext2/super.c b/fs/ext2/super.c index 647cd88..da8bdea 100644 --- a/fs/ext2/super.c +++ b/fs/ext2/super.c @@ -132,6 +132,7 @@ static void ext2_put_super (struct super_block * sb) percpu_counter_destroy(&sbi->s_dirs_counter); brelse (sbi->s_sbh); sb->s_fs_info = NULL; + kfree(sbi->s_blockgroup_lock); kfree(sbi); return; @@ -756,6 +757,13 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); if (!sbi) return -ENOMEM; + + sbi->s_blockgroup_lock = + kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); + if (!sbi->s_blockgroup_lock) { + kfree(sbi); + return -ENOMEM; + } sb->s_fs_info = sbi; sbi->s_sb_block = sb_block; @@ -983,7 +991,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) printk ("EXT2-fs: not enough memory\n"); goto failed_mount; } - bgl_lock_init(&sbi->s_blockgroup_lock); + bgl_lock_init(sbi->s_blockgroup_lock); sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL); if (!sbi->s_debts) { printk ("EXT2-fs: not enough memory\n"); diff --git a/fs/ext3/super.c b/fs/ext3/super.c index f6c94f2..f41df22 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c @@ -439,6 +439,7 @@ static void ext3_put_super (struct super_block * sb) ext3_blkdev_remove(sbi); } sb->s_fs_info = NULL; + kfree(sbi->s_blockgroup_lock); kfree(sbi); return; } @@ -1548,6 +1549,13 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); if (!sbi) return -ENOMEM; + + sbi->s_blockgroup_lock = + kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); + if (!sbi->s_blockgroup_lock) { + kfree(sbi); + return -ENOMEM; + } sb->s_fs_info = sbi; sbi->s_mount_opt = 0; sbi->s_resuid = EXT3_DEF_RESUID; @@ -1788,7 +1796,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) goto failed_mount; } - bgl_lock_init(&sbi->s_blockgroup_lock); + bgl_lock_init(sbi->s_blockgroup_lock); for (i = 0; i < db_count; i++) { block = descriptor_loc(sb, logic_sb_block, i); diff --git a/include/linux/blockgroup_lock.h b/include/linux/blockgroup_lock.h index 8607312..d6d4787 100644 --- a/include/linux/blockgroup_lock.h +++ b/include/linux/blockgroup_lock.h @@ -54,6 +54,6 @@ static inline void bgl_lock_init(struct blockgroup_lock *bgl) * superblock types */ #define sb_bgl_lock(sb, block_group) \ - (&(sb)->s_blockgroup_lock.locks[(block_group) & (NR_BG_LOCKS-1)].lock) + (&(sb)->s_blockgroup_lock->locks[(block_group) & (NR_BG_LOCKS-1)].lock) #endif diff --git a/include/linux/ext2_fs_sb.h b/include/linux/ext2_fs_sb.h index f273415..7e61de9 100644 --- a/include/linux/ext2_fs_sb.h +++ b/include/linux/ext2_fs_sb.h @@ -101,7 +101,7 @@ struct ext2_sb_info { struct percpu_counter s_freeblocks_counter; struct percpu_counter s_freeinodes_counter; struct percpu_counter s_dirs_counter; - struct blockgroup_lock s_blockgroup_lock; + struct blockgroup_lock *s_blockgroup_lock; /* root of the per fs reservation window tree */ spinlock_t s_rsv_window_lock; struct rb_root s_rsv_window_root; diff --git a/include/linux/ext3_fs_sb.h b/include/linux/ext3_fs_sb.h index b65f028..ec10d96 100644 --- a/include/linux/ext3_fs_sb.h +++ b/include/linux/ext3_fs_sb.h @@ -60,7 +60,7 @@ struct ext3_sb_info { struct percpu_counter s_freeblocks_counter; struct percpu_counter s_freeinodes_counter; struct percpu_counter s_dirs_counter; - struct blockgroup_lock s_blockgroup_lock; + struct blockgroup_lock *s_blockgroup_lock; /* root of the per fs reservation window tree */ spinlock_t s_rsv_window_lock;