Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp798678ybz; Wed, 22 Apr 2020 08:11:57 -0700 (PDT) X-Google-Smtp-Source: APiQypIf19K/I0Fr5c2qHA4bY+zxxUKSY5vZPSIKISG1BRIbi+jb1CE5mmEpa8fToEFUGSTaEF38 X-Received: by 2002:a17:907:9c4:: with SMTP id bx4mr25806504ejc.199.1587568317709; Wed, 22 Apr 2020 08:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587568317; cv=none; d=google.com; s=arc-20160816; b=jzL1USNhnGyZeg4CAcncoShjUieYuPbB2iHBlyALANTGmr+lzuVL6tOYJxsfG/uWIK g+OQDgwIT65wcsMWSfQ4GVJQP1KQVLcvSROpp+9VOA1XdaZPOY47/Ev5cMqQ3YJL7sw/ nAXaTsEfNlmqwxlJ2oZ+BP8Pr18s/BhjSyBGCJq3BVysNPNwp2kA9ih+TDjKu4jX9NIm SZcTN52Op5NGaTZTGEoniRMwaMs3MqI4/6+csZkVqydH5Dn3tl1+gCzvp/KcAZbRFoH5 c4EDaJPhmmXN5ybbcaNf3BJvtpm8rektslo861YRI5uqwC7uTsDy3qXkYIuw5G3VFAN4 ZzqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=pRe6n46G2KmUwcgJbSgNzt61qeWsawXQJ5athRSo+EE=; b=IzISBbjtxmUFixFFzLeljgJD6G6eYczMysCJh+uSM31O6EHHnh5ALAiFAi22HHibK7 5KK06KgD/hVT79GIAx5AG+RM2roaFyjY9iJQ1Gw9Xm7GMhaiUB4Wx8wFBWZJHdqCnIz0 VWHNloOuBElPIIfsePP8Z+uU/QbQycPjF/rocqsR9km2KURm+laxK1UsN3mQn/qLKNpA mVZhvF7OwCOlTSnQeGAhWn5MNSEYFt2LNRlqA5wdEDWP+PJorEVXlXozIdkpwcDLtLSJ 6HbL3ph0Vgnhj0X/8ei9rqjqIGEYbODjonIuNU9hwKM5LN9JSuJvjkdOZU6Os8ZKHRyl j39w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m2si1417778ejk.483.2020.04.22.08.11.14; Wed, 22 Apr 2020 08:11:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbgDVPGS (ORCPT + 99 others); Wed, 22 Apr 2020 11:06:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:57990 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbgDVPDG (ORCPT ); Wed, 22 Apr 2020 11:03:06 -0400 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 20257AD48; Wed, 22 Apr 2020 15:03:03 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 5BB1A1E0E6E; Wed, 22 Apr 2020 17:03:03 +0200 (CEST) From: Jan Kara To: Matthew Wilcox Cc: , LKML , Jan Kara Subject: [PATCH 02/23] xarray: Provide xas_erase() and xas_store_noinit() helpers Date: Wed, 22 Apr 2020 17:02:35 +0200 Message-Id: <20200422150256.23473-3-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200422150256.23473-1-jack@suse.cz> References: <20200422150256.23473-1-jack@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. We also introduce xas_store_noinit() helper that works like xas_store() except that it does not initialize marks (and thus has better performance). In the following patches, all callers of xas_store() will be converted either to xas_erase() or xas_store_noinit(). Signed-off-by: Jan Kara --- include/linux/xarray.h | 2 ++ lib/xarray.c | 59 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 14c893433139..06acef49ec95 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -1491,6 +1491,8 @@ 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_store_noinit(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 dae68dd13a02..ed98fc152b17 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -753,20 +753,7 @@ static void update_node(struct xa_state *xas, struct xa_node *node, xas_delete_node(xas); } -/** - * xas_store() - Store this entry in the XArray. - * @xas: XArray operation state. - * @entry: New entry. - * - * If @xas is operating on a multi-index entry, the entry returned by this - * function is essentially meaningless (it may be an internal entry or it - * may be %NULL, even if there are non-NULL entries at some of the indices - * covered by the range). This is not a problem for any current users, - * and can be changed if needed. - * - * Return: The old entry at this index. - */ -void *xas_store(struct xa_state *xas, void *entry) +static void *__xas_store(struct xa_state *xas, void *entry, bool init_marks) { struct xa_node *node; void __rcu **slot = &xas->xa->xa_head; @@ -799,7 +786,7 @@ void *xas_store(struct xa_state *xas, void *entry) if (xas->xa_sibs) xas_squash_marks(xas); } - if (!entry) + if (init_marks) xas_init_marks(xas); for (;;) { @@ -831,8 +818,33 @@ void *xas_store(struct xa_state *xas, void *entry) update_node(xas, node, count, values); return first; } + +/** + * xas_store() - Store this entry in the XArray. + * @xas: XArray operation state. + * @entry: New entry. + * + * If @xas is operating on a multi-index entry, the entry returned by this + * function is essentially meaningless (it may be an internal entry or it + * may be %NULL, even if there are non-NULL entries at some of the indices + * covered by the range). This is not a problem for any current users, + * and can be changed if needed. + * + * Return: The old entry at this index. + */ +void *xas_store(struct xa_state *xas, void *entry) +{ + return __xas_store(xas, entry, true); +} EXPORT_SYMBOL_GPL(xas_store); +/* This is like xas_store() but does not initialize marks on stored entry */ +void *xas_store_noinit(struct xa_state *xas, void *entry) +{ + return __xas_store(xas, entry, false); +} +EXPORT_SYMBOL_GPL(xas_store_noinit); + /** * xas_get_mark() - Returns the state of this mark. * @xas: XArray operation state. @@ -1314,6 +1326,23 @@ 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) +{ + return __xas_store(xas, NULL, true); +} +EXPORT_SYMBOL(xas_erase); + /** * __xa_erase() - Erase this entry from the XArray while locked. * @xa: XArray. -- 2.16.4