Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: erofs: move shrink accounting inside the function

This patch moves the &erofs_global_shrink_cnt accounting
from the caller to erofs_workgroup_get(). It's cleaner and
it matches erofs_workgroup_put() better. No behavior change.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Gao Xiang and committed by
Greg Kroah-Hartman
4501ca36 d60eff43

+7 -10
+7 -10
drivers/staging/erofs/utils.c
··· 34 34 #define __erofs_workgroup_get(grp) atomic_inc(&(grp)->refcount) 35 35 #define __erofs_workgroup_put(grp) atomic_dec(&(grp)->refcount) 36 36 37 - static int erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt) 37 + static int erofs_workgroup_get(struct erofs_workgroup *grp) 38 38 { 39 39 int o; 40 40 41 41 repeat: 42 42 o = erofs_wait_on_workgroup_freezed(grp); 43 - 44 43 if (unlikely(o <= 0)) 45 44 return -1; 46 45 47 46 if (unlikely(atomic_cmpxchg(&grp->refcount, o, o + 1) != o)) 48 47 goto repeat; 49 48 50 - *ocnt = o; 49 + /* decrease refcount paired by erofs_workgroup_put */ 50 + if (unlikely(o == 1)) 51 + atomic_long_dec(&erofs_global_shrink_cnt); 51 52 return 0; 52 53 } 53 54 54 - struct erofs_workgroup *erofs_find_workgroup( 55 - struct super_block *sb, pgoff_t index, bool *tag) 55 + struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb, 56 + pgoff_t index, bool *tag) 56 57 { 57 58 struct erofs_sb_info *sbi = EROFS_SB(sb); 58 59 struct erofs_workgroup *grp; 59 - int oldcount; 60 60 61 61 repeat: 62 62 rcu_read_lock(); ··· 65 65 *tag = xa_pointer_tag(grp); 66 66 grp = xa_untag_pointer(grp); 67 67 68 - if (erofs_workgroup_get(grp, &oldcount)) { 68 + if (erofs_workgroup_get(grp)) { 69 69 /* prefer to relax rcu read side */ 70 70 rcu_read_unlock(); 71 71 goto repeat; 72 72 } 73 73 74 - /* decrease refcount added by erofs_workgroup_put */ 75 - if (unlikely(oldcount == 1)) 76 - atomic_long_dec(&erofs_global_shrink_cnt); 77 74 DBG_BUGON(index != grp->index); 78 75 } 79 76 rcu_read_unlock();