Skip to contentSkip to conversation

ext4: Memory leak fix ext4_group_info allocation.

PATCH In review Aneesh Kumar K.V 2 participants 2 messages Jul 15, 2009 – Jul 17, 2009 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Memory leak fix ext4_group_info allocation.

commit 5f21b0e642d7bf6fe4434c9ba12bc9cb96b17cf7 was done to reallocate groupinfo struct during resize properly. That goal was to allocate new groupinfo struct when we are adding new block groups during resize. Calling ext4_mb_add_group_info in the mballoc initialization code path resulted in we reallocating the group info struct . Fix this by not separately allocating group info in the mballoc init path and always depend on ext4_mb_add_group_info to allocate group info struct.

The earlier code also had a bug that we allocated less number of group info struct for the last meta group. But on resize we expected that we had EXT4_DESC_PER_BLOCK group info struct for each meta group.

---
 fs/ext4/mballoc.c |   19 -------------------
 1 files changed, 0 insertions(+), 19 deletions(-)
fs/ext4/mballoc.c +0 -17
index 519a0a6..2a9d327 100644
@@ -2564,13 +2564,11 @@ static int ext4_mb_init_backend(struct super_block *sb)
 {
 	ext4_group_t ngroups = ext4_get_groups_count(sb);
 	ext4_group_t i;
-	int metalen;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	struct ext4_super_block *es = sbi->s_es;
 	int num_meta_group_infos;
 	int num_meta_group_infos_max;
 	int array_size;
-	struct ext4_group_info **meta_group_info;
 	struct ext4_group_desc *desc;
 
 	/* This is the number of blocks used by GDT */
@@ -2615,22 +2613,6 @@ static int ext4_mb_init_backend(struct super_block *sb)
 		goto err_freesgi;
 	}
 	EXT4_I(sbi->s_buddy_cache)->i_disksize = 0;
-
-	metalen = sizeof(*meta_group_info) << EXT4_DESC_PER_BLOCK_BITS(sb);
-	for (i = 0; i < num_meta_group_infos; i++) {
-		if ((i + 1) == num_meta_group_infos)
-			metalen = sizeof(*meta_group_info) *
-				(ngroups -
-					(i << EXT4_DESC_PER_BLOCK_BITS(sb)));
-		meta_group_info = kmalloc(metalen, GFP_KERNEL);
-		if (meta_group_info == NULL) {
-			printk(KERN_ERR "EXT4-fs: can't allocate mem for a "
-			       "buddy group\n");
-			goto err_freemeta;
-		}
-		sbi->s_group_info[i] = meta_group_info;
-	}
maintainer Tested-by Catalin Marinas on v1 1/1
#1 lore raw
Quoted 9 lines · Aneesh Kumar K.V

commit 5f21b0e642d7bf6fe4434c9ba12bc9cb96b17cf7 was done to reallocate groupinfo struct during resize properly. That goal was to allocate new groupinfo struct when we are adding new block groups during resize. Calling ext4_mb_add_group_info in the mballoc initialization code path resulted in we reallocating the group info struct . Fix this by not separately allocating group info in the mballoc init path and always depend on ext4_mb_add_group_info to allocate group info struct.

Quoted 4 lines

The earlier code also had a bug that we allocated less number of group info struct for the last meta group. But on resize we expected that we had EXT4_DESC_PER_BLOCK group info struct for each meta group.

Added to the ext4 patch queue, although I did rewrite the patch description:

ext4: Fix memory leak fix when mounting an ext4 filesystem

From: "Aneesh Kumar K.V" <[email protected]>

The allocation of the ext4_group_info array was moved to a new function ext4_mb_add_group_info() in commit 5f21b0e6 so that online resize would use a common (and correct) codepath. Unfortunately, the call to the new ext4_mb_add_group_info() function was added without removing the code which originally allocated the array. This caused a memory leak each time an ext4 filesystem was mounted.

The fix is simple; remove the code that did the original allocation, since it is no longer needed.

- Ted