From patchwork Tue Feb 4 14:25:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 11364721 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EF3714B4 for ; Tue, 4 Feb 2020 14:25:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 26BE4217BA for ; Tue, 4 Feb 2020 14:25:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26BE4217BA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5C03C6B0008; Tue, 4 Feb 2020 09:25:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 56FDD6B000A; Tue, 4 Feb 2020 09:25:21 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 485A76B000D; Tue, 4 Feb 2020 09:25:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2F0676B0008 for ; Tue, 4 Feb 2020 09:25:21 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D794C2466 for ; Tue, 4 Feb 2020 14:25:20 +0000 (UTC) X-FDA: 76452667200.23.toad87_2ea6a96a1731f X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,jack@suse.cz,:willy@infradead.org:linux-fsdevel@vger.kernel.org::jack@suse.cz,RULES_HIT:30045:30054:30056:30090,0,RBL:195.135.220.15:@suse.cz:.lbl8.mailshell.net-62.2.6.2 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: toad87_2ea6a96a1731f X-Filterd-Recvd-Size: 3954 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Tue, 4 Feb 2020 14:25:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 801A9AF37; Tue, 4 Feb 2020 14:25:18 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id E754E1E0BB3; Tue, 4 Feb 2020 15:25:15 +0100 (CET) From: Jan Kara To: Matthew Wilcox Cc: , , Jan Kara Subject: [PATCH 2/8] xarray: Provide xas_erase() helper Date: Tue, 4 Feb 2020 15:25:08 +0100 Message-Id: <20200204142514.15826-3-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200204142514.15826-1-jack@suse.cz> References: <20200204142514.15826-1-jack@suse.cz> 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: Currently xas_store() clears marks when stored value is NULL. This is somewhat counter-intuitive and also causes measurable performance impact when mark clearing is not needed (e.g. because marks are already clear). So provide xas_erase() helper (similarly to existing xa_erase()) which stores NULL at given index and also takes care of clearing marks. Use this helper from __xa_erase() and item_kill_tree() in tools/testing. In the following patches, callers that use the mark-clearing property of xas_store() will be converted to xas_erase() and remaining users can enjoy better performance. Signed-off-by: Jan Kara --- include/linux/xarray.h | 1 + lib/xarray.c | 24 +++++++++++++++++++++++- tools/testing/radix-tree/test.c | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 5370716d7010..be6c6950837e 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -1491,6 +1491,7 @@ static inline bool xas_retry(struct xa_state *xas, const void *entry) void *xas_load(struct xa_state *); void *xas_store(struct xa_state *, void *entry); +void *xas_erase(struct xa_state *); void *xas_find(struct xa_state *, unsigned long max); void *xas_find_conflict(struct xa_state *); diff --git a/lib/xarray.c b/lib/xarray.c index 1d9fab7db8da..ae8b7070e82c 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1319,6 +1319,28 @@ static void *xas_result(struct xa_state *xas, void *curr) return curr; } +/** + * xas_erase() - Erase this entry from the XArray + * @xas: XArray operation state. + * + * After this function returns, loading from @index will return %NULL. The + * function also clears all marks associated with the @index. If the index is + * part of a multi-index entry, all indices will be erased and none of the + * entries will be part of a multi-index entry. + * + * Return: The entry which used to be at this index. + */ +void *xas_erase(struct xa_state *xas) +{ + void *entry; + + entry = xas_store(xas, NULL); + xas_init_marks(xas); + + return entry; +} +EXPORT_SYMBOL(xas_erase); + /** * __xa_erase() - Erase this entry from the XArray while locked. * @xa: XArray. @@ -1334,7 +1356,7 @@ static void *xas_result(struct xa_state *xas, void *curr) void *__xa_erase(struct xarray *xa, unsigned long index) { XA_STATE(xas, xa, index); - return xas_result(&xas, xas_store(&xas, NULL)); + return xas_result(&xas, xas_erase(&xas)); } EXPORT_SYMBOL(__xa_erase); diff --git a/tools/testing/radix-tree/test.c b/tools/testing/radix-tree/test.c index a15d0512e633..07dc2b4dc587 100644 --- a/tools/testing/radix-tree/test.c +++ b/tools/testing/radix-tree/test.c @@ -261,7 +261,7 @@ void item_kill_tree(struct xarray *xa) if (!xa_is_value(entry)) { item_free(entry, xas.xa_index); } - xas_store(&xas, NULL); + xas_erase(&xas); } assert(xa_empty(xa));