* [PATCH 0/6] hfs: stop using write_supers and s_dirt @ 2012-06-12 8:13 Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 1/6] hfs: push lock_super down Artem Bityutskiy ` (5 more replies) 0 siblings, 6 replies; 8+ messages in thread From: Artem Bityutskiy @ 2012-06-12 8:13 UTC (permalink / raw) To: Al Viro; +Cc: Linux FS Maling List, Linux Kernel Maling List This patch-set makes HFS file-system stop using the VFS '->write_supers()' call-back and the '->s_dirt' superblock field because I plan to remove them once all users are gone. Like the other similar patch-sets, we switch to a delayed job for writing out the superblock instead of using the 's_dirt' flag. Additionally, this patch-set includes several clean-ups. Reminder: The goal is to get rid of the 'sync_supers()' kernel thread. This kernel thread wakes up every 5 seconds (by default) and calls '->write_super()' for all mounted file-systems. And the bad thing is that this is done even if all the superblocks are clean. Moreover, many file-systems do not even need this end they do not register the '->write_super()' method at all (e.g., btrfs). So 'sync_supers()' most often just generates useless wake-ups and wastes power. I am trying to make all file-systems independent of '->write_super()' and plan to remove 'sync_supers()' and '->write_super()' completely once there are no more users. Al, in the past I was trying to upstream patches which optimized 'sync_super()', but you wanted me to kill it completely instead, which I am trying to do now, see http://lkml.org/lkml/2010/7/22/96 Tested using the fsstress test from the LTP project. ====== Overall status: 1. ext4: patches submitted, waiting for review from Ted Ts'o: https://lkml.org/lkml/2012/4/2/111 2. udf: patch submitted, should be in Jan Kara's tree: https://lkml.org/lkml/2012/6/4/233 3 exofs: patch submitted, not sure if it will go to the exofs tree: https://lkml.org/lkml/2012/6/4/211 4. affs: patches submitted, should be in Al Viro's tree: https://lkml.org/lkml/2012/6/6/400 4. ext2: done, see commit f72cf5e223a28d3b3ea7dc9e40464fd534e359e8 5. vfat: done, see commit 78491189ddb6d84d4a4abae992ed891a236d0263 6. jffs2: done, see commit 208b14e507c00ff7f108e1a388dd3d8cc805a443 7. reiserfs: done, see commit 033369d1af1264abc23bea2e174aa47cdd212f6f TODO: hfsplus, sysv, ufs ====== fs/hfs/extent.c | 2 +- fs/hfs/hfs_fs.h | 15 +++++++---- fs/hfs/inode.c | 14 +++------- fs/hfs/mdb.c | 15 +++++++++++ fs/hfs/super.c | 73 +++++++++++++++++++++++++++---------------------------- 5 files changed, 65 insertions(+), 54 deletions(-) Thanks, Artem. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/6] hfs: push lock_super down 2012-06-12 8:13 [PATCH 0/6] hfs: stop using write_supers and s_dirt Artem Bityutskiy @ 2012-06-12 8:13 ` Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 2/6] hfs: get rid of lock_super Artem Bityutskiy ` (4 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: Artem Bityutskiy @ 2012-06-12 8:13 UTC (permalink / raw) To: Al Viro; +Cc: Linux FS Maling List, Linux Kernel Maling List From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> HFS uses 'lock_super()'/'unlock_super()' around 'hfs_mdb_commit()' in order to serialize MDB (Master Directory Block) changes. Push it down to 'hfs_mdb_commit()' in order to simplify the code a bit. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> --- fs/hfs/inode.c | 2 -- fs/hfs/mdb.c | 2 ++ fs/hfs/super.c | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index 761ec06..daf3d63 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -645,11 +645,9 @@ static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end, /* sync the superblock to buffers */ sb = inode->i_sb; if (sb->s_dirt) { - lock_super(sb); sb->s_dirt = 0; if (!(sb->s_flags & MS_RDONLY)) hfs_mdb_commit(sb); - unlock_super(sb); } /* .. finally sync the buffers to disk */ err = sync_blockdev(sb->s_bdev); diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index 1563d5c..3f558d58 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c @@ -260,6 +260,7 @@ void hfs_mdb_commit(struct super_block *sb) { struct hfs_mdb *mdb = HFS_SB(sb)->mdb; + lock_super(sb); if (test_and_clear_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags)) { /* These parameters may have been modified, so write them back */ mdb->drLsMod = hfs_mtime(); @@ -317,6 +318,7 @@ void hfs_mdb_commit(struct super_block *sb) size -= len; } } + unlock_super(sb); } void hfs_mdb_close(struct super_block *sb) diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 7b4c537..f7c06bb 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -50,21 +50,17 @@ MODULE_LICENSE("GPL"); */ static void hfs_write_super(struct super_block *sb) { - lock_super(sb); sb->s_dirt = 0; /* sync everything to the buffers */ if (!(sb->s_flags & MS_RDONLY)) hfs_mdb_commit(sb); - unlock_super(sb); } static int hfs_sync_fs(struct super_block *sb, int wait) { - lock_super(sb); hfs_mdb_commit(sb); sb->s_dirt = 0; - unlock_super(sb); return 0; } -- 1.7.7.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] hfs: get rid of lock_super 2012-06-12 8:13 [PATCH 0/6] hfs: stop using write_supers and s_dirt Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 1/6] hfs: push lock_super down Artem Bityutskiy @ 2012-06-12 8:13 ` Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 3/6] hfs: remove extra mdb write on unmount Artem Bityutskiy ` (3 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: Artem Bityutskiy @ 2012-06-12 8:13 UTC (permalink / raw) To: Al Viro; +Cc: Linux FS Maling List, Linux Kernel Maling List From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Stop using lock_super for serializing the MDB changes - use the buffer-head own lock instead. Tested with fsstress. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> --- fs/hfs/mdb.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index 3f558d58..7a32240 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c @@ -260,7 +260,7 @@ void hfs_mdb_commit(struct super_block *sb) { struct hfs_mdb *mdb = HFS_SB(sb)->mdb; - lock_super(sb); + lock_buffer(HFS_SB(sb)->mdb_bh); if (test_and_clear_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags)) { /* These parameters may have been modified, so write them back */ mdb->drLsMod = hfs_mtime(); @@ -284,9 +284,13 @@ void hfs_mdb_commit(struct super_block *sb) &mdb->drXTFlSize, NULL); hfs_inode_write_fork(HFS_SB(sb)->cat_tree->inode, mdb->drCTExtRec, &mdb->drCTFlSize, NULL); + + lock_buffer(HFS_SB(sb)->alt_mdb_bh); memcpy(HFS_SB(sb)->alt_mdb, HFS_SB(sb)->mdb, HFS_SECTOR_SIZE); HFS_SB(sb)->alt_mdb->drAtrb |= cpu_to_be16(HFS_SB_ATTRIB_UNMNT); HFS_SB(sb)->alt_mdb->drAtrb &= cpu_to_be16(~HFS_SB_ATTRIB_INCNSTNT); + unlock_buffer(HFS_SB(sb)->alt_mdb_bh); + mark_buffer_dirty(HFS_SB(sb)->alt_mdb_bh); sync_dirty_buffer(HFS_SB(sb)->alt_mdb_bh); } @@ -309,7 +313,11 @@ void hfs_mdb_commit(struct super_block *sb) break; } len = min((int)sb->s_blocksize - off, size); + + lock_buffer(bh); memcpy(bh->b_data + off, ptr, len); + unlock_buffer(bh); + mark_buffer_dirty(bh); brelse(bh); block++; @@ -318,7 +326,7 @@ void hfs_mdb_commit(struct super_block *sb) size -= len; } } - unlock_super(sb); + unlock_buffer(HFS_SB(sb)->mdb_bh); } void hfs_mdb_close(struct super_block *sb) -- 1.7.7.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] hfs: remove extra mdb write on unmount 2012-06-12 8:13 [PATCH 0/6] hfs: stop using write_supers and s_dirt Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 1/6] hfs: push lock_super down Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 2/6] hfs: get rid of lock_super Artem Bityutskiy @ 2012-06-12 8:13 ` Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 4/6] hfs: simplify a bit checking for R/O Artem Bityutskiy ` (2 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: Artem Bityutskiy @ 2012-06-12 8:13 UTC (permalink / raw) To: Al Viro; +Cc: Linux FS Maling List, Linux Kernel Maling List From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> HFS calls 'hfs_write_super()' from 'hfs_put_super()' in order to write the MDB to the media. However, it is not needed because VFS calls '->sync_fs()' before calling '->put_super()' - so by the time we are in 'hfs_write_super()', the MDB is already synchronized. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> --- fs/hfs/super.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/fs/hfs/super.c b/fs/hfs/super.c index f7c06bb..47e4119 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -74,8 +74,6 @@ static int hfs_sync_fs(struct super_block *sb, int wait) */ static void hfs_put_super(struct super_block *sb) { - if (sb->s_dirt) - hfs_write_super(sb); hfs_mdb_close(sb); /* release the MDB's resources */ hfs_mdb_put(sb); -- 1.7.7.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] hfs: simplify a bit checking for R/O 2012-06-12 8:13 [PATCH 0/6] hfs: stop using write_supers and s_dirt Artem Bityutskiy ` (2 preceding siblings ...) 2012-06-12 8:13 ` [PATCH 3/6] hfs: remove extra mdb write on unmount Artem Bityutskiy @ 2012-06-12 8:13 ` Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 5/6] hfs: introduce VFS superblock object back-reference Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 6/6] hfs: get rid of hfs_sync_super Artem Bityutskiy 5 siblings, 0 replies; 8+ messages in thread From: Artem Bityutskiy @ 2012-06-12 8:13 UTC (permalink / raw) To: Al Viro; +Cc: Linux FS Maling List, Linux Kernel Maling List From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> We have the following pattern in 2 places in HFS if (!RDONLY) hfs_mdb_commit(); This patch pushes the RDONLY check down to 'hfs_mdb_commit()'. This will make the following patches a bit simpler. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> --- fs/hfs/inode.c | 3 +-- fs/hfs/mdb.c | 3 +++ fs/hfs/super.c | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index daf3d63..629eba4 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -646,8 +646,7 @@ static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end, sb = inode->i_sb; if (sb->s_dirt) { sb->s_dirt = 0; - if (!(sb->s_flags & MS_RDONLY)) - hfs_mdb_commit(sb); + hfs_mdb_commit(sb); } /* .. finally sync the buffers to disk */ err = sync_blockdev(sb->s_bdev); diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index 7a32240..5fd51a5 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c @@ -260,6 +260,9 @@ void hfs_mdb_commit(struct super_block *sb) { struct hfs_mdb *mdb = HFS_SB(sb)->mdb; + if (sb->s_flags & MS_RDONLY) + return; + lock_buffer(HFS_SB(sb)->mdb_bh); if (test_and_clear_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags)) { /* These parameters may have been modified, so write them back */ diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 47e4119..0730135 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -53,8 +53,7 @@ static void hfs_write_super(struct super_block *sb) sb->s_dirt = 0; /* sync everything to the buffers */ - if (!(sb->s_flags & MS_RDONLY)) - hfs_mdb_commit(sb); + hfs_mdb_commit(sb); } static int hfs_sync_fs(struct super_block *sb, int wait) -- 1.7.7.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] hfs: introduce VFS superblock object back-reference 2012-06-12 8:13 [PATCH 0/6] hfs: stop using write_supers and s_dirt Artem Bityutskiy ` (3 preceding siblings ...) 2012-06-12 8:13 ` [PATCH 4/6] hfs: simplify a bit checking for R/O Artem Bityutskiy @ 2012-06-12 8:13 ` Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 6/6] hfs: get rid of hfs_sync_super Artem Bityutskiy 5 siblings, 0 replies; 8+ messages in thread From: Artem Bityutskiy @ 2012-06-12 8:13 UTC (permalink / raw) To: Al Viro; +Cc: Linux FS Maling List, Linux Kernel Maling List From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Add an 'sb' VFS superblock back-reference to the 'struct hfs_sb_info' data structure - we will need to find the VFS superblock from a 'struct hfs_sb_info' object in the next patch, so this change is jut a preparation. Remove few useless newlines while on it. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> --- fs/hfs/hfs_fs.h | 6 +----- fs/hfs/super.c | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h index 1bf967c..3515612 100644 --- a/fs/hfs/hfs_fs.h +++ b/fs/hfs/hfs_fs.h @@ -137,16 +137,12 @@ struct hfs_sb_info { gid_t s_gid; /* The gid of all files */ int session, part; - struct nls_table *nls_io, *nls_disk; - struct mutex bitmap_lock; - unsigned long flags; - u16 blockoffset; - int fs_div; + struct super_block *sb; }; #define HFS_FLG_BITMAP_DIRTY 0 diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 0730135..99c6239 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -380,6 +380,7 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent) if (!sbi) return -ENOMEM; + sbi->sb = sb; sb->s_fs_info = sbi; res = -EINVAL; -- 1.7.7.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] hfs: get rid of hfs_sync_super 2012-06-12 8:13 [PATCH 0/6] hfs: stop using write_supers and s_dirt Artem Bityutskiy ` (4 preceding siblings ...) 2012-06-12 8:13 ` [PATCH 5/6] hfs: introduce VFS superblock object back-reference Artem Bityutskiy @ 2012-06-12 8:13 ` Artem Bityutskiy 2012-07-02 14:15 ` Artem Bityutskiy 5 siblings, 1 reply; 8+ messages in thread From: Artem Bityutskiy @ 2012-06-12 8:13 UTC (permalink / raw) To: Al Viro; +Cc: Linux FS Maling List, Linux Kernel Maling List From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> This patch makes hfs stop using the VFS '->write_super()' method along with the 's_dirt' superblock flag, because they are on their way out. The whole "superblock write-out" VFS infrastructure is served by the 'sync_supers()' kernel thread, which wakes up every 5 (by default) seconds and writes out all dirty superblocks using the '->write_super()' call-back. But the problem with this thread is that it wastes power by waking up the system every 5 seconds, even if there are no diry superblocks, or there are no client file-systems which would need this (e.g., btrfs does not use '->write_super()'). So we want to kill it completely and thus, we need to make file-systems to stop using the '->write_super()' VFS service, and then remove it together with the kernel thread. Tested using fsstress from the LTP project. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> --- fs/hfs/extent.c | 2 +- fs/hfs/hfs_fs.h | 9 ++++++- fs/hfs/inode.c | 11 +++------ fs/hfs/mdb.c | 2 + fs/hfs/super.c | 65 +++++++++++++++++++++++++++++------------------------- 5 files changed, 50 insertions(+), 39 deletions(-) diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c index 2c16316..a67955a 100644 --- a/fs/hfs/extent.c +++ b/fs/hfs/extent.c @@ -432,7 +432,7 @@ out: if (inode->i_ino < HFS_FIRSTUSER_CNID) set_bit(HFS_FLG_ALT_MDB_DIRTY, &HFS_SB(sb)->flags); set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); } return res; diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h index 3515612..8275175 100644 --- a/fs/hfs/hfs_fs.h +++ b/fs/hfs/hfs_fs.h @@ -14,6 +14,7 @@ #include <linux/mutex.h> #include <linux/buffer_head.h> #include <linux/fs.h> +#include <linux/workqueue.h> #include <asm/byteorder.h> #include <asm/uaccess.h> @@ -143,6 +144,9 @@ struct hfs_sb_info { u16 blockoffset; int fs_div; struct super_block *sb; + int work_queued; /* non-zero delayed work is queued */ + struct delayed_work mdb_work; /* MDB flush delayed work */ + spinlock_t work_lock; /* protects mdb_work and work_queued */ }; #define HFS_FLG_BITMAP_DIRTY 0 @@ -222,6 +226,9 @@ extern int hfs_compare_dentry(const struct dentry *parent, extern void hfs_asc2mac(struct super_block *, struct hfs_name *, struct qstr *); extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *); +/* super.c */ +extern void hfs_mark_mdb_dirty(struct super_block *sb); + extern struct timezone sys_tz; /* @@ -249,7 +256,7 @@ static inline const char *hfs_mdb_name(struct super_block *sb) static inline void hfs_bitmap_dirty(struct super_block *sb) { set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); } #define sb_bread512(sb, sec, data) ({ \ diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index 629eba4..cb78138 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -220,7 +220,7 @@ struct inode *hfs_new_inode(struct inode *dir, struct qstr *name, umode_t mode) insert_inode_hash(inode); mark_inode_dirty(inode); set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); return inode; } @@ -235,7 +235,7 @@ void hfs_delete_inode(struct inode *inode) if (HFS_I(inode)->cat_key.ParID == cpu_to_be32(HFS_ROOT_CNID)) HFS_SB(sb)->root_dirs--; set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); return; } HFS_SB(sb)->file_count--; @@ -248,7 +248,7 @@ void hfs_delete_inode(struct inode *inode) } } set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); } void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext, @@ -644,10 +644,7 @@ static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end, /* sync the superblock to buffers */ sb = inode->i_sb; - if (sb->s_dirt) { - sb->s_dirt = 0; - hfs_mdb_commit(sb); - } + flush_delayed_work_sync(&HFS_SB(sb)->mdb_work); /* .. finally sync the buffers to disk */ err = sync_blockdev(sb->s_bdev); if (!ret) diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index 5fd51a5..a5cd355 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c @@ -263,6 +263,8 @@ void hfs_mdb_commit(struct super_block *sb) if (sb->s_flags & MS_RDONLY) return; + cancel_delayed_work(&HFS_SB(sb)->mdb_work); + lock_buffer(HFS_SB(sb)->mdb_bh); if (test_and_clear_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags)) { /* These parameters may have been modified, so write them back */ diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 99c6239..14528ee 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -29,38 +29,9 @@ static struct kmem_cache *hfs_inode_cachep; MODULE_LICENSE("GPL"); -/* - * hfs_write_super() - * - * Description: - * This function is called by the VFS only. When the filesystem - * is mounted r/w it updates the MDB on disk. - * Input Variable(s): - * struct super_block *sb: Pointer to the hfs superblock - * Output Variable(s): - * NONE - * Returns: - * void - * Preconditions: - * 'sb' points to a "valid" (struct super_block). - * Postconditions: - * The MDB is marked 'unsuccessfully unmounted' by clearing bit 8 of drAtrb - * (hfs_put_super() must set this flag!). Some MDB fields are updated - * and the MDB buffer is written to disk by calling hfs_mdb_commit(). - */ -static void hfs_write_super(struct super_block *sb) -{ - sb->s_dirt = 0; - - /* sync everything to the buffers */ - hfs_mdb_commit(sb); -} - static int hfs_sync_fs(struct super_block *sb, int wait) { hfs_mdb_commit(sb); - sb->s_dirt = 0; - return 0; } @@ -73,11 +44,44 @@ static int hfs_sync_fs(struct super_block *sb, int wait) */ static void hfs_put_super(struct super_block *sb) { + cancel_delayed_work_sync(&HFS_SB(sb)->mdb_work); hfs_mdb_close(sb); /* release the MDB's resources */ hfs_mdb_put(sb); } +static void flush_mdb(struct work_struct *work) +{ + struct hfs_sb_info *sbi; + struct super_block *sb; + + sbi = container_of(work, struct hfs_sb_info, mdb_work.work); + sb = sbi->sb; + + spin_lock(&sbi->work_lock); + sbi->work_queued = 0; + spin_unlock(&sbi->work_lock); + + hfs_mdb_commit(sb); +} + +void hfs_mark_mdb_dirty(struct super_block *sb) +{ + struct hfs_sb_info *sbi = HFS_SB(sb); + unsigned long delay; + + if (sb->s_flags & MS_RDONLY) + return; + + spin_lock(&sbi->work_lock); + if (!sbi->work_queued) { + delay = msecs_to_jiffies(dirty_writeback_interval * 10); + queue_delayed_work(system_long_wq, &sbi->mdb_work, delay); + sbi->work_queued = 1; + } + spin_unlock(&sbi->work_lock); +} + /* * hfs_statfs() * @@ -177,7 +181,6 @@ static const struct super_operations hfs_super_operations = { .write_inode = hfs_write_inode, .evict_inode = hfs_evict_inode, .put_super = hfs_put_super, - .write_super = hfs_write_super, .sync_fs = hfs_sync_fs, .statfs = hfs_statfs, .remount_fs = hfs_remount, @@ -382,6 +385,8 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent) sbi->sb = sb; sb->s_fs_info = sbi; + spin_lock_init(&sbi->work_lock); + INIT_DELAYED_WORK(&sbi->mdb_work, flush_mdb); res = -EINVAL; if (!parse_options((char *)data, sbi)) { -- 1.7.7.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 6/6] hfs: get rid of hfs_sync_super 2012-06-12 8:13 ` [PATCH 6/6] hfs: get rid of hfs_sync_super Artem Bityutskiy @ 2012-07-02 14:15 ` Artem Bityutskiy 0 siblings, 0 replies; 8+ messages in thread From: Artem Bityutskiy @ 2012-07-02 14:15 UTC (permalink / raw) To: Al Viro, Andrew Morton; +Cc: Linux FS Maling List, Linux Kernel Maling List [-- Attachment #1: Type: text/plain, Size: 8165 bytes --] From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Date: Tue, 12 Jun 2012 10:40:56 +0300 Subject: [PATCH 19/23] hfs: get rid of hfs_sync_super This patch makes hfs stop using the VFS '->write_super()' method along with the 's_dirt' superblock flag, because they are on their way out. The whole "superblock write-out" VFS infrastructure is served by the 'sync_supers()' kernel thread, which wakes up every 5 (by default) seconds and writes out all dirty superblocks using the '->write_super()' call-back. But the problem with this thread is that it wastes power by waking up the system every 5 seconds, even if there are no diry superblocks, or there are no client file-systems which would need this (e.g., btrfs does not use '->write_super()'). So we want to kill it completely and thus, we need to make file-systems to stop using the '->write_super()' VFS service, and then remove it together with the kernel thread. Tested using fsstress from the LTP project. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> --- fs/hfs/extent.c | 2 +- fs/hfs/hfs_fs.h | 9 +++++++- fs/hfs/inode.c | 11 ++++------ fs/hfs/mdb.c | 2 ++ fs/hfs/super.c | 65 ++++++++++++++++++++++++++++++------------------------- 5 files changed, 50 insertions(+), 39 deletions(-) |This is patch is the same except that it fixes several white-space |issues. If you prefer an incremental patch, please, let me know. The |issues are: | |WARNING:SUSPECT_CODE_INDENT: suspect code indent for conditional statements (8, 15) |#213: FILE: fs/hfs/super.c:73: |+ if (sb->s_flags & MS_RDONLY) |+ return; | |WARNING:SUSPECT_CODE_INDENT: suspect code indent for conditional statements (8, 15) |#217: FILE: fs/hfs/super.c:77: |+ if (!sbi->work_queued) { |+ delay = msecs_to_jiffies(dirty_writeback_interval * 10); diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c index 2c16316..a67955a 100644 --- a/fs/hfs/extent.c +++ b/fs/hfs/extent.c @@ -432,7 +432,7 @@ out: if (inode->i_ino < HFS_FIRSTUSER_CNID) set_bit(HFS_FLG_ALT_MDB_DIRTY, &HFS_SB(sb)->flags); set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); } return res; diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h index 3515612..8275175 100644 --- a/fs/hfs/hfs_fs.h +++ b/fs/hfs/hfs_fs.h @@ -14,6 +14,7 @@ #include <linux/mutex.h> #include <linux/buffer_head.h> #include <linux/fs.h> +#include <linux/workqueue.h> #include <asm/byteorder.h> #include <asm/uaccess.h> @@ -143,6 +144,9 @@ struct hfs_sb_info { u16 blockoffset; int fs_div; struct super_block *sb; + int work_queued; /* non-zero delayed work is queued */ + struct delayed_work mdb_work; /* MDB flush delayed work */ + spinlock_t work_lock; /* protects mdb_work and work_queued */ }; #define HFS_FLG_BITMAP_DIRTY 0 @@ -222,6 +226,9 @@ extern int hfs_compare_dentry(const struct dentry *parent, extern void hfs_asc2mac(struct super_block *, struct hfs_name *, struct qstr *); extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *); +/* super.c */ +extern void hfs_mark_mdb_dirty(struct super_block *sb); + extern struct timezone sys_tz; /* @@ -249,7 +256,7 @@ static inline const char *hfs_mdb_name(struct super_block *sb) static inline void hfs_bitmap_dirty(struct super_block *sb) { set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); } #define sb_bread512(sb, sec, data) ({ \ diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index 629eba4..cb78138 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -220,7 +220,7 @@ struct inode *hfs_new_inode(struct inode *dir, struct qstr *name, umode_t mode) insert_inode_hash(inode); mark_inode_dirty(inode); set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); return inode; } @@ -235,7 +235,7 @@ void hfs_delete_inode(struct inode *inode) if (HFS_I(inode)->cat_key.ParID == cpu_to_be32(HFS_ROOT_CNID)) HFS_SB(sb)->root_dirs--; set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); return; } HFS_SB(sb)->file_count--; @@ -248,7 +248,7 @@ void hfs_delete_inode(struct inode *inode) } } set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags); - sb->s_dirt = 1; + hfs_mark_mdb_dirty(sb); } void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext, @@ -644,10 +644,7 @@ static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end, /* sync the superblock to buffers */ sb = inode->i_sb; - if (sb->s_dirt) { - sb->s_dirt = 0; - hfs_mdb_commit(sb); - } + flush_delayed_work_sync(&HFS_SB(sb)->mdb_work); /* .. finally sync the buffers to disk */ err = sync_blockdev(sb->s_bdev); if (!ret) diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c index 5fd51a5..a5cd355 100644 --- a/fs/hfs/mdb.c +++ b/fs/hfs/mdb.c @@ -263,6 +263,8 @@ void hfs_mdb_commit(struct super_block *sb) if (sb->s_flags & MS_RDONLY) return; + cancel_delayed_work(&HFS_SB(sb)->mdb_work); + lock_buffer(HFS_SB(sb)->mdb_bh); if (test_and_clear_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags)) { /* These parameters may have been modified, so write them back */ diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 99c6239..14528ee 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -29,38 +29,9 @@ static struct kmem_cache *hfs_inode_cachep; MODULE_LICENSE("GPL"); -/* - * hfs_write_super() - * - * Description: - * This function is called by the VFS only. When the filesystem - * is mounted r/w it updates the MDB on disk. - * Input Variable(s): - * struct super_block *sb: Pointer to the hfs superblock - * Output Variable(s): - * NONE - * Returns: - * void - * Preconditions: - * 'sb' points to a "valid" (struct super_block). - * Postconditions: - * The MDB is marked 'unsuccessfully unmounted' by clearing bit 8 of drAtrb - * (hfs_put_super() must set this flag!). Some MDB fields are updated - * and the MDB buffer is written to disk by calling hfs_mdb_commit(). - */ -static void hfs_write_super(struct super_block *sb) -{ - sb->s_dirt = 0; - - /* sync everything to the buffers */ - hfs_mdb_commit(sb); -} - static int hfs_sync_fs(struct super_block *sb, int wait) { hfs_mdb_commit(sb); - sb->s_dirt = 0; - return 0; } @@ -73,11 +44,44 @@ static int hfs_sync_fs(struct super_block *sb, int wait) */ static void hfs_put_super(struct super_block *sb) { + cancel_delayed_work_sync(&HFS_SB(sb)->mdb_work); hfs_mdb_close(sb); /* release the MDB's resources */ hfs_mdb_put(sb); } +static void flush_mdb(struct work_struct *work) +{ + struct hfs_sb_info *sbi; + struct super_block *sb; + + sbi = container_of(work, struct hfs_sb_info, mdb_work.work); + sb = sbi->sb; + + spin_lock(&sbi->work_lock); + sbi->work_queued = 0; + spin_unlock(&sbi->work_lock); + + hfs_mdb_commit(sb); +} + +void hfs_mark_mdb_dirty(struct super_block *sb) +{ + struct hfs_sb_info *sbi = HFS_SB(sb); + unsigned long delay; + + if (sb->s_flags & MS_RDONLY) + return; + + spin_lock(&sbi->work_lock); + if (!sbi->work_queued) { + delay = msecs_to_jiffies(dirty_writeback_interval * 10); + queue_delayed_work(system_long_wq, &sbi->mdb_work, delay); + sbi->work_queued = 1; + } + spin_unlock(&sbi->work_lock); +} + /* * hfs_statfs() * @@ -177,7 +181,6 @@ static const struct super_operations hfs_super_operations = { .write_inode = hfs_write_inode, .evict_inode = hfs_evict_inode, .put_super = hfs_put_super, - .write_super = hfs_write_super, .sync_fs = hfs_sync_fs, .statfs = hfs_statfs, .remount_fs = hfs_remount, @@ -382,6 +385,8 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent) sbi->sb = sb; sb->s_fs_info = sbi; + spin_lock_init(&sbi->work_lock); + INIT_DELAYED_WORK(&sbi->mdb_work, flush_mdb); res = -EINVAL; if (!parse_options((char *)data, sbi)) { -- 1.7.10 [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-07-02 14:15 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-06-12 8:13 [PATCH 0/6] hfs: stop using write_supers and s_dirt Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 1/6] hfs: push lock_super down Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 2/6] hfs: get rid of lock_super Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 3/6] hfs: remove extra mdb write on unmount Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 4/6] hfs: simplify a bit checking for R/O Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 5/6] hfs: introduce VFS superblock object back-reference Artem Bityutskiy 2012-06-12 8:13 ` [PATCH 6/6] hfs: get rid of hfs_sync_super Artem Bityutskiy 2012-07-02 14:15 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).