Re: [PATCH v3 2/2] kernfs: Reduce contention around global per-fs kernfs_rwsem.

From: Tejun Heo
Date: Thu Jan 13 2022 - 11:42:08 EST


Hello,

On Thu, Jan 13, 2022 at 09:42:59PM +1100, Imran Khan wrote:
> @@ -748,11 +749,14 @@ int kernfs_add_one(struct kernfs_node *kn)
> goto out_unlock;
>
> /* Update timestamps on the parent */
> + rwsem = iattr_rwsem_ptr(parent);
> + down_write(rwsem);
> ps_iattr = parent->iattr;
> if (ps_iattr) {
> ktime_get_real_ts64(&ps_iattr->ia_ctime);
> ps_iattr->ia_mtime = ps_iattr->ia_ctime;
> }
> + up_write(rwsem);
>
> up_write(&root->kernfs_rwsem);

Hmmm, so the additions / removals are still fs-global lock protected. Would
it be possible to synchronize them through hashed locks too? We can provide
double locking helpers - look up locks for both parent and child and if
different lock in the defined order (parent first most likely) and record
what happened in a token so that it can be undone later.

Without going through the code carefully, I don't remember whether there's
something which depends on global locking but I'm sure we can fix them too.
It'd be really nice if we can make all operations similarly scalable cuz
with heavy stacking addition/removals can get pretty hot too.

Thanks.

--
tejun