From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org
Cc: LKML <linux-kernel@vger.kernel.org>,
oliver.yang@linux.alibaba.com,
Gao Xiang <hsiangkao@linux.alibaba.com>
Subject: [PATCH] erofs: simplify RCU read critical sections
Date: Fri, 19 Jun 2026 16:34:03 +0800 [thread overview]
Message-ID: <20260619083403.3993627-1-hsiangkao@linux.alibaba.com> (raw)
- use scoped_guard() for RCU read critical section in
z_erofs_decompress_kickoff();
- simplify the RCU critical section loop in
z_erofs_pcluster_begin().
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
fs/erofs/zdata.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index c6240dccbb0f..1c65b741b288 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -806,6 +806,7 @@ static int z_erofs_pcluster_begin(struct z_erofs_frontend *fe)
struct super_block *sb = fe->inode->i_sb;
struct z_erofs_pcluster *pcl = NULL;
void *ptr = NULL;
+ bool needretry;
int ret;
DBG_BUGON(fe->pcl);
@@ -825,19 +826,16 @@ static int z_erofs_pcluster_begin(struct z_erofs_frontend *fe)
}
ptr = map->buf.page;
} else {
- while (1) {
+ do {
rcu_read_lock();
pcl = xa_load(&EROFS_SB(sb)->managed_pslots, map->m_pa);
- if (!pcl || z_erofs_get_pcluster(pcl)) {
- DBG_BUGON(pcl && map->m_pa != pcl->pos);
- rcu_read_unlock();
- break;
- }
+ needretry = pcl && !z_erofs_get_pcluster(pcl);
rcu_read_unlock();
- }
+ } while (needretry);
}
if (pcl) {
+ DBG_BUGON(map->m_pa != pcl->pos);
fe->pcl = pcl;
ret = -EEXIST;
} else {
@@ -1459,21 +1457,19 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,
if (sbi->sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON;
#ifdef CONFIG_EROFS_FS_PCPU_KTHREAD
- struct kthread_worker *worker;
+ scoped_guard(rcu) {
+ struct kthread_worker *worker;
- rcu_read_lock();
- worker = rcu_dereference(
+ worker = rcu_dereference(
z_erofs_pcpu_workers[raw_smp_processor_id()]);
- if (!worker) {
- INIT_WORK(&io->u.work, z_erofs_decompressqueue_work);
- queue_work(z_erofs_workqueue, &io->u.work);
- } else {
- kthread_queue_work(worker, &io->u.kthread_work);
+ if (worker) {
+ kthread_queue_work(worker, &io->u.kthread_work);
+ return;
+ }
}
- rcu_read_unlock();
-#else
- queue_work(z_erofs_workqueue, &io->u.work);
+ INIT_WORK(&io->u.work, z_erofs_decompressqueue_work);
#endif
+ queue_work(z_erofs_workqueue, &io->u.work);
return;
}
gfp_flag = memalloc_noio_save();
--
2.43.5
reply other threads:[~2026-06-19 8:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260619083403.3993627-1-hsiangkao@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oliver.yang@linux.alibaba.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