[Devel,rh7,v2,10/10] tcache: Move add/sub out of pni->lock

Submitted by Kirill Tkhai on Aug. 16, 2017, 11:53 a.m.

Details

Message ID 150288440598.16671.14194756689538519464.stgit@localhost.localdomain
State New
Series "tcache: Manage LRU lists under per-filesystem lock"
Headers show

Commit Message

Kirill Tkhai Aug. 16, 2017, 11:53 a.m.
This minimizes number of operations happening under pni->lock.
Note, that we do add before linking to the list, so parallel
shrink does not make nr_pages negative.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 mm/tcache.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/tcache.c b/mm/tcache.c
index 2b82a00c647..97ab1ccdd9e 100644
--- a/mm/tcache.c
+++ b/mm/tcache.c
@@ -261,8 +261,9 @@  static void tcache_lru_add(struct tcache_pool *pool, struct page *page)
 	struct tcache_nodeinfo *ni = &tcache_nodeinfo[nid];
 	struct tcache_pool_nodeinfo *pni = &pool->nodeinfo[nid];
 
-	spin_lock(&pni->lock);
 	atomic_long_inc(&ni->nr_pages);
+
+	spin_lock(&pni->lock);
 	pni->nr_pages++;
 	list_add_tail(&page->lru, &pni->lru);
 
@@ -300,6 +301,7 @@  static void tcache_lru_del(struct tcache_pool *pool, struct page *page,
 	int nid = page_to_nid(page);
 	struct tcache_nodeinfo *ni = &tcache_nodeinfo[nid];
 	struct tcache_pool_nodeinfo *pni = &pool->nodeinfo[nid];
+	bool deleted = false;
 
 	spin_lock(&pni->lock);
 
@@ -308,7 +310,7 @@  static void tcache_lru_del(struct tcache_pool *pool, struct page *page,
 		goto out;
 
 	__tcache_lru_del(pni, page);
-	atomic_long_dec(&ni->nr_pages);
+	deleted = true;
 
 	if (reused)
 		pni->recent_gets++;
@@ -323,6 +325,8 @@  static void tcache_lru_del(struct tcache_pool *pool, struct page *page,
 	}
 out:
 	spin_unlock(&pni->lock);
+	if (deleted)
+		atomic_long_dec(&ni->nr_pages);
 }
 
 static int tcache_create_pool(void)
@@ -1070,8 +1074,6 @@  tcache_lru_isolate(int nid, struct page **pages, int nr_to_isolate)
 	if (!nr_isolated)
 		goto unlock;
 
-	atomic_long_sub(nr_isolated, &ni->nr_pages);
-
 	if (!RB_EMPTY_NODE(rbn) || !list_empty(&pni->lru)) {
 		spin_lock(&ni->lock);
 		if (!RB_EMPTY_NODE(rbn))
@@ -1087,6 +1089,8 @@  tcache_lru_isolate(int nid, struct page **pages, int nr_to_isolate)
 	spin_unlock(&pni->lock);
 	tcache_put_pool(pni->pool);
 out:
+	if (nr_isolated)
+		atomic_long_sub(nr_isolated, &ni->nr_pages);
 	return nr_isolated;
 }