From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 289D61C1F2F; Tue, 1 Apr 2025 10:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743503462; cv=none; b=Ko07XgDg4oGNElbqgJjoHLKsGWNhsaxGTPMrh0RqFsjZgzj/8383ddc2+UVstAj+Pw4bTj13bOj3enhA4k7py0V5H39YWqbcPhINegBOBuyrrjg7eqFxgGhy9Psbq7wCHXLHe8MAAR4BCWm60rcKnaJEItm0lC9IWWsJOnUH1sk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743503462; c=relaxed/simple; bh=AU4Ttg827+/kKmAuG3mOJegyr0ZDJ3Y7O4gZo2FW2lk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bHlB+CmLNus9awoKVASMIq9pWu9LI94lfjb8W+xHH/etCey1vhvyy/syptZa99TXoISAhmaff5ZDBXNEDJMQnrqJSylFY7PRsYkhztxycpjLPSKylWfCKwzbLJJcoLsC0uZptL5LXX7ktlrGWPtxgusxe7OOFA04rqjlX+NRcf4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RiI/eGDI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RiI/eGDI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C365C4CEE4; Tue, 1 Apr 2025 10:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743503461; bh=AU4Ttg827+/kKmAuG3mOJegyr0ZDJ3Y7O4gZo2FW2lk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RiI/eGDIKo8HFQzr+MiuHPGsDjwCzqt0l45EGHvWcBWPicQssCEJDUjsEb1QwuQZK V3fa8J6QbrgZEZuH8r7m2pd3WxCP66ZYAD4yDE0sFI7Gk1z+70c6FjQh+z9pBDrEy1 Ya4ulJD7Ysf5PTCO7LMioHuJNTjZ7YdkpycowacZ+nvW+x6thaA5AyKVPYzrpMYGMx vlt0xPxJxQ8sSKc3D6991fFwwAH1jIGXpY8ybX6QTHXSETUE9FxcEhegTNRRV8HZ7B Nz+q1FCJpg1ZmSKNnMBQ0HYVkkVi5s0aPF+uAPscCXnMntGuXQq94S4/4k9NmAxe8V oTiaJVOx5cnUg== Date: Tue, 1 Apr 2025 12:30:57 +0200 From: Christian Brauner To: Mateusz Guzik Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 2/2] fs: cache the string generated by reading /proc/filesystems Message-ID: <20250401-fernhalten-lockvogel-ba56b2b108d2@brauner> References: <20250329192821.822253-1-mjguzik@gmail.com> <20250329192821.822253-3-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20250329192821.822253-3-mjguzik@gmail.com> On Sat, Mar 29, 2025 at 08:28:21PM +0100, Mateusz Guzik wrote: > It is being read surprisingly often (e.g., by mkdir, ls and even sed!). > > This is lock-protected pointer chasing over a linked list to pay for > sprintf for every fs (32 on my boxen). > > Instead cache the result. > > While here mark the file as permanent to avoid atomic refs on each op > (which can also degrade to taking a spinlock). > > open+read+close cycle single-threaded (ops/s): > before: 450929 > after: 982308 (+117%) > > Here the main bottleneck is memcg. > > open+read+close cycle with 20 processes (ops/s): > before: 578654 > after: 3163961 (+446%) > > The main bottleneck *before* is spinlock acquire in procfs eliminated by > marking the file as permanent. The main bottleneck *after* is the > spurious lockref trip on open. > > The file looks like a sterotypical C from the 90s, right down to an > open-code and slightly obfuscated linked list. I intentionally did not > clean up any of it -- I think the file will be best served by a Rust > rewrite when the time comes. > > Signed-off-by: Mateusz Guzik > --- > + pde = proc_create_single("filesystems", 0, NULL, filesystems_proc_show); > + proc_make_permanent(pde); > return 0; This all looks good enough for me especially if it's really that much of a bottleneck for some workloads. But the above part is broken because proc_create_single() may return NULL afair and that means proc_make_permanent()->pde_make_permanent() will NULL-deref. I'll fix that up locally.