linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] list_lru: Prefetch neighboring list entries before acquiring lock
@ 2017-11-29 14:17 Waiman Long
  2017-11-29 21:53 ` Andrew Morton
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Waiman Long @ 2017-11-29 14:17 UTC (permalink / raw)
  To: Andrew Morton, Vladimir Davydov, Johannes Weiner, Dave Chinner
  Cc: linux-kernel, linux-mm, Waiman Long

The list_lru_del() function removes the given item from the LRU list.
The operation looks simple, but it involves writing into the cachelines
of the two neighboring list entries in order to get the deletion done.
That can take a while if the cachelines aren't there yet, thus
prolonging the lock hold time.

To reduce the lock hold time, the cachelines of the two neighboring
list entries are now prefetched before acquiring the list_lru_node's
lock.

Using a multi-threaded test program that created a large number
of dentries and then killed them, the execution time was reduced
from 38.5s to 36.6s after applying the patch on a 2-socket 36-core
72-thread x86-64 system.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 mm/list_lru.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/mm/list_lru.c b/mm/list_lru.c
index f141f0c..65aae44 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -132,8 +132,16 @@ bool list_lru_del(struct list_lru *lru, struct list_head *item)
 	struct list_lru_node *nlru = &lru->node[nid];
 	struct list_lru_one *l;
 
+	/*
+	 * Prefetch the neighboring list entries to reduce lock hold time.
+	 */
+	if (unlikely(list_empty(item)))
+		return false;
+	prefetchw(item->prev);
+	prefetchw(item->next);
+
 	spin_lock(&nlru->lock);
-	if (!list_empty(item)) {
+	if (likely(!list_empty(item))) {
 		l = list_lru_from_kmem(nlru, item);
 		list_del_init(item);
 		l->nr_items--;
-- 
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2017-12-06  8:07 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 14:17 [PATCH] list_lru: Prefetch neighboring list entries before acquiring lock Waiman Long
2017-11-29 21:53 ` Andrew Morton
2017-11-30  0:42   ` Dave Chinner
2017-11-30 13:54     ` Waiman Long
2017-11-30 20:38       ` Dave Chinner
2017-11-30 20:55         ` Waiman Long
2017-11-30 20:47       ` Andrew Morton
2017-11-30 20:49         ` Waiman Long
2017-12-01  0:09         ` Minchan Kim
2017-12-01 14:14           ` Waiman Long
2017-12-01 22:02             ` Dave Chinner
2017-11-30  0:53 ` Minchan Kim
2017-11-30 13:43   ` Waiman Long
2017-11-30 23:53     ` Minchan Kim
2017-11-30 14:34 ` Matthew Wilcox
2017-12-05 14:49 ` Michal Hocko
2017-12-05 23:56   ` Andrew Morton
2017-12-06  8:07     ` Michal Hocko

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).