fat: improve sync performance by grouping writes in fat_mirror_bhs [really unmangled]
Subsystems (2)
PATCH 1/1 fat: improve sync performance by grouping writes in fat_mirror_bhs [really unmangled]
From: Holden Karau <[email protected]> http://www.holdenkarau.com
This is an attempt at improving fat_mirror_bhs in sync mode [namely it writes all of the data for a backup block, and then blocks untill finished]. The old behaviour would write & block in smaller chunks, so this should be slightly faster. It also removes the fixme requesting that it be fixed to behave this way :-)
---
Sorry about the mangled patch, this time it really shouldn't be mangled :-) Important note; I do not normally play with filesystems. This MAY eat your file system, it has not eaten mine but that does not mean much at all [although I don't think it will]. I'd greatly appreciate comments & suggestions. In case the patch gets mangled [again] I've put it up at
http://www.holdenkarau.com/~holden/projects/fat/001_improve_fat_sync_performance.patch
And now for the actual patch:
fs/fat/fatent.c +30 -32
@@ -1,5 +1,6 @@/* * Copyright (C) 2004, OGAWA Hirofumi +* Copyright (C) 2006, Holden Karau [Xandros] * Released under GPL v2. */
@@ -343,34 +344,46 @@ int fat_ent_read(struct inode *inode, streturn ops->ent_get (fatent); } -/* FIXME: We can write the blocks as more big chunk. */ static int fat_mirror_bhs (struct super_block *sb,struct buffer_head **bhs, -int nr_bhs) +int nr_bhs ) { +return fat_mirror_bhs_optw (sb , bhs , nr_bhs,0 ); +} + +static int fat_mirror_bhs_optw (struct super_block *sb,struct buffer_head **bhs, +int nr_bhs ,int wait) {struct msdos_sb_info *sbi =MSDOS_SB (sb); -struct buffer_head *c_bh; +struct buffer_head *c_bh[nr_bhs];int err, n, copy; +/* Always wait if mounted -o sync */ +if (sb->s_flags &MS_SYNCHRONOUS ) { + wait =1 ; + } + err =0 ; + err =fat_sync_bhs_optw ( bhs , nr_bhs , wait); +if (err) + goto error;for (copy =1 ; copy < sbi->fats; copy++) {sector_t backup_fat = sbi->fat_length * copy; -for (n =0 ; n < nr_bhs; n++) { - c_bh =sb_getblk (sb, backup_fat + bhs[n]->b_blocknr); -if (!c_bh) { + c_bh[n] =sb_getblk (sb, backup_fat + bhs[n]->b_blocknr); +if (!c_bh[n]) { err = -ENOMEM ; goto error; } -memcpy (c_bh->b_data, bhs[n]->b_data, sb->s_blocksize); -set_buffer_uptodate (c_bh); -mark_buffer_dirty (c_bh); -if (sb->s_flags &MS_SYNCHRONOUS ) - err =sync_dirty_buffer (c_bh); -brelse (c_bh); +set_buffer_uptodate (c_bh[n]); +mark_buffer_dirty (c_bh[n]); +memcpy (c_bh[n]->b_data, bhs[n]->b_data, sb->s_blocksize); + } + err =fat_sync_bhs_optw ( c_bh , nr_bhs , wait ); +for (n =0 ; n < nr_bhs; n++ ) { +brelse (c_bh[n]); + }if (err) goto error; } - } error:return err; }
@@ -383,12 +396,7 @@ int fat_ent_write(struct inode *inode, sint err; ops->ent_put (fatent, new); -if (wait) { - err =fat_sync_bhs (fatent->bhs, fatent->nr_bhs); -if (err) -return err; - } -return fat_mirror_bhs (sb, fatent->bhs, fatent->nr_bhs); +return fat_mirror_bhs_optw (sb, fatent->bhs, fatent->nr_bhs , wait); } static inline int fat_ent_next(struct msdos_sb_info *sbi,
@@ -505,9 +513,9 @@ out:fatent_brelse (&fatent);if (!err) {if (inode_needs_sync (inode)) - err =fat_sync_bhs (bhs, nr_bhs); -if (!err) - err =fat_mirror_bhs (sb, bhs, nr_bhs); + err =fat_mirror_bhs_optw (sb , bhs, nr_bhs ,1 ); +else + err =fat_mirror_bhs_optw (sb, bhs, nr_bhs ,0 ); }for (i =0 ; i < nr_bhs; i++)brelse (bhs[i]);
@@ -549,11 +557,6 @@ int fat_free_clusters(struct inode *inod }if (nr_bhs + fatent.nr_bhs >MAX_BUF_PER_PAGE ) { -if (sb->s_flags &MS_SYNCHRONOUS ) { - err =fat_sync_bhs (bhs, nr_bhs); -if (err) - goto error; - } err =fat_mirror_bhs (sb, bhs, nr_bhs);if (err) goto error;
@@ -564,11 +567,6 @@ int fat_free_clusters(struct inode *inodfat_collect_bhs (bhs, &nr_bhs, &fatent); }while (cluster !=FAT_ENT_EOF ); -if (sb->s_flags &MS_SYNCHRONOUS ) { - err =fat_sync_bhs (bhs, nr_bhs); -if (err) - goto error; - } err =fat_mirror_bhs (sb, bhs, nr_bhs); error:fatent_brelse (&fatent);
fs/fat/misc.c +8 -1
@@ -194,11 +194,17 @@ void fat_date_unix2dos(int unix_date, __EXPORT_SYMBOL_GPL (fat_date_unix2dos); -int fat_sync_bhs (struct buffer_head **bhs,int nr_bhs) + +int fat_sync_bhs (struct buffer_head **bhs,int nr_bhs ) { +return fat_sync_bhs_optw (bhs , nr_bhs ,1 ); +} + +int fat_sync_bhs_optw (struct buffer_head **bhs,int nr_bhs ,int wait) {int i, err =0 ;ll_rw_block (SWRITE , nr_bhs, bhs); +if (wait) {for (i =0 ; i < nr_bhs; i++) {wait_on_buffer (bhs[i]);if (buffer_eopnotsupp (bhs[i])) {
@@ -207,6 +213,7 @@ int fat_sync_bhs(struct buffer_head **bh }else if (!err && !buffer_uptodate (bhs[i])) err = -EIO ; } + }return err; }
include/linux/msdos_fs.h +1 -0
@@ -419,6 +419,7 @@ extern int fat_chain_add(struct inode *iextern int date_dos2unix (unsigned short time,unsigned short date);extern void fat_date_unix2dos (int unix_date,__le16 *time,__le16 *date);extern int fat_sync_bhs (struct buffer_head **bhs,int nr_bhs); +extern int fat_sync_bhs_optw (struct buffer_head **bhs,int nr_bhs,int wait);int fat_cache_init (void );void fat_cache_destroy (void );
Quoted 8 lines · Holden Karau
From: Holden Karau <[email protected]> http://www.holdenkarau.com
This is an attempt at improving
fat_mirror_bhsin sync mode [namely it writes all of the data for a backup block, and then blocks untill finished]. The old behaviour would write & block in smaller chunks, so this should be slightly faster. It also removes the fixme requesting that it be fixed to behave this way :-)Signed-off-by Holden Karau <[email protected]> http://www.holdenkarau.com
So how much is performance improved?
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
I didn't pay too much attention, but found some low hanging fruits.
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 353
Quoted 10 lines · Holden Karau
fs/fat/fatent.c +6
-2-/* FIXME: We can write the blocks as more big chunk. */ static int fat_mirror_bhs (struct super_block *sb,struct buffer_head **bhs, -int nr_bhs) +int nr_bhs ) { +return fat_mirror_bhs_optw (sb , bhs , nr_bhs,0 ); +} + +static int fat_mirror_bhs_optw (struct super_block *sb,struct buffer_head **bhs, +int nr_bhs ,int wait)
Does this compile without warnings? Looks as if you should reverse the order of the two functions.
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 362
Quoted 10 lines
{
fs/fat/fatent.c +5
-1struct msdos_sb_info *sbi =MSDOS_SB (sb); -struct buffer_head *c_bh; +struct buffer_head *c_bh[nr_bhs];int err, n, copy; +/* Always wait if mounted -o sync */ +if (sb->s_flags &MS_SYNCHRONOUS ) { + wait =1 ; + }
Coding style. Use a tab for indentation and don't use braces for single-line conditional statements.
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 365
Quoted 3 lines
fs/fat/fatent.c +2
-0+ err =0 ; + err =fat_sync_bhs_optw ( bhs , nr_bhs , wait);
The err=0; is superfluous now, isn't it?
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 367
Quoted 2 lines
fs/fat/fatent.c +2
-0+if (err) + goto error;
Indentation.
Jörn
Signature · 7 lines
Fantasy is more important than knowledge. Knowledge is limited, while fantasy embraces the whole world. -- Albert Einstein - To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Based on some rather off-the cuff bench marking I've done I get around a 5 to 10% performance improve over the stock 2.6.18.1 performance. As the saying goes, there are lies, damn lies, and bench marks, so YMMV.
Quoted 17 lines · Nick Piggin
Quoted 8 lines · Holden Karau
From: Holden Karau <[email protected]> http://www.holdenkarau.com
This is an attempt at improving
fat_mirror_bhsin sync mode [namely it writes all of the data for a backup block, and then blocks untill finished]. The old behaviour would write & block in smaller chunks, so this should be slightly faster. It also removes the fixme requesting that it be fixed to behave this way :-)Signed-off-by Holden Karau <[email protected]> http://www.holdenkarau.comSo how much is performance improved?
--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com
Signature · 1 line
Cell: 613-276-1645
Hi Jörn,
Thanks for your time, I'll make those changes [along with a few other things I noticed while benchmarking it]. Before I put together a patch, does anyone else see any obvious stuff I should clean up?
Cheers,
Holden :-)
Quoted 4 lines · Jörn Engel
I didn't pay too much attention, but found some low hanging fruits.
Quoted 1 line · Holden Karau
Quoted 13 lines
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 353
Quoted 9 lines
fs/fat/fatent.c +6
-2-/* FIXME: We can write the blocks as more big chunk. */ static int fat_mirror_bhs (struct super_block *sb,struct buffer_head **bhs, -int nr_bhs) +int nr_bhs ) { +return fat_mirror_bhs_optw (sb , bhs , nr_bhs,0 ); +} + +static int fat_mirror_bhs_optw (struct super_block *sb,struct buffer_head **bhs, +int nr_bhs ,int wait)Does this compile without warnings? Looks as if you should reverse the order of the two functions.
For some reason it compiles without warnings for me, but I'll switch the order.
Quoted 6 lines
Quoted 6 lines
{ struct msdos_sb_info *sbi = MSDOS_SB(sb);fs/fat/fatent.c +1
-1-struct buffer_head *c_bh; +struct buffer_head *c_bh[nr_bhs];int err, n, copy;
Quoted 8 lines
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 362
Quoted 4 lines
fs/fat/fatent.c +4
-0+/* Always wait if mounted -o sync */ +if (sb->s_flags &MS_SYNCHRONOUS ) { + wait =1 ; + }Coding style. Use a tab for indentation and don't use braces for single-line conditional statements.
Sorry about that. A lot of the places where I used braces are because I had some debugging output in there while I was hacking on it. I'll change it.
Quoted 6 lines
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 365
Quoted 3 lines
fs/fat/fatent.c +2
-0+ err =0 ; + err =fat_sync_bhs_optw ( bhs , nr_bhs , wait);The err=0; is superfluous now, isn't it?
.... no comment :-)
Quoted 5 lines
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 367
Quoted 2 lines
fs/fat/fatent.c +2
-0+if (err) + goto error;Indentation.
oops :-) I'll fix that.
Quoted 7 lines
Jörn
--
Fantasy is more important than knowledge. Knowledge is limited, while fantasy embraces the whole world.
-- Albert Einstein
Signature · 1 line
Cell: 613-276-1645
Some of these may overlap with what others suggested.
On Thu, Oct 26, 2006 at 07:59:42AM -0400, Holden Karau wrote:
...
Quoted 2 lines
fs/fat/fatent.c +0
-0
...
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 350
Quoted 6 lines
fs/fat/fatent.c +3
-2-/* FIXME: We can write the blocks as more big chunk. */ static int fat_mirror_bhs (struct super_block *sb,struct buffer_head **bhs, -int nr_bhs) +int nr_bhs ) { +return fat_mirror_bhs_optw (sb , bhs , nr_bhs,0 ); +}
Coding style... (brackets and indentation)
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 362
Quoted 12 lines
fs/fat/fatent.c +7
-1+static int fat_mirror_bhs_optw (struct super_block *sb,struct buffer_head **bhs, +int nr_bhs ,int wait) {struct msdos_sb_info *sbi =MSDOS_SB (sb); -struct buffer_head *c_bh; +struct buffer_head *c_bh[nr_bhs];int err, n, copy; +/* Always wait if mounted -o sync */ +if (sb->s_flags &MS_SYNCHRONOUS ) { + wait =1 ; + }
Ditto (indentation).
Quoted 26 lines
fs/fat/fatent.c +10
-9err =0 ; + err =fat_sync_bhs_optw ( bhs , nr_bhs , wait); +if (err) + goto error;for (copy =1 ; copy < sbi->fats; copy++) {sector_t backup_fat = sbi->fat_length * copy; -for (n =0 ; n < nr_bhs; n++) { - c_bh =sb_getblk (sb, backup_fat + bhs[n]->b_blocknr); -if (!c_bh) { + c_bh[n] =sb_getblk (sb, backup_fat + bhs[n]->b_blocknr); +if (!c_bh[n]) { err = -ENOMEM ; goto error; } -memcpy (c_bh->b_data, bhs[n]->b_data, sb->s_blocksize); -set_buffer_uptodate (c_bh); -mark_buffer_dirty (c_bh); -if (sb->s_flags &MS_SYNCHRONOUS ) - err =sync_dirty_buffer (c_bh); -brelse (c_bh); +set_buffer_uptodate (c_bh[n]); +mark_buffer_dirty (c_bh[n]); +memcpy (c_bh[n]->b_data, bhs[n]->b_data, sb->s_blocksize); + } + err =fat_sync_bhs_optw ( c_bh , nr_bhs , wait );
fs/fat/fatent.c int fat_ent_read(struct inode *inode, st · line 389
Quoted 10 lines
fs/fat/fatent.c +3
-1+for (n =0 ; n < nr_bhs; n++ ) { +brelse (c_bh[n]); + }if (err) goto error; } - } error:return err; }
Ditto.
fs/fat/fatent.c out: · line 518
Quoted 10 lines
fs/fat/fatent.c +3
-3@@ -505,9 +513,9 @@ out:fatent_brelse (&fatent);if (!err) {if (inode_needs_sync (inode)) - err =fat_sync_bhs (bhs, nr_bhs); -if (!err) - err =fat_mirror_bhs (sb, bhs, nr_bhs); + err =fat_mirror_bhs_optw (sb , bhs, nr_bhs ,1 ); +else + err =fat_mirror_bhs_optw (sb, bhs, nr_bhs ,0 );
Ditto.
fs/fat/misc.c void fat_date_unix2dos(int unix_date, __ · line 200
Quoted 11 lines
fs/fat/misc.c +4
-1@@ -194,11 +194,17 @@ void fat_date_unix2dos(int unix_date, __EXPORT_SYMBOL_GPL (fat_date_unix2dos); -int fat_sync_bhs (struct buffer_head **bhs,int nr_bhs) + +int fat_sync_bhs (struct buffer_head **bhs,int nr_bhs ) { +return fat_sync_bhs_optw (bhs , nr_bhs ,1 ); +}
Indentation & bracket placement.
Quoted 10 lines
fs/fat/misc.c +2
-0+int fat_sync_bhs_optw (struct buffer_head **bhs,int nr_bhs ,int wait) {int i, err =0 ;ll_rw_block (SWRITE , nr_bhs, bhs); +if (wait) {for (i =0 ; i < nr_bhs; i++) {wait_on_buffer (bhs[i]);if (buffer_eopnotsupp (bhs[i])) {
fs/fat/misc.c int fat_sync_bhs(struct buffer_head **bh · line 216
Quoted 4 lines
fs/fat/misc.c +1
-0@@ -207,6 +213,7 @@ int fat_sync_bhs(struct buffer_head **bh }else if (!err && !buffer_uptodate (bhs[i])) err = -EIO ; } + }
Indentation.
Josef "Jeff" Sipek.
Signature · 3 lines
Mankind invented the atomic bomb, but no mouse would ever construct a mousetrap. - Albert Einstein