linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree
@ 2015-12-01  0:53 Jaegeuk Kim
  2015-12-01  1:30 ` kbuild test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2015-12-01  0:53 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim

While handling extent trees, we can enter into a reclaiming path anytime.
If it tries to release some extent nodes in the same extent tree,
write_lock(&et->lock) would be hanged.
In order to avoid the deadlock, we can just skip it.

Note that, if it is an unreferenced tree, we should get write_lock(&et->lock)
successfully and release all of therein nodes.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/extent_cache.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 7ddba81..21b1b8e 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -615,9 +615,10 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
 		for (i = 0; i < found; i++) {
 			struct extent_tree *et = treevec[i];
 
-			write_lock(&et->lock);
-			node_cnt += __free_extent_tree(sbi, et, false);
-			write_unlock(&et->lock);
+			if (down_write_trylock(&et->lock)) {
+				node_cnt += __free_extent_tree(sbi, et, false);
+				write_unlock(&et->lock);
+			}
 
 			if (node_cnt + tree_cnt >= nr_shrink)
 				goto unlock_out;
-- 
2.4.9 (Apple Git-60)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree
  2015-12-01  0:53 [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree Jaegeuk Kim
@ 2015-12-01  1:30 ` kbuild test robot
  2015-12-01  1:46 ` [PATCH v2] " Jaegeuk Kim
  2015-12-01  2:16 ` [PATCH] " kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2015-12-01  1:30 UTC (permalink / raw)
  Cc: kbuild-all, linux-kernel, linux-fsdevel, linux-f2fs-devel,
	Jaegeuk Kim

[-- Attachment #1: Type: text/plain, Size: 2054 bytes --]

Hi Jaegeuk,

[auto build test WARNING on: f2fs/dev]
[also build test WARNING on: v4.4-rc3 next-20151127]

url:    https://github.com/0day-ci/linux/commits/Jaegeuk-Kim/f2fs-avoid-deadlock-in-f2fs_shrink_extent_tree/20151201-085538
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs dev
config: i386-randconfig-i1-201548 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   fs/f2fs/extent_cache.c: In function 'f2fs_shrink_extent_tree':
>> fs/f2fs/extent_cache.c:618:27: warning: passing argument 1 of 'down_write_trylock' from incompatible pointer type [-Wincompatible-pointer-types]
       if (down_write_trylock(&et->lock)) {
                              ^
   In file included from include/linux/fs.h:20:0,
                    from fs/f2fs/extent_cache.c:14:
   include/linux/rwsem.h:123:12: note: expected 'struct rw_semaphore *' but argument is of type 'rwlock_t * {aka struct <anonymous> *}'
    extern int down_write_trylock(struct rw_semaphore *sem);
               ^

vim +/down_write_trylock +618 fs/f2fs/extent_cache.c

   602		}
   603		spin_unlock(&sbi->extent_lock);
   604	
   605		/*
   606		 * reset ino for searching victims from beginning of global extent tree.
   607		 */
   608		ino = F2FS_ROOT_INO(sbi);
   609	
   610		while ((found = radix_tree_gang_lookup(root,
   611					(void **)treevec, ino, EXT_TREE_VEC_SIZE))) {
   612			unsigned i;
   613	
   614			ino = treevec[found - 1]->ino + 1;
   615			for (i = 0; i < found; i++) {
   616				struct extent_tree *et = treevec[i];
   617	
 > 618				if (down_write_trylock(&et->lock)) {
   619					node_cnt += __free_extent_tree(sbi, et, false);
   620					write_unlock(&et->lock);
   621				}
   622	
   623				if (node_cnt + tree_cnt >= nr_shrink)
   624					goto unlock_out;
   625			}
   626		}

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 22406 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] f2fs: avoid deadlock in f2fs_shrink_extent_tree
  2015-12-01  0:53 [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree Jaegeuk Kim
  2015-12-01  1:30 ` kbuild test robot
@ 2015-12-01  1:46 ` Jaegeuk Kim
  2015-12-01 14:44   ` [f2fs-dev] " Chao Yu
  2015-12-01  2:16 ` [PATCH] " kbuild test robot
  2 siblings, 1 reply; 5+ messages in thread
From: Jaegeuk Kim @ 2015-12-01  1:46 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel, linux-f2fs-devel

Change log from v1:
 o fix bug

>From 8cd63b5e91daeeccc1f158425c74de0f462c96af Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk@kernel.org>
Date: Mon, 30 Nov 2015 16:26:44 -0800
Subject: [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree

While handling extent trees, we can enter into a reclaiming path anytime.
If it tries to release some extent nodes in the same extent tree,
write_lock(&et->lock) would be hanged.
In order to avoid the deadlock, we can just skip it.

Note that, if it is an unreferenced tree, we should get write_lock(&et->lock)
successfully and release all of therein nodes.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/extent_cache.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 7ddba81..de063f2 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -615,9 +615,10 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
 		for (i = 0; i < found; i++) {
 			struct extent_tree *et = treevec[i];
 
-			write_lock(&et->lock);
-			node_cnt += __free_extent_tree(sbi, et, false);
-			write_unlock(&et->lock);
+			if (write_trylock(&et->lock)) {
+				node_cnt += __free_extent_tree(sbi, et, false);
+				write_unlock(&et->lock);
+			}
 
 			if (node_cnt + tree_cnt >= nr_shrink)
 				goto unlock_out;
-- 
2.4.9 (Apple Git-60)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree
  2015-12-01  0:53 [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree Jaegeuk Kim
  2015-12-01  1:30 ` kbuild test robot
  2015-12-01  1:46 ` [PATCH v2] " Jaegeuk Kim
@ 2015-12-01  2:16 ` kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2015-12-01  2:16 UTC (permalink / raw)
  Cc: kbuild-all, linux-kernel, linux-fsdevel, linux-f2fs-devel,
	Jaegeuk Kim

[-- Attachment #1: Type: text/plain, Size: 4415 bytes --]

Hi Jaegeuk,

[auto build test WARNING on: f2fs/dev]
[also build test WARNING on: v4.4-rc3 next-20151127]

url:    https://github.com/0day-ci/linux/commits/Jaegeuk-Kim/f2fs-avoid-deadlock-in-f2fs_shrink_extent_tree/20151201-085538
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs dev
config: x86_64-randconfig-s2-12010958 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   In file included from include/linux/linkage.h:4:0,
                    from include/linux/fs.h:4,
                    from fs/f2fs/extent_cache.c:14:
   fs/f2fs/extent_cache.c: In function 'f2fs_shrink_extent_tree':
   fs/f2fs/extent_cache.c:618:27: warning: passing argument 1 of 'down_write_trylock' from incompatible pointer type [-Wincompatible-pointer-types]
       if (down_write_trylock(&et->lock)) {
                              ^
   include/linux/compiler.h:147:28: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                               ^
>> fs/f2fs/extent_cache.c:618:4: note: in expansion of macro 'if'
       if (down_write_trylock(&et->lock)) {
       ^
   In file included from include/linux/fs.h:20:0,
                    from fs/f2fs/extent_cache.c:14:
   include/linux/rwsem.h:123:12: note: expected 'struct rw_semaphore *' but argument is of type 'rwlock_t * {aka struct <anonymous> *}'
    extern int down_write_trylock(struct rw_semaphore *sem);
               ^
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/fs.h:4,
                    from fs/f2fs/extent_cache.c:14:
   fs/f2fs/extent_cache.c:618:27: warning: passing argument 1 of 'down_write_trylock' from incompatible pointer type [-Wincompatible-pointer-types]
       if (down_write_trylock(&et->lock)) {
                              ^
   include/linux/compiler.h:147:40: note: in definition of macro '__trace_if'
     if (__builtin_constant_p((cond)) ? !!(cond) :   \
                                           ^
>> fs/f2fs/extent_cache.c:618:4: note: in expansion of macro 'if'
       if (down_write_trylock(&et->lock)) {
       ^
   In file included from include/linux/fs.h:20:0,
                    from fs/f2fs/extent_cache.c:14:
   include/linux/rwsem.h:123:12: note: expected 'struct rw_semaphore *' but argument is of type 'rwlock_t * {aka struct <anonymous> *}'
    extern int down_write_trylock(struct rw_semaphore *sem);
               ^
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/fs.h:4,
                    from fs/f2fs/extent_cache.c:14:
   fs/f2fs/extent_cache.c:618:27: warning: passing argument 1 of 'down_write_trylock' from incompatible pointer type [-Wincompatible-pointer-types]
       if (down_write_trylock(&et->lock)) {
                              ^
   include/linux/compiler.h:158:16: note: in definition of macro '__trace_if'
      ______r = !!(cond);     \
                   ^
>> fs/f2fs/extent_cache.c:618:4: note: in expansion of macro 'if'
       if (down_write_trylock(&et->lock)) {
       ^
   In file included from include/linux/fs.h:20:0,
                    from fs/f2fs/extent_cache.c:14:
   include/linux/rwsem.h:123:12: note: expected 'struct rw_semaphore *' but argument is of type 'rwlock_t * {aka struct <anonymous> *}'
    extern int down_write_trylock(struct rw_semaphore *sem);
               ^

vim +/if +618 fs/f2fs/extent_cache.c

   602		}
   603		spin_unlock(&sbi->extent_lock);
   604	
   605		/*
   606		 * reset ino for searching victims from beginning of global extent tree.
   607		 */
   608		ino = F2FS_ROOT_INO(sbi);
   609	
   610		while ((found = radix_tree_gang_lookup(root,
   611					(void **)treevec, ino, EXT_TREE_VEC_SIZE))) {
   612			unsigned i;
   613	
   614			ino = treevec[found - 1]->ino + 1;
   615			for (i = 0; i < found; i++) {
   616				struct extent_tree *et = treevec[i];
   617	
 > 618				if (down_write_trylock(&et->lock)) {
   619					node_cnt += __free_extent_tree(sbi, et, false);
   620					write_unlock(&et->lock);
   621				}
   622	
   623				if (node_cnt + tree_cnt >= nr_shrink)
   624					goto unlock_out;
   625			}
   626		}

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 22392 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs: avoid deadlock in f2fs_shrink_extent_tree
  2015-12-01  1:46 ` [PATCH v2] " Jaegeuk Kim
@ 2015-12-01 14:44   ` Chao Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2015-12-01 14:44 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-kernel, linux-fsdevel, linux-f2fs-devel

On 12/1/15 9:46 AM, Jaegeuk Kim wrote:
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Reviewed-by: Chao Yu <chao2.yu@samsung.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-01 14:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-01  0:53 [PATCH] f2fs: avoid deadlock in f2fs_shrink_extent_tree Jaegeuk Kim
2015-12-01  1:30 ` kbuild test robot
2015-12-01  1:46 ` [PATCH v2] " Jaegeuk Kim
2015-12-01 14:44   ` [f2fs-dev] " Chao Yu
2015-12-01  2:16 ` [PATCH] " kbuild test robot

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).