fs/erofs/data.c | 9 +-------- fs/erofs/internal.h | 1 - fs/erofs/super.c | 5 ----- 3 files changed, 1 insertion(+), 14 deletions(-)
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>
Hi Bingwu, On Sun, Aug 16, 2026 at 10:00:12AM +0800, Bingwu Zhang wrote: > 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. Thanks for the patch. In principle, yes, but it's also no problem to leave it as-is in case some use cases later need adjust the device_info of a dev for example at runtime. Or if it causes any noticeable performance penalty, that will be one reason to drop it now. Thanks, Gao Xiang > > Signed-off-by: Bingwu Zhang <xtex@astrafall.org>
Hi, On Sunday, August 16, 2026 11:06:05 AM China Standard Time Gao Xiang wrote: > Hi Bingwu, > > On Sun, Aug 16, 2026 at 10:00:12AM +0800, Bingwu Zhang wrote: > > 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. > > Thanks for the patch. > > In principle, yes, but it's also no problem to leave it as-is in case > some use cases later need adjust the device_info of a dev for example > at runtime. > > Or if it causes any noticeable performance penalty, that will be one > reason to drop it now. Thanks for the reply. I don't think it caused any notice performance difference so it looks good to me to keep the rwsem. Thanks, Bingwu Zhang > > Thanks, > Gao Xiang > > > Signed-off-by: Bingwu Zhang <xtex@astrafall.org>
© 2016 - 2026 Red Hat, Inc.