linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Matthew Wilcox <willy@infradead.org>
Cc: <linux-fsdevel@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 02/23] xarray: Provide xas_erase() and xas_store_noinit() helpers
Date: Wed, 22 Apr 2020 17:02:35 +0200	[thread overview]
Message-ID: <20200422150256.23473-3-jack@suse.cz> (raw)
In-Reply-To: <20200422150256.23473-1-jack@suse.cz>

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 <jack@suse.cz>
---
 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


  parent reply	other threads:[~2020-04-22 15:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22 15:02 [PATCH 0/23 v2] mm: Speedup page cache truncation Jan Kara
2020-04-22 15:02 ` [PATCH 01/23] xarray: Remove stale comment Jan Kara
2020-04-22 15:02 ` Jan Kara [this message]
2020-04-22 15:02 ` [PATCH 03/23] xarray: Use xas_store_noinit() in __xa_store, __xa_insert, __xa_alloc Jan Kara
2020-04-22 15:02 ` [PATCH 04/23] xarray: Switch xa_store_range() to use xas_store_noinit() Jan Kara
2020-04-22 15:02 ` [PATCH 05/23] xarray: Use xas_erase() in __xa_erase() Jan Kara
2020-04-22 15:02 ` [PATCH 06/23] xarray: Explicitely set XA_FREE_MARK in __xa_cmpxchg() Jan Kara
2020-04-22 15:02 ` [PATCH 07/23] xarray: Switch __xa_cmpxchg() to use xas_store_noinit() Jan Kara
2020-04-22 15:02 ` [PATCH 08/23] dax: Use xas_erase() in __dax_invalidate_entry() Jan Kara
2020-04-22 15:02 ` [PATCH 09/23] dax: Use dax_store_noinit() in grab_mapping_entry() Jan Kara
2020-04-22 15:02 ` [PATCH 10/23] dax: Convert xas_store() to xas_store_noinit() Jan Kara
2020-04-22 15:02 ` [PATCH 11/23] mm: Use xas_erase() in page_cache_delete_batch() Jan Kara
2020-04-22 15:02 ` [PATCH 12/23] mm: Use xas_erase() in collapse_file() Jan Kara
2020-04-22 15:02 ` [PATCH 13/23] mm: Use xas_store_noinit() when storing non-NULL Jan Kara
2020-04-22 15:02 ` [PATCH 14/23] workingset: Use xas_store_noinit() to clear shadow entry Jan Kara
2020-04-22 15:02 ` [PATCH 15/23] swap: Use xas_erase() when removing page from swap cache Jan Kara
2020-04-22 15:02 ` [PATCH 16/23] idr: Use xas_erase() in ida_destroy() Jan Kara
2020-04-22 15:02 ` [PATCH 17/23] idr: Use xas_erase() in ida_free() Jan Kara
2020-04-22 15:02 ` [PATCH 18/23] idr: Convert xas_store() to xas_store_noinit() Jan Kara
2020-04-22 15:02 ` [PATCH 19/23] testing: Use xas_erase() to remove entries from xarray Jan Kara
2020-04-22 15:02 ` [PATCH 20/23] testing: Use xas_store_noinit() for non-NULL entries Jan Kara
2020-04-22 15:02 ` [PATCH 21/23] testing: Introduce xa_erase_order() and use it Jan Kara
2020-04-22 15:02 ` [PATCH 22/23] testing: Switch xa_store_order() to xas_store_noinit() Jan Kara
2020-04-22 15:02 ` [PATCH 23/23] xarray: Remove xas_store() Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200422150256.23473-3-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).