Skip to contentSkip to conversation

erofs: get rid of erofs_{find,insert}_workgroup

PATCH Superseded Gao Xiang 2 participants 5 messages Oct 17, 2024 – Oct 18, 2024 EROFS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/3 erofs: get rid of erofs_{find,insert}_workgroup

Just fold them into the only two callers since
they are simple enough.

---
 fs/erofs/internal.h |  5 +----
 fs/erofs/zdata.c    | 38 +++++++++++++++++++++++++---------
 fs/erofs/zutil.c    | 50 +--------------------------------------------
 3 files changed, 30 insertions(+), 63 deletions(-)
fs/erofs/internal.h +1 -4
index 4efd578d7c62..8081ee43cd83 100644
@@ -457,10 +457,7 @@ void erofs_release_pages(struct page **pagepool);
 
 #ifdef CONFIG_EROFS_FS_ZIP
 void erofs_workgroup_put(struct erofs_workgroup *grp);
-struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
-					     pgoff_t index);
-struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
-					       struct erofs_workgroup *grp);
+bool erofs_workgroup_get(struct erofs_workgroup *grp);
 void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
 void erofs_shrinker_register(struct super_block *sb);
 void erofs_shrinker_unregister(struct super_block *sb);
fs/erofs/zdata.c +28 -10
index a569ff9dfd04..7423354d6957 100644
@@ -714,9 +714,10 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
 {
 	struct erofs_map_blocks *map = &fe->map;
 	struct super_block *sb = fe->inode->i_sb;
+	struct erofs_sb_info *sbi = EROFS_SB(sb);
 	bool ztailpacking = map->m_flags & EROFS_MAP_META;
 	struct z_erofs_pcluster *pcl;
-	struct erofs_workgroup *grp;
+	struct erofs_workgroup *grp, *pre;
 	int err;
 
 	if (!(map->m_flags & EROFS_MAP_ENCODED) ||
@@ -752,15 +753,23 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
 		pcl->obj.index = 0;	/* which indicates ztailpacking */
 	} else {
 		pcl->obj.index = erofs_blknr(sb, map->m_pa);
-
-		grp = erofs_insert_workgroup(fe->inode->i_sb, &pcl->obj);
-		if (IS_ERR(grp)) {
-			err = PTR_ERR(grp);
-			goto err_out;
+		while (1) {
+			xa_lock(&sbi->managed_pslots);
+			pre = __xa_cmpxchg(&sbi->managed_pslots, grp->index,
+					   NULL, grp, GFP_KERNEL);
+			if (!pre || xa_is_err(pre) || erofs_workgroup_get(pre)) {
+				xa_unlock(&sbi->managed_pslots);
+				break;
+			}
+			/* try to legitimize the current in-tree one */
+			xa_unlock(&sbi->managed_pslots);
+			cond_resched();
 		}
-
-		if (grp != &pcl->obj) {
-			fe->pcl = container_of(grp,
+		if (xa_is_err(pre)) {
+			err = xa_err(pre);
+			goto err_out;
+		} else if (pre) {
+			fe->pcl = container_of(pre,
 					struct z_erofs_pcluster, obj);
 			err = -EEXIST;
 			goto err_out;
@@ -789,7 +798,16 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
 	DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
 
 	if (!(map->m_flags & EROFS_MAP_META)) {
-		grp = erofs_find_workgroup(sb, blknr);
+		while (1) {
+			rcu_read_lock();
+			grp = xa_load(&EROFS_SB(sb)->managed_pslots, blknr);
+			if (erofs_workgroup_get(grp)) {
+				DBG_BUGON(blknr != grp->index);
+				rcu_read_unlock();
+				break;
+			}
+			rcu_read_unlock();
+		}
 	} else if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) {
 		DBG_BUGON(1);
 		return -EFSCORRUPTED;
fs/erofs/zutil.c +1 -49

62 lines not on this page · raw message

Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/3 erofs: move erofs_workgroup operations into zdata.c

Move related helpers into zdata.c as an intermediate step of getting rid of struct erofs_workgroup, and rename:

erofs_workgroup_put => z_erofs_put_pcluster erofs_workgroup_get => z_erofs_get_pcluster erofs_try_to_release_workgroup => erofs_try_to_release_pcluster erofs_shrink_workstation => z_erofs_shrink_scan

---
 fs/erofs/internal.h |   8 ++--
 fs/erofs/zdata.c    | 102 ++++++++++++++++++++++++++++++++++++++---
 fs/erofs/zutil.c    | 107 +++-----------------------------------------
 3 files changed, 105 insertions(+), 112 deletions(-)
fs/erofs/internal.h +3 -5
index 8081ee43cd83..5fa7ac0575b2 100644
@@ -456,17 +456,15 @@ static inline void erofs_pagepool_add(struct page **pagepool, struct page *page)
 void erofs_release_pages(struct page **pagepool);
 
 #ifdef CONFIG_EROFS_FS_ZIP
-void erofs_workgroup_put(struct erofs_workgroup *grp);
-bool erofs_workgroup_get(struct erofs_workgroup *grp);
-void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
+extern atomic_long_t erofs_global_shrink_cnt;
 void erofs_shrinker_register(struct super_block *sb);
 void erofs_shrinker_unregister(struct super_block *sb);
 int __init erofs_init_shrinker(void);
 void erofs_exit_shrinker(void);
 int __init z_erofs_init_subsystem(void);
 void z_erofs_exit_subsystem(void);
-int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
-					struct erofs_workgroup *egrp);
+unsigned long z_erofs_shrink_scan(struct erofs_sb_info *sbi,
+				  unsigned long nr_shrink);
 int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
 			    int flags);
 void *z_erofs_get_gbuf(unsigned int requiredpages);
fs/erofs/zdata.c +95 -7

150 lines not on this page · raw message

fs/erofs/zutil.c +7 -100

140 lines not on this page · raw message

Signature · 1 line
2.43.5
author
#2 lore raw

PATCH 3/3 erofs: sunset `struct erofs_workgroup`

In reply to Gao Xiang

struct erofs_workgroup was introduced to provide a unique header for all physically indexed objects. However, after big pclusters and shared pclusters are implemented upstream, it seems that all EROFS encoded data (which requires transformation) can be represented with struct z_erofs_pcluster directly.

Move all members into struct z_erofs_pcluster for simplicity.

---
 fs/erofs/internal.h |   6 --
 fs/erofs/zdata.c    | 131 ++++++++++++++++++++------------------------
 2 files changed, 60 insertions(+), 77 deletions(-)
fs/erofs/internal.h +0 -6
index 5fa7ac0575b2..3905d991c49b 100644
@@ -208,12 +208,6 @@ enum {
 	EROFS_ZIP_CACHE_READAROUND
 };
 
-/* basic unit of the workstation of a super_block */
-struct erofs_workgroup {
-	pgoff_t index;
-	struct lockref lockref;
-};
-
 enum erofs_kmap_type {
 	EROFS_NO_KMAP,		/* don't map the buffer */
 	EROFS_KMAP,		/* use kmap_local_page() to map the buffer */
fs/erofs/zdata.c +60 -71

332 lines not on this page · raw message

Signature · 1 line
2.43.5
reviewer
#3 lore raw
In reply to Gao Xiang

fs/erofs/zdata.c static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe) · line 804

Quoted 9 lines
fs/erofs/zdata.c +4 -1
@@ -789,7 +798,16 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
  	DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
 
  	if (!(map->m_flags & EROFS_MAP_META)) {
-		grp = erofs_find_workgroup(sb, blknr);
+		while (1) {
+			rcu_read_lock();
+			grp = xa_load(&EROFS_SB(sb)->managed_pslots, blknr);
+			if (erofs_workgroup_get(grp)) {

I guess here should be modified as below, please refer to erofs_find_workgroup().

			if (grp && erofs_workgroup_get(grp)) {
Quoted 26 lines
fs/erofs/zdata.c +6 -0
+				DBG_BUGON(blknr != grp->index);
+				rcu_read_unlock();
+				break;
+			}
+			rcu_read_unlock();
+		}
  	} else if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) {
  		DBG_BUGON(1);
  		return -EFSCORRUPTED;
fs/erofs/zutil.c +1 -1
index 37afe2024840..218b0249a482 100644
@@ -214,7 +214,7 @@ void erofs_release_pages(struct page **pagepool)
  	}
  }
 
-static bool erofs_workgroup_get(struct erofs_workgroup *grp)
+bool erofs_workgroup_get(struct erofs_workgroup *grp)
  {
  	if (lockref_get_not_zero(&grp->lockref))
  		return true;
@@ -231,54 +231,6 @@ static bool erofs_workgroup_get(struct erofs_workgroup *grp)
  	return true;
  }
 

fs/erofs/zutil.c static bool erofs_workgroup_get(struct erofs_workgroup *grp) · line 243

Quoted 10 lines
fs/erofs/zutil.c +0 -10
-struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
-					     pgoff_t index)
-{
-	struct erofs_sb_info *sbi = EROFS_SB(sb);
-	struct erofs_workgroup *grp;
-
-repeat:
-	rcu_read_lock();
-	grp = xa_load(&sbi->managed_pslots, index);
-	if (grp) {

Please refer to this logic.

fs/erofs/zutil.c static bool erofs_workgroup_get(struct erofs_workgroup *grp) · line 254

Quoted 11 lines
fs/erofs/zutil.c +0 -11
-		if (!erofs_workgroup_get(grp)) {
-			/* prefer to relax rcu read side */
-			rcu_read_unlock();
-			goto repeat;
-		}
-
-		DBG_BUGON(index != grp->index);
-	}
-	rcu_read_unlock();
-	return grp;
-}

Thanks,

Chunhai

author
#4 lore raw
Quoted 11 lines · Chunhai Guo

fs/erofs/zdata.c static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe) · line 804

Quoted 9 lines
fs/erofs/zdata.c +4 -1
@@ -789,7 +798,16 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
   	DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
 
   	if (!(map->m_flags & EROFS_MAP_META)) {
-		grp = erofs_find_workgroup(sb, blknr);
+		while (1) {
+			rcu_read_lock();
+			grp = xa_load(&EROFS_SB(sb)->managed_pslots, blknr);
+			if (erofs_workgroup_get(grp)) {

I guess here should be modified as below, please refer to erofs_find_workgroup().

Yeah, nice catch! Will fix it in the next version.

Thanks,
Gao Xiang