From patchwork Thu Jan 19 20:55:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chanudet X-Patchwork-Id: 45962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp544422wrn; Thu, 19 Jan 2023 13:04:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXub9Ebf37DqaeRWq+D4cGbeuLxz8WCvIz2erJgaE1crjy1071faX+6OZcpVlsAOTAaqmEKq X-Received: by 2002:a05:6402:ea2:b0:479:971e:5da8 with SMTP id h34-20020a0564020ea200b00479971e5da8mr12855602eda.13.1674162290414; Thu, 19 Jan 2023 13:04:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674162290; cv=none; d=google.com; s=arc-20160816; b=FCaPGkkzzhkkJkdzdrXi5+XTyahqJ4Q6OYqNwJM7vyvQOVIgglt9FCkpRLIV0oe6cc /LYIuqP+mQiTIT7k2UoFalk5BwYYhoChKy+qvpdjGmyEXIsbjkF8W8XLvixJ2VBd1ldY y+sIEHVP/N51qlhov7hFBHcm4hfnsYQmw051WNT7alO3Qmgvmeh1cfhVTo2Bviw6oP1p /D+I3zVgg+SgGkTkYaANJSF6PbhxgGU8kOOCRnG6KMRDEOjMzIHQFeEYHD7Up0EfX8lL U5nktdXoOE6w7cV8RdI+1KX9p3CjDut/w/TIUmtZU9itHoYPigdbDINW7ZqouMWFLS0E R6Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kMg8gNQDfp59Z8c/Laiz+GjWJb2Q7J01BdsOGckaZ2o=; b=gwq1fxUA0WPAlDoOmHaAkDIO3++HjrIJm3vxtOoqBtJ38xfgMLpqlhyvjqnlV/lyqS X9W35b1XEvlxtDgzzIkXnGTpour/uAuGzqC0uVb8zagwy3p7gnPxC4oDz5biwqQZF3bS rj+cHZI0vWLEiyJL2AVn8niF5ojMKaLGMVsqSr6BfXXEUnEUgy5lfwNXX/JqknfZ5WZ4 chYbIj72ZygVbNhUXHfaOUeaQbDAvPwkkc932621diUOqz8xAaKGAOZp3s+3WdA9z27U BfhN+/pjh8kzEtvDWK3bdjmrx1wn1GV1dC0rhg1fv9PfLzuF5ogZKYQGacpc27wkXSLf yAjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B9LMim7h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a056402354a00b0049df75caf05si13154248edd.244.2023.01.19.13.04.26; Thu, 19 Jan 2023 13:04:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B9LMim7h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbjASVDT (ORCPT + 99 others); Thu, 19 Jan 2023 16:03:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbjASVBp (ORCPT ); Thu, 19 Jan 2023 16:01:45 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 517E8A1988 for ; Thu, 19 Jan 2023 12:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674161848; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kMg8gNQDfp59Z8c/Laiz+GjWJb2Q7J01BdsOGckaZ2o=; b=B9LMim7hpI/xfFEpfdJDvNneIWI4w0oKspN66P352BZ0nyNQLcIj6OiqDQHD9sKzHYcLWZ Deg4RlXGBn1S4RuAnyMBmdM8QJ0/I358TyWhBIJxnczge2r4pO5nNrGLHcLngc8flbrxua MKG3AE/+flT5yUy+EAE70abWiYILgDw= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-616-PZxuKgRwMbW6Y3yQvqkUKQ-1; Thu, 19 Jan 2023 15:57:26 -0500 X-MC-Unique: PZxuKgRwMbW6Y3yQvqkUKQ-1 Received: by mail-qk1-f200.google.com with SMTP id bi3-20020a05620a318300b00702545f73d5so2074385qkb.8 for ; Thu, 19 Jan 2023 12:57:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kMg8gNQDfp59Z8c/Laiz+GjWJb2Q7J01BdsOGckaZ2o=; b=Ugh/KvUZYHDngGXnhoQhhERMtqpapj+EIOLuY9pOdSxWIPnBsyox7wi8tbtnwNbrAI bLehJcWBTxyQpVTE7iikazLDFqKa82uoouK6eoZhiH48baq94U2y09WhMrMws6kuVhr3 L7BQjdsVAlqWljiOLzZ1NLT9UGuH9tykMP6RgEAz7Xn0UJpaEyxdL+3qRU/rgFeWsVyM rxIy4TUeTe+dMBMIazKPT3J9YB3OVjgtqJG2zS4HZ2OsyzOZvSv59Dmpzy4mbCz8qkcA 89ZdhL/ohnvrxTHqwhvFZFJl8D0wx3nHxaxO16xgdoBlT1YqhpEfF7KzpKe/wSKU8xH7 zNQg== X-Gm-Message-State: AFqh2kqR6eBtFdGrVo97y3nIihQGKZ1OZiMO9C/Emv3SDHk3BznLPjnY tWU5/HGIOrPKKxCAGbyGhfKAyUKbItDCF/uYz0esm5rBbCRZMynrVRWFhRbJjtAUeJJePKF/pCA KCPtCoNnl+kpROsHndLySNan0 X-Received: by 2002:a05:6214:438a:b0:531:aafe:70f7 with SMTP id oh10-20020a056214438a00b00531aafe70f7mr16998218qvb.22.1674161846313; Thu, 19 Jan 2023 12:57:26 -0800 (PST) X-Received: by 2002:a05:6214:438a:b0:531:aafe:70f7 with SMTP id oh10-20020a056214438a00b00531aafe70f7mr16998202qvb.22.1674161846092; Thu, 19 Jan 2023 12:57:26 -0800 (PST) Received: from localhost (pool-71-184-142-128.bstnma.fios.verizon.net. [71.184.142.128]) by smtp.gmail.com with ESMTPSA id t11-20020a05620a034b00b006fa31bf2f3dsm24317491qkm.47.2023.01.19.12.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 12:57:25 -0800 (PST) From: Eric Chanudet To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Larsson , Andrew Halaney , Eric Chanudet Subject: [RFC PATCH 1/1] fs/namespace: defer free_mount from namespace_unlock Date: Thu, 19 Jan 2023 15:55:21 -0500 Message-Id: <20230119205521.497401-2-echanude@redhat.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119205521.497401-1-echanude@redhat.com> References: <20230119205521.497401-1-echanude@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755486370383353604?= X-GMAIL-MSGID: =?utf-8?q?1755486397939523026?= From: Alexander Larsson Use call_rcu to defer releasing the umount'ed or detached filesystem when calling namepsace_unlock(). Calling synchronize_rcu_expedited() has a significant cost on RT kernel that default to rcupdate.rcu_normal_after_boot=1. For example, on a 6.2-rt1 kernel: perf stat -r 10 --null --pre 'mount -t tmpfs tmpfs mnt' -- umount mnt 0.07464 +- 0.00396 seconds time elapsed ( +- 5.31% ) With this change applied: perf stat -r 10 --null --pre 'mount -t tmpfs tmpfs mnt' -- umount mnt 0.00162604 +- 0.00000637 seconds time elapsed ( +- 0.39% ) Waiting for the grace period before completing the syscall does not seem mandatory. The struct mount umount'ed are queued up for release in a separate list and no longer accessible to following syscalls. Signed-off-by: Alexander Larsson Signed-off-by: Eric Chanudet --- fs/namespace.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index ab467ee58341..11d219a6e83c 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -44,6 +44,11 @@ static unsigned int m_hash_shift __read_mostly; static unsigned int mp_hash_mask __read_mostly; static unsigned int mp_hash_shift __read_mostly; +struct mount_delayed_release { + struct rcu_head rcu; + struct hlist_head release_list; +}; + static __initdata unsigned long mhash_entries; static int __init set_mhash_entries(char *str) { @@ -1582,11 +1587,31 @@ int may_umount(struct vfsmount *mnt) EXPORT_SYMBOL(may_umount); -static void namespace_unlock(void) +static void free_mounts(struct hlist_head *mount_list) { - struct hlist_head head; struct hlist_node *p; struct mount *m; + + hlist_for_each_entry_safe(m, p, mount_list, mnt_umount) { + hlist_del(&m->mnt_umount); + mntput(&m->mnt); + } +} + +static void delayed_mount_release(struct rcu_head *head) +{ + struct mount_delayed_release *drelease = + container_of(head, struct mount_delayed_release, rcu); + + free_mounts(&drelease->release_list); + kfree(drelease); +} + +static void namespace_unlock(void) +{ + struct hlist_head head; + struct mount_delayed_release *drelease; + LIST_HEAD(list); hlist_move_list(&unmounted, &head); @@ -1599,12 +1624,15 @@ static void namespace_unlock(void) if (likely(hlist_empty(&head))) return; - synchronize_rcu_expedited(); - - hlist_for_each_entry_safe(m, p, &head, mnt_umount) { - hlist_del(&m->mnt_umount); - mntput(&m->mnt); + drelease = kmalloc(sizeof(*drelease), GFP_KERNEL); + if (unlikely(!drelease)) { + synchronize_rcu_expedited(); + free_mounts(&head); + return; } + + hlist_move_list(&head, &drelease->release_list); + call_rcu(&drelease->rcu, delayed_mount_release); } static inline void namespace_lock(void)