Re: [PATCH 2/2] ipc,namespace: batch free ipc_namespace structures

From: Al Viro
Date: Thu Jan 26 2023 - 16:14:23 EST


On Thu, Jan 26, 2023 at 03:57:21PM -0500, Rik van Riel wrote:
> Instead of waiting for an RCU grace period between each ipc_namespace
> structure that is being freed, wait an RCU grace period for every batch
> of ipc_namespace structures.
>
> Thanks to Al Viro for the suggestion of the helper function.
>
> This speeds up the run time of the test case that allocates ipc_namespaces
> in a loop from 6 minutes, to a little over 1 second:
>
> real 0m1.192s
> user 0m0.038s
> sys 0m1.152s
>
> Signed-off-by: Rik van Riel <riel@xxxxxxxxxxx>
> Reported-by: Chris Mason <clm@xxxxxxxx>
> Suggested-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>

OK, except that I'd rather
a) made it
if (mnt)
real_mount(mnt)->mnt_ns = NULL;
so that it would treat NULL as no-op and
b) made kern_unmount() and kern_unmount_array() use it:
void kern_unmount(struct vfsmount *mnt)
{
/* release long term mount so mount point can be released */
if (!IS_ERR(mnt)) {
mnt_make_shorterm(mnt);
synchronize_rcu(); /* yecchhh... */
mntput(mnt);
}
}

void kern_unmount_array(struct vfsmount *mnt[], unsigned int num)
{
unsigned int i;

for (i = 0; i < num; i++)
mnt_make_shorterm(mnt[i]);
synchronize_rcu_expedited();
for (i = 0; i < num; i++)
mntput(mnt[i]);
}