[Devel] [PATCH rh7 6/9] tcache: Move reclaim weight calculations out of __tcache_insert_reclaim_node()

Kirill Tkhai ktkhai at virtuozzo.com
Tue Aug 15 14:24:08 MSK 2017


Update the weight after recent_gets or recent_puts changed.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 mm/tcache.c |   31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/mm/tcache.c b/mm/tcache.c
index f70de72c3c1..21f1347b517 100644
--- a/mm/tcache.c
+++ b/mm/tcache.c
@@ -243,6 +243,26 @@ static inline bool tcache_check_events(struct tcache_nodeinfo *ni,
 	return true;
 }
 
+static inline unsigned long tcache_page_timestamp(struct page *page)
+{
+	return page->private;
+}
+
+static void update_reclaim_weight(struct tcache_nodeinfo *ni,
+				  struct tcache_pool_nodeinfo *pni)
+{
+	/*
+	 * Prohibit changing of the weights, when there are may be
+	 * a parallel queuer. Otherwise, this will be a surprise for it.
+	 */
+	assert_spin_locked(&ni->lock);
+	assert_spin_locked(&pni->lock);
+
+	pni->reuse_ratio = pni->recent_gets * 100 / (pni->recent_puts + 1);
+	pni->timestamp = tcache_page_timestamp(list_first_entry(&pni->lru,
+								struct page, lru));
+}
+
 /*
  * Add a page to the LRU list. This effectively makes the page visible to the
  * shrinker, so it must only be called after the page was properly initialized
@@ -270,6 +290,7 @@ static void tcache_lru_add(struct tcache_pool *pool, struct page *page)
 	if (tcache_check_events(ni, pni) || RB_EMPTY_NODE(&pni->reclaim_node)) {
 		if (!RB_EMPTY_NODE(&pni->reclaim_node))
 			rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
+		update_reclaim_weight(ni, pni);
 		__tcache_insert_reclaim_node(ni, pni);
 	}
 
@@ -311,6 +332,7 @@ static void tcache_lru_del(struct tcache_pool *pool, struct page *page,
 	if (tcache_check_events(ni, pni)) {
 		if (!RB_EMPTY_NODE(&pni->reclaim_node))
 			rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
+		update_reclaim_weight(ni, pni);
 		__tcache_insert_reclaim_node(ni, pni);
 	}
 out:
@@ -699,11 +721,6 @@ static inline struct tcache_node *tcache_page_node(struct page *page)
 	return (struct tcache_node *)page->mapping;
 }
 
-static inline unsigned long tcache_page_timestamp(struct page *page)
-{
-	return page->private;
-}
-
 static inline void tcache_init_page(struct page *page,
 				    struct tcache_node *node, pgoff_t index)
 {
@@ -977,10 +994,6 @@ __tcache_insert_reclaim_node(struct tcache_nodeinfo *ni,
 
 	BUG_ON(list_empty(&pni->lru));
 
-	pni->reuse_ratio = pni->recent_gets * 100 / (pni->recent_puts + 1);
-	pni->timestamp = tcache_page_timestamp(list_first_entry(&pni->lru,
-							struct page, lru));
-
 	while (*link) {
 		parent = *link;
 		pni2 = rb_entry(parent, struct tcache_pool_nodeinfo,



More information about the Devel mailing list