Skip to contentSkip to conversation

sync_sb_inodes cleanup

PATCH In review Vladimir Saveliev 2 participants 5 messages May 10, 2005 – May 13, 2005 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sync_sb_inodes cleanup

Hello

sync_sb_inodes is called twice and both times like:
spin_lock(&inode_lock);
sync_sb_inodes(sb, wbc); spin_unlock(&inode_lock);

This patch makes generic_sync_sb_inodes to spin lock itself. Please, apply this patch. It helps reiser4 to get rid of some oddities.

sync_sb_inodes is always called like:

	spin_lock(&inode_lock);
	sync_sb_inodes(sb, wbc);
	spin_unlock(&inode_lock);

This patch moves spin_lock/spin_unlock down to sync_sb_inodes.

 fs/fs-writeback.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
fs/fs-writeback.c renamed from fs/fs-writeback.c~sync_sb_inodes-cleanup +4 -8
diff -puN fs/fs-writeback.c~sync_sb_inodes-cleanup fs/fs-writeback.c
@@ -283,8 +283,6 @@ __writeback_single_inode(struct inode *i
  * WB_SYNC_HOLD is a hack for sys_sync(): reattach the inode to sb->s_dirty so
  * that it can be located for waiting on in __writeback_single_inode().
  *
- * Called under inode_lock.
- *
  * If `bdi' is non-zero then we're being asked to writeback a specific queue.
  * This function assumes that the blockdev superblock's inodes are backed by
  * a variety of queues, so all inodes are searched.  For other superblocks,
@@ -305,6 +303,8 @@ generic_sync_sb_inodes(struct super_bloc
 {
 	const unsigned long start = jiffies;	/* livelock avoidance */
 
+	spin_lock(&inode_lock);
+
 	if (!wbc->for_kupdate || list_empty(&sb->s_io))
 		list_splice_init(&sb->s_dirty, &sb->s_io);
 
@@ -384,6 +384,7 @@ generic_sync_sb_inodes(struct super_bloc
 		if (wbc->nr_to_write <= 0)
 			break;
 	}
+	spin_unlock(&inode_lock);
 	return;		/* Leave any unwritten inodes on s_io */
 }
 EXPORT_SYMBOL(generic_sync_sb_inodes);
@@ -436,11 +437,8 @@ restart:
 			 * be unmounted by the time it is released.
 			 */
 			if (down_read_trylock(&sb->s_umount)) {
-				if (sb->s_root) {
-					spin_lock(&inode_lock);
+				if (sb->s_root)
 					sync_sb_inodes(sb, wbc);
-					spin_unlock(&inode_lock);
-				}
 				up_read(&sb->s_umount);
 			}
 			spin_lock(&sb_lock);
@@ -476,9 +474,7 @@ void sync_inodes_sb(struct super_block *
 			(inodes_stat.nr_inodes - inodes_stat.nr_unused) +
 			nr_dirty + nr_unstable;
 	wbc.nr_to_write += wbc.nr_to_write / 2;		/* Bit more for luck */
-	spin_lock(&inode_lock);
 	sync_sb_inodes(sb, &wbc);
-	spin_unlock(&inode_lock);
 }
 
 /*

_

#1 lore raw
Quoted 9 lines · Vladimir Saveliev

This patch makes generic_sync_sb_inodes to spin lock itself. Please, apply this patch. It helps reiser4 to get rid of some oddities.

[snip]

{
const unsigned long start = jiffies; /* livelock avoidance */

+ spin_lock(&inode_lock);

Looking at what jiffies is used for, it is probably is not a big deal, but you should move the assignment of start to after acquiring the lock, as that could take quite some time.

Robert Love

#2 lore raw

Hello

Quoted 7 lines · Robert Love
Quoted 5 lines · Vladimir Saveliev

This patch makes generic_sync_sb_inodes to spin lock itself. Please, apply this patch. It helps reiser4 to get rid of some oddities.

[snip]

Quoted 9 lines
Quoted 4 lines

{
const unsigned long start = jiffies; /* livelock avoidance */

+ spin_lock(&inode_lock);

Looking at what jiffies is used for, it is probably is not a big deal, but you should move the assignment of start to after acquiring the lock, as that could take quite some time.

I did not want to un-const start. It would be required for the assignment move, wouldn't it?

Quoted 4 lines

Robert Love

#3 lore raw
Quoted 2 lines · Vladimir Saveliev

I did not want to un-const start. It would be required for the assignment move, wouldn't it?

Well, the const is just a programming convention. It is useful here, but just a convention; removing it changes nothing behavior-wise. Your patch, though, changes behavior.

How bad do you need to push the spin locks into the function?

Robert Love

#4 lore raw

Hello

Quoted 9 lines · Robert Love
Quoted 2 lines · Vladimir Saveliev

I did not want to un-const start. It would be required for the assignment move, wouldn't it?

Well, the const is just a programming convention. It is useful here, but just a convention; removing it changes nothing behavior-wise. Your patch, though, changes behavior.

ok, I will move assignment.

Quoted 2 lines

How bad do you need to push the spin locks into the function?

The reason is that reiser4 implements its own sync_inodes method of struct super_operations. reiser4_sync_inodes first calls generic_sync_sb_inodes and then calls reiser4' function to flush atoms to disk. If generic_sync_sb_inodes would exit with inode_lock locked, reiser4_sync_inodes would have to unlock inode_lock after generic_sync_sb_inodes and lock it before exit. inode_lock is static for fs/inode.c, so, we asked whether it would be possible to have spinlocking in generic_sync_sb_inodes.