Skip to content

Commit

Permalink
erofs: use spin_lock to protect workgroup tree
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
asuka-mio authored and Hadenix committed Feb 2, 2024
1 parent 5554e2f commit db56f1e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions fs/erofs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct erofs_sb_info {

/* the dedicated workstation for compression */
struct radix_tree_root workstn_tree;
spinlock_t tree_lock;

/* threshold for decompression synchronously */
unsigned int max_sync_decompress_pages;
Expand Down
1 change: 1 addition & 0 deletions fs/erofs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)

#ifdef CONFIG_EROFS_FS_ZIP
INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
spin_lock_init(&sbi->tree_lock);
#endif

/* get the root inode */
Expand Down
8 changes: 4 additions & 4 deletions fs/erofs/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int erofs_register_workgroup(struct super_block *sb,
return err;

sbi = EROFS_SB(sb);
xa_lock(&sbi->workstn_tree);
spin_lock(&sbi->tree_lock);

/*
* Bump up reference count before making this workgroup
Expand All @@ -101,7 +101,7 @@ int erofs_register_workgroup(struct super_block *sb,
*/
__erofs_workgroup_put(grp);

xa_unlock(&sbi->workstn_tree);
spin_unlock(&sbi->tree_lock);
radix_tree_preload_end();
return err;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ static unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,

int i, found;
repeat:
xa_lock(&sbi->workstn_tree);
spin_lock(&sbi->tree_lock);

found = radix_tree_gang_lookup(&sbi->workstn_tree,
batch, first_index, PAGEVEC_SIZE);
Expand All @@ -185,7 +185,7 @@ static unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
if (!--nr_shrink)
break;
}
xa_unlock(&sbi->workstn_tree);
spin_unlock(&sbi->tree_lock);

if (i && nr_shrink)
goto repeat;
Expand Down

0 comments on commit db56f1e

Please sign in to comment.