Received: by 10.223.164.202 with SMTP id h10csp309594wrb; Thu, 30 Nov 2017 10:40:09 -0800 (PST) X-Google-Smtp-Source: AGs4zMbYeJzsPPRvX33xVGzDUtZvFiSPC4Iil3JPLgQ+21C1/UzJiZSNKkBLlB2sNx5bpzcD5mSw X-Received: by 10.99.174.73 with SMTP id e9mr3132711pgp.297.1512067209105; Thu, 30 Nov 2017 10:40:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512067209; cv=none; d=google.com; s=arc-20160816; b=G1U+sSjgFXib3NKPU++8y56ft4YcJ3SkKG3l8RVK+Y6qBF25nM71gkhGAn43c+hhVy lL2TfpO+U6zSnODa2Wh17dSmeeZrYPDiyv3XdnzvDtTr+J2iv6MTq0NlzSStBPWaf99B yda9UvHtpARnCk3pACmpKAHD2f32kCBlbUEVDXnysJd/3qj6+cSyj0JI86LbZPwRBO6V EVOcozkyiN7KjVpcfAS8yydUriwqFNKR8VsKabcf8mqpsIslg7RNlA1Mdq2stRxOEoOA mnjY9lwSIqa9LJmtJRIlaNb9f7sekQXvTvbfTWKfl6IP9Qk7twDnntfQFczlQ0DZmzas GxAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=TUdtxyigWZGIH9x0kPBHKOy2nHPc/kLBqtxeoVBJq8k=; b=JpsOWiAXfe0W1Dt1VY1yWiSnvj9j+Aayu7xvR89T1VwemZj9nY6IRc4Z2BwPNYQhJW cWJ5o5rX6wnOfkKgZFtxZEztknasZp03Vqn0a1r8nurOTAI7j266Aq5rHCHTVPQM2t8Y ouetJmIZcqOI+77jdo0AkyHUDeo5VvYmh2Vxtyc0oo88hZKGzYOllPxQUH0ubos+W/+E RWOTQBIGxcMgIqXUJejcw38W/HbOqBLPXCNxKXgTXwgY8a44vlYJHt9cFaeaRe2qejtE 08vtJjXuk1WRhGKXLJCPOzwm944D+wm9c3SQEEorXP5HNy7gj9E+TTpLd0CVqon/iQDf 9IYw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si3355348pgc.445.2017.11.30.10.39.55; Thu, 30 Nov 2017 10:40:09 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751908AbdK3Sic (ORCPT + 99 others); Thu, 30 Nov 2017 13:38:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34482 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750761AbdK3Sib (ORCPT ); Thu, 30 Nov 2017 13:38:31 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66B958047F; Thu, 30 Nov 2017 18:38:31 +0000 (UTC) Received: from helium.redhat.com (unknown [10.36.118.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F30D6031E; Thu, 30 Nov 2017 18:38:30 +0000 (UTC) From: Giuseppe Scrivano To: linux-kernel@vger.kernel.org Cc: gscrivan@redhat.com, Andrew Morton Subject: [PATCH v2] ipc, mqueue: lazy call kern_mount_data in new namespaces Date: Thu, 30 Nov 2017 19:38:16 +0100 Message-Id: <20171130183816.26916-1-gscrivan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 30 Nov 2017 18:38:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. This is a net saving for new IPC namespaces that don't use mq_open(). In this case there won't be any kern_mount_data() cost at all. On my machine, the time for creating 1000 new IPC namespaces dropped from ~8s to ~2s. Signed-off-by: Giuseppe Scrivano --- v1 here: https://lkml.org/lkml/2017/11/27/427 v1 -> v2: Declare and use a mutex instead of a spinlock. include/linux/ipc_namespace.h | 2 +- ipc/mqueue.c | 48 ++++++++++++++++++++++++++++++++++--------- ipc/namespace.c | 2 +- 3 files changed, 40 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..27a82a3fef50 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,9 +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; + static DEFINE_MUTEX(mnt_lock); + + mutex_lock(&mnt_lock); + mnt = ipc_ns->mq_mnt; + if (unlikely(!mnt)) { + mnt = kern_mount_data(&mqueue_fs_type, ipc_ns); + if (IS_ERR(mnt)) { + mutex_unlock(&mnt_lock); + return PTR_ERR(mnt); + } + ipc_ns->mq_mnt = mnt; + } + mutex_unlock(&mnt_lock); + + root = mnt->mnt_root; audit_mq_open(oflag, mode, attr); @@ -863,6 +879,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 +1600,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 +1610,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 +1656,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 1585493516618308134@xxx Thu Nov 30 12:20:45 +0000 2017 X-GM-THRID: 1585224021535347143 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread