[Devel,rh7,v2,07/10] tcache: Move erase-insert logic out of tcache_check_events()

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

Details

Message ID 150288437990.16671.18437834784615317611.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.
Make the function return true, when erase-insert (requeue)
should be executed. Move erase-insert out of the function.

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

Patch hide | download patch | download mbox

diff --git a/mm/tcache.c b/mm/tcache.c
index 2c97c5cb6d5..dc0e8fbb990 100644
--- a/mm/tcache.c
+++ b/mm/tcache.c
@@ -216,8 +216,7 @@  static struct rb_node *update_ni_rb_first(struct tcache_nodeinfo *ni)
 static void __tcache_insert_reclaim_node(struct tcache_nodeinfo *ni,
 					 struct tcache_pool_nodeinfo *pni);
 
-static inline void __tcache_check_events(struct tcache_nodeinfo *ni,
-					 struct tcache_pool_nodeinfo *pni)
+static inline bool tcache_check_events(struct tcache_pool_nodeinfo *pni)
 {
 	/*
 	 * We don't want to rebalance reclaim_tree on each get/put, because it
@@ -228,7 +227,7 @@  static inline void __tcache_check_events(struct tcache_nodeinfo *ni,
 	 */
 	pni->events++;
 	if (likely(pni->events < 1024))
-		return;
+		return false;
 
 	pni->events = 0;
 
@@ -238,7 +237,7 @@  static inline void __tcache_check_events(struct tcache_nodeinfo *ni,
 	 * it will be done by the shrinker once it tries to scan it.
 	 */
 	if (unlikely(list_empty(&pni->lru)))
-		return;
+		return false;
 
 	/*
 	 * This can only happen if the node was removed from the tree on pool
@@ -246,11 +245,9 @@  static inline void __tcache_check_events(struct tcache_nodeinfo *ni,
 	 * then.
 	 */
 	if (unlikely(RB_EMPTY_NODE(&pni->reclaim_node)))
-		return;
+		return false;
 
-	rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
-	__tcache_insert_reclaim_node(ni, pni);
-	update_ni_rb_first(ni);
+	return true;
 }
 
 /*
@@ -277,11 +274,12 @@  static void tcache_lru_add(struct tcache_pool *pool, struct page *page)
 		pni->recent_puts /= 2;
 	}
 
-	__tcache_check_events(ni, pni);
-
-	if (unlikely(RB_EMPTY_NODE(&pni->reclaim_node)))
+	if (tcache_check_events(pni) || RB_EMPTY_NODE(&pni->reclaim_node)) {
+		if (!RB_EMPTY_NODE(&pni->reclaim_node))
+			rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
 		__tcache_insert_reclaim_node(ni, pni);
-
+		update_ni_rb_first(ni);
+	}
 	spin_unlock(&pni->lock);
 	spin_unlock(&ni->lock);
 }
@@ -317,7 +315,12 @@  static void tcache_lru_del(struct tcache_pool *pool, struct page *page,
 	if (reused)
 		pni->recent_gets++;
 
-	__tcache_check_events(ni, pni);
+	if (tcache_check_events(pni)) {
+		if (!RB_EMPTY_NODE(&pni->reclaim_node))
+			rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
+		__tcache_insert_reclaim_node(ni, pni);
+		update_ni_rb_first(ni);
+	}
 out:
 	spin_unlock(&pni->lock);
 	spin_unlock(&ni->lock);
@@ -944,7 +947,7 @@  tcache_remove_from_reclaim_trees(struct tcache_pool *pool)
 			rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
 			update_ni_rb_first(ni);
 			/*
-			 * Clear the node for __tcache_check_events() not to
+			 * Clear the node for tcache_check_events() not to
 			 * reinsert the pool back into the tree.
 			 */
 			RB_CLEAR_NODE(&pni->reclaim_node);

Comments

Kirill Tkhai Aug. 16, 2017, 1:39 p.m.
On 16.08.2017 16:40, Andrey Ryabinin wrote:
> 
> 
> On 08/16/2017 02:53 PM, Kirill Tkhai wrote:
>> Make the function return true, when erase-insert (requeue)
>> should be executed. Move erase-insert out of the function.
>>
>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
> 
>>  /*
>> @@ -277,11 +274,12 @@ static void tcache_lru_add(struct tcache_pool *pool, struct page *page)
>>  		pni->recent_puts /= 2;
>>  	}
>>  
>> -	__tcache_check_events(ni, pni);
>> -
>> -	if (unlikely(RB_EMPTY_NODE(&pni->reclaim_node)))
>> +	if (tcache_check_events(pni) || RB_EMPTY_NODE(&pni->reclaim_node)) {
>> +		if (!RB_EMPTY_NODE(&pni->reclaim_node))
>> +			rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
>>  		__tcache_insert_reclaim_node(ni, pni);
>> -
>> +		update_ni_rb_first(ni);
> 
> Ok, now I see that you added it here. I guess that supposed to be in patch 05.

Ok, I'll move it to patch 5/10. Thanks.

> 
>> +	}
>>  	spin_unlock(&pni->lock);
>>  	spin_unlock(&ni->lock);
>>  }
Andrey Ryabinin Aug. 16, 2017, 1:40 p.m.
On 08/16/2017 02:53 PM, Kirill Tkhai wrote:
> Make the function return true, when erase-insert (requeue)
> should be executed. Move erase-insert out of the function.
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---

>  /*
> @@ -277,11 +274,12 @@ static void tcache_lru_add(struct tcache_pool *pool, struct page *page)
>  		pni->recent_puts /= 2;
>  	}
>  
> -	__tcache_check_events(ni, pni);
> -
> -	if (unlikely(RB_EMPTY_NODE(&pni->reclaim_node)))
> +	if (tcache_check_events(pni) || RB_EMPTY_NODE(&pni->reclaim_node)) {
> +		if (!RB_EMPTY_NODE(&pni->reclaim_node))
> +			rb_erase(&pni->reclaim_node, &ni->reclaim_tree);
>  		__tcache_insert_reclaim_node(ni, pni);
> -
> +		update_ni_rb_first(ni);

Ok, now I see that you added it here. I guess that supposed to be in patch 05.

> +	}
>  	spin_unlock(&pni->lock);
>  	spin_unlock(&ni->lock);
>  }