[PATCH 0/5] seqlock: introduce SEQLOCK_READ_SECTION()

Oleg Nesterov posted 5 patches 2 months, 1 week ago
fs/d_path.c             | 31 +++++++++++++------------------
fs/proc/array.c         |  9 ++-------
fs/proc/base.c          |  9 ++-------
include/linux/seqlock.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
kernel/sched/cputime.c  | 14 +++-----------
5 files changed, 69 insertions(+), 43 deletions(-)
[PATCH 0/5] seqlock: introduce SEQLOCK_READ_SECTION()
Posted by Oleg Nesterov 2 months, 1 week ago
OK, let me name it SEQLOCK_READ_SECTION().

Al, could you look at 5/5? Please nack it if you think it makes no sense
or wrong. I abused __dentry_path() to add another example. To simplify the
review, this is how it looks after the patch:

	static char *__dentry_path(const struct dentry *d, struct prepend_buffer *p)
	{
		const struct dentry *dentry;
		struct prepend_buffer b;

		rcu_read_lock();
		__SEQLOCK_READ_SECTION(&rename_lock, lockless, seq, NULL) {
			dentry = d;
			b = *p;
			while (!IS_ROOT(dentry)) {
				const struct dentry *parent = dentry->d_parent;

				prefetch(parent);
				if (!prepend_name(&b, &dentry->d_name))
					break;
				dentry = parent;
			}
			if (lockless)
				rcu_read_unlock();
		}

		if (b.len == p->len)
			prepend_char(&b, '/');
		return extract_string(&b);
	}


TODO: add another trivial helper

	static inline int need_seqretry_or_lock(seqlock_t *lock, int *seq)
	{
		int ret = !(*seq & 1) && read_seqretry(lock, *seq);

		if (ret)
			*seq = 1; /* make this counter odd */

		return ret;
	}

which can be used when the read section is more complex. Say, d_walk().

Oleg.
---

 fs/d_path.c             | 31 +++++++++++++------------------
 fs/proc/array.c         |  9 ++-------
 fs/proc/base.c          |  9 ++-------
 include/linux/seqlock.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/cputime.c  | 14 +++-----------
 5 files changed, 69 insertions(+), 43 deletions(-)
Re: [PATCH 0/5] seqlock: introduce SEQLOCK_READ_SECTION()
Posted by Al Viro 2 months, 1 week ago
On Sun, Oct 05, 2025 at 04:49:29PM +0200, Oleg Nesterov wrote:
> OK, let me name it SEQLOCK_READ_SECTION().
> 
> Al, could you look at 5/5? Please nack it if you think it makes no sense
> or wrong. I abused __dentry_path() to add another example. To simplify the
> review, this is how it looks after the patch:
> 
> 	static char *__dentry_path(const struct dentry *d, struct prepend_buffer *p)
> 	{
> 		const struct dentry *dentry;
> 		struct prepend_buffer b;
> 
> 		rcu_read_lock();
> 		__SEQLOCK_READ_SECTION(&rename_lock, lockless, seq, NULL) {
> 			dentry = d;
> 			b = *p;
> 			while (!IS_ROOT(dentry)) {
> 				const struct dentry *parent = dentry->d_parent;
> 
> 				prefetch(parent);
> 				if (!prepend_name(&b, &dentry->d_name))
> 					break;
> 				dentry = parent;
> 			}
> 			if (lockless)
> 				rcu_read_unlock();

<cringe>

> 		}
> 
> 		if (b.len == p->len)
> 			prepend_char(&b, '/');
> 		return extract_string(&b);
> 	}
> 
> 
> TODO: add another trivial helper
> 
> 	static inline int need_seqretry_or_lock(seqlock_t *lock, int *seq)
> 	{
> 		int ret = !(*seq & 1) && read_seqretry(lock, *seq);
> 
> 		if (ret)
> 			*seq = 1; /* make this counter odd */
> 
> 		return ret;
> 	}
> 
> which can be used when the read section is more complex. Say, d_walk().

prepend_path() would be interesting to look at...
Re: [PATCH 0/5] seqlock: introduce SEQLOCK_READ_SECTION()
Posted by Oleg Nesterov 2 months, 1 week ago
On 10/05, Al Viro wrote:
>
> On Sun, Oct 05, 2025 at 04:49:29PM +0200, Oleg Nesterov wrote:
>
> > 	static char *__dentry_path(const struct dentry *d, struct prepend_buffer *p)
> > 	{
> > 		const struct dentry *dentry;
> > 		struct prepend_buffer b;
> >
> > 		rcu_read_lock();
> > 		__SEQLOCK_READ_SECTION(&rename_lock, lockless, seq, NULL) {
> > 			dentry = d;
> > 			b = *p;
> > 			while (!IS_ROOT(dentry)) {
> > 				const struct dentry *parent = dentry->d_parent;
> >
> > 				prefetch(parent);
> > 				if (!prepend_name(&b, &dentry->d_name))
> > 					break;
> > 				dentry = parent;
> > 			}
> > 			if (lockless)
> > 				rcu_read_unlock();
>
> <cringe>

Weird or buggy?

> prepend_path() would be interesting to look at...

Yeah, I have already looked at it.

Not sure yet what the "good" cleanup could do. Will think about it more.

Oleg.