[Devel,RHEL7,COMMIT] tcache: Move add/sub out of pni->lock

Submitted by Konstantin Khorenko on Aug. 31, 2017, 3:18 p.m.

Details

Message ID 201708311518.v7VFIMaZ018011@finist_ce7.work
State New
Series "tcache: Manage LRU lists under per-filesystem lock"
Headers show

Commit Message

Konstantin Khorenko Aug. 31, 2017, 3:18 p.m.
The commit is pushed to "branch-rh7-3.10.0-514.26.1.vz7.35.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.26.1.vz7.35.5
------>
commit 673358de1fce85596dcd17e1bde8b7a9639fcc1c
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Thu Aug 31 18:18:22 2017 +0300

    tcache: Move add/sub out of pni->lock
    
    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>
    Acked-by: Andrey Ryabinin <aryabinin@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 5faa390..d1a2c53 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)
@@ -1071,8 +1075,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))
@@ -1088,6 +1090,8 @@  tcache_lru_isolate(int nid, struct page **pages, int nr_to_isolate)
 	spin_unlock_irq(&pni->lock);
 	tcache_put_pool(pni->pool);
 out:
+	if (nr_isolated)
+		atomic_long_sub(nr_isolated, &ni->nr_pages);
 	return nr_isolated;
 }