mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bingwu Zhang <xtex@envs.net>
To: Gao Xiang <xiang@kernel.org>, Chao Yu <chao@kernel.org>,
	 Yue Hu <zbestahu@gmail.com>,
	Jeffle Xu <jefflexu@linux.alibaba.com>,
	 Sandeep Dhavale <dhavale@google.com>,
	Hongbo Li <hongbohbli@tencent.com>,
	 Chunhai Guo <guochunhai@vivo.com>
Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	 Bingwu Zhang <xtex@astrafall.org>
Subject: [PATCH] erofs: remove erofs_dev_context->rwsem
Date: Sun, 16 Aug 2026 10:00:12 +0800	[thread overview]
Message-ID: <20260816-erofs-remove-rwsem-v1-1-78b60b855fa6@astrafall.org> (raw)

From: Bingwu Zhang <xtex@astrafall.org>

devs->tree is only modified in initialization and
destruction code paths and will never be concurrent
with data reading. Thus there is no need to guard
idr_alloc/idr_find with a rwsem.

Signed-off-by: Bingwu Zhang <xtex@astrafall.org>
---
 fs/erofs/data.c     | 9 +--------
 fs/erofs/internal.h | 1 -
 fs/erofs/super.c    | 5 -----
 3 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 9aa48c8d67d1..49d62eac6eb4 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -216,21 +216,15 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
 	erofs_fill_from_devinfo(map, sb, &EROFS_SB(sb)->dif0);
 	map->m_bdev = sb->s_bdev;	/* use s_bdev for the primary device */
 	if (map->m_deviceid) {
-		down_read(&devs->rwsem);
 		dif = idr_find(&devs->tree, map->m_deviceid - 1);
-		if (!dif) {
-			up_read(&devs->rwsem);
+		if (!dif)
 			return -ENODEV;
-		}
 		if (devs->flatdev) {
 			map->m_pa += erofs_pos(sb, dif->uniaddr);
-			up_read(&devs->rwsem);
 			return 0;
 		}
 		erofs_fill_from_devinfo(map, sb, dif);
-		up_read(&devs->rwsem);
 	} else if (devs->extra_devices && !devs->flatdev) {
-		down_read(&devs->rwsem);
 		idr_for_each_entry(&devs->tree, dif, id) {
 			if (!dif->uniaddr)
 				continue;
@@ -243,7 +237,6 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
 				break;
 			}
 		}
-		up_read(&devs->rwsem);
 	}
 	return 0;
 }
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 57bd21859c65..811c160035ce 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -65,7 +65,6 @@ struct erofs_mount_opts {
 
 struct erofs_dev_context {
 	struct idr tree;
-	struct rw_semaphore rwsem;
 
 	unsigned int extra_devices;
 	bool flatdev;
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 9d8f862f309f..12ecdd4b85ac 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -215,7 +215,6 @@ static int erofs_scan_devices(struct super_block *sb,
 
 	sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;
 	pos = le16_to_cpu(dsb->devt_slotoff) * EROFS_DEVT_SLOT_SIZE;
-	down_read(&sbi->devs->rwsem);
 	if (sbi->devs->extra_devices) {
 		idr_for_each_entry(&sbi->devs->tree, dif, id) {
 			err = erofs_init_device(&buf, sb, dif, &pos);
@@ -242,7 +241,6 @@ static int erofs_scan_devices(struct super_block *sb,
 				break;
 		}
 	}
-	up_read(&sbi->devs->rwsem);
 	erofs_put_metabuf(&buf);
 	return err;
 }
@@ -489,9 +487,7 @@ static int erofs_fc_parse_param(struct fs_context *fc,
 			kfree(dif);
 			return -ENOMEM;
 		}
-		down_write(&sbi->devs->rwsem);
 		ret = idr_alloc(&sbi->devs->tree, dif, 0, 0, GFP_KERNEL);
-		up_write(&sbi->devs->rwsem);
 		if (ret < 0) {
 			kfree(dif->path);
 			kfree(dif);
@@ -850,7 +846,6 @@ static int erofs_init_fs_context(struct fs_context *fc)
 	fc->s_fs_info = sbi;
 
 	idr_init(&sbi->devs->tree);
-	init_rwsem(&sbi->devs->rwsem);
 	erofs_default_options(sbi);
 	fc->ops = &erofs_context_ops;
 	return 0;

---
base-commit: 3eb40771c00a8488fa6ed2cc1fe203477908bf38
change-id: 20260814-erofs-remove-rwsem-5a0982d5da80

Best regards,
--  
Bingwu Zhang <xtex@astrafall.org>


             reply	other threads:[~2026-08-16  1:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-16  2:00 Bingwu Zhang [this message]
2026-08-16  3:06 ` Gao Xiang
2026-08-16  3:11   ` xtex

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260816-erofs-remove-rwsem-v1-1-78b60b855fa6@astrafall.org \
    --to=xtex@envs.net \
    --cc=chao@kernel.org \
    --cc=dhavale@google.com \
    --cc=guochunhai@vivo.com \
    --cc=hongbohbli@tencent.com \
    --cc=jefflexu@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiang@kernel.org \
    --cc=xtex@astrafall.org \
    --cc=zbestahu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®