From patchwork Tue Jul 25 18:31:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13326908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB1FDC001DE for ; Tue, 25 Jul 2023 18:31:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BA0C6B0075; Tue, 25 Jul 2023 14:31:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 169156B0078; Tue, 25 Jul 2023 14:31:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0302C8D0001; Tue, 25 Jul 2023 14:31:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EA4666B0075 for ; Tue, 25 Jul 2023 14:31:09 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C1E921C9F01 for ; Tue, 25 Jul 2023 18:31:09 +0000 (UTC) X-FDA: 81050976258.13.AE12375 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 02271180020 for ; Tue, 25 Jul 2023 18:31:07 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GaMZE71T; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690309868; h=from:from:sender: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: references:dkim-signature; bh=U+idnXgtCiYyfmrR6DDYhj/Exl3lEbcydBPfAtp7VF8=; b=FfTF+k4jQPzenhytacAoRCbgP93jNV7Ru5dEKzzI8kffEYCbYVAx+DXS31B0LVoi3ngK42 e2H+LUipb6n7rHluaQ7Jm9tNCA/RAVS5097feYlGfR0lr+Y8oTHTxZqYI8L/JSzNp/gimU 2c6PzLoNDL7WZJkv9UCtv49t9iYColM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GaMZE71T; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690309868; a=rsa-sha256; cv=none; b=pV31GWArGJrbL62FUTF5W4NfRBPlcibuZXl6lKQODlVvsgNnXWNw68x0A07MiWOgp+GLkN PKdnldIO0uLhFaBWWgNsRiymGvcD0T6f94PqQyiqEs+/DX4MhS+qyYFzRsOAS1ChrnG4kq pfRsdP65p/cIW8ZPXv3rLd1RyK3N8jE= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AF4C5616BF; Tue, 25 Jul 2023 18:31:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FA0EC433C7; Tue, 25 Jul 2023 18:31:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690309866; bh=F5JqDshbxaXCKris4572/rBxtI1EmqM7jtTeptVm1Hg=; h=Subject:From:To:Cc:Date:From; b=GaMZE71Ta/JLhienrTM3trvjeVgjaWFXxXsfKf4Wnm964prrKS4U6YQuXe0+dUQ5j J9I2JOg0vHRHJvF5cjzIPg73WNpz6XbdrKyMuTMXHpRxQ8TctI3I9iIKiTPbQtgihj bOmdgsUQu77EI3p6U/fVma77YnQVMv5RLSMDz3+dGzC/JyGX8TBUM48OH96EQk9BzR 5XNcdiso7pSCs9T9onwgxkLe/xglfJLRlQVvEVRPcSVOEa0y2w4UFiq1x4azqOKLQk Rx3SbH8GTGeKbNs1HMHY8KeUHUSz+fabZDbzjRff37ijHXdvYob3nqB610bebLO29J D6zp+bsYW+hgQ== Subject: [PATCH RFC] libfs: Remove parent dentry locking in offset_iterate_dir() From: Chuck Lever To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: kernel test robot , Chuck Lever , oliver.sang@intel.com, oe-lkp@lists.linux.dev, ying.huang@intel.com, feng.tang@intel.com, fengwei.yin@intel.com Date: Tue, 25 Jul 2023 14:31:04 -0400 Message-ID: <169030957098.157536.9938425508695693348.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 02271180020 X-Stat-Signature: auim6da8fyw18ct6h8qdioyckmrm4pts X-Rspam-User: X-HE-Tag: 1690309867-735607 X-HE-Meta: U2FsdGVkX18cwRvnspcCSNDvrUReQPqsDkTShgaEYM4Oyf2rlDBKw9e4SJ0kAJoisO81yzmfezhBZzOY6gZW83LWaOZmRKe6XszS5eQP6HglKkAHhWSmYMh/FfG0CUa0OIAkp4Vkj547MFgux/7+jANLDovRB1Fk4kOiWQGOwPYl4uw0wcyfdbLtA8OBvwf6XYE6PZk7DdCm1AKYSVe2ZDVcoCM8GQ6MBokvd/n5o1ffrKlNdaw0i8/8PnTUsO144N/ynyAv9rDl2SBNyOTnsIqYksv02FO56BV6iotARO9mB1DHiFkohrkCvgtZk+3167Rynam6QG24JOuQJk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icity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Chuck Lever Since offset_iterate_dir() does not walk the parent's d_subdir list nor does it manipulate the parent's d_child, there doesn't seem to be a reason to hold the parent's d_lock. The offset_ctx's xarray can be sufficiently protected with just the RCU read lock. Flame graph data captured during the git regression run shows a 20% reduction in CPU cycles consumed in offset_find_next(). Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202307171640.e299f8d5-oliver.sang@intel.com Signed-off-by: Chuck Lever --- fs/libfs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) This is a possible fix for the will-it-scale regression recently reported by the kernel test robot. It passes the git regression test over NFS and doesn't seem to perturb xfstests. I'm not able to run lkp here yet, so anyone who can run the will-it-scale test, please report the results. Many thanks. diff --git a/fs/libfs.c b/fs/libfs.c index fcc0f1f3c2dc..b69c41fb3c63 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -406,7 +406,7 @@ static struct dentry *offset_find_next(struct xa_state *xas) child = xas_next_entry(xas, U32_MAX); if (!child) goto out; - spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); + spin_lock(&child->d_lock); if (simple_positive(child)) found = dget_dlock(child); spin_unlock(&child->d_lock); @@ -424,17 +424,14 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) inode->i_ino, fs_umode_to_dtype(inode->i_mode)); } -static void offset_iterate_dir(struct dentry *dir, struct dir_context *ctx) +static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { - struct inode *inode = d_inode(dir); struct offset_ctx *so_ctx = inode->i_op->get_offset_ctx(inode); XA_STATE(xas, &so_ctx->xa, ctx->pos); struct dentry *dentry; while (true) { - spin_lock(&dir->d_lock); dentry = offset_find_next(&xas); - spin_unlock(&dir->d_lock); if (!dentry) break; @@ -478,7 +475,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx) if (!dir_emit_dots(file, ctx)) return 0; - offset_iterate_dir(dir, ctx); + offset_iterate_dir(d_inode(dir), ctx); return 0; }