From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2383C2D0B1 for ; Tue, 4 Feb 2020 14:25:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 68A6420730 for ; Tue, 4 Feb 2020 14:25:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68A6420730 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) Received: by kanga.kvack.org (Postfix, from userid 40) id 56FDD6B000A; Tue, 4 Feb 2020 09:25:21 -0500 (EST) 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-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-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)); -- 2.16.4