Re: [Devel] [PATCH rh7 v2 2/2] tcache: speedup tcaches operations on empty tcache.

2016-12-13 Thread Kirill Tkhai
On 13.12.2016 15:28, Andrey Ryabinin wrote:
> If tcache is empty we can bail out immediately from
> tcache_cleancache_[get_page, invalidate_page,invalidate_inode]().
> As a fast way of identifying empty tcache this patch adds global atomic
> counter of tcache nodes.
> 
> https://jira.sw.ru/browse/PSBM-56475
> 
> Signed-off-by: Andrey Ryabinin 

Reviewed-by: Kirill Tkhai 

> ---
> Changes since v1:
>   switch to long counter to prevent possible overflows
> 
>  mm/tcache.c | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/mm/tcache.c b/mm/tcache.c
> index cec5a4e..805adde 100644
> --- a/mm/tcache.c
> +++ b/mm/tcache.c
> @@ -98,6 +98,8 @@ struct tcache_pool {
>   struct tcache_pool_nodeinfo nodeinfo[0];
>  };
>  
> +static atomic_long_t nr_tcache_nodes;
> +
>  /*
>   * Tcache nodes correspond to inodes. A node is created automatically when a
>   * new page is added to the cache (cleancache_put_page) and destroyed either
> @@ -561,6 +563,7 @@ retry:
>   node->pool = pool;
>   node->key = *key;
>   atomic_long_inc(>nr_nodes);
> + atomic_long_inc(_tcache_nodes);
>   __tcache_insert_node(>root, node, rb_link, rb_parent);
>   }
>   spin_unlock_irqrestore(>lock, flags);
> @@ -590,6 +593,7 @@ static void tcache_node_release_fn(struct kref *kref)
>   __tcache_delete_node(>root, node);
>   spin_unlock(>lock);
>  
> + atomic_long_inc(_tcache_nodes);
>   atomic_long_dec(>pool->nr_nodes);
>   kfree(node);
>  }
> @@ -1168,6 +1172,9 @@ static int tcache_cleancache_get_page(int pool_id,
>   struct tcache_node *node;
>   struct page *cache_page = NULL;
>  
> + if (!atomic_long_read(_tcache_nodes))
> + return -1;
> +
>   node = tcache_get_node_and_pool(pool_id, , false);
>   if (node) {
>   cache_page = tcache_detach_page(node, index, true);
> @@ -1192,6 +1199,9 @@ static void tcache_cleancache_invalidate_page(int 
> pool_id,
>   struct tcache_node *node;
>   struct page *page;
>  
> + if (!atomic_long_read(_tcache_nodes))
> + return;
> +
>   node = tcache_get_node_and_pool(pool_id, , false);
>   if (node) {
>   page = tcache_detach_page(node, index, false);
> @@ -1206,6 +1216,9 @@ static void tcache_cleancache_invalidate_inode(int 
> pool_id,
>  {
>   struct tcache_pool *pool;
>  
> + if (!atomic_long_read(_tcache_nodes))
> + return;
> +
>   pool = tcache_get_pool(pool_id);
>   if (pool) {
>   tcache_invalidate_node(pool, );
> 
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7 v2 2/2] tcache: speedup tcaches operations on empty tcache.

2016-12-13 Thread Andrey Ryabinin
If tcache is empty we can bail out immediately from
tcache_cleancache_[get_page, invalidate_page,invalidate_inode]().
As a fast way of identifying empty tcache this patch adds global atomic
counter of tcache nodes.

https://jira.sw.ru/browse/PSBM-56475

Signed-off-by: Andrey Ryabinin 
---
Changes since v1:
  switch to long counter to prevent possible overflows

 mm/tcache.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/mm/tcache.c b/mm/tcache.c
index cec5a4e..805adde 100644
--- a/mm/tcache.c
+++ b/mm/tcache.c
@@ -98,6 +98,8 @@ struct tcache_pool {
struct tcache_pool_nodeinfo nodeinfo[0];
 };
 
+static atomic_long_t nr_tcache_nodes;
+
 /*
  * Tcache nodes correspond to inodes. A node is created automatically when a
  * new page is added to the cache (cleancache_put_page) and destroyed either
@@ -561,6 +563,7 @@ retry:
node->pool = pool;
node->key = *key;
atomic_long_inc(>nr_nodes);
+   atomic_long_inc(_tcache_nodes);
__tcache_insert_node(>root, node, rb_link, rb_parent);
}
spin_unlock_irqrestore(>lock, flags);
@@ -590,6 +593,7 @@ static void tcache_node_release_fn(struct kref *kref)
__tcache_delete_node(>root, node);
spin_unlock(>lock);
 
+   atomic_long_inc(_tcache_nodes);
atomic_long_dec(>pool->nr_nodes);
kfree(node);
 }
@@ -1168,6 +1172,9 @@ static int tcache_cleancache_get_page(int pool_id,
struct tcache_node *node;
struct page *cache_page = NULL;
 
+   if (!atomic_long_read(_tcache_nodes))
+   return -1;
+
node = tcache_get_node_and_pool(pool_id, , false);
if (node) {
cache_page = tcache_detach_page(node, index, true);
@@ -1192,6 +1199,9 @@ static void tcache_cleancache_invalidate_page(int pool_id,
struct tcache_node *node;
struct page *page;
 
+   if (!atomic_long_read(_tcache_nodes))
+   return;
+
node = tcache_get_node_and_pool(pool_id, , false);
if (node) {
page = tcache_detach_page(node, index, false);
@@ -1206,6 +1216,9 @@ static void tcache_cleancache_invalidate_inode(int 
pool_id,
 {
struct tcache_pool *pool;
 
+   if (!atomic_long_read(_tcache_nodes))
+   return;
+
pool = tcache_get_pool(pool_id);
if (pool) {
tcache_invalidate_node(pool, );
-- 
2.7.3

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel