From patchwork Tue Feb 13 21:37:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp822345dyb; Tue, 13 Feb 2024 13:38:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU4ewdP8+YvXA8ouJ2JSve4Mxk1SXK1MPPPxNf1ZLIXRHPprzUZKpzLM7T4vbTV0oju/BL7ym3jUpfYqD41TZpwpno8FQ== X-Google-Smtp-Source: AGHT+IHT2y4chocRRBN10bHJebLmMb8eH9gJHiVaRBlfnBKK8i5ykEg5CbwCi0tx1HmSbd3sGQPl X-Received: by 2002:a50:ee87:0:b0:562:b78:2f71 with SMTP id f7-20020a50ee87000000b005620b782f71mr703499edr.28.1707860299381; Tue, 13 Feb 2024 13:38:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707860299; cv=pass; d=google.com; s=arc-20160816; b=jI6khYp2jTuH/zHELQ2qVT4D4YH0mb5MPPZ6TVhKwlLF5bl5qpkG1bLDVSt7MP+yvH urJR5TIMaiHbQLmqghU9QooqdDQR5HSrbPErXYHKSGVJenDIcqc6+0KJH5B00m0LlP/X Jo32HSc8d6D38G0Ovl9O0kUEewRGX7sPygrpxiPlfhhsa1FQjPXcBPrvsYLcni2OUMmS a+V20D2z4dXoqjWeZ7ecz69kFsueqgoqEOWLIDpe5QzmeV0X2wLrF2wtOuR8020B3wMj Dsf4UJhRNV8GinD2jH0LDXNbPmTkP5R0tu77hkpKiEqMAIvD2nV4+J6WAjMVhw1h0nkH dJcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=Kg9PtooROHeKx8fIUbKlppQOORYDMz/IXh3imJbt6ck=; fh=ifzQqXbMVwuKP042Ite/CwEpsvkvGxn2CQCpNe4OVKM=; b=lAxToWmmmGpWhHkwFmZh070uqAPSLIvLOkMzoFY8JZQ75aCgxOewLjCjUigClW6hn1 v8kFcs8nhVTRUOWwSrcMZxiBfpZeEpBmGIgPY/M7Dneyiaa0ZkIZ23Wi+eMR16RXe5OB Mj6vqAuOV949/ItVyDsKJFsLoqcA2p7yJ+O12DF0xXAQSelyO0qwSj0f2rCpBNcAQMrU D5y1hwTq6bsL0oV3vb1hsGHEKPYvfnaTNUoLE2INsXM10GgG80yppzOklRLEh4LZhJ5n 9jDg2B8K1Qv5PKFk80nB4Q0U3zwRXOToUO65zXvg8afZOcA9tyYqvLh+guJa/c96D072 wd8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Qf4/d1Yg"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64342-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64342-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVsuHsUUj0Z8Ne0FhBEk/5v/252R1jSx3pHKP75M8oKnsizPvw69vnaK1SqG5fpawnuN4UbxnbcK80wSrj0F146N8Zvqw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g25-20020a50d5d9000000b00561b9400659si2296827edj.284.2024.02.13.13.38.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:38:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64342-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Qf4/d1Yg"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64342-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64342-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 001A51F25AAA for ; Tue, 13 Feb 2024 21:38:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B543626B2; Tue, 13 Feb 2024 21:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qf4/d1Yg" 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 9E0246216A; Tue, 13 Feb 2024 21:37:27 +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=1707860247; cv=none; b=bFbN3VGzqtqCVAPxiyxu6/yWZ28O7KFMnEP5/n84RSUCoQhimr/zy3T2IlvjbPYyQ3BojbZ1OapE/SEtXasiPGKFu1wjKEeFyh09s9V9Qm+xGucCnBvItdfUBALXie/Gtjui+3xAU5aKh1ignQZpQ9pf96qqyiy7FCuQkZhi+YU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860247; c=relaxed/simple; bh=DgxR48FdvStP6/D6Ne/g9o7gPlflm/a2urdscmeMLJk=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t5HFQiwQeGxylnHZUuPwcMHYVxdeC2vOhdihTRuvN7O1Atv8aDHIdlPiFeCp08X8+Mk1KV2ZJFk0mpNo9q23P/A6mXQWISmRyzONcLXlPNGqSSNdYuGpXVW24X+u3o4X8EyMqa9ybLAAt9ntviAPTqK1oiF9Vwi/0yO6jscAgKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qf4/d1Yg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FEAFC433C7; Tue, 13 Feb 2024 21:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860247; bh=DgxR48FdvStP6/D6Ne/g9o7gPlflm/a2urdscmeMLJk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Qf4/d1YgBMtbSniw/Z88hN4lMjBLBDisTs5pGMp+UPlKkqlI/sbFKI33U7LRO+2ay nZw+t7hHnnJwPjgKmA75MYvWUwvIOtRcjz3V9PQoKiIoqz6xKCa+mEUmeNtI5m/xko SQQBO4/wd0ZrZcGZupAzXrUFuFIawodE9jPpQ6ep8tXj3VS6SNGKgCEYPyJERgFyxb 4/68TNcUkF28v5gcfRkJsUDp3Su9HGYgbFLfdxfM4zAMXfFr5VRJEdc/pvAmBvdD5e mvOJ7KOHuIm9/QluD4G7YhZraRi4VI/iw19vVrf79E9C+AuWSWbxBaJ0bcueJeh/9s +zD9/Ry1/SiRw== Subject: [PATCH RFC 1/7] libfs: Rename "so_ctx" From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:37:25 -0500 Message-ID: <170786024524.11135.12492553100384328157.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790821321604832106 X-GMAIL-MSGID: 1790821321604832106 From: Chuck Lever Most of instances of "so_ctx" were renamed before the simple offset work was merged, but there were a few that were missed. Signed-off-by: Chuck Lever Reviewed-by: Jan Kara --- fs/libfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index eec6031b0155..bfbe1a8c5d2d 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -271,7 +271,7 @@ void simple_offset_init(struct offset_ctx *octx) * @octx: directory offset ctx to be updated * @dentry: new dentry being added * - * Returns zero on success. @so_ctx and the dentry offset are updated. + * Returns zero on success. @octx and the dentry's offset are updated. * Otherwise, a negative errno value is returned. */ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) @@ -430,8 +430,8 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { - struct offset_ctx *so_ctx = inode->i_op->get_offset_ctx(inode); - XA_STATE(xas, &so_ctx->xa, ctx->pos); + struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); + XA_STATE(xas, &octx->xa, ctx->pos); struct dentry *dentry; while (true) { From patchwork Tue Feb 13 21:37:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp828670dyb; Tue, 13 Feb 2024 13:55:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWekGGMhN15qAdKRceMFWc5QcDy4PpTbEBu7LylIdAiIfP9AiIyp1xLhIRVxptDsHNpM7p9GgXvs0EX5IXKpcGLRaM5+Q== X-Google-Smtp-Source: AGHT+IFTQ01FBh1A1i+b2SPOlOFKnixtQEgjTCHbm1hZjVjh/NwP2uEOjjbe9ClTrku/OWyWc8Cl X-Received: by 2002:a17:902:a3c1:b0:1db:55cc:d222 with SMTP id q1-20020a170902a3c100b001db55ccd222mr429868plb.4.1707861350820; Tue, 13 Feb 2024 13:55:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707861350; cv=pass; d=google.com; s=arc-20160816; b=RfgEX806XWnRVuSPBu7GuCYHjj0YGnYzKw0A5BGALqAB5526ICAboS7imCgF9rBw/y KuvwHBBG7EXUMiVRnsAq3VjWX0nSmjHFdzwDvpHv2JrqozZ1hH+HbhBf7LWTrKNyzXGc qtqkrpEniJ2DVePzC2Km1i3ebW9u8POLtu9o3DpaLKxUM5+bQ5pdEsXwtYU1xAZqBBDy hmz7Ygw7Br9CEsBtYxc5T8FEMKA3OT6+M/2SX8CsDiYymbAB5opE1ar9zD2BvNWml5JE 2YzWXOarPnesMHo3UTOATgsv4KOCH412gWOtHWRgKiZ0qxh3jXsBavu0rPWvhcEuAejN KW2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=mZDvb//WTZ9zZsQSCdxiKoP98n1vIsP+SpP9N6y1aoM=; fh=CIdlduNe0Mj3lyq04DQs/Jf4lhLrrj4s+U0lQJa1O38=; b=cVJd6W7ViVtTrEn95v4xRrIBxmqsY5JCRNd6CZpo1qErq+D1hiBf91L+8K3X4zhL6v 0Gn5ni6UTtFf6AV4YKdsAq+DayhuWtZX1v+F9Q12Y+ZYJf/EJ1w1/kaIu3Vvv4DgPRwi HTnVns1RVsuZ9UKvuNr63X2DKwKvufv3o7JpOjsPdRtZ4OUdwchxVznpt/2sPijl1l+l T/xQNMcYgtgqYexAhZaLQA4CkHx6Ot4jHrQFQY6+C2M8Z+pY6Y72Mh5AbPudyQGfSTYv 24k24RptS8i9kx9Bxg2PKwSjquMitUsduseXJ/+A9tUKNEFZLMYkUdZ6y8LuX47pTSqb P5Bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Z/MEawuU"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64343-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVLTO6WS4yAhqAu20PGXIyfGahrthqnWEuwuFJDoTco0nA47VcnOnufMvO1UpTYfgK1xHDgtMXBLPMfoiRleM/Dgqq7zQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d15-20020a170902ef0f00b001db40a7519dsi1292003plx.590.2024.02.13.13.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:55:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Z/MEawuU"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64343-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 88873B208B3 for ; Tue, 13 Feb 2024 21:38:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93285626D5; Tue, 13 Feb 2024 21:37:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z/MEawuU" 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 ED835612FE; Tue, 13 Feb 2024 21:37:34 +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=1707860255; cv=none; b=gPPErK0qRkQHam2HyJOoBmWhCRJP9Zeo9X78oPmaGhzSs1JR1QtsXF3qo73r46fyjAgm+1l2wpQyUCsZCCvaN9gPqJ3lEC8fvYzk0fCNQyZL7Ns+/505fqJ/l29OyO1R/SnKHhvnh9aoBNIxfxcUYPdJnn0WtmaTXQw2wktCQyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860255; c=relaxed/simple; bh=O0qvn792AlXiXQ1lPPSwqR9KB9RhTSpZi4O/hP+kqjE=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kTFCLqsV6zZCsC7e3ajXCAozB41GhRegOtp+DOuRE1kk6ToUIxtP6KGtvPGz2UjaO5TzwmJ5JSQqjn0MgpVknVnwuHLwbDFBF6p9yiMut/1KYQrgVV3Tm+Pkf5YcDQZixSxES4xK60knu/kj4+xCd1BfdrK6ivp4ivVYEHNHlr0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z/MEawuU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D906C43390; Tue, 13 Feb 2024 21:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860254; bh=O0qvn792AlXiXQ1lPPSwqR9KB9RhTSpZi4O/hP+kqjE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Z/MEawuUMQulNCp3MzLp2FmSSCfSgusNftEj26+lYW33qg3nVQgaYiwA/JCowq7NM UoX2zesRaT68Nrwd8NX3XY9+HeCzOAKrXh9q+a2QuyR3XFug07/4eurf+sd/VWQwQz u6UnXVo1sm6+EFDsCqRoRkAXjb/yXCTJW2mUFtRM/z3D12EH5T4iDL3KGIH4lRDfkm LGL5+KOaU4C13CeGv8HXfxKN1X702KXavl8GCO3zYbhf/FzrlS1bI10WT8bpxMnz2a Jc2Ikzn20LMe/okVAdTAeuZjsWRAww2x+GFLS+XM3E5c8lhxYbjiKkMAs/IyqJULrd wSQ6F6bJbwXGQ== Subject: [PATCH RFC 2/7] libfs: Define a minimum directory offset From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:37:32 -0500 Message-ID: <170786025248.11135.14453586596030949713.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790822423574860819 X-GMAIL-MSGID: 1790822423574860819 From: Chuck Lever This value is used in several places, so make it a symbolic constant. Signed-off-by: Chuck Lever Reviewed-by: Jan Kara --- fs/libfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index bfbe1a8c5d2d..a38af72f4719 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -240,6 +240,11 @@ const struct inode_operations simple_dir_inode_operations = { }; EXPORT_SYMBOL(simple_dir_inode_operations); +/* 0 is '.', 1 is '..', so always start with offset 2 or more */ +enum { + DIR_OFFSET_MIN = 2, +}; + static void offset_set(struct dentry *dentry, u32 offset) { dentry->d_fsdata = (void *)((uintptr_t)(offset)); @@ -261,9 +266,7 @@ void simple_offset_init(struct offset_ctx *octx) { xa_init_flags(&octx->xa, XA_FLAGS_ALLOC1); lockdep_set_class(&octx->xa.xa_lock, &simple_offset_xa_lock); - - /* 0 is '.', 1 is '..', so always start with offset 2 */ - octx->next_offset = 2; + octx->next_offset = DIR_OFFSET_MIN; } /** @@ -276,7 +279,7 @@ void simple_offset_init(struct offset_ctx *octx) */ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) { - static const struct xa_limit limit = XA_LIMIT(2, U32_MAX); + static const struct xa_limit limit = XA_LIMIT(DIR_OFFSET_MIN, U32_MAX); u32 offset; int ret; @@ -481,7 +484,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx) return 0; /* In this case, ->private_data is protected by f_pos_lock */ - if (ctx->pos == 2) + if (ctx->pos == DIR_OFFSET_MIN) file->private_data = NULL; else if (file->private_data == ERR_PTR(-ENOENT)) return 0; From patchwork Tue Feb 13 21:37:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200663 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp822590dyb; Tue, 13 Feb 2024 13:38:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX9FUIG368RXk7EznvK0h/osx/xShJDVR9Q3z3NqdMbEVOs8rGjZ8EIabRfBioYiJMEoNAEDXWKPg2MKtgM2We9HHt7bg== X-Google-Smtp-Source: AGHT+IHqS6jVvcfjGatJfl8KWoFTi4QgbSmrfF/wW/7JcxOTyKtKIFw9ncbv/yGN3EdfLgHpAgW9 X-Received: by 2002:aa7:c61a:0:b0:560:799:f802 with SMTP id h26-20020aa7c61a000000b005600799f802mr565527edq.21.1707860336402; Tue, 13 Feb 2024 13:38:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707860336; cv=pass; d=google.com; s=arc-20160816; b=OmQclZAj1VI5jk00UxSr9i1SycE1GbIz7dOrICMncVyDjoXw772eI8MkLGgns7pOpE x5JxiqxM0MgFT+xn31ExRZLYNHmPdFCjBCP7IeCoGJcyJXp4AS6McjEKtBLqNvLbMRpR HcB7PbRITNlPQ/oj3rJVbWOpHTJvPKqWQk5rUBbswQvCPxDGdZxHQLPbl2WHo0SQBalH a7n9AWzFdgFAUR8y6ZjQhidIeczUh4Darp2u64P4gZ4hCJQC3tnmaP2UVILBqOzzoB6u x3XpXZ38Of3f4C5M2pWrd6wG90RAM2ufCz48bOq1R/XNiwn+HCf5AzgSKvdtAcziY+W1 l+JQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=6D7+ic2NMajZjJRZ58O+PQEBSPCxwZs8miT0K3jUJcc=; fh=TYWtjyHSO/m1Bhd8aBI4t89VyAFptvDq1hevsVP2hC8=; b=YJHU9XIU/jMnVj+SaV6FdjuGmlv33nHqze16qhYCa9UQljVy9jMm6Cs2ADR6mgnvMy mGFaat4HNjYK4GJ+toiTyo58hsGf8IOujdjoLgS0vFqoYNo4lo+e+cCoCF7STQ0dWYiv JsruorZJfAwtobII4SLE5ZDUQfu/0zOQjchoFElLwefr8aNExvzwNGc/4/eKtlg+XKKe hvdW66SlFzLpq4rV2mv/otgucxKqsicYRqr0zAks3UaHWEdC7jotqUZ4ZtYetbwzghrI Q0IvQ6UaJpRTGKJytMT060HbxfOWullWRSroyYUXlnj8PG8UeZlkRRcMiuH8vMhDfO/J bMEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Sb+F8d6i; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64344-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64344-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXIq3yK9cSvCy5tvi9iTL4KVVEHCVQNc8HQK+hROpgM9SbRxopXOaqomFK7rNPcv1QxH3OyN8qMxUS63eThuFAIMlXJ+A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m9-20020aa7c489000000b00560a161d4e2si4313061edq.232.2024.02.13.13.38.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:38:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64344-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Sb+F8d6i; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64344-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64344-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0B2351F25996 for ; Tue, 13 Feb 2024 21:38:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA9B5627F6; Tue, 13 Feb 2024 21:37:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sb+F8d6i" 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 3EC5D612FE; Tue, 13 Feb 2024 21:37:41 +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=1707860262; cv=none; b=ol3klbs8h7D8Ghp2YGu7mzah7RXB1SSLXT65UTcggiUnSrnlR1x7n4SggOzpGP/VXKHK3d9ObOMfsFXz8nKwn7g5UwdEXfaH2A7mpioeFxvQrI9nmY+a7RIbVPGijuYxNPvhe5NCqJlvZeB3uJ/E05NQ89W+IuO3VaYxxFAoc10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860262; c=relaxed/simple; bh=Mc8iA4R+RvlCogjizmfuBdLaRuEY94aY5Pgh2nLn8ac=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iArl/XWpnrGqAwYGOoH1E5ISwibdm2IP2szQjsYMEzSjoavM8GGt58NSnzTQrVNgRz+85Z2CzFSkBekd2mGb194Kn7eIvoC0lXOMWulxgQ90/7HVWtotCWyqTtwOqoX56EuO4WMQlZV4Fa3Ym96oZuvvOKV3cRQds025+cfjyeA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sb+F8d6i; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1874C433C7; Tue, 13 Feb 2024 21:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860261; bh=Mc8iA4R+RvlCogjizmfuBdLaRuEY94aY5Pgh2nLn8ac=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Sb+F8d6imFeQ45gYeWAN4/BMaT90jG5csQsCSot0PbyMT88i+74CZeUtTPvUxmuUP t7FsY5dTvXbuSKoD8EVHTD8zCxRCTcuApqgMgZ21lhygy+SW4ZxqjBJsTye+y9s532 2VQycVXwzvuXfNBx7QujixZBOFpQ2k+da0/+MZ5FsbBHbiJ8Y7tUguIoLfpsAiomNz 6mFTz8/lMazFoYkJqBJagtYvSSnkHH7k2ksf24CyKW+70KC7jCqYsBGrvQtH3C0jxc G2qH/gokXheDzLuRZiLeolXi1GnEcqa3Y+gPx9AVvs6JbEzWwH8p7cstiyVtjXES19 iDaqW0CwmhJ/A== Subject: [PATCH RFC 3/7] libfs: Add simple_offset_empty() From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:37:39 -0500 Message-ID: <170786025969.11135.16880338029664682984.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790821359848425405 X-GMAIL-MSGID: 1790821359848425405 From: Chuck Lever For simple filesystems that use directory offset mapping, rely strictly on the directory offset map to tell when a directory has no children. After this patch is applied, the emptiness test holds only the RCU read lock when the directory being tested has no children. In addition, this adds another layer of confirmation that simple_offset_add/remove() are working as expected. Signed-off-by: Chuck Lever Reviewed-by: Jan Kara --- fs/libfs.c | 32 ++++++++++++++++++++++++++++++++ include/linux/fs.h | 1 + mm/shmem.c | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index a38af72f4719..3cf773950f93 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -313,6 +313,38 @@ void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry) offset_set(dentry, 0); } +/** + * simple_offset_empty - Check if a dentry can be unlinked + * @dentry: dentry to be tested + * + * Returns 0 if @dentry is a non-empty directory; otherwise returns 1. + */ +int simple_offset_empty(struct dentry *dentry) +{ + struct inode *inode = d_inode(dentry); + struct offset_ctx *octx; + struct dentry *child; + unsigned long index; + int ret = 1; + + if (!inode || !S_ISDIR(inode->i_mode)) + return ret; + + index = 2; + octx = inode->i_op->get_offset_ctx(inode); + xa_for_each(&octx->xa, index, child) { + spin_lock(&child->d_lock); + if (simple_positive(child)) { + spin_unlock(&child->d_lock); + ret = 0; + break; + } + spin_unlock(&child->d_lock); + } + + return ret; +} + /** * simple_offset_rename_exchange - exchange rename with directory offsets * @old_dir: parent of dentry being moved diff --git a/include/linux/fs.h b/include/linux/fs.h index ed5966a70495..03d141809a2c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3267,6 +3267,7 @@ struct offset_ctx { void simple_offset_init(struct offset_ctx *octx); int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry); void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry); +int simple_offset_empty(struct dentry *dentry); int simple_offset_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, diff --git a/mm/shmem.c b/mm/shmem.c index d7c84ff62186..6fed524343cb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3374,7 +3374,7 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry) static int shmem_rmdir(struct inode *dir, struct dentry *dentry) { - if (!simple_empty(dentry)) + if (!simple_offset_empty(dentry)) return -ENOTEMPTY; drop_nlink(d_inode(dentry)); @@ -3431,7 +3431,7 @@ static int shmem_rename2(struct mnt_idmap *idmap, return simple_offset_rename_exchange(old_dir, old_dentry, new_dir, new_dentry); - if (!simple_empty(new_dentry)) + if (!simple_offset_empty(new_dentry)) return -ENOTEMPTY; if (flags & RENAME_WHITEOUT) { From patchwork Tue Feb 13 21:37:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp822718dyb; Tue, 13 Feb 2024 13:39:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWuIWk317+4PaiYfBSlzOOx1+d7QVvBHPtYQDjHs+3b0r8+m62Uk2IyS27gZFRWTizkyaFK0bFRcBoI8WLhFQXRGUy80A== X-Google-Smtp-Source: AGHT+IGbRNCaJdnAzjFLH3DCcLGur8SvVC+nT4kZePChzH0k4VPBhN0I4Jx4gvckm6RG3LI6ZCu7 X-Received: by 2002:aa7:dcc1:0:b0:560:ecd5:968b with SMTP id w1-20020aa7dcc1000000b00560ecd5968bmr620509edu.23.1707860356015; Tue, 13 Feb 2024 13:39:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707860356; cv=pass; d=google.com; s=arc-20160816; b=R319JNwyeZR4y3OCh3g6iNLPD50ZFKL4WGQW5T5Y6QZCNHgS7ZWVAMmCilDh3WhbKt drmwYCLAMC5yGZloocC0cNvDAoHl9G8pvpdunfq2QVKkEHo1J0Xhp8cfWbImJw4k/NSL NyqjN+Fk8muQdjm9JXHJND3uBxASGIQKsw1iWk4zbIF/LAPJG0Fkiq09qx7Zkw426O3V EuOf+Vk/er3N+UxZbcS0oXTQ85lpzuTCYdj9mesXFGAUy/o/m6bwBGxVWKkmrchxcRdd k7L3CdNNLs0384gKFNw9+v0uS/L7VYnbPU1Nb1/9eDefNH6Ylnml7pEd6E9SiwlV3Khi Hg6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=SMUmZcMQoKBIp6RbfLcR8dux0Zzz6xVP4+GW5vJ+kwE=; fh=6B1VA/QIVtNS52ci42WmkswUe3L7Tz4HCp9WUssS/nc=; b=CtcIVA1zxDoXJ99M1PeN6AemXKvAMmwiGsWd8vpqR+S117MBLyyiZ2JkddToOF2fqX f7VC2XUZLVjx5L1/w27z8ECNzCi+o+Szq0d6u8WOZAlYrEB1Aig9AzGosG1Ojt7cayGw HV1yfzSb31VoT2yqrfoup0who6PKvaerUCsr3LubBwXP1pl7/vHWqu5qjeZWY8Qng3dj etNIRheS1qjFpgWUXpoNF7JmjUFFip/bhiiumzUU2V7cYqivKr3m62DQyKGXC2wqJrzM rVK8OqfyG1w+19jZjGDykn4qaeyi/eX8c5FMvHLUlhQhwfldiNV77zTongVBDwqeYv53 Zc0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="PkQ/ab+E"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64345-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64345-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCV7FaEhZNQPuOzbA9zmDpy++6KRz4oW4Yg0buEmTC+jKX1IuIM5y19QwNUIsz0XbJB5bo94GT8+0u7ZO2R+8h4Wn02H0w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dz9-20020a0564021d4900b00561c2ff3059si2103300edb.90.2024.02.13.13.39.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:39:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64345-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="PkQ/ab+E"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64345-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64345-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9BBDB1F262F0 for ; Tue, 13 Feb 2024 21:39:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C2C56215D; Tue, 13 Feb 2024 21:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PkQ/ab+E" 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 79343627FC; Tue, 13 Feb 2024 21:37:49 +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=1707860269; cv=none; b=dv6AjudXLVaZ+L+Rme+XGIE6AkWoa0gDsulNFfonBXH5nXN9hcbOgjaYqU/gofM2HIqmzNcB4yX0pmWrGbhK3tETewjgeouYOVF/jLjXZzbYn9xZCZmTitv6ph3ZVka/w43FCysCeLIqh8LEGCXQN/3F5UbfqfSxAXzu0uZgrC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860269; c=relaxed/simple; bh=B9f3lBdgCzE5vmYqmwo7dByZImNHwFkUKnKEUUxLAe8=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OEJKTk2lBvj6i0k8JDwEEZkdAQ771P8/B0KxqZWsYnJEF/ZYKT435FMNCteVwLk6ZLYUY9aPugEl5iAEMN1p5WWBObjYds9I0AxRTW8AXER5fpeCB9/rBL0ddpb8BbMHVu4D5TphjsUIRHcDNGj7POslb/buuEF7fw+gBuhcbgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PkQ/ab+E; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE3A7C43394; Tue, 13 Feb 2024 21:37:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860268; bh=B9f3lBdgCzE5vmYqmwo7dByZImNHwFkUKnKEUUxLAe8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=PkQ/ab+EPwdPOyd464qxdNkzqn2xi7f9q0FG4sKVLAxTjTQ90270JXf63scaWItPs 3R3bCR7Z8H5if7CxsyH9UMheVQWe8dMYi9JFTZQfMp8m5ioWrpMyMetI59GGHPBIUT ZPrLmGb8dWnIEJGxy8feBPvHFutAHe2dVrzGg6MURRtIh8ZFKZloKeI2FI/Pr+rHCV atLlBXsFRH+m+gj1sWA9hal2rnKQHcTsJxc3xxwBhRlorLAeVZDTY2nCncNd5gGoST +jdPDEllTXrg+sRu+kErmotNcbkAj+wk05dEh7+hamk+Bu+JBOaP0wXg6xyiTJnrjS dYVXrTAGWCz8g== Subject: [PATCH RFC 4/7] maple_tree: Add mtree_alloc_cyclic() From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:37:47 -0500 Message-ID: <170786026697.11135.8612663853690724956.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790821380565166436 X-GMAIL-MSGID: 1790821380565166436 From: Chuck Lever I need a cyclic allocator for the simple_offset implementation in fs/libfs.c. Signed-off-by: Chuck Lever --- include/linux/maple_tree.h | 7 +++ lib/maple_tree.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index b3d63123b945..a53ad4dabd7e 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -171,6 +171,7 @@ enum maple_type { #define MT_FLAGS_LOCK_IRQ 0x100 #define MT_FLAGS_LOCK_BH 0x200 #define MT_FLAGS_LOCK_EXTERN 0x300 +#define MT_FLAGS_ALLOC_WRAPPED 0x0800 #define MAPLE_HEIGHT_MAX 31 @@ -319,6 +320,9 @@ int mtree_insert_range(struct maple_tree *mt, unsigned long first, int mtree_alloc_range(struct maple_tree *mt, unsigned long *startp, void *entry, unsigned long size, unsigned long min, unsigned long max, gfp_t gfp); +int mtree_alloc_cyclic(struct maple_tree *mt, unsigned long *startp, + void *entry, unsigned long range_lo, unsigned long range_hi, + unsigned long *next, gfp_t gfp); int mtree_alloc_rrange(struct maple_tree *mt, unsigned long *startp, void *entry, unsigned long size, unsigned long min, unsigned long max, gfp_t gfp); @@ -499,6 +503,9 @@ void *mas_find_range(struct ma_state *mas, unsigned long max); void *mas_find_rev(struct ma_state *mas, unsigned long min); void *mas_find_range_rev(struct ma_state *mas, unsigned long max); int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp); +int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp, + void *entry, unsigned long range_lo, unsigned long range_hi, + unsigned long *next, gfp_t gfp); bool mas_nomem(struct ma_state *mas, gfp_t gfp); void mas_pause(struct ma_state *mas); diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 6f241bb38799..af0970288727 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4290,6 +4290,56 @@ static inline void *mas_insert(struct ma_state *mas, void *entry) } +/** + * mas_alloc_cyclic() - Internal call to find somewhere to store an entry + * @mas: The maple state. + * @startp: Pointer to ID. + * @range_lo: Lower bound of range to search. + * @range_hi: Upper bound of range to search. + * @entry: The entry to store. + * @next: Pointer to next ID to allocate. + * @gfp: The GFP_FLAGS to use for allocations. + * + * Return: 0 if the allocation succeeded without wrapping, 1 if the + * allocation succeeded after wrapping, or -EBUSY if there are no + * free entries. + */ +int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp, + void *entry, unsigned long range_lo, unsigned long range_hi, + unsigned long *next, gfp_t gfp) +{ + unsigned long min = range_lo; + int ret = 0; + + range_lo = max(min, *next); + ret = mas_empty_area(mas, range_lo, range_hi, 1); + if ((mas->tree->ma_flags & MT_FLAGS_ALLOC_WRAPPED) && ret == 0) { + mas->tree->ma_flags &= ~MT_FLAGS_ALLOC_WRAPPED; + ret = 1; + } + if (ret < 0 && range_lo > min) { + ret = mas_empty_area(mas, min, range_hi, 1); + if (ret == 0) + ret = 1; + } + if (ret < 0) + return ret; + + do { + mas_insert(mas, entry); + } while (mas_nomem(mas, gfp)); + if (mas_is_err(mas)) + return xa_err(mas->node); + + *startp = mas->index; + *next = *startp + 1; + if (*next == 0) + mas->tree->ma_flags |= MT_FLAGS_ALLOC_WRAPPED; + + return ret; +} +EXPORT_SYMBOL(mas_alloc_cyclic); + static __always_inline void mas_rewalk(struct ma_state *mas, unsigned long index) { retry: @@ -6443,6 +6493,49 @@ int mtree_alloc_range(struct maple_tree *mt, unsigned long *startp, } EXPORT_SYMBOL(mtree_alloc_range); +/** + * mtree_alloc_cyclic() - Find somewhere to store this entry in the tree. + * @mt: The maple tree. + * @startp: Pointer to ID. + * @range_lo: Lower bound of range to search. + * @range_hi: Upper bound of range to search. + * @entry: The entry to store. + * @next: Pointer to next ID to allocate. + * @gfp: The GFP_FLAGS to use for allocations. + * + * Finds an empty entry in @mt after @next, stores the new index into + * the @id pointer, stores the entry at that index, then updates @next. + * + * @mt must be initialized with the MT_FLAGS_ALLOC_RANGE flag. + * + * Context: Any context. Takes and releases the mt.lock. May sleep if + * the @gfp flags permit. + * + * Return: 0 if the allocation succeeded without wrapping, 1 if the + * allocation succeeded after wrapping, -ENOMEM if memory could not be + * allocated, -EINVAL if @mt cannot be used, or -EBUSY if there are no + * free entries. + */ +int mtree_alloc_cyclic(struct maple_tree *mt, unsigned long *startp, + void *entry, unsigned long range_lo, unsigned long range_hi, + unsigned long *next, gfp_t gfp) +{ + int ret; + + MA_STATE(mas, mt, 0, 0); + + if (!mt_is_alloc(mt)) + return -EINVAL; + if (WARN_ON_ONCE(mt_is_reserved(entry))) + return -EINVAL; + mtree_lock(mt); + ret = mas_alloc_cyclic(&mas, startp, entry, range_lo, range_hi, + next, gfp); + mtree_unlock(mt); + return ret; +} +EXPORT_SYMBOL(mtree_alloc_cyclic); + int mtree_alloc_rrange(struct maple_tree *mt, unsigned long *startp, void *entry, unsigned long size, unsigned long min, unsigned long max, gfp_t gfp) From patchwork Tue Feb 13 21:37:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp831045dyb; Tue, 13 Feb 2024 14:01:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUzQm7F26Fo/Sm3iFC8aKP9NxQiBFZ3kPIOEVcnEhbH8toSb/K9mVN82x8Xu82HeqWkjzSep7Rp7CCm+WDVAkibJlsIzw== X-Google-Smtp-Source: AGHT+IHKf1vlvmi0+E4FfjytRHl/QMYWK5Yew8YpBniVVcnKGWwc03jqIo4gjy/hhVczFool004R X-Received: by 2002:a05:6359:4c27:b0:179:24b4:41f6 with SMTP id kj39-20020a0563594c2700b0017924b441f6mr634814rwc.7.1707861679863; Tue, 13 Feb 2024 14:01:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707861679; cv=pass; d=google.com; s=arc-20160816; b=fcygHO2OerBx2cr77i8ahVOOq9xfv04deqwjWTviL5p+w3b+ufpO5VbVom3QV324m1 IH8bDRaQ8RrnQTWRjpHYLm+ca8xx3oBpavj1K5VcU//uXS9/AI1FxreQLOJa3pvpwjSO PitKxxb6gnAl1HIOSY4p9JfqQFoqEnxwTfBI328umpSU6lwWKbEBdpb9BrAT3AF8J4w4 MHsADXfJtm10KcBpZyJoS26jCXL6oKWTFlIcLdDxScWzwUuDWFvXk35CHSXtDkggWqo4 86xaxVoBSNCfJ4Elg/33dk/VfdwpZQFcRkI9jMi6ZVua7sbIYwf+pQuhGDO2xypPo0w2 M7Jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=dH9/7pSMHgIoq16nk50EO6AL6CLhc0Zg3gckgnzjmrE=; fh=e9TlNvPRSP+k2k9yxWXTkQzW5fHcZwyraIzc9d5mMAk=; b=APw3ZFNR6FXI1nfptp9n2ebrICmuvH3nxeZzaw07hx0oNmgF4Wxs5UQp36IGDYSRwN QLS6VWbpYKpVrV6NCEtZjxsM1rOtTtXv7xRAYgleB/G57cBQCDoZ+H1WOUVy6c225Nq0 TYUhgzVWjDTE42cdYiQ7J/g3iW5JuIwEVB2HhcUEKgfLetFjKVUbDlzNymyun/PgKoGX JQWJK+84Ibev3ioRFBFwyTTTZinjOZZvAkE95tkVjrWuYUvODKON07lRXNTwbD8uSn/c bmXEeOpwcc/MYBuHl4GL0vWzP4SNOgzt8kj9eWOYq/koRy8Gqn0/sgWsdP5R5owjPnii an9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Th8U8xQD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVo9S3tCptgDbmW/Fuep5c4TncbWVcixGK0umY7/99eqKHJk9IIpwXie/Yh3Ow/VdDeJXjyPbyw39wZqGQs07wnVjYFrg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b26-20020a63931a000000b005dc5568b149si2550003pge.297.2024.02.13.14.01.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:01:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Th8U8xQD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 18B5FB22B75 for ; Tue, 13 Feb 2024 21:39:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E7C8629EE; Tue, 13 Feb 2024 21:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Th8U8xQD" 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 81441627FC; Tue, 13 Feb 2024 21:37:56 +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=1707860276; cv=none; b=fCSGrRJVznXsHjz1Ns3eyN1Dg6tEu4DFmmabvyET91Vqjpd0KccgvQsp78TJvg/lry3LIZiD0HYwsQdEIVCKXEN3ijVoOXxMbUyQNku9BcNzR0KGHoRq3NFHOe3MldomX2OmK8G/iUVD34EHADQeA39IpOby5PjiYcfXOwIrLRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860276; c=relaxed/simple; bh=r6dLn2R32hxUVKrwHaR6P90sYMJO3HfuXaP1srQuHsY=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DkXA/J50pGzMakWih6ua2sc/DLzVgRNjo14XddvgEJi76TybHcPRKwMIF9nvVdgRyt+pgdcsgdUphTnOTZOOcGsHXtqL1Cks+jJLIZRF5hsShNe08PtQ3oEJXKlvb1wtWdCywgNEqQtQ+rkWLF+cYDNXhYSXUoheLVnqWTw7Qu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Th8U8xQD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DFACC433F1; Tue, 13 Feb 2024 21:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860276; bh=r6dLn2R32hxUVKrwHaR6P90sYMJO3HfuXaP1srQuHsY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Th8U8xQDYjqE1oQO4SMhsymZnm2aTPh8ZM7SpIcq4/V3kMtNsQxxEPtEb+A/tXJZf G7CeU83YmDWCAhd/8bx6jK94iSNmgavwSA4WP4N4dJI0dRaDB/zSKquDqTQXzeFO7m nC38c/PXELlpiHWShA/rc3NbKs6cX7/7sxgiSLwa58znNQ1vr0pOGxb0cnwQgQdJbs a8EcruWbXzSxvwZRj8o8Y+0+5a327ukO27y3BcROelsesxB4/7N/jTda8uI3qtQj8A oJsu3SksCpvwru3/pix1RG4ASCwWk4HWxBO5o5oD9ZaLDJTRzKXMbRscRM2tuNVH9G qMSYb7+IbpL7g== Subject: [PATCH RFC 5/7] test_maple_tree: testing the cyclic allocation From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:37:54 -0500 Message-ID: <170786027413.11135.7987491534374292548.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790822768575181855 X-GMAIL-MSGID: 1790822768575181855 From: Liam R. Howlett This tests the interactions of the cyclic allocations, the maple state index and last, and overflow. Signed-off-by: Liam R. Howlett Signed-off-by: Chuck Lever --- lib/test_maple_tree.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 29185ac5c727..399380db449c 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -3599,6 +3599,45 @@ static noinline void __init check_state_handling(struct maple_tree *mt) mas_unlock(&mas); } +static noinline void __init alloc_cyclic_testing(struct maple_tree *mt) +{ + unsigned long location; + unsigned long next; + int ret = 0; + MA_STATE(mas, mt, 0, 0); + + next = 0; + mtree_lock(mt); + for (int i = 0; i < 100; i++) { + mas_alloc_cyclic(&mas, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MAS_BUG_ON(&mas, i != location - 2); + MAS_BUG_ON(&mas, mas.index != location); + MAS_BUG_ON(&mas, mas.last != location); + MAS_BUG_ON(&mas, i != next - 3); + } + + mtree_unlock(mt); + mtree_destroy(mt); + next = 0; + mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE); + for (int i = 0; i < 100; i++) { + mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, i != location - 2); + MT_BUG_ON(mt, i != next - 3); + MT_BUG_ON(mt, mtree_load(mt, location) != mt); + } + + mtree_destroy(mt); + /* Overflow test */ + next = ULONG_MAX - 1; + ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, ret != 0); + ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, ret != 0); + ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, ret != 1); +} + static DEFINE_MTREE(tree); static int __init maple_tree_seed(void) { @@ -3880,6 +3919,11 @@ static int __init maple_tree_seed(void) check_state_handling(&tree); mtree_destroy(&tree); + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); + alloc_cyclic_testing(&tree); + mtree_destroy(&tree); + + #if defined(BENCH) skip: #endif From patchwork Tue Feb 13 21:38:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp823281dyb; Tue, 13 Feb 2024 13:40:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWq+GrpAfi6jIHf7PfCLe4FE9afSV3KHlQhB5bgyM8zuwg5Arw1Q46prH2jocLD9AwLfHRfPJpa0pzm/M6XMqsel3sQpg== X-Google-Smtp-Source: AGHT+IGgxFopY3nPApmitOP+TpwT5eRFvYuumkOpAp0nSTBizoOFja0p5HjanR0UJkM0BuSmK7WV X-Received: by 2002:a17:90a:be14:b0:296:6b49:b416 with SMTP id a20-20020a17090abe1400b002966b49b416mr666215pjs.49.1707860441371; Tue, 13 Feb 2024 13:40:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707860441; cv=pass; d=google.com; s=arc-20160816; b=uPynRCP8LYJKSVctymkzfWytQPY291xesji2n4DpcESEqRL3fmClP+TeNBP7610spf jBxdozgq2TxVuEvbjcVWw+zqG4WalogdneQgwpG9J5h72u6o+5M4rBJeq6HVHTMyhtKC E6fcGpnFgVYMtJFxKnHyPJUIuY+xuo2QYIGdiZyThptayTW5EvRB5SmMtikvPsDYuL/Z T9/0bfLXlOJQxFPabxh+E2eT1NltC0dUvxEwjMM8oOYGlLIfPwzW/dvojWc5TEXfjUNo QFm3x7Aa/T1rGNI71W69atOky6OjZgi29LV3Jygj5DH+qErjbpXIum1XMMXpP1mV3m0N 0tvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=0SER4lOz/AH2yj5owcu/4zqzTVorxUC2vU0ru7wDFG4=; fh=oiYmNWjiwWdtt3fdo8rcMGV6cM67ZqpY9GUeyHNMRH4=; b=cdNI/zWNDcmiJVneGjMoj90srHLrK+x+zTePyIFYv7KOYeFshgZjtjJTYJV8jmJHa3 +Ggxk1smya/v5npxY0uPjvmmN2cD1vqsTUo2D4xZqr60yeWwSKbR0NMdGNbIdInzAo3V OU3e2avnPnKrk6gudg2eDviK5+OLVegWmupciwTY8Ts7A8wV6Xo2+WvtKNq+Faizu2GO vSIaMaLszB8SyIR59THb+5WcMwgZdypDBi7gGwnT6U5Y6BM0UV23PfBkpVZjK99K9haP 3j3Dt0Vj8DOBEi+WXABcNw4WMbzlyowOt987KMMN0vcQGvOvDb7Qtv/9HeOdPkh9kyKN Ki8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FG7j61xv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64347-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64347-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUZKQO64SB1fY9XZkgLO4ocjc09N2UjWK+vj+rwvAke2hn4nHCMqRSqARtSECs4oj3vft/KSJcDnGZTk6LOnF+LIewloQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c9-20020a170902c1c900b001d8ead4fbfesi2566967plc.191.2024.02.13.13.40.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:40:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64347-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FG7j61xv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64347-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64347-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 87B41283F4B for ; Tue, 13 Feb 2024 21:39:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE54E6216E; Tue, 13 Feb 2024 21:38:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FG7j61xv" 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 AEC3C61688; Tue, 13 Feb 2024 21:38:03 +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=1707860283; cv=none; b=YIwHcU8lJI3aSxJYwzZdwSntz2388jXmWFK2jVusOxH7l4RcwncNAwcDgaf1gv3QGOijS62HUuHhDJ0Hqby69HeESRri3I9ijT5LL5/7jVmIkWvpxSZOqUO6tcTsm9Lk+ZzK9UrhrcNy6utsD/+L+46ljzf+JP905URRkmViYP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860283; c=relaxed/simple; bh=KGqt+JHPo7CMimpAfjV92G5RJ+LvokLdXc+VC2S1AlQ=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oVtmvM6R5p00fSWNyB3NcRMssUShTG0KD4rvGPIzpcsBM9swbYpE5jEapSdgf/MBmLmVRFgdKE/2j10ZBETowdFXtZQOwYpbT83gV8tqI8bMY6ESgoGFj7POMWSCssayK4y7FqnXnTQxdVc/GlKCBrktmlos8dVdo1SvzP1H+v0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FG7j61xv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C6B8C433F1; Tue, 13 Feb 2024 21:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860283; bh=KGqt+JHPo7CMimpAfjV92G5RJ+LvokLdXc+VC2S1AlQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=FG7j61xv3XzeLrMru1T0AuzhJtumhe7YDI4XxvKqKzZErrZwLX9fcCO+Ik0BsBBKz y2HK3IiVkalN33FSz9+c8RRFS5yv1P/s570qwwK4A1HiYLX+BSffOA/RvoQ+F2QnqB 7RgknMYrNxdARbcEimBh6CwC7aBu/Cgct8Rs1vM4/su6p/cBDjro7gKVP3NkCdVTqw kHEYMT3APXIbiLWNXceuQq/2JflUJexQigp2iom0MFZGAA21wJjQa9YREfL4/mNkod R1nvl7c7hVJUnFzZ7I83N503q4+pMhWDj7kVXBYxEnZUNQONDco1zKaW19Mxav9op8 Z9F26fNWv5Ulw== Subject: [PATCH RFC 6/7] libfs: Convert simple directory offsets to use a Maple Tree From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:38:01 -0500 Message-ID: <170786028128.11135.4581426129369576567.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790821470259376236 X-GMAIL-MSGID: 1790821470259376236 From: Chuck Lever Test robot reports: > kernel test robot noticed a -19.0% regression of aim9.disk_src.ops_per_sec on: > > commit: a2e459555c5f9da3e619b7e47a63f98574dc75f1 ("shmem: stable directory offsets") > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git master Feng Tang further clarifies that: > ... the new simple_offset_add() > called by shmem_mknod() brings extra cost related with slab, > specifically the 'radix_tree_node', which cause the regression. Willy's analysis is that, over time, the test workload causes xa_alloc_cyclic() to fragment the underlying SLAB cache. This patch replaces the offset_ctx's xarray with a Maple Tree in the hope that Maple Tree's dense node mode will handle this scenario more scalably. In addition, we can widen the directory offset to an unsigned long everywhere. Suggested-by: Matthew Wilcox Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202309081306.3ecb3734-oliver.sang@intel.com Signed-off-by: Chuck Lever --- fs/libfs.c | 53 ++++++++++++++++++++++++++-------------------------- include/linux/fs.h | 5 +++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 3cf773950f93..f073e9aeb2bf 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -245,17 +245,17 @@ enum { DIR_OFFSET_MIN = 2, }; -static void offset_set(struct dentry *dentry, u32 offset) +static void offset_set(struct dentry *dentry, unsigned long offset) { - dentry->d_fsdata = (void *)((uintptr_t)(offset)); + dentry->d_fsdata = (void *)offset; } -static u32 dentry2offset(struct dentry *dentry) +static unsigned long dentry2offset(struct dentry *dentry) { - return (u32)((uintptr_t)(dentry->d_fsdata)); + return (unsigned long)dentry->d_fsdata; } -static struct lock_class_key simple_offset_xa_lock; +static struct lock_class_key simple_offset_lock_class; /** * simple_offset_init - initialize an offset_ctx @@ -264,8 +264,8 @@ static struct lock_class_key simple_offset_xa_lock; */ void simple_offset_init(struct offset_ctx *octx) { - xa_init_flags(&octx->xa, XA_FLAGS_ALLOC1); - lockdep_set_class(&octx->xa.xa_lock, &simple_offset_xa_lock); + mt_init_flags(&octx->mt, MT_FLAGS_ALLOC_RANGE); + lockdep_set_class(&octx->mt.ma_lock, &simple_offset_lock_class); octx->next_offset = DIR_OFFSET_MIN; } @@ -279,15 +279,14 @@ void simple_offset_init(struct offset_ctx *octx) */ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) { - static const struct xa_limit limit = XA_LIMIT(DIR_OFFSET_MIN, U32_MAX); - u32 offset; + unsigned long offset; int ret; if (dentry2offset(dentry) != 0) return -EBUSY; - ret = xa_alloc_cyclic(&octx->xa, &offset, dentry, limit, - &octx->next_offset, GFP_KERNEL); + ret = mtree_alloc_cyclic(&octx->mt, &offset, dentry, DIR_OFFSET_MIN, + ULONG_MAX, &octx->next_offset, GFP_KERNEL); if (ret < 0) return ret; @@ -303,13 +302,13 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) */ void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry) { - u32 offset; + unsigned long offset; offset = dentry2offset(dentry); if (offset == 0) return; - xa_erase(&octx->xa, offset); + mtree_erase(&octx->mt, offset); offset_set(dentry, 0); } @@ -330,9 +329,9 @@ int simple_offset_empty(struct dentry *dentry) if (!inode || !S_ISDIR(inode->i_mode)) return ret; - index = 2; + index = DIR_OFFSET_MIN; octx = inode->i_op->get_offset_ctx(inode); - xa_for_each(&octx->xa, index, child) { + mt_for_each(&octx->mt, child, index, ULONG_MAX) { spin_lock(&child->d_lock); if (simple_positive(child)) { spin_unlock(&child->d_lock); @@ -362,8 +361,8 @@ int simple_offset_rename_exchange(struct inode *old_dir, { struct offset_ctx *old_ctx = old_dir->i_op->get_offset_ctx(old_dir); struct offset_ctx *new_ctx = new_dir->i_op->get_offset_ctx(new_dir); - u32 old_index = dentry2offset(old_dentry); - u32 new_index = dentry2offset(new_dentry); + unsigned long old_index = dentry2offset(old_dentry); + unsigned long new_index = dentry2offset(new_dentry); int ret; simple_offset_remove(old_ctx, old_dentry); @@ -389,9 +388,9 @@ int simple_offset_rename_exchange(struct inode *old_dir, out_restore: offset_set(old_dentry, old_index); - xa_store(&old_ctx->xa, old_index, old_dentry, GFP_KERNEL); + mtree_store(&old_ctx->mt, old_index, old_dentry, GFP_KERNEL); offset_set(new_dentry, new_index); - xa_store(&new_ctx->xa, new_index, new_dentry, GFP_KERNEL); + mtree_store(&new_ctx->mt, new_index, new_dentry, GFP_KERNEL); return ret; } @@ -404,7 +403,7 @@ int simple_offset_rename_exchange(struct inode *old_dir, */ void simple_offset_destroy(struct offset_ctx *octx) { - xa_destroy(&octx->xa); + mtree_destroy(&octx->mt); } /** @@ -434,15 +433,15 @@ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) /* In this case, ->private_data is protected by f_pos_lock */ file->private_data = NULL; - return vfs_setpos(file, offset, U32_MAX); + return vfs_setpos(file, offset, MAX_LFS_FILESIZE); } -static struct dentry *offset_find_next(struct xa_state *xas) +static struct dentry *offset_find_next(struct ma_state *mas) { struct dentry *child, *found = NULL; rcu_read_lock(); - child = xas_next_entry(xas, U32_MAX); + child = mas_find(mas, ULONG_MAX); if (!child) goto out; spin_lock(&child->d_lock); @@ -456,7 +455,7 @@ static struct dentry *offset_find_next(struct xa_state *xas) static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) { - u32 offset = dentry2offset(dentry); + unsigned long offset = dentry2offset(dentry); struct inode *inode = d_inode(dentry); return ctx->actor(ctx, dentry->d_name.name, dentry->d_name.len, offset, @@ -466,11 +465,11 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); - XA_STATE(xas, &octx->xa, ctx->pos); + MA_STATE(mas, &octx->mt, ctx->pos, ctx->pos); struct dentry *dentry; while (true) { - dentry = offset_find_next(&xas); + dentry = offset_find_next(&mas); if (!dentry) return ERR_PTR(-ENOENT); @@ -480,7 +479,7 @@ static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) } dput(dentry); - ctx->pos = xas.xa_index + 1; + ctx->pos = mas.index + 1; } return NULL; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 03d141809a2c..55144c12ee0f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -3260,8 +3261,8 @@ extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, const void __user *from, size_t count); struct offset_ctx { - struct xarray xa; - u32 next_offset; + struct maple_tree mt; + unsigned long next_offset; }; void simple_offset_init(struct offset_ctx *octx); From patchwork Tue Feb 13 21:38:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp823390dyb; Tue, 13 Feb 2024 13:40:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXnz1G7vm62t7d/4CkYl8SseVckY67/1I+XmaYyAAJc0rtJJj0OLAHfzPV4Iyqxy1YgXEkjOb1yKcblb6GnK50a1lo7tw== X-Google-Smtp-Source: AGHT+IHlJtG6lBPnnKBpXjVCoSNwnPGhAVegn0unloePjb9L4dZCbrzNRI99+6r/KdgQmHPPW7PB X-Received: by 2002:a0c:f594:0:b0:686:ab05:59fb with SMTP id k20-20020a0cf594000000b00686ab0559fbmr768714qvm.8.1707860458757; Tue, 13 Feb 2024 13:40:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707860458; cv=pass; d=google.com; s=arc-20160816; b=RUEIAExlqT//m+1Hz+PXHF+/x8E8o10I1xRzp9jWZ06+8Mh2lK88aG/2kNDxvI1+XQ JhL1epsUlhFSnNqF50a9wtJ+eI3ybwJ25N/nE+X4BUjwtyiynffku6Pl9U5BIekuqB4O UexNxFQVFBF6c5Qyhl8B1+RI8c4/ZjqIDThg3zL6Go7edHERUDDi4yWqMLwuYkWly/5E l/Lk+sHXHzgHtaPrMBWItErukYHJk/g1fHX0beF2mP/vgnBbOW6GEGkwwRhWbOsH8KoG y41Qs8dQPbl577EPnIGeRaiZXKwFjtZ9p+oLDobctBxmEwHH1+59ywlS77ccBDH/U1CB y7qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=R/sSg6xxDbxmhGUF8KYJydF2AEnkGCxNzIuo/Lb2e1I=; fh=XC7QALz6am8mCRHWKOZO3uxZQg3wt+lVBimFUtIi/zs=; b=CjvIGu905Sx9bJplvskt/VSSBu7DvZuFTBDr/xJcJRQPiWLJFyZyxQcWTDz7Ch++uR kJ4q+NoMba/Bn/UeA+J8o08cl35KM0S6LyI2xb953hFmurCMP7BtEKNFXoMzS/Ug8/rl oYa2ZxOpsFDYmA1sgOGg/iUpY8pcs02A0MJrETiUmVmcaI7Va2bw0zi7SzV9ajOM/1oG fgovsh0NVaqYtxe3RJ4e3MGYhCdj0MhQyglubgJMvniJ27e3Y9JH852p3YiUX3VMsqTm yPpkdwFNanaiSJQMreYZMrLiWzvDzcofYw0KPF7TyUiSRxCPMj10zjGN9gluoaGrUUMa QShA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BtQTNyV5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64348-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64348-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWdOA9wn3MUEwclOcT4dBtgvni0A2i4a48vcOOJ0A0bQvmS6yqpw0ulRkr8kHu2TxMmaMV4+Ei7fnNVc4ssJv7CLGk2aA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 5-20020a0562140dc500b0068cd85d5d9csi4036388qvt.93.2024.02.13.13.40.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:40:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64348-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BtQTNyV5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64348-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64348-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3C3B01C2737A for ; Tue, 13 Feb 2024 21:40:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 716DD62A1A; Tue, 13 Feb 2024 21:38:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BtQTNyV5" 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 E16E4629E7; Tue, 13 Feb 2024 21:38:10 +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=1707860291; cv=none; b=AgYFfxcwSXUYGoWaQBTXtoTOvjAb6AQpLz64GCS32gcjOn+65kuJ67bgqOBFwctJ/7G9DO9JNXJEa1YMI12qDfrt2TlHexjrqTF6pUP8W1eUyQslYBhtgmtNlMgUrLt7j7y1iuA3WMvCsY/fD6auYpfgnpAqhDcdejqe7q2swfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860291; c=relaxed/simple; bh=SovcTJwr5T0bwcx24VxTqCxw8DF70LVQIJpozpuEJ/c=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rW/KUxZb4jC1VjwUzXhJWfah05t/rAqctgkP1j3p+A2hrGDv/jk8j2VtQnGJSXSo9TJyxFqOjmAwL9kuldIKPEA0Uqci+DOu/mMdbGmr4AxQ1SDlksbu4mDXvyMk4twEylCVGKJY3ijm2p90lr4dwKkhGSUa4KCOXMnyTCuCoE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BtQTNyV5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C3E2C433C7; Tue, 13 Feb 2024 21:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860290; bh=SovcTJwr5T0bwcx24VxTqCxw8DF70LVQIJpozpuEJ/c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=BtQTNyV5Zn/oTgtUO3HAG41FZzx+r21bj4Czooq47TPXHx+lj/idVHknoPLK3RJVH XgyxesfzyB2xskU8InhLkEzRzd2KWcyozSsJCvHLwQa4wW/pOt4dWfHHMJDxF/hD3A LxnOHDiCc8VnukMJfNU0tmiGpoGIVz5iOCXClF4YTEHFcAVLNGtutlmBjVMtVdx6Cb YlYV2q3zpxRKJXV6PPZuUtDHrlJfnxTdXlgzmcoClySh5Gm1bEay5VT63RB9M3AflK 19AvfgMz+13A6rmaQthtztDQ268tQjbpw0iXdKSAJPuHCcfVETwWx0apSTAmxJX+fZ BdiSRx/XBm5NA== Subject: [PATCH RFC 7/7] libfs: Re-arrange locking in offset_iterate_dir() From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:38:08 -0500 Message-ID: <170786028847.11135.14775608389430603086.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790821488500366785 X-GMAIL-MSGID: 1790821488500366785 From: Chuck Lever Liam says that, unlike with xarray, once the RCU read lock is released ma_state is not safe to re-use for the next mas_find() call. But the RCU read lock has to be released on each loop iteration so that dput() can be called safely. Thus we are forced to walk the offset tree with fresh state for each directory entry. mt_find() can do this for us, though it might be a little less efficient than maintaining ma_state locally. Since offset_iterate_dir() doesn't build ma_state locally any more, there's no longer a strong need for offset_find_next(). Clean up by rolling these two helpers together. Signed-off-by: Chuck Lever --- fs/libfs.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index f073e9aeb2bf..6e01fde1cf95 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -436,23 +436,6 @@ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) return vfs_setpos(file, offset, MAX_LFS_FILESIZE); } -static struct dentry *offset_find_next(struct ma_state *mas) -{ - struct dentry *child, *found = NULL; - - rcu_read_lock(); - child = mas_find(mas, ULONG_MAX); - if (!child) - goto out; - spin_lock(&child->d_lock); - if (simple_positive(child)) - found = dget_dlock(child); - spin_unlock(&child->d_lock); -out: - rcu_read_unlock(); - return found; -} - static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) { unsigned long offset = dentry2offset(dentry); @@ -465,13 +448,22 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { struct offset_ctx *octx = inode->i_op->get_offset_ctx(inode); - MA_STATE(mas, &octx->mt, ctx->pos, ctx->pos); - struct dentry *dentry; + struct dentry *dentry, *found; + unsigned long offset; + offset = ctx->pos; while (true) { - dentry = offset_find_next(&mas); + found = mt_find(&octx->mt, &offset, ULONG_MAX); + if (!found) + goto out_noent; + + dentry = NULL; + spin_lock(&found->d_lock); + if (simple_positive(found)) + dentry = dget_dlock(found); + spin_unlock(&found->d_lock); if (!dentry) - return ERR_PTR(-ENOENT); + goto out_noent; if (!offset_dir_emit(ctx, dentry)) { dput(dentry); @@ -479,9 +471,12 @@ static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) } dput(dentry); - ctx->pos = mas.index + 1; + ctx->pos = offset; } return NULL; + +out_noent: + return ERR_PTR(-ENOENT); } /**