aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/data.c
diff options
context:
space:
mode:
authorGu Zheng <guz.fnst@cn.fujitsu.com>2013-09-27 06:08:30 -0400
committerJaegeuk Kim <jaegeuk.kim@samsung.com>2013-10-06 22:33:05 -0400
commite479556bfdd136669854292eb57ed0139d7253d5 (patch)
tree95772ba1ac8cf1e79c89145daf40c417814896da /fs/f2fs/data.c
parent2e5558f4a5cf16a7394fd5770087303db8912c66 (diff)
f2fs: use rw_sem instead of fs_lock(locks mutex)
The fs_locks is used to block other ops(ex, recovery) when doing checkpoint. And each other operate routine(besides checkpoint) needs to acquire a fs_lock, there is a terrible problem here, if these are too many concurrency threads acquiring fs_lock, so that they will block each other and may lead to some performance problem, but this is not the phenomenon we want to see. Though there are some optimization patches introduced to enhance the usage of fs_lock, but the thorough solution is using a *rw_sem* to replace the fs_lock. Checkpoint routine takes write_sem, and other ops take read_sem, so that we can block other ops(ex, recovery) when doing checkpoint, and other ops will not disturb each other, this can avoid the problem described above completely. Because of the weakness of rw_sem, the above change may introduce a potential problem that the checkpoint thread might get starved if other threads are intensively locking the read semaphore for I/O.(Pointed out by Xu Jin) In order to avoid this, a wait_list is introduced, the appending read semaphore ops will be dropped into the wait_list if checkpoint thread is waiting for write semaphore, and will be waked up when checkpoint thread gives up write semaphore. Thanks to Kim's previous review and test, and will be very glad to see other guys' performance tests about this patch. V2: -fix the potential starvation problem. -use more suitable func name suggested by Xu Jin. Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com> [Jaegeuk Kim: adjust minor coding standard] Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'fs/f2fs/data.c')
-rw-r--r--fs/f2fs/data.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 941f9b9ca3a5..2535d3b1a763 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -560,9 +560,9 @@ write:
560 inode_dec_dirty_dents(inode); 560 inode_dec_dirty_dents(inode);
561 err = do_write_data_page(page); 561 err = do_write_data_page(page);
562 } else { 562 } else {
563 int ilock = mutex_lock_op(sbi); 563 f2fs_lock_op(sbi);
564 err = do_write_data_page(page); 564 err = do_write_data_page(page);
565 mutex_unlock_op(sbi, ilock); 565 f2fs_unlock_op(sbi);
566 need_balance_fs = true; 566 need_balance_fs = true;
567 } 567 }
568 if (err == -ENOENT) 568 if (err == -ENOENT)
@@ -641,7 +641,6 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
641 pgoff_t index = ((unsigned long long) pos) >> PAGE_CACHE_SHIFT; 641 pgoff_t index = ((unsigned long long) pos) >> PAGE_CACHE_SHIFT;
642 struct dnode_of_data dn; 642 struct dnode_of_data dn;
643 int err = 0; 643 int err = 0;
644 int ilock;
645 644
646 f2fs_balance_fs(sbi); 645 f2fs_balance_fs(sbi);
647repeat: 646repeat:
@@ -650,7 +649,7 @@ repeat:
650 return -ENOMEM; 649 return -ENOMEM;
651 *pagep = page; 650 *pagep = page;
652 651
653 ilock = mutex_lock_op(sbi); 652 f2fs_lock_op(sbi);
654 653
655 set_new_dnode(&dn, inode, NULL, NULL, 0); 654 set_new_dnode(&dn, inode, NULL, NULL, 0);
656 err = get_dnode_of_data(&dn, index, ALLOC_NODE); 655 err = get_dnode_of_data(&dn, index, ALLOC_NODE);
@@ -664,7 +663,7 @@ repeat:
664 if (err) 663 if (err)
665 goto err; 664 goto err;
666 665
667 mutex_unlock_op(sbi, ilock); 666 f2fs_unlock_op(sbi);
668 667
669 if ((len == PAGE_CACHE_SIZE) || PageUptodate(page)) 668 if ((len == PAGE_CACHE_SIZE) || PageUptodate(page))
670 return 0; 669 return 0;
@@ -700,7 +699,7 @@ out:
700 return 0; 699 return 0;
701 700
702err: 701err:
703 mutex_unlock_op(sbi, ilock); 702 f2fs_unlock_op(sbi);
704 f2fs_put_page(page, 1); 703 f2fs_put_page(page, 1);
705 return err; 704 return err;
706} 705}