* [PATCH 0/2] nfs: refactor bit operations using clear_and_wake_up_bit
@ 2026-06-22 17:55 Arnaud Bonnet
2026-06-22 17:55 ` [PATCH 1/2] nfs: replace atomic bitops sequence with clear_and_wake_up_bit helper Arnaud Bonnet
2026-06-22 17:55 ` [PATCH 2/2] nfs: refactor pNFS functions using clear_and_wake_up_bit Arnaud Bonnet
0 siblings, 2 replies; 3+ messages in thread
From: Arnaud Bonnet @ 2026-06-22 17:55 UTC (permalink / raw)
To: trondmy, anna
Cc: linux-nfs, linux-kernel, code, skhan, me, jkoolstra,
Arnaud Bonnet
Several functions in nfs code use the exact following sequence of calls
when dealing with flags:
clear_bit_unlock();
smp_mb__after_atomic();
wake_up_bit();
Since commit 8236b0ae31c8 ("bdi: wake up concurrent wb_shutdown()
callers.") came the helper clear_and_wake_up_bit() for this exact
purpose, and has since been adopted by several subsystems, including
vfs.
This function is already used in files such as nfs4state.c and
pnfs_nfs.c and this serie aims to continue this effort, which also
allows to remove some no longer used code.
Tested on x86 hardware using a loopback pNFS SCSI layout:
* doing image compression/decompression using xz and
* recompiling tinyconfig kernels on the remounted partition
No error reported under sanitizers.
Suggested-by: Agatha Isabelle Moreira <code@agatha.dev>
Link: https://kernelnewbies.org/Beginner%20Cleanup%20and%20Refactor%20Tasks%20by%20Agatha%20Isabelle%20Moreira#task_007
Signed-off-by: Arnaud Bonnet <abo@medichon.fr>
---
Arnaud Bonnet (2):
nfs: replace atomic bitops sequence with clear_and_wake_up_bit helper
nfs: refactor pNFS functions using clear_and_wake_up_bit
fs/nfs/inode.c | 4 +---
fs/nfs/pnfs.c | 35 ++++++++++-------------------------
2 files changed, 11 insertions(+), 28 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] nfs: replace atomic bitops sequence with clear_and_wake_up_bit helper
2026-06-22 17:55 [PATCH 0/2] nfs: refactor bit operations using clear_and_wake_up_bit Arnaud Bonnet
@ 2026-06-22 17:55 ` Arnaud Bonnet
2026-06-22 17:55 ` [PATCH 2/2] nfs: refactor pNFS functions using clear_and_wake_up_bit Arnaud Bonnet
1 sibling, 0 replies; 3+ messages in thread
From: Arnaud Bonnet @ 2026-06-22 17:55 UTC (permalink / raw)
To: trondmy, anna
Cc: linux-nfs, linux-kernel, code, skhan, me, jkoolstra,
Arnaud Bonnet
Commit 8236b0ae31c83 ("bdi: wake up concurrent wb_shutdown() callers.")
introduces the clear_and_wake_up_bit() helper as a wrapper for the
common clear -> barrier -> wake up bitops sequence.
Use the helper in nfs_clear_invalid_mapping as inode.c already relies
on functions from <linux/wait_bit.h> and to homogenize with other
subsystems.
Suggested-by: Agatha Isabelle Moreira <code@agatha.dev>
Link: https://kernelnewbies.org/Beginner%20Cleanup%20and%20Refactor%20Tasks%20by%20Agatha%20Isabelle%20Moreira#task_007
Signed-off-by: Arnaud Bonnet <abo@medichon.fr>
---
fs/nfs/inode.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index e26030e73696..9c74de557592 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1542,9 +1542,7 @@ int nfs_clear_invalid_mapping(struct address_space *mapping)
ret = nfs_invalidate_mapping(inode, mapping);
trace_nfs_invalidate_mapping_exit(inode, ret);
- clear_bit_unlock(NFS_INO_INVALIDATING, bitlock);
- smp_mb__after_atomic();
- wake_up_bit(bitlock, NFS_INO_INVALIDATING);
+ clear_and_wake_up_bit(NFS_INO_INVALIDATING, bitlock);
out:
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] nfs: refactor pNFS functions using clear_and_wake_up_bit
2026-06-22 17:55 [PATCH 0/2] nfs: refactor bit operations using clear_and_wake_up_bit Arnaud Bonnet
2026-06-22 17:55 ` [PATCH 1/2] nfs: replace atomic bitops sequence with clear_and_wake_up_bit helper Arnaud Bonnet
@ 2026-06-22 17:55 ` Arnaud Bonnet
1 sibling, 0 replies; 3+ messages in thread
From: Arnaud Bonnet @ 2026-06-22 17:55 UTC (permalink / raw)
To: trondmy, anna
Cc: linux-nfs, linux-kernel, code, skhan, me, jkoolstra,
Arnaud Bonnet
Commit 8236b0ae31c83 ("bdi: wake up concurrent wb_shutdown() callers.")
introduces the clear_and_wake_up_bit() helper as a wrapper for the
common clear -> barrier -> wake up bitops sequence.
The file pnfs.c has several helpers with identical contents. Thus they
are replaced with the more recent clean_and_wake_up_bit() global helper
which describes accurately its effects at the call and still specifies
the cleared bit. This also homogenizes the code with other subsystems.
Since the helpers are no longer used after this, they can be safely
removed.
Suggested-by: Agatha Isabelle Moreira <code@agatha.dev>
Link: https://kernelnewbies.org/Beginner%20Cleanup%20and%20Refactor%20Tasks%20by%20Agatha%20Isabelle%20Moreira#task_007
Signed-off-by: Arnaud Bonnet <abo@medichon.fr>
---
fs/nfs/pnfs.c | 35 ++++++++++-------------------------
1 file changed, 10 insertions(+), 25 deletions(-)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 743467e9ba20..96ee18af1ebf 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -2100,15 +2100,6 @@ static bool pnfs_is_first_layoutget(struct pnfs_layout_hdr *lo)
return test_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags);
}
-static void pnfs_clear_first_layoutget(struct pnfs_layout_hdr *lo)
-{
- unsigned long *bitlock = &lo->plh_flags;
-
- clear_bit_unlock(NFS_LAYOUT_FIRST_LAYOUTGET, bitlock);
- smp_mb__after_atomic();
- wake_up_bit(bitlock, NFS_LAYOUT_FIRST_LAYOUTGET);
-}
-
static void _add_to_server_list(struct pnfs_layout_hdr *lo,
struct nfs_server *server)
{
@@ -2284,7 +2275,8 @@ pnfs_update_layout(struct inode *ino,
iomode, lo, lseg,
PNFS_UPDATE_LAYOUT_INVALID_OPEN);
nfs4_schedule_stateid_recovery(server, ctx->state);
- pnfs_clear_first_layoutget(lo);
+ clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET,
+ &lo->plh_flags);
pnfs_put_layout_hdr(lo);
goto lookup_again;
}
@@ -2353,7 +2345,8 @@ pnfs_update_layout(struct inode *ino,
if (!exception.retry)
goto out_put_layout_hdr;
if (first)
- pnfs_clear_first_layoutget(lo);
+ clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET,
+ &lo->plh_flags);
trace_pnfs_update_layout(ino, pos, count,
iomode, lo, lseg, PNFS_UPDATE_LAYOUT_RETRY);
pnfs_put_layout_hdr(lo);
@@ -2365,7 +2358,7 @@ pnfs_update_layout(struct inode *ino,
out_put_layout_hdr:
if (first)
- pnfs_clear_first_layoutget(lo);
+ clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags);
trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg,
PNFS_UPDATE_LAYOUT_EXIT);
pnfs_put_layout_hdr(lo);
@@ -2457,7 +2450,7 @@ static void _lgopen_prepare_attached(struct nfs4_opendata *data,
lgp = pnfs_alloc_init_layoutget_args(ino, ctx, ¤t_stateid, &rng,
nfs_io_gfp_mask());
if (!lgp) {
- pnfs_clear_first_layoutget(lo);
+ clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags);
nfs_layoutget_end(lo);
pnfs_put_layout_hdr(lo);
return;
@@ -2561,7 +2554,8 @@ void nfs4_lgopen_release(struct nfs4_layoutget *lgp)
{
if (lgp != NULL) {
if (lgp->lo) {
- pnfs_clear_first_layoutget(lgp->lo);
+ clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET,
+ &lgp->lo->plh_flags);
nfs_layoutget_end(lgp->lo);
}
pnfs_layoutget_free(lgp);
@@ -3273,15 +3267,6 @@ pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc)
}
EXPORT_SYMBOL_GPL(pnfs_generic_pg_readpages);
-static void pnfs_clear_layoutcommitting(struct inode *inode)
-{
- unsigned long *bitlock = &NFS_I(inode)->flags;
-
- clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock);
- smp_mb__after_atomic();
- wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING);
-}
-
/*
* There can be multiple RW segments.
*/
@@ -3306,7 +3291,7 @@ static void pnfs_list_write_lseg_done(struct inode *inode, struct list_head *lis
pnfs_put_lseg(lseg);
}
- pnfs_clear_layoutcommitting(inode);
+ clear_and_wake_up_bit(NFS_INO_LAYOUTCOMMITTING, &NFS_I(inode)->flags);
}
void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg)
@@ -3446,7 +3431,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
spin_unlock(&inode->i_lock);
kfree(data);
clear_layoutcommitting:
- pnfs_clear_layoutcommitting(inode);
+ clear_and_wake_up_bit(NFS_INO_LAYOUTCOMMITTING, &NFS_I(inode)->flags);
goto out;
}
EXPORT_SYMBOL_GPL(pnfs_layoutcommit_inode);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-22 19:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 17:55 [PATCH 0/2] nfs: refactor bit operations using clear_and_wake_up_bit Arnaud Bonnet
2026-06-22 17:55 ` [PATCH 1/2] nfs: replace atomic bitops sequence with clear_and_wake_up_bit helper Arnaud Bonnet
2026-06-22 17:55 ` [PATCH 2/2] nfs: refactor pNFS functions using clear_and_wake_up_bit Arnaud Bonnet
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.