Skip to contentSkip to conversation

ext4: remove unsafe and unnecessary memset()

PATCH Applied Guo Chao 3 participants 13 messages Nov 30, 2012 – Dec 3, 2012 ext4 file system

lore
Share & tools
lore

Guo Chao

author
#0 lore raw

PATCH 1/4 ext4: remove unsafe and unnecessary memset()

We memset this page before checking whether it's valid. But we need not memset zeroed page at all.

---
 fs/ext4/super.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/super.c +0 -1
index ad6cd8a..66a4e20 100644
@@ -3206,7 +3206,6 @@ int ext4_calculate_overhead(struct super_block *sb)
 	ext4_fsblk_t overhead = 0;
 	char *buf = (char *) get_zeroed_page(GFP_KERNEL);
 
-	memset(buf, 0, PAGE_SIZE);
 	if (!buf)
 		return -ENOMEM;
 
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/4 ext4: use sync_inode_metadata() when sync inode metadata

We have a dedicated interface to sync inode metadata.

---
 fs/ext4/fsync.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/ext4/fsync.c +1 -5
index be1d89f..dfbc1fe 100644
@@ -44,7 +44,6 @@
  */
 static int ext4_sync_parent(struct inode *inode)
 {
-	struct writeback_control wbc;
 	struct dentry *dentry = NULL;
 	struct inode *next;
 	int ret = 0;
@@ -66,10 +65,7 @@ static int ext4_sync_parent(struct inode *inode)
 		ret = sync_mapping_buffers(inode->i_mapping);
 		if (ret)
 			break;
-		memset(&wbc, 0, sizeof(wbc));
-		wbc.sync_mode = WB_SYNC_ALL;
-		wbc.nr_to_write = 0;         /* only write out the inode */
-		ret = sync_inode(inode, &wbc);
+		ret = sync_inode_metadata(inode, 1);
 		if (ret)
 			break;
 	}
Signature · 1 line
1.7.9.5
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] ext4: use sync_inode_metadata() when sync inode metadata

Quoted 28 lines · Guo Chao

Date: Fri, 30 Nov 2012 14:41:44 +0800
From: Guo Chao <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH 2/4] ext4: use sync_inode_metadata() when sync inode metadata

We have a dedicated interface to sync inode metadata.

---
 fs/ext4/fsync.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/ext4/fsync.c +0 -1
index be1d89f..dfbc1fe 100644
@@ -44,7 +44,6 @@
  */
 static int ext4_sync_parent(struct inode *inode)
 {
-	struct writeback_control wbc;
 	struct dentry *dentry = NULL;
 	struct inode *next;
 	int ret = 0;
@@ -66,10 +65,7 @@ static int ext4_sync_parent(struct inode *inode)
 		ret = sync_mapping_buffers(inode->i_mapping);

fs/ext4/fsync.c static int ext4_sync_parent(struct inode *inode) · line 71

Quoted 10 lines
fs/ext4/fsync.c +1 -4
 		if (ret)
 			break;
-		memset(&wbc, 0, sizeof(wbc));
-		wbc.sync_mode = WB_SYNC_ALL;
-		wbc.nr_to_write = 0;         /* only write out the inode */
-		ret = sync_inode(inode, &wbc);
+		ret = sync_inode_metadata(inode, 1);
 		if (ret)
 			break;
 	}

Makes sense.

author
#4 lore raw

PATCH 3/4 ext4: remove redundant code in ext4_alloc_inode()

In reply to Guo Chao

inode_init_always() will initialize inode->i_data.writeback_index anyway, no need to do this in ext4_alloc_inode().

---
 fs/ext4/super.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/super.c +0 -1
index 66a4e20..15d28e3 100644
@@ -940,7 +940,6 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
 		return NULL;
 
 	ei->vfs_inode.i_version = 1;
-	ei->vfs_inode.i_data.writeback_index = 0;
 	memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
 	INIT_LIST_HEAD(&ei->i_prealloc_list);
 	spin_lock_init(&ei->i_prealloc_lock);
Signature · 1 line
1.7.9.5
Reviewed-by on v1 3/4
#5 lore raw

Re: [PATCH 3/4] ext4: remove redundant code in ext4_alloc_inode()

Quoted 20 lines · Guo Chao

Date: Fri, 30 Nov 2012 14:41:45 +0800
From: Guo Chao <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH 3/4] ext4: remove redundant code in ext4_alloc_inode()

inode_init_always() will initialize inode->i_data.writeback_index anyway, no need to do this in ext4_alloc_inode().

---
 fs/ext4/super.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/super.c +0 -0
index 66a4e20..15d28e3 100644

fs/ext4/super.c static struct inode *ext4_alloc_inode(struct super_block *sb) · line 945

Quoted 7 lines
fs/ext4/super.c +0 -1
@@ -940,7 +940,6 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
 		return NULL;
 
 	ei->vfs_inode.i_version = 1;
-	ei->vfs_inode.i_data.writeback_index = 0;
 	memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
 	INIT_LIST_HEAD(&ei->i_prealloc_list);
 	spin_lock_init(&ei->i_prealloc_lock);

Looks good

maintainer Applied
#6 lore raw

Re: [PATCH 3/4] ext4: remove redundant code in ext4_alloc_inode()

In reply to Guo Chao
Quoted 4 lines · Guo Chao

inode_init_always() will initialize inode->i_data.writeback_index anyway, no need to do this in ext4_alloc_inode().

Thanks, applied.

- Ted

author
#7 lore raw

PATCH 4/4 ext4: remove redundant initialization in ext4_fill_super()

In reply to Guo Chao

We use kzalloc() to allocate sbi, no need to zero its field.

---
 fs/ext4/super.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/super.c +0 -1
index 15d28e3..a99f6c7 100644
@@ -3799,7 +3799,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 
 	INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
 	mutex_init(&sbi->s_orphan_lock);
-	sbi->s_resize_flags = 0;
 
 	sb->s_root = NULL;
 
Signature · 1 line
1.7.9.5
#8 lore raw

Re: [PATCH 4/4] ext4: remove redundant initialization in ext4_fill_super()

Quoted 20 lines · Guo Chao

Date: Fri, 30 Nov 2012 14:41:46 +0800
From: Guo Chao <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH 4/4] ext4: remove redundant initialization in

    ext4_fill_super()

We use kzalloc() to allocate sbi, no need to zero its field.

---
 fs/ext4/super.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/super.c +0 -0
index 15d28e3..a99f6c7 100644

fs/ext4/super.c static int ext4_fill_super(struct super_block *sb, void *data, int silent) · line 3804

Quoted 7 lines
fs/ext4/super.c +0 -1
@@ -3799,7 +3799,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 
 	INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
 	mutex_init(&sbi->s_orphan_lock);
-	sbi->s_resize_flags = 0;
 
 	sb->s_root = NULL;
 

There are other members of sbi which we initialize to zero even though we use kzalloc.

Thanks!
-Lukas

Reviewed-by on v1 1/4
#10 lore raw
In reply to Guo Chao
Quoted 19 lines · Guo Chao

Date: Fri, 30 Nov 2012 14:41:43 +0800
From: Guo Chao <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH 1/4] ext4: remove unsafe and unnecessary memset()

We memset this page before checking whether it's valid. But we need not memset zeroed page at all.

---
 fs/ext4/super.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/super.c +0 -0
index ad6cd8a..66a4e20 100644

fs/ext4/super.c int ext4_calculate_overhead(struct super_block *sb) · line 3210

Quoted 6 lines
fs/ext4/super.c +0 -1
@@ -3206,7 +3206,6 @@ int ext4_calculate_overhead(struct super_block *sb)
 	ext4_fsblk_t overhead = 0;
 	char *buf = (char *) get_zeroed_page(GFP_KERNEL);
 
-	memset(buf, 0, PAGE_SIZE);
 	if (!buf)
 		return -ENOMEM;

Good catch, thanks!

#11 lore raw
Quoted 30 lines · Lukáš Czerner

Date: Fri, 30 Nov 2012 14:20:42 +0100 (CET)
From: Lukáš Czerner <[email protected]>
To: Guo Chao <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: [PATCH 1/4] ext4: remove unsafe and unnecessary memset()

Quoted 22 lines · Guo Chao

Date: Fri, 30 Nov 2012 14:41:43 +0800
From: Guo Chao <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH 1/4] ext4: remove unsafe and unnecessary memset()

We memset this page before checking whether it's valid. But we need not memset zeroed page at all.

---
 fs/ext4/super.c |    1 -
 1 file changed, 1 deletion(-)
fs/ext4/super.c +0 -0
index ad6cd8a..66a4e20 100644
@@ -3206,7 +3206,6 @@ int ext4_calculate_overhead(struct super_block *sb)
 	ext4_fsblk_t overhead = 0;
 	char *buf = (char *) get_zeroed_page(GFP_KERNEL);
 
Quoted 7 lines

fs/ext4/super.c int ext4_calculate_overhead(struct super_block *sb) · line 3210

Quoted 3 lines
fs/ext4/super.c +0 -1
-	memset(buf, 0, PAGE_SIZE);
 	if (!buf)
 		return -ENOMEM;

Good catch, thanks!

It looks like that it has been already fixed with a different patch.

http://www.spinics.net/lists/linux-ext4/msg35310.html

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#12 lore raw
Quoted 5 lines · Lukáš Czerner

On Fri, 30 Nov 2012, Lukáš Czerner wrote:
It looks like that it has been already fixed with a different patch.

http://www.spinics.net/lists/linux-ext4/msg35310.html

Hmm ... I did search this function in marc.info. Looks like I should switch to another database. Thank you for review.

Thanks,
Guo Chao

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html