From patchwork Sat Feb 17 20:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13561580 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 F235AC5475B for ; Sat, 17 Feb 2024 20:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C12E8D0005; Sat, 17 Feb 2024 15:23:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 672598D0001; Sat, 17 Feb 2024 15:23:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EAFF8D0005; Sat, 17 Feb 2024 15:23:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3773B8D0001 for ; Sat, 17 Feb 2024 15:23:45 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1740DA0349 for ; Sat, 17 Feb 2024 20:23:45 +0000 (UTC) X-FDA: 81802421610.03.AC351AA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 5E0AE1C0009 for ; Sat, 17 Feb 2024 20:23:43 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P4X30OxK; spf=pass (imf18.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=1708201423; 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=LMwQkCs3Uwwg0hCaF42Dp3GN9kHRnCL1eJ1vax4uPe8=; b=kz5H1WJappccMC7hrqykju3K1JrLNxbOGayiMNbsaB3XLgf/KBBvlEsZzkhfyFsIfWDEX5 zzoxtXeTMlSWIzsDyRzKkEA2xGMzpiWBfbOVIoIMWP/zZf7y0JoOpMHyGA0SvSSMIyCXB+ zCHfV1OT2W44o2O2zGJdqfDS18UMeH0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708201423; a=rsa-sha256; cv=none; b=lcfw6L+enosabQoe7HXgSdjJyAgHt96Dql/RIHVZAyCXIVfKd0D5au+/33S5DhJa/lzURL e6auoX1xpepc2osJD7BRjc9FB05l9d0Wp43Ns9KTzCqb5JDgVE1bY6UzM1Jhe/wE6eH/qZ DWnQDriJvIZsldBxD/zU37ayIPQFh1s= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P4X30OxK; spf=pass (imf18.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 8042A6066F; Sat, 17 Feb 2024 20:23:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32618C433F1; Sat, 17 Feb 2024 20:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708201422; bh=R5X4D36CuE1wpCsrFE/3Fuex0DnO2GtnjfkqVv5cjQg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=P4X30OxKc0EN8nPXm8GE/AdSc3yeT5iVNwWMRGyRMVcJFIie5F4caTrhUc28NAuXO 9voVKSq/opp81jg2cRH3/szMzpTTQ/4XgrT8WdD2WpFkvBWhxoEj1F/vcTYv1kOP4+ FZdDrkL9Ov1gk0qvcx9T66jKl6xWpHB0h4rQB5Ze7WhCUX3SKZ6cEUOGk9Z5vnO5+j XY0aze0RMR8AG9xJitjPfN95aBR+joD0NoDr2zyACqqmGYNchunmvsmDUeW9cgCf9a DCi8QemiRpOkaILmDK6aiHQNcv88w0pNMBL71uYhHVosom/O2z6gP7OwvFkgLUc3ph MCA7wONlVDoYw== Subject: [PATCH v2 1/6] 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: Sat, 17 Feb 2024 15:23:40 -0500 Message-ID: <170820142021.6328.15047865406275957018.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> References: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 5E0AE1C0009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: wuacf1o78d7iea4eg5ywaoz3m4q8byaz X-HE-Tag: 1708201423-772189 X-HE-Meta: U2FsdGVkX1/ezRKmVi8CYt8bL1UrJC4+pLcoCP2x6N+kbPUORzdTVgssy/YNmwpUeMa0XB6L3ugH3QTOdKzdBlML4f8KkolX6SNo7hESABsWpFuV52gcYfgMzuXRDF0X1tJWsQnxLnsmCQRS4hTupwysAjLCmO06RG7L2GrQyvzF5dWamfI0D+yek+g9JZdKfaY6PRj+CulwTPynuQ44ut8B5a1NFIXmePDKUGXJT2dfCY/PrwC4XJWVDjYLN5Pldi6bBPSA4nUGvWIfw4CVrF4/g/TgC19jqjuS6dPMF4eFMnSvIR6w0z6KqvWrEEYpJZOefOWC5gZQmbyUoQri+p/Qb1EDvWhb9IhM4cls6c8D8FIO54pp4mjHruIH7HvJcj8CSo0rOAKz+nizFT7zvTbJXAgXfkasCgpL3tc3dePun0T8XZrNAEsWR/7xP13Jy3eL+LIWGMwCbnxyQtXKE6CDtIZK48jNVaqajR3lsE6dl82j9ThCOgrUcLSw7L/CqiA+7lxc75NoqjSLJ9vNiQSbO6133vp+trvwEl5h7XZcmN9MYWv489tTaA7W6nTuL4PqTe+h6t4dNNh8F4+94M4nn74tC4iDu0Na3ysWTraDox0fpkaBd3dJ9VaK6XhSq/F3vqBVoDYWC54Tl8Muk1eOibc8Tv7F14QdPti3iZ30dO2CMN5gt+Gwwrf/DwngFl2cFwOREBeC3km45dT290H0IIBTRaRF6gifhbnyW4QZgzFJ0E+ya3TXKOGxFt54CeYLsvdK5kdJyhvJovJg7rpeKxL0IXZfYmShFzGrvKo2mjCZ9zHSIVqFRgt8XRX7yOZ0142wpS4RZ0826NvxSY1N2A4jo9z5eACl0/W2qZ0GDdWh4jZT5sj1iaZ9mzK6UNzICo/cy+tJuCRobjP2hnJV4EXwhzOYWOIdydbDMx+bax9/LhS26ue1HsGE2x86Fsrt7drD30kLsiKOjlp iHLVUi4/ qMk3xfW8SXkXZ1NVAqoyk2FZD07wQ9T6lBLLRhHVcoE5H7f8/wSq86sjlDmNqpFgB/avaNScIpvAxx+s5rVVbs46gzd9yWYJ7chCHbjrAfBWKyK0aWfhocvsdHqOQKzjgj28oXiU2yi3rUQIdLyxuCkFXhu5AbAZuA9AwWMSauxZ7O9nwEVrtrWo681gXKUXHaapgdKPJpZh9ecgmrJj4FmbRvPexa8SwqkTWwiDoUR6o5fKsQU3wOR/CoffGTQ3K+duWqBMOJDjFTR30egypZjHiZKt/cQ1k/SJqa/y4wzexAXc= 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 and Matthew say that once the RCU read lock is released, xa_state is not safe to re-use for the next xas_find() call. But the RCU read lock must be released on each loop iteration so that dput(), which might_sleep(), can be called safely. Thus we are forced to walk the offset tree with fresh state for each directory entry. xa_find() can do this for us, though it might be a little less efficient than maintaining xa_state locally. We believe that in the current code base, inode->i_rwsem provides protection for the xa_state maintained in offset_iterate_dir(). However, there is no guarantee that will continue to be the case in the future. Since offset_iterate_dir() doesn't build xa_state locally any more, there's no longer a strong need for offset_find_next(). Clean up by rolling these two helpers together. Suggested-by: Liam R. Howlett Message-ID: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> Signed-off-by: Chuck Lever Reviewed-by: Jan Kara --- fs/libfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index eec6031b0155..752e24c669d9 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -402,12 +402,13 @@ static loff_t offset_dir_llseek(struct file *file, loff_t offset, int whence) return vfs_setpos(file, offset, U32_MAX); } -static struct dentry *offset_find_next(struct xa_state *xas) +static struct dentry *offset_find_next(struct offset_ctx *octx, loff_t offset) { struct dentry *child, *found = NULL; + XA_STATE(xas, &octx->xa, offset); rcu_read_lock(); - child = xas_next_entry(xas, U32_MAX); + child = xas_next_entry(&xas, U32_MAX); if (!child) goto out; spin_lock(&child->d_lock); @@ -430,12 +431,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 *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); struct dentry *dentry; while (true) { - dentry = offset_find_next(&xas); + dentry = offset_find_next(octx, ctx->pos); if (!dentry) return ERR_PTR(-ENOENT); @@ -444,8 +444,8 @@ static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) break; } + ctx->pos = dentry2offset(dentry) + 1; dput(dentry); - ctx->pos = xas.xa_index + 1; } return NULL; } From patchwork Sat Feb 17 20:23: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: 13561581 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 4450BC48BC4 for ; Sat, 17 Feb 2024 20:23:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 981D38D0006; Sat, 17 Feb 2024 15:23:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 930E58D0001; Sat, 17 Feb 2024 15:23:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F8158D0006; Sat, 17 Feb 2024 15:23:55 -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 6B4338D0001 for ; Sat, 17 Feb 2024 15:23:55 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 345E814031E for ; Sat, 17 Feb 2024 20:23:55 +0000 (UTC) X-FDA: 81802422030.14.F12F6E6 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf20.hostedemail.com (Postfix) with ESMTP id 1E9B81C0013 for ; Sat, 17 Feb 2024 20:23:52 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u+UucdZp; spf=pass (imf20.hostedemail.com: domain of cel@kernel.org designates 145.40.73.55 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=1708201433; 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=4esY7/t9LpWl+KnSBbx/mU7dFpjJbd72wLpgnvk0B5o=; b=28xU6szaqMo1KgMhgDvZgV/YcnbNi55f4PmI1YctSRLsEQIlerWfuylESQLoNJNemWSa/9 m/KkSEpOXrNQiyPAozKOtQj75TfNYjPze05JOpBSSg+858gbwkOeheViCSy2dWKR5pScAC hfOH9dxXGrJQ0vFhs9tpP1rEXsXkZtk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708201433; a=rsa-sha256; cv=none; b=SyJrcXgls9bWw+xuGlxd9kIskjZzvUJOO/nZH1Dl5W4TtHd5TZdyuDYqCalE4ketpjANJC uZvvyBzdH5apCHbmk5bWC8dXkSx1LkksG+mzG6QnOVK8TkeVCOiIe9nrs6C2kAsWQRyVTh HaV0k7TUyID5vuLj0E85UolPEQjKW1k= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u+UucdZp; spf=pass (imf20.hostedemail.com: domain of cel@kernel.org designates 145.40.73.55 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 sin.source.kernel.org (Postfix) with ESMTP id 3315FCE0B88; Sat, 17 Feb 2024 20:23:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67695C433F1; Sat, 17 Feb 2024 20:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708201429; bh=zZF7EKK8ftmerUGGzBqiAHI4dgUgyTG9wsRPzQOCpuw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=u+UucdZptl0WKrqPf/GzRK/R6NMFecqwM1YYAZqGuTX8Ybt6NeHmaEbfcq4uMU3U9 Ecw2UXrIEBHT8fRD9InGawCnpOxNmcCwZ3ahX2kS2mH4tgddN77dJbqWyCVNT0bMA0 uCsmWi90+2ZSjAPCwOFrlaJNnxcvMf1DHC0MSm/5B9QZw7+aAvDn42p2lZ+yy+GcIn qhcNCJFzcAb5Jnw3TT63+A5NFCXaOpx52dL57L05xf7l8y9xkTdOKKrbztYnBt3Vns pWl/My0Gwa3PLUcjSsCc6gbFPHphzxIOwKUeNRyGz/+J92oHuycuFbRbeF/gWsHo+A Yq/c76UNcJfgQ== Subject: [PATCH v2 2/6] 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: Sat, 17 Feb 2024 15:23:47 -0500 Message-ID: <170820142741.6328.12428356024575347885.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> References: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 1E9B81C0013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: difzgxs35ixwhxz6dzsocqdhst9nz13d X-HE-Tag: 1708201432-209799 X-HE-Meta: U2FsdGVkX18sm6DTAQ+rW3WzFmA1YhZw2N5HReaRjuQaY/LFRw6O8XWT+bCBRyHRQT/xU3QRBm/I/5yibovGuCOdp8JbhesFgT+0cm8+3Vn9QH4gC8TxLWn9iRRsXMwqDfQOE733EGo3eUL9hfqIxUc0Qx2Waz62v1x92XAsx2Orbu05wuAh9uCSArB62nN3HPcFXHldawmzrWh14sQDc0cXKOUq7EEz7XDVOYgBKpJaS/l89egKTtwZau3U6ekds2kqrkE835YUMQYdM+c4k5akbEBNmKVSPOea3sM+n7EBVgo4QCZ5zYZdzcU/gxpHshOzN23preYlsfc8gQmo2C2O+iYEuqQmIzJ1na+EWNSrRUoEdfkoH4XM5MnTBfgZcPnspSUpPbsgXr4cR5KyJh5zMuhEcPFapikDFKVBWB7qsFbyhYU4iBHqPZNn6DQbf04SvWZ2mPAgZnfSHd3XKk/eVoX2s4wTAuA/yteEP5MfJt+VP5uRweYnDhpQdqAvSyKKjZesshtrMxbQdi72oqJ7nfEkMBARq6VGsrApqmSeMmb69wN8lIOR6DSWEcF+6+9C2TJfSE5qpk9vYNMHzQs/Z+K3vQ1xWqQZW5BDz0hvsA74PYjnzZV90WBkSdtB542eYSO890siOFVlUSu3IpVL1SrQoqhpE39i6Y3EBXnBh54aRxyUP3G12S4Ec/NNNzeVtSESJ6/Mfs0Rfd6Q111l/sj/ZflpZF4IsoPAKpS/dOO/9tMFhKsZRyKNtSKUb9jgzlf3TgPL9Qekt7prjabvGxuWjaeHQzteUvNRZv5ITrdznkTBD3mhSDzjLo5PEcrXkVh1A5aK0tblGotfRVIpZuNJbYnqKxLkmRRe/FNAcmSJLrQ94jcIOFimDf8Vc/YSdgKN0ps7btlVHC21EaecJissp20Uo7v+38CHnT3SPx0msWoboNhsBkXn55FDTN3FIax3dJHRKMQOJq/ yqZuiZHk +jYVXXpd8UHi8QbPyXB5AC0mVaRVwBTKVcT1USXsKKKQZuBcTVqWyE2u7CqrcxFDFpJBhfZX4KCqaFuP3+Z6j3HDUAu1vk7uCimzHxz2+WLt1BeSaB94MTpCOvT/N8HidvAatLJuVYG3qV7vcJ0WuI/0eXUtSMQUloaEjxAyuKFxoEndeXj/K5X5LHRxrEd01CJ099ynwmnAXOSouZCuQKj0ncBFftBKHaa8w 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. Reviewed-by: Jan Kara Signed-off-by: Chuck Lever --- fs/libfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 752e24c669d9..f0045db739df 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 Sat Feb 17 20:23: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: 13561582 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 67B34C48BC3 for ; Sat, 17 Feb 2024 20:24:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB11D8D0007; Sat, 17 Feb 2024 15:23:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E3A158D0001; Sat, 17 Feb 2024 15:23:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDC1E8D0007; Sat, 17 Feb 2024 15:23:59 -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 B65F08D0001 for ; Sat, 17 Feb 2024 15:23:59 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 60AEB80198 for ; Sat, 17 Feb 2024 20:23:59 +0000 (UTC) X-FDA: 81802422198.27.37FD7D4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id B2366C000A for ; Sat, 17 Feb 2024 20:23:57 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hSPSc3YT; spf=pass (imf22.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708201437; a=rsa-sha256; cv=none; b=iqqPrcVTRy9v1J7tvyRxYhLpbSuzNG1UkV+rb73NMK6FVfJOjFGD6oyKVkOLCwd4vhvOiA Gzv+MGCNc0FpYHmElNu9MB6x7aWMdfAcjWRQKpJmdKwRJXJj4LmuOBMkdCTpXdgMDYj9HZ 7n24yIduBP7wtjOJ1NmkTASsXImti4I= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hSPSc3YT; spf=pass (imf22.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=1708201437; 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=4qPfTWx2wBbF6c6gCarkXbRmheLFXCu0GVp2UOlPxx0=; b=AMexbdRR1l3G5NzHqm99IbppCZM5FoDQIvFb97FLJQ99JfDr+rhfF3ZCU+lSXHKWLc9SET mL90JIxyouU/cvj+eazyGCHGIBjKNVOyXrweI2Iw4HfDyJA/VFdl412wpy3AqD43TeY/ws Z5U0orBf9x/PZLjxIRTMCBDPBD8VGTE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E47C4606DC; Sat, 17 Feb 2024 20:23:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9828DC433C7; Sat, 17 Feb 2024 20:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708201436; bh=Wl5YZpZIwNdyP0j7hPhqHmMF9/qk/KQwvYrvu9hugUU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=hSPSc3YTTnETZH7tpcODEx1noXHcGxWv4jbcdGMmkKFsEWnfprlfhBAMvQrRX//ay cgIsqNc565w8r+aJyx0o2wv3/D0ExShXnYuhchx1OdQ6esqSVlx4XCBIwsz0wR4Tc+ SLiXgISMOVYmI8HKJURtotqLYVMwdItc1YCaZMJaTNJ9wiCtKOi5mW2hiO9NAnrsL4 eCstP8GCNdyd2EaFgD7YXM37wiYuqB7EwqVdbHXQCbINlch7KtIHb/1vlLp4w3hwYH R9vt1ltVSLWnz79sr+OcRO1RCM8jv6mrvIq9talI2/YedhJ5Oy60DgXlVhj+DFJHq/ p8Xc60B+KN9Pw== Subject: [PATCH v2 3/6] 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: Sat, 17 Feb 2024 15:23:54 -0500 Message-ID: <170820143463.6328.7872919188371286951.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> References: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B2366C000A X-Stat-Signature: n9gtic3or9wsquixhabtyrgp5eujfi9w X-Rspam-User: X-HE-Tag: 1708201437-923113 X-HE-Meta: U2FsdGVkX19FwZYbyPjmlNiaPB/n3Df2hZOwnxKI26/xJ8yjVD9cJGyu5qYxD3A2O5J27pmQF/SN6iBWd5MIiSvT9N0bxW95GrajCmJtWtJAniMCyEiGV1IiHL0OI5ZfB028TsePDttxoJvrtiAQxCJPBk2DnBQvvx5RhMXiAIIr1CNO4/zXA2iM4RUnoE4aQesqTG4bmB+19fsjSBC+dAGyMsaAuHJnpaVzavqdGYayZMpAyQBfXvEQEsjp+bOWZjHctbrzAU12He6wxKDi5iyQ1M/ry/tunKdZUYw9wL0KqtuGWeSuT+zt33SH58S0maF/muw3N/uk2C+5Mey/3XEbRo08kUDcpdpu/vkg4SPjx6Qp5lWgH3GxAY5m8Kye7fO3Gwz3IhJ4tmt8Ugq77ZarCAVGnC6pjTPoRpBpLp0tnOsmuPGQTIyQHuMcnRbcrsM2y75UTTqPz5BVMfhGIOVAYBXDhj/F2OZO2hApFhnezvjX3Wxk7V4v139nM6007tz+xPIxJ3+R1BpTe4nCorb11gVk8R/LkrEJ6uUpWz2DFfERPF7EigIvoWgLeqVYIye9eEfxw5URcXhj1OTotGGUc8S5gtf7uqIch+f6aWiMTtg+bAOJrpBAkb+DuBhJZqE4MOQ4bkp2gwbRo3krxlkiPayfWLNqBrchjjqsCCgpByZF2z6Es1OfdVVzrZw2+0Nwx1XCA1QHTMfbCnfQVmCb6rA9dBzROzB90S+WZ3Vw235GzcwFYs3/sKBUg718NIZnbeuIP+vWPEYktcw3t4JSYaFPgQ4oXLm63zjf5MUv8W8Gm02Titu6q5S9h/jQYkmQkY1JyjhuzZtICKH6b7VMhZy+e21pYJ9WoWUJ8v97Ud9E4QE7JEcY/kvnPN2nucBy3+GU/jmWqB3Quk+5qWQc6fqDYE0TouUKWqrHEp+wScocXeoPQHO0aH70i4z3oudnHHZevob160mp25b J+wM99zm dr7VEqqB6zpbNJE1bc6bxeZAHnVD7y+T87g44XTFWFaN0yVQu7KyfczCM+h2NsEvSDUmJ8V8QdcJbpWhPUNkOwR6OvyUwu3WzmyXH7F8WPM/WyVVYMOSlAuFeuYNqzZBFe4+vyPf79ldQpGjP5ZkjQbhA0fsGVF01M2SwfqazWAkqh0PsWfqxmYVPlKELVoUEkMkl+uWyh/r7Yx9+te69Kjp6OrjBc+IUM+CayIrIu+xDQYkU0eKpMV+25iTf+f2eVFkZ9BZzFb1pTX8= 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. Reviewed-by: Jan Kara Signed-off-by: Chuck Lever --- 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 f0045db739df..f7f92a49a418 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 = DIR_OFFSET_MIN; + 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 Sat Feb 17 20:24: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: 13561589 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 704E6C48BC4 for ; Sat, 17 Feb 2024 20:24:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9ED28D0009; Sat, 17 Feb 2024 15:24:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4F7F8D0001; Sat, 17 Feb 2024 15:24:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C17DF8D0009; Sat, 17 Feb 2024 15:24: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 AC1028D0001 for ; Sat, 17 Feb 2024 15:24:06 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 641151A0321 for ; Sat, 17 Feb 2024 20:24:06 +0000 (UTC) X-FDA: 81802422492.27.9B40CEE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id DE37640014 for ; Sat, 17 Feb 2024 20:24:04 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LKKwFZ37; spf=pass (imf11.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708201445; a=rsa-sha256; cv=none; b=zZ71Zj/odW47DeSttzjBpUk5WQi65tnlm9lsbeb40occSu6ndpY2jaihx2OTSx4w4P0+uH bCCQ5V9LnijgG3hisWD393lBK9op7V+fI/3FL06xg0PGX0utBeSgfE0Gh3E6Lls9jp+KLo Qo1N0J/JzXkvp+pRb9MrPZ3gs8SC+nM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LKKwFZ37; spf=pass (imf11.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=1708201445; 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=mpvHtnUOzRSdkzdSu5oTfHp6r9we6FR9oEZnSYUpve+Mv08Bx4fgJzvSja8GO+ikG4brur +NvHOSgkkwSuWeFDICeoyK1pXeq/BmeeoI1vin0iR9B+cnK7znYb/5MWmfHElGGpvghAWN 5OwWzMEH8yIgAeFwEYktQoqcFJvKs/M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1431B608D6; Sat, 17 Feb 2024 20:24:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B44EAC43390; Sat, 17 Feb 2024 20:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708201443; bh=B9f3lBdgCzE5vmYqmwo7dByZImNHwFkUKnKEUUxLAe8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=LKKwFZ378z7nftyteopcpFImAvTgQDtbs6xRUS2AQ1HltVj6RhcqOIUwjYinyg1U0 GDDicWz5fjRAz4dbG9+0SL6K5hMzvUbHJ35XkN5ywzAsR9cfQwY7TiXSjSZ5oW5sit undKjeWvGc1a7gM6AwMn9yB8nc1zUm8pz2QzWsQo05o28qpCqLf2sWiKayXQCsipgw jNNOwjHB+9U8UjoIo9pD7Bo4l23YoRl2ygwooQhBOhzIhhnzp4mn5QrKSRmh/jZqPz q+XtUJWAzB7Cp2QTyfet6z7B5fjdWN0dgaLuOaU6PxCE6WYPA56RHSrvUhzJQpBufG lsiQTs4cxaUfA== Subject: [PATCH v2 4/6] 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: Sat, 17 Feb 2024 15:24:01 -0500 Message-ID: <170820144179.6328.12838600511394432325.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> References: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: DE37640014 X-Stat-Signature: i6qghuaokrb8grddmfyby6reem6j5xsw X-Rspam-User: X-HE-Tag: 1708201444-20106 X-HE-Meta: U2FsdGVkX18R4QlkLZ9jG6fiwphfgm7+7kBWhaXyS5BMs6kNbgneWisYAGpwpPXquPW8eGgov+JqUbEf0VMr2RSIWPc/MyU9NFBTywrh9/8ngmOTqd4vRqrEqppHk+1RJg7PEzTw3lv6SCWgU5rRwhBznN7FhaP5onxTx4+gT6A7wKHwJ5hnOMnVDbEAU4AK3NVI4gELZvhgoNR4lLi9gB+bmaxzkyyMCaPhPumZ5TV57oUM+J4rIdQzGhwqXOOuh/Fm+OGd+faGWqE0esqeUoLFel5kErign5KkMrUs/JjSNWL88sHc10t3Cq69Q+H7m0Ymnd5mJZhS8udZziO9JV9/+P6Md7kV4styatAHgq8sRLTYy4MgmIaIhYuq5trnbq97DE5fvgHqArf8m+TyHw85XacJ2lnNWq6kZ+eKK2v+O/ykiMhGHgr2deocdq3DQroo1YD0wrEJnisZ/izoqnaAFjwjmuQGrxHWe0KyDQpjmCjdbbJWP++iV+8Oi8eXN+bIiFvTa3mD8tpWU4wDJpSbBKujfX0m1ZJA6xRuwWIYweXe68mVYQpoDR0P+RcQHsKOIOxl7NgCzUWrcf3vzrGtvy9fkxO/Atj+4XfzndrJtIAtKCv4lGBrUTcNXMWq9vDvIYpyzBExUbdGiVSmfGlpSLf8a4N34CboHVugEM62PUrnKq3i8nsrzDTWfjFZuzJ5xUftnUZrPray80NtwtKJY/rQk1LuzDHXNabw4El9sqeGe1VspFV9JN1X0i8IGtj1UGh7gPjcF1Dyy47qJlEzYFw/JRSZYMt+/U/U+sD0S/B7nYXsghYnsqjkGw9olrsNE7RLdI2J/9GobWdSog2CPglFQze3mmwoSGKQStluTcpupxISoHU/7hjJLoDFJPIUSg+xJcOnQtWDLwcZTCpJW6/1B3mQUsCU3CgsqNhyA1dUnglgMa5ULYgStC4xgEF5lJAAmEw= 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 Sat Feb 17 20:24: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: 13561590 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 9D7C8C48BC4 for ; Sat, 17 Feb 2024 20:24:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16A128D0002; Sat, 17 Feb 2024 15:24:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 11BE38D0001; Sat, 17 Feb 2024 15:24:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFE318D0002; Sat, 17 Feb 2024 15:24:13 -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 DF01C8D0001 for ; Sat, 17 Feb 2024 15:24:13 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BBD6BA031B for ; Sat, 17 Feb 2024 20:24:13 +0000 (UTC) X-FDA: 81802422786.24.9888889 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 2768C1C0008 for ; Sat, 17 Feb 2024 20:24:11 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="O/VgTJ4c"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.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=1708201452; 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=wDtrTLjiqWsPVeuo4vTv6n84LzAk0FSzwbzXUkhsdCSBBMvN55DOmfY8UHIqM4BG+kMFlt y2TJpwu1UwJ02KDzWMfPGARPA3yZqzVEsRYjTViIyINPlC5Iv8UdI8TjcXsdWxbO88pnXa ejvTBX/SUVJe7RB250u40kpiPKa7/CM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="O/VgTJ4c"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.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=1708201452; a=rsa-sha256; cv=none; b=yAQMFLaKjga+8YuX2q0iFHGbCW10uGw6tqfBg5FEPSH0J3wP+qBhek4S6zyB4SnKSBgTaF PLkwG1n8jXywbHE2hROLrSitbcELSSkldWd1NE/EbrLCjd0KeCXoQmBfAzZNsXa6MVv0lg SQWLRgzctev92i0XJezyJ33OJEEwBgI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4792560109; Sat, 17 Feb 2024 20:24:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7B52C433C7; Sat, 17 Feb 2024 20:24:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708201451; bh=r6dLn2R32hxUVKrwHaR6P90sYMJO3HfuXaP1srQuHsY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=O/VgTJ4chu/g5D0kuQ6IwQrqk6Yged1gYNOnPpILQjot3IwuwxhS0tjBHhH+sQ2Kz Zxyb7DTRLGPN4oi1a1lmsh4iMS7n4x8eU7JR4n/7kJCgHm31IjaEMLd1aj3WKlJZTI cWR5pWetfkjmwe/CpCU4IWr+5zr/kolzJq/4IHeq53kuEhX7f+Lj34sgVaaCR9TUTA WqRRhpu5EBPzA0IeI1/a8ljmj1zl5QVpNFm6gr31iF/Lh2h1sWihqI5TErBNv7U0Gl nkriuby+Se6wuvehqDAuLb9N0LS2Jbw55eloingd6OQJgzmXnWAbWh+8Yghq/aV+hZ 9cHhYH/qLF81Q== Subject: [PATCH v2 5/6] 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: Sat, 17 Feb 2024 15:24:08 -0500 Message-ID: <170820144894.6328.13052830860966450674.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> References: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: omxmt9axgfb46pzekzi7tr3anqu16bn5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2768C1C0008 X-HE-Tag: 1708201451-708863 X-HE-Meta: U2FsdGVkX18tKMeVp+FHB4QXKZdmoBLuObfN4Nzo8vnXbloBoBR+qMRVWy3LdtTAdrp/xWxWRwGYpZy/99O9LfgfvLE3WSYH/cdm2RxI8YHTdZv/bp7+Fzi0geCmNYZeOUqZO1+bWlqGJongMXppLwJhZCPaw9yF2DFDkknFXiAwcu6TRFUHg5oPkXc+pX/L/YUjb2i29Mgp4jSdJmdMAob39VOGRqKSsTsiX92zk3ObE4fPpBIDK60u7HOHUgHCF85ZvPVqUKD9GqhAb9JPfUOK33cSCO8c6fyfndbcotKGbLSvEt0X+Vu6wmVMccf6LoBcqcYHRxcuCd4sTdVKAGhuUAZAd6l0iQWq2tOoZKC8nu54l5/KK2U3y43yUeeBk24FBrQV3nuVWdSXF5Bu8t0/K6V1RmdFYVS5F0YEF+XC0UB9Cok5gh2NxtxT1XhnJAuCGGteP1uMVJRbFO4fQDHBKeycrM45Buw21uKEjAhBZCghzgKvugBhwYPdjVTkpUUdf44BI9CbT3M/lMBHweFpLzOqyuhIz9cIlugHs4hHCx9ycLh6Bv5jRcq/fUCCF2g7xTyT0j5UlAsF2pOPLTneZhHlaenfGwgHN295RUAgfShzHxTalPUDboM9KXH/etxiDUhWSOlTG2CndMqOPMJZ9hUKdvQgd6EOtm0bA53iIAPhNhuemf6XW2aZLZY8vMrhqNXn/xy9uEt+kLZMWOmsercexin5TBxBnZdNKLBz6ogOFJ7cVB+JkyTV4F46jrUAJ7d/zk8yQ8nxANGDPjnv56Ii9PiqMEPsrZHW16fip+kaDbCe+uNU6fbgbzZBCyUxzSyPvxsPMUAJ5niV2wZ3xAsgUC0nz6KrlNBygG31OBIg8iOL49V6iV6CWQK91z+dWQvPkDUSKvc9oceoikVNDajrxhvN1zc8V5OoHbxE3W8KZ7S0hlM7Sw+nur00workMwK7r9SqITeMwUu CkrKJAxY OY/+FRphy405H7jifXbOgisxWpGp2s/3ByrWqzzZTHYWd94CSB0igomZ3r4qifBmD3MEppVhGfNG2gg94Jqres6w4M6LaKZrpMJ3Yfd+TZ+uoFdTdz3FspcYiaOsIUHdwit1ZmFTjQZcCUMrlm6kaQutLiacz6Otow2dy/Tsz3uSZ9iL+fqmTydWgiA2H+frru0BNCv8W4xvqzgwpZCXYQObGskRcZnuscG2mltXSUgBLeEqLrvPbM6lu4Zz5OymXWOXRAJig5KbcwFg= 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 Sat Feb 17 20:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13561591 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 F2D82C48BC4 for ; Sat, 17 Feb 2024 20:24:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 848FD8D000A; Sat, 17 Feb 2024 15:24:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F8A48D0001; Sat, 17 Feb 2024 15:24:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 699D38D000A; Sat, 17 Feb 2024 15:24:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 549558D0001 for ; Sat, 17 Feb 2024 15:24:21 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F00BC1C029B for ; Sat, 17 Feb 2024 20:24:20 +0000 (UTC) X-FDA: 81802423080.27.6C517DA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 4632A40004 for ; Sat, 17 Feb 2024 20:24:19 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hily6QXJ; spf=pass (imf04.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=1708201459; 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=enSJEC+a309h9BZDKMG+FAfIIaZiXnFN47ab++juM4Y=; b=GqWEpNeyEQhPR+0QN8bWN+lX7MIrvke5jOQnNt7PoO0i69C1BFbt+28lH+iULylz6LOcGb BNN0x1ixJzlboN1Eg0vQoJ0CcAW34Eo44LIB+OsJD1dGnqKi30/8AYU5jKJELKIO5fMKVI jEIIFmnaWaw0Ap//3x31x5HcGlf45Gw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708201459; a=rsa-sha256; cv=none; b=XmI1RmOkiCQ9P/qNlMSyfCCKRPFVr07Q9YYDBSusBoEVKP967rriHW3UBBAsaQFqPAkpeU 8Fe3EAWFfSbrVnU/StDObvc24gSH+Crma1YczK+SxrlSiw43/xY8qegZWTsI1sKKbhKc4n cGvf+VFFJOjpC7ie4aqIaSCPxfi+nAY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hily6QXJ; spf=pass (imf04.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 7026B60916; Sat, 17 Feb 2024 20:24:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B1A2C433F1; Sat, 17 Feb 2024 20:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708201458; bh=iJhBU4UKeak6qEJexG79zX3vwwtlWw+1xSLFESXosd8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Hily6QXJZ3MvOQfoHfmflOHSKjso6T7su5pOg1uRjgLZmE6bAK8Lyq/uERlhPLE6t sX2yH/nhAs6Ss3kB2NDRWijgMg9D+5/x3WC+AeJxc4pcG5reGPcPo6z8xuAWCuOWOI Ve02Le0hloVNEKIKxliDpYgSi+MVDE33yPWaXwDbMyrBVYu1c1ly4yey/kR9SxpuYM mpDRY6f9LSwab7UCGnvQvL/WFnHXaCg+vVXWzlMIdHBJy8j6lccu1EowhuPknUYwuw 9OXU/VwaeYJHMptnia1WNs5QVLPJhBk6e07ogG7mlf/U7xZRkhz9IJgiQxgzpSwjib TXq/fl/0XvXHg== Subject: [PATCH v2 6/6] 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: Sat, 17 Feb 2024 15:24:16 -0500 Message-ID: <170820145616.6328.12620992971699079156.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> References: <170820083431.6328.16233178852085891453.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4632A40004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: fzh31ujz3u6wqbjggzna7zr4ncbfmjys X-HE-Tag: 1708201459-927519 X-HE-Meta: U2FsdGVkX1/qEMMCbmCT+aZV1RRV5YKlnQoyarmXzW6zk2H884yjYwTHJ2xNf+z2dB+doYHuCN1BNhNLR3cPbLh9LcrVtmmsqYEYbsesvhUakhn7fJjyfGYbKaknUTdZ7NO22kppVWndNKWUTKxY/EAhcNhLd22iFBGP56E81nFOsD/+VfBW90BPBuGpZZY1zrYYC5qMK9Ew6s3Y/ztEbehQJfL3MZygS1gSPE8D7oKnfe5PpnH0kcNnF/CZHU+I1VVVQGEqr7xD9OU78q5qkl7sNNKj5wT5Sl9xLY89TdkTloj9b5EE3DlFohssDvhtnV97AcGk5tIRqk4VCK/ipqxNt4qUdviKZ+PONSuWHXMSp8DWDMr4KxhOgEOR24JMyWlnKCMf9tCOCisGhn3hAmoA9xdxR7oAT5O8DHK8olmyRkC/5mSYo6o4WfdTR2RXRn9Jn7sf8mg77Vyqqs7gSZpXX7ESNhnVWaf5wqPpEpPWc30LYynix1GC0c0Wkf+2F5Va4abjIPZ/RFOQM1AWG1JV4QwUUA/DKvKTMYmn7YH3+UpGBwf3Q+vuK5cC5ZBptNDIhCvjAANMdzGbrrbOwvnC+E2r6Ctea6m3dHIDgrTAdtJbbs3KyfQwmJBqEEAxxRZAM9BTFTS0IzduNHapclGINjK+gZl1tzWz8p6xmuKU1WrTl6paJscvTaN7ePR2GK7wGEFFVdUzOvK3msCQOZH/jFmZBHBNrVbG/d184EYIH8eXJwQQ1mZMKK0nveq0M7oUiXoe7ZjE9HGA5m276Ux2370xlJ4M6U77EHQ/8LosooMRs6RfGrTrtoYtapFcRLbxkzVClo+BUJSxRV/R72DsfER0lNTctHMO7RyJaAzAnikPvIrk/GKC6nrK/Tl6nFOrpVkHWX/lmNgHk8rgMVSTylPg32lFIZxlg6D77YDX4WVJibebxTtXEAQ6eDm2fNnWcSkLjHX5Gpb5gt9 aEDujFnE c9cic9MYS3JyrRujOWXfI67wzywe+j/GqzZUd2ES4Ij5eAl7nVvTJg1WaIOwBvdsBOLqYf4RgOnxtDTxnRGwoxyLAY8ks1xZ+2BT7sGkbnV4G5/suXyEL8pDDObrdD9MhdFTURqWJB6LxdHeSf3J3iVlr9uV7l6MBZJWsrQmUeY6kK4iqWhyeuEWuOnj7LLaLm1oLQZQsqIi/rlDK4vmGQ9DghPpMsRqv/4KnhXYqIXj2dEqpsDKB0I2CpdWIw42PzXumNFmrR5FSE7aS6urhJ7Jwsrl48ltx/yhxY7BXy/TneOP7y9UfW76jOZussUcA0yrGAJaCskcwHR1su8S84r7TZAUOkTYI+S2NTCwSQ8CIyY5qVm/0f3felg== 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 simple directory offset maximum to signed long (as loff_t is also signed). 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 Reviewed-by: Jan Kara --- fs/libfs.c | 47 +++++++++++++++++++++++------------------------ include/linux/fs.h | 5 +++-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index f7f92a49a418..d3d31197c8e4 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, long offset) { - dentry->d_fsdata = (void *)((uintptr_t)(offset)); + dentry->d_fsdata = (void *)offset; } -static u32 dentry2offset(struct dentry *dentry) +static long dentry2offset(struct dentry *dentry) { - return (u32)((uintptr_t)(dentry->d_fsdata)); + return (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; } @@ -274,20 +274,19 @@ 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) { - 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, + LONG_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; + long offset; offset = dentry2offset(dentry); if (offset == 0) return; - xa_erase(&octx->xa, offset); + mtree_erase(&octx->mt, offset); offset_set(dentry, 0); } @@ -332,7 +331,7 @@ int simple_offset_empty(struct dentry *dentry) 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, LONG_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); + long old_index = dentry2offset(old_dentry); + 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,16 +433,16 @@ 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, LONG_MAX); } static struct dentry *offset_find_next(struct offset_ctx *octx, loff_t offset) { + MA_STATE(mas, &octx->mt, offset, offset); struct dentry *child, *found = NULL; - XA_STATE(xas, &octx->xa, offset); rcu_read_lock(); - child = xas_next_entry(&xas, U32_MAX); + child = mas_find(&mas, LONG_MAX); if (!child) goto out; spin_lock(&child->d_lock); @@ -457,8 +456,8 @@ static struct dentry *offset_find_next(struct offset_ctx *octx, loff_t offset) static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) { - u32 offset = dentry2offset(dentry); struct inode *inode = d_inode(dentry); + long offset = dentry2offset(dentry); return ctx->actor(ctx, dentry->d_name.name, dentry->d_name.len, offset, inode->i_ino, fs_umode_to_dtype(inode->i_mode)); 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);