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

Konstantin Khorenko khorenko at virtuozzo.com
Thu Aug 31 18:18:22 MSK 2017


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 at 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 at virtuozzo.com>
    Acked-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/tcache.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

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;
 }
 


More information about the Devel mailing list