Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CCA9C54EAA for ; Fri, 27 Jan 2023 11:03:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232578AbjA0LDz (ORCPT ); Fri, 27 Jan 2023 06:03:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232699AbjA0LDw (ORCPT ); Fri, 27 Jan 2023 06:03:52 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B310340BE8 for ; Fri, 27 Jan 2023 03:03:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674817397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AIZ7SsGXjE6pNoVmeoTEDKKHIzvEwSlrhJ+UulUtcL0=; b=L41mATh3vWjdNGxAtf+4fR19d/zks9tFqqY5YtdR1dxZsWH6KmN0MfFNIJeBbGW6uvvHzF J90rJQPzZphBl866eJKqzOzB40ECuI31Tc86z03e6tk3VQdThgUqbPxN6FX9KDFpJoacXf jZMHS7zRrfmFVJ3a3eLHKCJ35CQwJIc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-639-PzKHVq1YNea7yyn5UE_uYw-1; Fri, 27 Jan 2023 06:03:13 -0500 X-MC-Unique: PzKHVq1YNea7yyn5UE_uYw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 37585101A52E; Fri, 27 Jan 2023 11:03:13 +0000 (UTC) Received: from localhost (unknown [10.39.194.132]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2187492C1B; Fri, 27 Jan 2023 11:03:11 +0000 (UTC) From: Giuseppe Scrivano To: Rik van Riel Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, kernel-team@meta.com, linux-fsdevel@vger.kernel.org, Chris Mason Subject: Re: [PATCH 2/2] ipc,namespace: batch free ipc_namespace structures References: <20230127011535.1265297-1-riel@surriel.com> <20230127011535.1265297-3-riel@surriel.com> Date: Fri, 27 Jan 2023 12:03:10 +0100 In-Reply-To: <20230127011535.1265297-3-riel@surriel.com> (Rik van Riel's message of "Thu, 26 Jan 2023 20:15:35 -0500") Message-ID: <878rhome8h.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rik van Riel writes: > 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 > Reported-by: Chris Mason > Suggested-by: Al Viro > --- > fs/namespace.c | 10 ++++++++++ > include/linux/mount.h | 1 + > ipc/namespace.c | 13 ++++++++++--- > 3 files changed, 21 insertions(+), 3 deletions(-) > > diff --git a/fs/namespace.c b/fs/namespace.c > index ab467ee58341..296432ba3716 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -1397,6 +1397,16 @@ struct vfsmount *mntget(struct vfsmount *mnt) > } > EXPORT_SYMBOL(mntget); > > +/* > + * Make a mount point inaccessible to new lookups. > + * Because there may still be current users, the caller MUST WAIT > + * for an RCU grace period before destroying the mount point. > + */ > +void mnt_make_shortterm(struct vfsmount *mnt) > +{ > + real_mount(mnt)->mnt_ns = NULL; > +} > + > /** > * path_is_mountpoint() - Check if path is a mount in the current namespace. > * @path: path to check > diff --git a/include/linux/mount.h b/include/linux/mount.h > index 62475996fac6..ec55a031aa8c 100644 > --- a/include/linux/mount.h > +++ b/include/linux/mount.h > @@ -88,6 +88,7 @@ extern void mnt_drop_write(struct vfsmount *mnt); > extern void mnt_drop_write_file(struct file *file); > extern void mntput(struct vfsmount *mnt); > extern struct vfsmount *mntget(struct vfsmount *mnt); > +extern void mnt_make_shortterm(struct vfsmount *mnt); > extern struct vfsmount *mnt_clone_internal(const struct path *path); > extern bool __mnt_is_readonly(struct vfsmount *mnt); > extern bool mnt_may_suid(struct vfsmount *mnt); > diff --git a/ipc/namespace.c b/ipc/namespace.c > index a26860a41dac..6ecc30effd3e 100644 > --- a/ipc/namespace.c > +++ b/ipc/namespace.c > @@ -145,10 +145,11 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids, > > static void free_ipc_ns(struct ipc_namespace *ns) > { > - /* mq_put_mnt() waits for a grace period as kern_unmount() > - * uses synchronize_rcu(). > + /* > + * Caller needs to wait for an RCU grace period to have passed > + * after making the mount point inaccessible to new accesses. > */ > - mq_put_mnt(ns); mq_put_mnt() is not needed anymore, should it be removed? > + mntput(ns->mq_mnt); > sem_exit_ns(ns); > msg_exit_ns(ns); > shm_exit_ns(ns); > @@ -168,6 +169,12 @@ static void free_ipc(struct work_struct *unused) > struct llist_node *node = llist_del_all(&free_ipc_list); > struct ipc_namespace *n, *t; > > + llist_for_each_entry_safe(n, t, node, mnt_llist) > + mnt_make_shortterm(n->mq_mnt); > + > + /* Wait for any last users to have gone away. */ > + synchronize_rcu(); > + > llist_for_each_entry_safe(n, t, node, mnt_llist) > free_ipc_ns(n); > }