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: 13555681 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 144A0C4829A for ; Tue, 13 Feb 2024 21:37:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 986C38D000E; Tue, 13 Feb 2024 16:37:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9367C6B0087; Tue, 13 Feb 2024 16:37:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 762AD8D000E; Tue, 13 Feb 2024 16:37:30 -0500 (EST) 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 6107F6B0085 for ; Tue, 13 Feb 2024 16:37:30 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2A568C0CAB for ; Tue, 13 Feb 2024 21:37:30 +0000 (UTC) X-FDA: 81788092260.19.800F95D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 66C56160004 for ; Tue, 13 Feb 2024 21:37:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Qf4/d1Yg"; spf=pass (imf08.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707860248; 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:in-reply-to:references:references:dkim-signature; bh=Kg9PtooROHeKx8fIUbKlppQOORYDMz/IXh3imJbt6ck=; b=iWdLJZg1uRw+MGJzNB3AU14y13mGskDxec7ZHSV8VLI0ARoAGOJ5QVR9+I7a4qutOhDvnp 8+pRh+0jgSqbgytdw5mpHgrxEsycM3OihkI2AwoC9ZGODbJIxOBGxCmPv+TALrwotY9juE 9oHlDiVJaJLILv/Busn3fhrCZBBNIB4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707860248; a=rsa-sha256; cv=none; b=3hFLHe9ALBxKiAm5jB85CSCmBYUKM0beTI2N+neaRgRcaABVDq87WE6PH+RGLHYy3ujn6N uscjyoXYf1F51pH8hBMeK8yoIPmF0kVHVmzKyiUooFO/xgJnIe1XuQXFYUghUk7AECEiSD mdq/RTyQzBwZD0gS0oyW/0tDEimPhog= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Qf4/d1Yg"; spf=pass (imf08.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 942EA616FC; Tue, 13 Feb 2024 21:37:27 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 66C56160004 X-Rspam-User: X-Stat-Signature: r6fj19ait56ak966hmkihrt93qjdc9bb X-Rspamd-Server: rspam03 X-HE-Tag: 1707860248-519686 X-HE-Meta: U2FsdGVkX19kTRR5EMzHF/w2TBE8p+3iMItrF6ghB4Z5QuB96rhLji41uePiOaixISMeXalR+ytnc2b/Aj9ndjrsd7edoUVp6EQw3db0FlUolnMtzykYUbJino2+xnO4vjQUVTTWh14B2V2iRCb/qyHaPEUWmXpPbh7DtzA22/GEzMw/1mz2YbDRsW5G9b5721W0IzsfL3gzqpRP5ZJofwEoYr1Uy1y1H0p4V6EhBnFs3ZLlw6jxdXx7TkU+TNbZ0o327zV2b1DAUxXbNIb7r7w3/Me9c22q3LOgFyfSz0pQsdj9FLD+OhtGrU35uTwWTmV4eRIMI0g+l1j0i8zZBMO9kH6HOncRfMkL8wuLisaecWfRKoQH1On4iKwpXqH1oKDQPW4zEG6U7Y8y2+PApTdQDxrxu1PcwE/OpfkyfcEDVD81c3lndW8YQn4ugH0cnGB09uWP/OHY14i13OIEdK/5VkRl5dShA6LVI6gTAE+mCzPt/fxNYBieDtPf/lm96SIc6yC1vhAxJOjBO5CaSnBAxMCkJBMGWGKPgW3RFILDT5hgSjiIPh3Na8CF/6OzgLQkIGdt99+GQ0NsDy4Sxx+QhLdlcSxxnHTbfDrAXEs4fCI+qqt50Tpdri3LpgtnUgUfSZ5nYvOPfYqwesHjlVWchbPzBNEIkPF1ihxsONh3D3SmESNHHKwbuyVr4zJrEHX1NN42b4Z5M30AsxedOxjoxwSFQW77G5vWrwh01zEYF0XJn83DtTkHPcBim2zA2gDI0o8kfhIG/o1Ol9fQKFx4m2fiFrECdtlKKkBjxzVAT1OngpLrohNcfamKn3LnB8pytU9AitunA4ONkzo10M/M2ypAyBF3CsX9Qva1njG4tWS0NfO9wTIxio6TxpeFuBnXlbIzAVUKqHFD0ePoVSPHABUnLP7HM6yEtjoilzv2L63TBPLXlIUjcQqMhNLYn2jsWNWODyWJZWDhV2/ Yd1QEqqP npIYnlkCnPTASPCkhVOP/p65KNqDXqLW5eNm+wbw/+mXW7+FHzLH8nWKO4KnEfAL3XxDCVJHM/42vw3M11uePYtTeLdTVNeIn7CF8HD3Y7Hb6oyYvuKXPb8SpoUgEwa8Rn4/Sn/QoIsuBVJpKmshih04d5yPL8dPJK71WpenC6KD7F6STbcFL2wjBfM5nnAbPgnTGS1kbV3ma7k/zfcKx9b4RkPL1HAF74qXC+KF+6y1LXNh/XoWdHsYfhuFuvZTHzP7Xdphk/NtWKk+/2GefR+ORJw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13555682 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 46E45C4829A for ; Tue, 13 Feb 2024 21:37:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE23E8D0012; Tue, 13 Feb 2024 16:37:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6B496B008C; Tue, 13 Feb 2024 16:37:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0D878D0012; Tue, 13 Feb 2024 16:37:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9EB6F6B0089 for ; Tue, 13 Feb 2024 16:37:37 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 471C6120467 for ; Tue, 13 Feb 2024 21:37:37 +0000 (UTC) X-FDA: 81788092554.25.C115DC2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 944164000E for ; Tue, 13 Feb 2024 21:37:35 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Z/MEawuU"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1707860255; 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:in-reply-to:references:references:dkim-signature; bh=mZDvb//WTZ9zZsQSCdxiKoP98n1vIsP+SpP9N6y1aoM=; b=Fyzoyo02vYcnZINX7phkqvM+WFRkrWwF4mIXEaRZUfgTSAlMTXdYsnOKXoTBVsD0RDhqjA oAl4bwrLjWSWjDdg/LDXbI0D1bkz3fhPtz3jEtXpMquMfJ0FhrpgPSettxmEORNKEEyJvg IlC3NuexVmZ5kJzrtD6oKDmitLjtjsY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Z/MEawuU"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1707860255; a=rsa-sha256; cv=none; b=6EDRebLcO3cip4Aie32L3/wFox8uvT4oBusSEQRa7SjhZRJCdekkWGznqTa16qfKOQ9lLl LCrw6VhyaXhbEW1lwIOyS5lolPFvfHFyn4TCpUKuRJK8qy+0Mof5Q7g0ndmLUNMmDQX2+U KuF56kr8FI0OKKAJuFe/nJf/Fj0aFKQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C5FC4616C6; Tue, 13 Feb 2024 21:37:34 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 944164000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: kuajbe1ue4mxzjkxwhxump5dszba9fgk X-HE-Tag: 1707860255-537736 X-HE-Meta: U2FsdGVkX19J2EPdNN7JAfdBP6tMvO5tDLxfvBt0q7/YW9IoVi3v5IkLqoLyV6R02/yX/cxwG2Pot3eLu4H9MxSSUYWG8xUlrKlE4SrEeZs7sMP3jK0o2fbOfkcgQj9jxnHiQaYAjGhgoRgbL5MbHb5VL4/hCLaPfhGvyCvZvTnmdgL/1rwG8qTCZHROUvYvDZzZDt6dgzbO8Yw67hLVh4vhYyXnFKMkdSjqVmKguAnj3eaK2m7ekYeA4XAKr5SfZmq+/GhjOBPQEdnVWHT1vKYvHvN5Z7CdcQ56mUfeacQ0Kdts2FOqQcIfCceVjCyaR+1I0kb5QgnfBtqtea8AkJf8ypWnL2vcqX7ec2Jf/k3Xu71ff/156bILVTD3zDRV32JLXs3g4PmE8ATjoy2LfZefi6slFdS0WUUVZlVuRwQAA7atQ7X+9rlXlW+oDVsdv7/M5hOo/8hwzgCwWstfYTV8sBVo4VAFRD0Xx1ZVGNl4SIBSvwMSxPgEnK7y1KrExkB/cWjs10ozryEb9o7iWcF+SNvEgAlcV96mh3GA5sgZWxFnYqEBmBC/qF/5S6yUAggDVKBnx0Opz/JGXxr23ga10yaK7M8POGjAR72uzVi4fq8tXAX7ITHg+iya/+DhbD/olhS1diR3mDzx+3Qr0MyLKLl7se4L17dU/+RAGwF9TG4XyHKWAmIjSmU8tl7q5y69IPWZfRD5aZwu7W7hi2JHsU1RnZLZ5riF48yam/3zO+G2mbboE4t1n1WQ2ybNFEkgnyh3wYwzRdMVfPzRDcErDhxDIRDOtEefolcp7vIOSDB22jxqFPyKXWsubbJ9mI7gnMqC2Ec2/8XF+d2QH7rjqGzrRfNXDg/q0zdPJJMXwYNH7WwZd+ilhCD5kZoS2nTEAxyFHOU2wJb3+y8KPUZ9mGkpN8/bFBafSltOUqs9Kuy1ioTMbg0Vn8jnRFau80Yt9AetPj72CdhHmas gye/RzkM 1Bqer3GI0+o4mcIiORlxpwBAy0UPealYd+UOznKhGtICjzpFBRd97hD03Xv2XeTCwUJm0dNm4f6RKuV7F/5D7mdtuuYbkZVsGn8M2L+dOFZY7M2Cz3t9KHms1LLhkrbRnM9j3F4dKffqAJx3oK74ZknD65eULSvwkC0TMSG6n+QvXw0t5UBvUz4QMiPh+sR8IUEEs0I3wx7ERAX8YxWIyG8y07x7UtfANx9KV X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13555683 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 65582C4829A for ; Tue, 13 Feb 2024 21:37:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E90BE8D0013; Tue, 13 Feb 2024 16:37:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E19306B0096; Tue, 13 Feb 2024 16:37:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6DAC8D0013; Tue, 13 Feb 2024 16:37:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B1DDD6B0095 for ; Tue, 13 Feb 2024 16:37:44 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7D0DD401FD for ; Tue, 13 Feb 2024 21:37:44 +0000 (UTC) X-FDA: 81788092848.28.8707B4D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id C887DC0018 for ; Tue, 13 Feb 2024 21:37:42 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Sb+F8d6i; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.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=1707860262; 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:in-reply-to:references:references:dkim-signature; bh=6D7+ic2NMajZjJRZ58O+PQEBSPCxwZs8miT0K3jUJcc=; b=HlYxLEIFHP1Se/BHxv7XjvL3OaWC7rnqU5wFF4E6K2Zm86Fyc/nwew7J88xx/mxyrLLYHZ gc7+sAMDraanENVI90XAXPw1PWUSgAyMRPjWgo29OCmXir1uA8U7BFEwulAywYa1yHnejB cOwIleo87Sfrnch85VTQzXVnf2NFa5Q= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Sb+F8d6i; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.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=1707860262; a=rsa-sha256; cv=none; b=2mRQcXiKc/JyMciTu4KnhNViKqG8ylRwSGPtsd7k/JszKC6WGognx0A2Kq1Se9SK36C4fB hZtYluILo0ZJgx2AEmqVpRwl2vubrC5wdJcqOwePhCIr+dlp/5FyO765h9BfMq1zyQxx2j tZfNYtuPGZHvysYXtOngDPnvHyoYmmI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 16DDC616E9; Tue, 13 Feb 2024 21:37:42 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: C887DC0018 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7sf63g1his75syhwb1j9yjhtmgdnnnau X-HE-Tag: 1707860262-32708 X-HE-Meta: U2FsdGVkX1835ifjHrF2xtoBwI/vDzLm9Riy5IWBVcOgKOv4u3QxjhIMELJklKhZqPOC4aofbcavZ1YjuJaLrMpgzIySYAk+C4d/XSBV3U6hNWmTAhatkkBqGVGcfmjqQ86jH702KVZUnGO72bvuiGxvFdUKI1mEKH7dI1+knx11yKF0JPfBEwzd+oKRWvts7zjyyoH0eca/F2pznLNZSzm6Ivhksur3WLBP2FKvAdWeLNT+GyDKIQKoyhXV3UoxKSIbVMFY9fs58l0KRH3vj6XGmPk8imkFS7DvZXpAIuousHTSXxM5s1P9aIsWadf8w4hya6WCUZH55l6sBsPGpz2CrKXDdvhbZwHrUcOOBIyCdmz8gHglmxe0YAObleKYiaZZ4G5uz3hA88+22XYZ6pgUdaI4Q/2VawlXERtbOoWk/c4C13dXkOY/yb03uwHY6MQPdC+JMjGmlSqsSAGU6qR3tDWXJbn/JaAlUcpZTSWXZT3/cJU2PxfeJoPkGxjnhaF5X5y63gGcZChI78FTfEaS4yGh/HlIB+SPGsQdhI3e5grfZMq+0ioFM2VoTuY+LYcEMVwGKBh7gNGKVckHFtvAgazf4GHEz/3yoXqC4q6wJtv0T5Jv7Lb5xwt5zkBOCShrWPRJaXGuvgNfC9mh+JVQDZ0uhmObzUIb/tp0bUyUfr0orde2xkoRfl7BD9zFEBIZXuuKHwNbyolBrxI8VZtrpDfL4MKqb+PB33qCJF6OwIgeCoxV6lQsIbFHh33mD8AJGfzRk7Wxt/tXEKWssIA9vQDOyYhj07y42ZOuP15RsRjMKlXQ6ioT/lXpFGalYjozga6aP6r0HKqcVYBSDp3ZZJ0sur9R+uSzb8YXCsjbeGtLiF/7dleZVu27zsFmuyq7RgpcNf67lC7DkEhUBnvqhvn0RxgMa/CFp/b0uG7DlLT5RT6Us+dtiKaDg9vhWQSZFoAqGzJD/uc/3zW KLctDE22 ujldN+fdNRtwKnlqLoXzU5yXvDRxBOlMoIRYLvG4n83Pt84RE2R48rNuryvnkeGLig7N4m+GYZnu3hUfZwvoAUfdL6JfLVXsrkq05TZEy+kQwaWjHhgJSCVwnmQpX7bZLo030ApKdqg1lC+De6AQLAODFZ/kAQmCx34TZLKlhiwBiJzjh+VwFn+YSprqekFkog3Y4eimeRuRlGJs/tRAWChGpublQDLrMNFBW6hfZ0FaIjqHSAbr1VbalcTU7X53NUpTyqwt8OwvAvV0RRuOForHKQw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13555684 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 D8FABC4829A for ; Tue, 13 Feb 2024 21:37:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 592198D0014; Tue, 13 Feb 2024 16:37:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 519066B009B; Tue, 13 Feb 2024 16:37:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CFA98D0014; Tue, 13 Feb 2024 16:37:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0FA996B0098 for ; Tue, 13 Feb 2024 16:37:52 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CA9A3C0D06 for ; Tue, 13 Feb 2024 21:37:51 +0000 (UTC) X-FDA: 81788093142.05.C18BD97 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 1C14B160005 for ; Tue, 13 Feb 2024 21:37:49 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="PkQ/ab+E"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1707860270; 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:in-reply-to:references:references:dkim-signature; bh=SMUmZcMQoKBIp6RbfLcR8dux0Zzz6xVP4+GW5vJ+kwE=; b=tDKK/pbJE6tys3Yeft5YF8S+F1v2xn+Cd3eYBS05yrEANuRhhpo0YeE/otthIeiTtw6zDO p9Osp2RkJH3U8Q8Hga4cLBr3hoFoefqHLWcwCzd9zP/3Tjq0AzYA0Uyk9sCEsIZktrpEc4 0jhac5sdFYoqBdiFU5zFQFxb8+4JquU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="PkQ/ab+E"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1707860270; a=rsa-sha256; cv=none; b=IroAx7eG5iZeSPVWi4cZtRiCzRnA2a3pW+VvD6voiW2voOdMfX2MhhrH8XpynJFHDnWgOj 8scXCXDWT8SNKtLi9aPXAhClUag53KfuSAJcbiHTKyP44rZLHqe8MrZdiwrNtaeyBE0mD8 2sR18G7s94XISUTGur9avAqEcDHu2NI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3D748616FE; Tue, 13 Feb 2024 21:37:49 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 1C14B160005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: jma67h9nk3xcq34etc9g5kqjaqddi889 X-HE-Tag: 1707860269-596367 X-HE-Meta: U2FsdGVkX190CTOC8kHhFMZAB2BbYz1y1x81O6lQ/bIDpcYOndqhYHG/lA5UtnQGhXG8S2Ndy4H4R4UT24Q0goVEl/e9w78aiTJShhlodtrSqUXJ9VJQl5591So+HekvK1arLeai/Ein5apQh34iB3Nz2SkOjnz13PtzmRIa9Ocn4gJvNHGB2TlwMOsB/o/j0MGoQH5QJPDk/CGXlue6dxtTtjctXAkYTymYnLAoHln3gN2FSealB/yLrMBPQ2KTqgI0ppUEBfVHQxz1ufceb0KM86wXAt6oZj88rOvhl4+kZEGajBicUQ3q58PQhjsuuULwKnklA3P3W8Mq/JPR143bn1dN7ycPuAVQRVAR1pJ/YPU8PyC3cCSOwtGI8ANC7ALNYific3pukgl46nYbwRTrj6gHCVVab5uApCQz9kQw5pOsTUllyeNt7ANUDxrMWRSXBB44aXx9rHdW9MnKaD/EonmTbMAQMCX503eXDuizhT47mV1/JZmnJkz3WdyJ0EQjXHz4Sa+/lfJwRBUPk1RatoHMzMU75OcTOccUcw5GTIhzR7vnDnt8+m+EuLphEvA+YbO0Wnze1+kqK0U2JOFsq9wD17I5NBayZQ0FCcGqujj2FyiWsMo+BqLjU8B9PooTl1Vre9z35LAQ4L57li/UDHXVeFHS8lM6BcsBjjVAT44zVnKf08UEpmSbffvmw1p7UIYBL1S14HBIqYUctH3Zpm29uuyDDKO/Pz9Y7byk7wPGDFIl5f1KSxChtzd1mBE1cbvFwpecqzHIiO2V8WoSqj2BfFvvyUI7ztwyGf7ENBN4pQsobTMVvBAe6H45qKWPyJSgjZbnrbnabrGmA6PSBW0It2YdztvzMvxlGPGP3EbDi+Mt+BULpzX7Ea9aScf+1pdkMmR0O9LtbgGlMilqI7fFAe2BIinpCG6b58Dy2ohWz7Yr5drcDzjxO+hGeXKdKqjlFI7zMd6SbiI ZYuPnpgC yHvJvrUqmgrUJtfks6CkbWBgEsiYTpPHjb96VjYhX55YlPMk24RYKtueRflJvNjdEEtJQOdvyyR4fS6OlBNZN82XBkOyU7D8nM60s+IYtiw6ts843Lfhn0bbYN4n/CF2XEqyRTmCwlRTmN46+RQE78Xwz7d0t4Z7UfadeFuHFvfb3MbPB9EfF3vGn1zxlsmQAbpXdlnHssWnUk34oTNhi4q+XvXWB6GcshPWBw0Q0/XXanboVd0zPmLJ/BYLAQBxu5Nzb4otESpQJ+3BPG/EBanPfuOAOc2NJ+BYguJdeo3rBFfm4KKDf/IGzpw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13555685 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 875FDC48260 for ; Tue, 13 Feb 2024 21:37:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E7538D0015; Tue, 13 Feb 2024 16:37:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 170F46B009D; Tue, 13 Feb 2024 16:37:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB6C28D0015; Tue, 13 Feb 2024 16:37:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D6B796B009C for ; Tue, 13 Feb 2024 16:37:58 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B79CC1A0CF7 for ; Tue, 13 Feb 2024 21:37:58 +0000 (UTC) X-FDA: 81788093436.22.7C45F35 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 1DF872000E for ; Tue, 13 Feb 2024 21:37:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Th8U8xQD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.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=1707860277; 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:in-reply-to:references:references:dkim-signature; bh=dH9/7pSMHgIoq16nk50EO6AL6CLhc0Zg3gckgnzjmrE=; b=tpRxu6LiDoHlmwTL5C7ihYu40nz5u4yiYOn8YEOtF9R0cMhzS986SYir/cA9ROjJ/oJ/6A grSyXkDOmlwuAPQ41oCe5yxc3qbv63SYjUsH4/mrUNL+/fLjSNNcfpjWRWZuYNhRJK0jW0 YYuzwPYEdpJoivhjoR4sCxZeJ1enRDQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Th8U8xQD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.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=1707860277; a=rsa-sha256; cv=none; b=5tTBwE9nKUylTZkhdTY29dEl/APOBk3HeLKNhCkLFYjsFUoXBgPORwZzw5rrMyNO7/yUd4 foRZRr6PBC/l27RxUVD3mS3YunZi6RP39yFBAwnx667VLcC91+sPC3yieZCjB3SQRBjSuI FW0cQ0TNnYIPU8CxZA8ZG0ZZiPTJ7do= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 61BAA61702; Tue, 13 Feb 2024 21:37:56 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 1DF872000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: w3ah34s85asdw4hgsa7di4b9zfjffcsy X-HE-Tag: 1707860276-268094 X-HE-Meta: U2FsdGVkX1/2pqlwpysWd2nuZcP4jMxq5/tgIRdXKWFZNgBUz9WMFvYtE1/ji3F5PVxRmpnGDbaMjEBQfv9YRqysbRs+0SIgBgxUxk+hXB6sgv3iFfxYVyFHrkg1+IQkjqDae47S0o0+1EqFsiTYC500lDs+4q5T7a+jvgjok/IxtHeqk+kUFR0eGmqDY5RJ1pei/TE/p4ZFhpze7CiRxDX8FGVq/3OapGC/3HcZL4WsdDd8oZGzHX/V8olP/dBSusffJ9/0t6TNVdTLfRTBgS7FCh4Z5uXgBdRT5qd4oofGB3f2LaJZls1A2uFsv51hm28FClByYC8kr0YirllDVWZBdrGtK/96A/qCsKVyL7J/HLIplIGhw5dmMV4Fs0EhbfZe1NYnr/jEPlWUTQ48XAFfQ3+di2G2sip6HzxIgkp09OvJTXaO32dgPkhWdXO8CQhfK2cIetbnVKIEhEXlIntQTsUtq0cMuXZ1FUwA/RacJXzuL+6gf10GI0COUaTweDcqxo/FIjfkHEuYSB5EJvoo5BPFbDvkV6N3hpBZx3O0Rc89peOWU1iPo/yMkiNJlxDsA5M+HBfMS4/IYre7mGmbemy/3yirQBdbRPVHs7LI9Z9pQLXrui3uyMUbjwjkDPqrxwSSBQznNPl2Z8GpO2YpGFzbDog6/1rYJKeBqOmTP9C9DOTCv6VFHNrUZeDYtJ5pF26X2GETpwWw9u964z/6Es9qi8nfFxjhniheykxDFkYaZyyAGz/hfX8rHsBap03JsAcuFOozSvfeDF8I4we1aHbQtKmZmmt9aD08DIzseeD6H1yWs3kCzLfEsv6b3xO2F218hsAWnJcERk3+777ZEEqi2DETQGLMFp9scAwJaKEuwqfX+SK2qnu9/ji7HI/rpKJtgixwpYu9qCz6+YISuxEBYSJIK26y4a54uaQWpWjIzghCXDhzxI77B+h2Yw3EoTNz8hZVAgYuQaS pMyc7L82 KIuzWJ7KI6UK8PAtIYRyi3xHS8fRMzNv30aQRoDFxwOPC3FupUIhhDqK7NL8GwJgZP8fGgfJ95PsndJfsluCRbir0LPZj1uJ6/uda5eP9ZjJkdyA9opP9Y52j9r3ku3feVT7CGHnuUFbzKoex9o7UUfuoZDaOv54KDi+VEsBcWr7DX/iD/iGeScYhSJcryHUJpAsgju9law5dN3L4a48NCfsMMW2edpdKf4b/FEmFJSj2ihVu6X7EolYV0Ft5vQ54XBTVFBfjNA0EXHQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13555686 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 04382C48260 for ; Tue, 13 Feb 2024 21:38:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 877426B0083; Tue, 13 Feb 2024 16:38:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8265E6B009C; Tue, 13 Feb 2024 16:38:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A0B56B009D; Tue, 13 Feb 2024 16:38:06 -0500 (EST) 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 53F156B0083 for ; Tue, 13 Feb 2024 16:38:06 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 295BF14069F for ; Tue, 13 Feb 2024 21:38:06 +0000 (UTC) X-FDA: 81788093772.27.CF86435 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 6197214000D for ; Tue, 13 Feb 2024 21:38:04 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FG7j61xv; spf=pass (imf26.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707860284; 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:in-reply-to:references:references:dkim-signature; bh=0SER4lOz/AH2yj5owcu/4zqzTVorxUC2vU0ru7wDFG4=; b=SKZo8mYUqGHsbx6MlpcjCo5VAuvyPJdhVA7NA2iLc1L+rmSKE2A5M+NoJZnznh1ERZFs5S Py9+XkLi9uMpz/KNh7FHkPMdBoiArG2JOUX1QXB+uoHSGnhkHd353+EhJw8z6nOkrODVQX Nuf2sukIHr4lmUTZIE+vnEKES2F09wc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707860284; a=rsa-sha256; cv=none; b=Gh41wEJ1pb5m1x3pKBwDB/qpicI4gN5rIpyhJxWdFRZIsFHGTvDVAzuGMB58gydV72Ti/I +w4utyEHRuay1hUgKTIx2azG/CjJn24GbQwZavi/DYGlhchf+yRC2DzT2NZjrpvLJgCu8e oUkfBbPAjjqftyXLCKmswEH/iRidA+8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FG7j61xv; spf=pass (imf26.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9249561704; Tue, 13 Feb 2024 21:38:03 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 6197214000D X-Rspam-User: X-Stat-Signature: y5uibsur9usst5c6jz17h7mnrxtcphbq X-Rspamd-Server: rspam03 X-HE-Tag: 1707860284-956477 X-HE-Meta: U2FsdGVkX19OPkZQqJd7uu1U0KtMeDsSbR4eIbJl/M8+/C/kGyZy+lSoBBNCdRwc6XbqzYVdInlD+dNwWFXTwf8QEy0j+IycgYrDKzys3jVwpwWWtstSJdRcKMywUefrqe2+xV3YLwGsY/v9Fd+HC8BoisGDSoPxQV0HqWglzXoCRV/u5SboF14eIqA3djB76lxZf6BMvxYpQ91LMrwciecFQ0i1uQO5Ex1KxKgkxRpTwZkU5QQj4CQf90B97hXUl2F+WnPm3WbtFZ/Tlh+JZwJSwG+bth/KJkd8TpUqK5vWr/Eb1zMUHg82Hwk1hqvXxE894Cf+uG1Q9q3y6lGMuLBzT9Ss0SPnCZOA0s7FMZnsCeCvgwyeRD1op9xmnbpbQSZ8TtK1hQp/FO+vQ4J/11QI4A34rdCfWmYWFlrN285x/I4VDr3dmVDX4KWk4cZ7CMz9hBpGn1h4SLnXMXo7yjzjWO++6CTay5El4wr2uTFES3i/Ulcpq+hUc7QZvTmGHMZ/CFfY2Wea33atKEk+jTk1nTZFZaYHFyfY42T3Lrn0qNWFNnwgiG5NT0a3cMyuqi4Sj/WUFlfuInc4rLBTAKhBzb7wtt9jMQXXH0eKRUkeNN7UPAofoXpgJ0EI2kQb8p+yfT+jueOwM1K2KKMF6QGujU3Y+zMndbqobabmMiGdSqhpEb+X58jtNzmJsopcN+8SKe+rgCzhczK8LBpUkka1yJfglQKEKEJO6bqDiBlMGCUMeTE+H92Bxt989Va2X3/KyfAwl4xNEu6sRg0Kqf+nHMsYGyHdcJYb75aEv5RITO/uSeaRBEmJotcmNoYtrzpzYx7nbJpWk4WIp/i5oiSTZQEAq11dYT6XwLJ5fRWe8O23GbMzpfoDOKWDLY5OIOmHw4WB08wsqdFAWamGFZzlmHxHRKrc7Aej7WZ7e9AJr2gP6hoPtVpGjGWt+C+SXX3HuS7wV0+usS+iIiR DzS8TyhD fdJ8qC15Pe5FW/5aPiaX8C9kymuuAM/mbn0I2N+zN0A0yZa4UnGKzhwn++nst7l3ZHRE2qTbDlVopPMyZ5WIcH17pXourqTF39vmOHn2fwMMmTwMg3a96OrV+lFtoKwQkx3PTS3So7vN8b+CbBUsiohYenu0N+Iwp1l7b2YlXf1wOijpPCI99pR0KLDvwbPe8qOtSFYsJ9TLXrjfL1pXT78nShpdYT9tNnCVTPsWj1zAIQJlTkJeQjMhJjwPHVRThGyFtgO6b7VpPdkU2u/MrzJInd2hL+6AlMXo7pEY6Uo5MTGYyvUOijBBPTtvP+C6vaSD7QaR4Xvp34512FoDik66b4AcinpWIt0dvUX9cJN9i2RzgKoRU2eQDSA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 13555687 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 E74D8C48260 for ; Tue, 13 Feb 2024 21:38:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 747DF8D0016; Tue, 13 Feb 2024 16:38:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 69F026B00A3; Tue, 13 Feb 2024 16:38:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51A4A8D0016; Tue, 13 Feb 2024 16:38:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3DF1C6B00A2 for ; Tue, 13 Feb 2024 16:38:16 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 161241C1593 for ; Tue, 13 Feb 2024 21:38:16 +0000 (UTC) X-FDA: 81788094192.18.F9B7D1F Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf21.hostedemail.com (Postfix) with ESMTP id C11431C0011 for ; Tue, 13 Feb 2024 21:38:13 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BtQTNyV5; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of cel@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707860294; a=rsa-sha256; cv=none; b=vRHa4+B9A71z1dudYz/6kCKglfWTSYYlvB9Je3dT3/nb8tYIxzn7sJedQJlwT50LEPw63l +Xw2f/lmVK/mVRO9lIwKmztvkane16qMqM2lQToqS8PRlqfgoFgimkhVvFIwNQHZDOHbGC TVrGdwFYrhUkVWP0PRBsQnnvItX2FwU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BtQTNyV5; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of cel@kernel.org designates 145.40.73.55 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=1707860294; 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:in-reply-to:references:references:dkim-signature; bh=R/sSg6xxDbxmhGUF8KYJydF2AEnkGCxNzIuo/Lb2e1I=; b=LZNvrptJy/5jv3bGX1mF6eiMy7LRqDQkuQcF114C5aUfnh0x7zovRbsaCQ5P46p1LNki/C EFyqkAubNq00xsDT892N3nZVhkHnxj80O6fmGROOtDKXZVH7BnizMBOb9m7KC0PWRt6432 WfygDx967yBhsOWi5aQdreI1dytxoMM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 26825CE1E4F; Tue, 13 Feb 2024 21:38:11 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C11431C0011 X-Stat-Signature: m3qqs5htqf1i83c5qz1ory9ya5nymx86 X-HE-Tag: 1707860293-846379 X-HE-Meta: U2FsdGVkX199RZvRZUBwTNgTT41yWVywZoEK8ju8OkFy6vV7H9E0XeXTNqnfLPMrXuwJl4IemYYocS3LXSoSpxIPbSJaD85yn0HNN859z1755eFB37ZILj/yIdHk9GcTuS/OXOGocAZLF9Ar3SvOgbbrWjIydFIWpgLHdoLrzY+eYPYf4gECPZB59qdhY2TnJqdkZocNmlPrDm3yCU9hO9bS9civhi2RlgnRSRA1Afys0+uqDVoT6ijxKmXHta4/QOxymCnsIB1uSTE3hgh+v+tBmfR8Zc5I1XUpfIHa3SP7wUPBAuPfCy8l/G6+8U7OKY7t+alcR7Ptd2PdWXxtEX5ogjzDzLq/Ol0g23aJw/5eq9n/m3FtDZ/cxgHmsK4IkEr3qv6hdmiRF/I13L+e70P/qmbiyq+/rQcn92RLeXMoJi2UiVnJPUqN0wkxWTX1O5hL1NVgW+7Inv+spnzIVi5FQugSBAenXaeVJlhO6IpK7cM2BzUExKNd/PJZKPqJZFYJvLp9fXwLjkM2n7n+MSlr9jYdKxXBZDkdKOEOopTORk68W2EfxcMgmv2BuIn1sGC2Bw46aEkI7f5RjeWVK9N4+FQJKdfsb9Frgw/dlLzqx8ky3xOZIw6vlfGuT1hfo4kMPjfz3fAfk9xc9bnm2M+ssDDerd5SjfffAX6I1NXd3RjDC8+IR+TINzhPQYp3OMu4meVzdWQU5epcVLdijqFbjxtc6DnR07npQvQuTOgh7J49nB9AQ2c7WQA2TSy2YPA31l8k8e+3c38FxjOajcI6eYnA2rRN2lc76ldLJHfOp+2b4uEEOP/HFQ8Y6oWZsI+S4xhlXGt1zjmptJa4pVxnAFhnLk2P15pTj6xNNR+0VTEX/Bbo6dy8blwSawWGwwr+Sb2WilhIften928TiF23OSBrFI81spJFhSK2dLQAmxi5uHn2UVgu71N5N8JVFaX56CsaW4Fg34Q8owR upXQMMAl nC7c+eYC4rtmHD4gAuywjp5RyztKzZvHBOx7HDcvFCuzF0l0BjDnHcP2xoHG8wSVpF8oVusjntz5Sah2ncXkVfBqxSdff4W/G1UmtgqUGhs8VNFR+YZtUNdvUGo7jHGOuj+93OE50h9qNfTL5pxLVWN80oXlXl2rw/5iukNia0cNtbqAJZ1ZnOSCrwvmZhDOA8sADrXJdqtzPLo514QDA1/ZBC8RiQqDoEcMiAiHfZujN66arLh++heXYz7QwmBhFLUaMV6XnE+y4tB8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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); } /**