[Devel] [PATCH rh7 v2 08/10] tcache: Make tcache_nodeinfo::nr_pages atomic_long_t
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Aug 16 14:53:09 MSK 2017
This allows to do not avoid tcache_nodeinfo::lock
to change nr_pages.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
mm/tcache.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/mm/tcache.c b/mm/tcache.c
index dc0e8fbb990..f91c66690af 100644
--- a/mm/tcache.c
+++ b/mm/tcache.c
@@ -160,7 +160,7 @@ struct tcache_nodeinfo {
struct rb_node __rcu *rb_first;
/* total number of pages on all LRU lists corresponding to this node */
- unsigned long nr_pages;
+ atomic_long_t nr_pages;
} ____cacheline_aligned_in_smp;
/*
@@ -263,8 +263,7 @@ static void tcache_lru_add(struct tcache_pool *pool, struct page *page)
spin_lock(&ni->lock);
spin_lock(&pni->lock);
-
- ni->nr_pages++;
+ atomic_long_inc(&ni->nr_pages);
pni->nr_pages++;
list_add_tail(&page->lru, &pni->lru);
@@ -310,7 +309,7 @@ static void tcache_lru_del(struct tcache_pool *pool, struct page *page,
goto out;
__tcache_lru_del(pni, page);
- ni->nr_pages--;
+ atomic_long_dec(&ni->nr_pages);
if (reused)
pni->recent_gets++;
@@ -1072,7 +1071,7 @@ tcache_lru_isolate(int nid, struct page **pages, int nr_to_isolate)
if (!nr_isolated)
goto unlock;
- ni->nr_pages -= nr_isolated;
+ atomic_long_sub(nr_isolated, &ni->nr_pages);
if (!RB_EMPTY_NODE(rbn)) {
rb_erase(rbn, &ni->reclaim_tree);
@@ -1135,9 +1134,7 @@ tcache_try_to_reclaim_page(struct tcache_pool *pool, int nid)
if (!ret)
goto out;
- spin_lock(&ni->lock);
- ni->nr_pages -= ret;
- spin_unlock(&ni->lock);
+ atomic_long_dec(&ni->nr_pages);
if (!__tcache_reclaim_page(page))
page = NULL;
@@ -1162,7 +1159,12 @@ static struct page *tcache_alloc_page(struct tcache_pool *pool)
static unsigned long tcache_shrink_count(struct shrinker *shrink,
struct shrink_control *sc)
{
- return tcache_nodeinfo[sc->nid].nr_pages;
+ atomic_long_t *nr_pages = &tcache_nodeinfo[sc->nid].nr_pages;
+ long ret;
+
+ ret = atomic_long_read(nr_pages);
+ WARN_ON(ret < 0);
+ return ret >= 0 ? ret : 0;
}
#define TCACHE_SCAN_BATCH 128UL
@@ -1379,6 +1381,7 @@ static int __init tcache_nodeinfo_init(void)
for (i = 0; i < nr_node_ids; i++) {
ni = &tcache_nodeinfo[i];
spin_lock_init(&ni->lock);
+ atomic_long_set(&ni->nr_pages, 0);
ni->reclaim_tree = RB_ROOT;
update_ni_rb_first(ni);
}
More information about the Devel
mailing list