]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: erofs: move shrink accounting inside the function
authorGao Xiang <gaoxiang25@huawei.com>
Wed, 16 Jan 2019 13:10:10 +0000 (21:10 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 18 Jan 2019 09:37:16 +0000 (10:37 +0100)
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>
drivers/staging/erofs/utils.c

index d24945aab133caf41f4805db097d5718c20d84b8..5695efaeb43abe419c8762657bc2be747f7cb72f 100644 (file)
@@ -34,29 +34,29 @@ static atomic_long_t erofs_global_shrink_cnt;
 #define __erofs_workgroup_get(grp)     atomic_inc(&(grp)->refcount)
 #define __erofs_workgroup_put(grp)     atomic_dec(&(grp)->refcount)
 
-static int erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt)
+static int erofs_workgroup_get(struct erofs_workgroup *grp)
 {
        int o;
 
 repeat:
        o = erofs_wait_on_workgroup_freezed(grp);
-
        if (unlikely(o <= 0))
                return -1;
 
        if (unlikely(atomic_cmpxchg(&grp->refcount, o, o + 1) != o))
                goto repeat;
 
-       *ocnt = o;
+       /* decrease refcount paired by erofs_workgroup_put */
+       if (unlikely(o == 1))
+               atomic_long_dec(&erofs_global_shrink_cnt);
        return 0;
 }
 
-struct erofs_workgroup *erofs_find_workgroup(
-       struct super_block *sb, pgoff_t index, bool *tag)
+struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
+                                            pgoff_t index, bool *tag)
 {
        struct erofs_sb_info *sbi = EROFS_SB(sb);
        struct erofs_workgroup *grp;
-       int oldcount;
 
 repeat:
        rcu_read_lock();
@@ -65,15 +65,12 @@ struct erofs_workgroup *erofs_find_workgroup(
                *tag = xa_pointer_tag(grp);
                grp = xa_untag_pointer(grp);
 
-               if (erofs_workgroup_get(grp, &oldcount)) {
+               if (erofs_workgroup_get(grp)) {
                        /* prefer to relax rcu read side */
                        rcu_read_unlock();
                        goto repeat;
                }
 
-               /* decrease refcount added by erofs_workgroup_put */
-               if (unlikely(oldcount == 1))
-                       atomic_long_dec(&erofs_global_shrink_cnt);
                DBG_BUGON(index != grp->index);
        }
        rcu_read_unlock();