Received: by 10.223.164.202 with SMTP id h10csp2702134wrb; Mon, 27 Nov 2017 23:13:55 -0800 (PST) X-Google-Smtp-Source: AGs4zMYQSxKSUjA+YJhBggYN8dCEOfYD+IvgY8dWetvzuBQ1epzg4csvQBSZXgO7+UX8yc1CGbAs X-Received: by 10.101.85.9 with SMTP id f9mr39862781pgr.263.1511853235739; Mon, 27 Nov 2017 23:13:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511853235; cv=none; d=google.com; s=arc-20160816; b=AlhAJ8u1sGHsfLmisGVCko/aiGWqLw2+TXIyCwoP3Uy/O+Mo4mDa0H/g1Je7l4GV+P I+bjQZN2QxDehUcqG+O+pZpxt3MW5jKuZxuWIcfnIS97i9/gb6r6MirJtbGE3uzIuO8z xQanqNqa17+nasaogrtzh+EPwh9aM1sPG1bGTiagbdHt0X99WGALr8rRT3s3spCl9a3O bwl/zJYatYcLGtWUOE3nHIhUdQVgert64vZuGaMXjHidu/JZw2zX6njrjmuzNSsM1ILV IPpdYL9Nfk84OmCL2uy5MJN8f3ZKmTBWVWK3ajzSOFlWpgYmhBM5TiZoVoisVQKoAUc0 D4zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=rJG4qW3DPRjhH/9UesOXkW0Oh9rEvUOb9VDoryltunw=; b=sfSTGjRDafMKJhQdsjMGGc3g300gSeK5ozy86tbBQG7jPZ/+XryQuuaK3DBqQQRsOs 7QT99AFnmgyoTSJOIONI+f3rFeNr3bMXSE0mLvtSx9m4qSVqHAGUTbghi8c3NYGsjRF8 5D+iy7f/FDFwCb7HCgGLqkatUOevkNDlTKMHpSnu5Ww09A2Vr4JBE/D1QVdOjuq8rX4w ZswVX4EeT87P64IkbqtxEqdMnadQf3NLjofbCwRVOpIriuSUYRxjK5LK8KqkqizA7ALs U2Y1oL0uFZfZilOomPqrtpKEEEhgkitXUeE868x77EGGWMILCDvkqRHs1RMkLdmshCaJ odpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f82si19134978pfe.355.2017.11.27.23.13.42; Mon, 27 Nov 2017 23:13:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751567AbdK1HNE (ORCPT + 77 others); Tue, 28 Nov 2017 02:13:04 -0500 Received: from mx2.suse.de ([195.135.220.15]:59086 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751418AbdK1HNC (ORCPT ); Tue, 28 Nov 2017 02:13:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B428CAC3D; Tue, 28 Nov 2017 07:13:00 +0000 (UTC) Date: Mon, 27 Nov 2017 23:09:48 -0800 From: Davidlohr Bueso To: Giuseppe Scrivano Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, mingo@kernel.org, akpm@linux-foundation.org Subject: Re: [RFC PATCH] ipc, mqueue: lazy call kern_mount_data in new namespaces Message-ID: <20171128070948.ur3rnugmjgf6znaj@linux-n805> References: <20171127125550.15514-1-gscrivan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20171127125550.15514-1-gscrivan@redhat.com> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is akpm domain. On Mon, 27 Nov 2017, Giuseppe Scrivano wrote: >kern_mount_data is a relatively expensive operation when creating a >new IPC namespace, so delay the mount until its first usage when not >creating the the global namespace. > >On my machine, the time for creating 1000 new IPC namespaces dropped >from ~8s to ~2s. Nice. > >Signed-off-by: Giuseppe Scrivano >--- > include/linux/ipc_namespace.h | 2 +- > ipc/mqueue.c | 47 ++++++++++++++++++++++++++++++++++--------- > ipc/namespace.c | 2 +- > 3 files changed, 39 insertions(+), 12 deletions(-) > >diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h >index b5630c8eb2f3..a06617c113f1 100644 >--- a/include/linux/ipc_namespace.h >+++ b/include/linux/ipc_namespace.h >@@ -81,7 +81,7 @@ static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {} > #endif /* CONFIG_SYSVIPC */ > > #ifdef CONFIG_POSIX_MQUEUE >-extern int mq_init_ns(struct ipc_namespace *ns); >+extern int mq_init_ns(struct ipc_namespace *ns, bool mount); > /* > * POSIX Message Queue default values: > * >diff --git a/ipc/mqueue.c b/ipc/mqueue.c >index d24025626310..46d2795bbf93 100644 >--- a/ipc/mqueue.c >+++ b/ipc/mqueue.c >@@ -87,6 +87,7 @@ struct mqueue_inode_info { > unsigned long qsize; /* size of queue in memory (sum of all msgs) */ > }; > >+static struct file_system_type mqueue_fs_type; > static const struct inode_operations mqueue_dir_inode_operations; > static const struct file_operations mqueue_file_operations; > static const struct super_operations mqueue_super_ops; >@@ -776,10 +777,24 @@ static int do_mq_open(const char __user *u_name, int oflag, umode_t mode, > struct filename *name; > int fd, error; > struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; >- struct vfsmount *mnt = ipc_ns->mq_mnt; >- struct dentry *root = mnt->mnt_root; >+ struct vfsmount *mnt; >+ struct dentry *root; > int ro; > >+ spin_lock(&mq_lock); >+ mnt = ipc_ns->mq_mnt; >+ if (unlikely(!mnt)) { >+ mnt = kern_mount_data(&mqueue_fs_type, ipc_ns); >+ if (IS_ERR(mnt)) { >+ spin_unlock(&mq_lock); >+ return PTR_ERR(mnt); >+ } >+ ipc_ns->mq_mnt = mnt; >+ } >+ spin_unlock(&mq_lock); >+ >+ root = mnt->mnt_root; >+ > audit_mq_open(oflag, mode, attr); > > if (IS_ERR(name = getname(u_name))) >@@ -863,6 +878,9 @@ SYSCALL_DEFINE1(mq_unlink, const char __user *, u_name) > struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; > struct vfsmount *mnt = ipc_ns->mq_mnt; > >+ if (!mnt) >+ return -ENOENT; >+ > name = getname(u_name); > if (IS_ERR(name)) > return PTR_ERR(name); >@@ -1581,7 +1599,8 @@ static struct file_system_type mqueue_fs_type = { > .fs_flags = FS_USERNS_MOUNT, > }; > >-int mq_init_ns(struct ipc_namespace *ns) >+ >+int mq_init_ns(struct ipc_namespace *ns, bool mount) > { > ns->mq_queues_count = 0; > ns->mq_queues_max = DFLT_QUEUESMAX; >@@ -1590,23 +1609,31 @@ int mq_init_ns(struct ipc_namespace *ns) > ns->mq_msg_default = DFLT_MSG; > ns->mq_msgsize_default = DFLT_MSGSIZE; > >- ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns); >- if (IS_ERR(ns->mq_mnt)) { >- int err = PTR_ERR(ns->mq_mnt); >+ if (!mount) > ns->mq_mnt = NULL; >- return err; >+ else { >+ int err; >+ >+ ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns); >+ if (IS_ERR(ns->mq_mnt)) { >+ err = PTR_ERR(ns->mq_mnt); >+ ns->mq_mnt = NULL; >+ return err; >+ } > } > return 0; > } > > void mq_clear_sbinfo(struct ipc_namespace *ns) > { >- ns->mq_mnt->mnt_sb->s_fs_info = NULL; >+ if (ns->mq_mnt) >+ ns->mq_mnt->mnt_sb->s_fs_info = NULL; > } > > void mq_put_mnt(struct ipc_namespace *ns) > { >- kern_unmount(ns->mq_mnt); >+ if (ns->mq_mnt) >+ kern_unmount(ns->mq_mnt); > } > > static int __init init_mqueue_fs(void) >@@ -1628,7 +1655,7 @@ static int __init init_mqueue_fs(void) > > spin_lock_init(&mq_lock); > >- error = mq_init_ns(&init_ipc_ns); >+ error = mq_init_ns(&init_ipc_ns, true); > if (error) > goto out_filesystem; > >diff --git a/ipc/namespace.c b/ipc/namespace.c >index f59a89966f92..9d3689577f66 100644 >--- a/ipc/namespace.c >+++ b/ipc/namespace.c >@@ -65,7 +65,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, > if (err) > goto fail_destroy_msg; > >- err = mq_init_ns(ns); >+ err = mq_init_ns(ns, false); > if (err) > goto fail_destroy_shm; > >-- >2.14.3 > From 1585224021535347143@xxx Mon Nov 27 12:57:15 +0000 2017 X-GM-THRID: 1585224021535347143 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread