Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5154033rdb; Tue, 12 Dec 2023 23:41:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrNWTchq6EaFi8fwgv6Bca6ZY8uJBZrN4iZeVUrjddbEhO2zq2+0KchPv7rRSOzVpzvxtW X-Received: by 2002:a05:6358:e813:b0:170:17eb:9c49 with SMTP id gi19-20020a056358e81300b0017017eb9c49mr8434798rwb.42.1702453261009; Tue, 12 Dec 2023 23:41:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702453260; cv=none; d=google.com; s=arc-20160816; b=sRnkhOnjssJcuLyXOinImAE2YBcwr1adecDwaJ7x7PKPZ9MQ2otuVJrtqDTvr34rOm uMTkZWM7zjQv+aC10Y9MMxhK6LLOfU09D07q4t/N0a0lhShXkeahk1i4UkT7kHOxigPm v4a1kfiumJgINinLo62q3Pj6NA2WxC7yNRczi4m117BYImC93XE5DIXjQJis4CuALeKr rhXew1DlNhCUpkPzgwsFwCMcqO/4S/HWvvF0sPEptGBZ6VtrFLckebhWGWRO3QhVCxkH F+C8gOpVoIFKumZ10TeXSn8IKq9s1M/BclEvku0Gn2FBaU1TaPue/TW6m7tcg3Je6fzr 0Z2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=+xadsfRa9t5Ek/KCGD+z2BjSpseXGN+GqLXIGDzo42w=; fh=9Q4fVaVQwfA7Ya919PMO0IelduVEgmrpK52qmykPlPg=; b=Y49Mcf7AuF9ifSG9u3PiP0cUK/Q9NTqUcRK50/RnDebrODerAItafKsLbg8QnOpsov +7MKNxj6uMvVRZr+wX2/6B0PVdLozqE+HcIqvNv9SKehtWEYSTpwZg0adbr1vmovOb3V lL/SrAs1xcEVMQiUPMJJobBJ45Jdppf6JipT725X5mVShvwRIDC3j9d4hbUee6wffihH Bre6GjV9mOePF5+1SLSayB9qORcFE8AX0whcUn32mxy86XYFGUdLTpfCru8sji0FZ3ii kLPrg7+eyrWzBGIWp4urRzcJ/fbeEdWs71lF67KOSTip4njjHjD9RpsK7r9hwwDFd9iM hYZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b=XCUzwBdJ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=R6VTVj7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id x18-20020a17090aca1200b00285a62cc148si10540658pjt.134.2023.12.12.23.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 23:41:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b=XCUzwBdJ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=R6VTVj7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 195DE8075949; Tue, 12 Dec 2023 23:40:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378696AbjLMHkZ (ORCPT + 99 others); Wed, 13 Dec 2023 02:40:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235282AbjLMHkV (ORCPT ); Wed, 13 Dec 2023 02:40:21 -0500 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C96E8DC; Tue, 12 Dec 2023 23:40:26 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 62D2B3200A90; Wed, 13 Dec 2023 02:40:25 -0500 (EST) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Wed, 13 Dec 2023 02:40:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1702453224; x=1702539624; bh=+xadsfRa9t 5Ek/KCGD+z2BjSpseXGN+GqLXIGDzo42w=; b=XCUzwBdJQoGDiXeCf/4+w+19aS jXvU+cTqB2FVUT+m798geBPyDjnB8RJrgDr3B4ZM7SE6Q7WOEgintCLCiz9dfgxf c1zizWJXjLGUDvJIcl7PNBK4+T8scxm6Pqw7PhrwIdEpCGiQmNQtbFywxaZhWax2 wBknrpa9p05NSaZMA9fO/uR4U4mOXxZx2Z6OAKJlBfmI27MGgzllTIpelsrGWVYy q7ASZWHGcqSeCbChf6G5MapzM3DEaHrDqU6q/6fGcRHysi0SGLRjFQ+W26xQUDIg dIQFfG7RVdHXvypUHUNvKCnreg4KyR4H5SknqcdHBpSNHo2Z0IceO7ius9rA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1702453224; x=1702539624; bh=+xadsfRa9t5Ek/KCGD+z2BjSpseX GN+GqLXIGDzo42w=; b=R6VTVj7I+OJdCqOLai9tUq2i+99xlc9idnS0jQ8uLOd7 U+RZq3jA7vJStAiPRS+kBThXEB2tt8BwBTop2AwLC5ZelNF7C4fGgOI8PlfDLZfN r9fJCA6I/JGSAvvZzb2UzlN7RXRVo+2mZele+R0545c73r0A9j//n/76QR1e7dmx n8vIViLtS81WdKd9czC90UKT0ghXs12qHKX7usEmQA25HAgrV+WJjnsNsAsec0cB 8o2fi/p/PO3fcqXXfj+SZhOmBJh26RSuPSo209ZiKHiFphOdg6aCAVKgmdvgmEZr QBgJf3nvUkEBk5+SQc/ZxE3Hq3tl5wTYal+HWtfoKw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelhedgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet rhhnugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrg htthgvrhhnpeffheeugeetiefhgeethfejgfdtuefggeejleehjeeutefhfeeggefhkedt keetffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grrhhnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0CD9BB6008D; Wed, 13 Dec 2023 02:40:24 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1283-g327e3ec917-fm-20231207.002-g327e3ec9 MIME-Version: 1.0 Message-Id: <833f0dd5-ded8-4925-9c3c-639728000598@app.fastmail.com> In-Reply-To: References: <20231212214819.247611-1-arnd@kernel.org> Date: Wed, 13 Dec 2023 08:40:01 +0100 From: "Arnd Bergmann" To: "Ian Kent" , "Arnd Bergmann" , "Alexander Viro" , "Christian Brauner" Cc: "Jan Kara" , "Miklos Szeredi" , "Seth Forshee (DigitalOcean)" , "Dave Chinner" , "Amir Goldstein" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] statmount: reduce runtime stack usage Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 23:40:46 -0800 (PST) On Wed, Dec 13, 2023, at 02:13, Ian Kent wrote: > On 13/12/23 05:48, Arnd Bergmann wrote: >> From: Arnd Bergmann >> >> prepare_kstatmount() constructs a copy of 'struct kstatmount' on the stack >> and copies it into the local variable on the stack of its caller. Because >> of the size of this structure, this ends up overflowing the limit for >> a single function's stack frame when prepare_kstatmount() gets inlined >> and both copies are on the same frame without the compiler being able >> to collapse them into one: >> >> fs/namespace.c:4995:1: error: stack frame size (1536) exceeds limit (1024) in '__se_sys_statmount' [-Werror,-Wframe-larger-than] >> 4995 | SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req, >> >> Mark the inner function as noinline_for_stack so the second copy is >> freed before calling do_statmount() enters filesystem specific code. >> The extra copy of the structure is a bit inefficient, but this >> system call should not be performance critical. > > Are you sure this is not performance sensitive, or is the performance > critical comment not related to the system call being called many times? > > > It's going to be a while (if ever) before callers change there ways. > > Consider what happens when a bunch of mounts are being mounted. > > > First there are a lot of events and making the getting of mount info. > more efficient means more of those events get processed (itself an issue > that's going to need notification sub-system improvement) resulting in > the system call being called even more. Ok, I'll send a v2 that is more efficent. I expected it to look uglier, but I don't think it's actually that bad: --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4957,15 +4957,12 @@ static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, if (!access_ok(buf, bufsize)) return -EFAULT; - *ks = (struct kstatmount){ - .mask = kreq->param, - .buf = buf, - .bufsize = bufsize, - .seq = { - .size = seq_size, - .buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT), - }, - }; + memset(ks, 0, sizeof(*ks)); + ks->mask = kreq->param, + ks->buf = buf, + ks->bufsize = bufsize, + ks->seq.size = seq_size, + ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT), if (!ks->seq.buf) return -ENOMEM; return 0;