* [PATCH] bcache: fix error count in memory shrink
@ 2018-01-31 2:46 tang.junhui
2018-03-05 22:02 ` Michael Lyle
0 siblings, 1 reply; 3+ messages in thread
From: tang.junhui @ 2018-01-31 2:46 UTC (permalink / raw)
To: colyli, mlyle; +Cc: linux-bcache, linux-block, tang.junhui
From: Tang Junhui <tang.junhui@zte.com.cn>
In bch_mca_scan(), nr btree nodes are expected to shrink, so the for(;;)
loop need to satisfy the condition freed < nr.
And since c->btree_cache_used always decrease after mca_data_free() calling
in for(;;) loop, so we need a auto variable to record c->btree_cache_used
before the for(;;) loop.
Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
---
drivers/md/bcache/btree.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 81e8dc3..7e9ef3d 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -664,6 +664,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
struct btree *b, *t;
unsigned long i, nr = sc->nr_to_scan;
unsigned long freed = 0;
+ unsigned int btree_cache_used;
if (c->shrinker_disabled)
return SHRINK_STOP;
@@ -700,7 +701,8 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
}
}
- for (i = 0; (nr--) && i < c->btree_cache_used; i++) {
+ btree_cache_used = c->btree_cache_used;
+ for (i = 0; freed < nr && i < btree_cache_used; i++) {
if (list_empty(&c->btree_cache))
goto out;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] bcache: fix error count in memory shrink
2018-01-31 2:46 [PATCH] bcache: fix error count in memory shrink tang.junhui
@ 2018-03-05 22:02 ` Michael Lyle
0 siblings, 0 replies; 3+ messages in thread
From: Michael Lyle @ 2018-03-05 22:02 UTC (permalink / raw)
To: tang.junhui, colyli; +Cc: linux-bcache, linux-block
Hi Tang Junhui---
I'm not really sure about this one. It changes the semantics of the
amount of work done-- nr_to_scan now means number of things to free
instead of the number to check.
If the system is under severe memory pressure, and most of the cache is
essential/actively used, this could greatly increase the amount of work
done.
As to the i < btree_cache_used, it's arguably a bug, but it only reduces
the amount of work done if the cache is very, very small.
Mike
On 01/30/2018 06:46 PM, tang.junhui@zte.com.cn wrote:
> From: Tang Junhui <tang.junhui@zte.com.cn>
>
> In bch_mca_scan(), nr btree nodes are expected to shrink, so the for(;;)
> loop need to satisfy the condition freed < nr.
> And since c->btree_cache_used always decrease after mca_data_free() calling
> in for(;;) loop, so we need a auto variable to record c->btree_cache_used
> before the for(;;) loop.
>
> Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
> ---
> drivers/md/bcache/btree.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
> index 81e8dc3..7e9ef3d 100644
> --- a/drivers/md/bcache/btree.c
> +++ b/drivers/md/bcache/btree.c
> @@ -664,6 +664,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
> struct btree *b, *t;
> unsigned long i, nr = sc->nr_to_scan;
> unsigned long freed = 0;
> + unsigned int btree_cache_used;
>
> if (c->shrinker_disabled)
> return SHRINK_STOP;
> @@ -700,7 +701,8 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
> }
> }
>
> - for (i = 0; (nr--) && i < c->btree_cache_used; i++) {
> + btree_cache_used = c->btree_cache_used;
> + for (i = 0; freed < nr && i < btree_cache_used; i++) {
> if (list_empty(&c->btree_cache))
> goto out;
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] bcache: fix error count in memory shrink
@ 2018-03-06 6:11 tang.junhui
0 siblings, 0 replies; 3+ messages in thread
From: tang.junhui @ 2018-03-06 6:11 UTC (permalink / raw)
To: mlyle; +Cc: linux-block, linux-bcache, tang.junhui
Hi Mike---
>Hi Tang Junhui---
>
>I'm not really sure about this one. It changes the semantics of the
>amount of work done-- nr_to_scan now means number of things to free
>instead of the number to check.
>
The code seems to be designed as that, sc->nr_to_scan marks how much btree
nodes to scan in c->btree_cache_used, and it doesn't include the btree
nodes in c->btree_cache_freeable.
>If the system is under severe memory pressure, and most of the cache is
>essential/actively used, this could greatly increase the amount of work
>done.
>
Yes, I didn't relize this.
>As to the i < btree_cache_used, it's arguably a bug, but it only reduces
>the amount of work done if the cache is very, very small.
>
I think it is a bug, I'll send a new patch to add variable to record
c->btree_cache_used befor for(;;) loop.
>Mike
>
>On 01/30/2018 06:46 PM, tang.junhui@zte.com.cn wrote:
>> From: Tang Junhui <tang.junhui@zte.com.cn>
>>
>> In bch_mca_scan(), nr btree nodes are expected to shrink, so the for(;;)
>> loop need to satisfy the condition freed < nr.
>> And since c->btree_cache_used always decrease after mca_data_free() calling
>> in for(;;) loop, so we need a auto variable to record c->btree_cache_used
>> before the for(;;) loop.
>>
>> Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
>> ---
>> drivers/md/bcache/btree.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
>> index 81e8dc3..7e9ef3d 100644
>> --- a/drivers/md/bcache/btree.c
>> +++ b/drivers/md/bcache/btree.c
>> @@ -664,6 +664,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
>> struct btree *b, *t;
>> unsigned long i, nr = sc->nr_to_scan;
>> unsigned long freed = 0;
>> + unsigned int btree_cache_used;
>>
>> if (c->shrinker_disabled)
>> return SHRINK_STOP;
>> @@ -700,7 +701,8 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
>> }
>> }
>>
>> - for (i = 0; (nr--) && i < c->btree_cache_used; i++) {
>> + btree_cache_used = c->btree_cache_used;
>> + for (i = 0; freed < nr && i < btree_cache_used; i++) {
>> if (list_empty(&c->btree_cache))
>> goto out;
>>
>>
Thanks,
Tang Junhui
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-06 6:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-31 2:46 [PATCH] bcache: fix error count in memory shrink tang.junhui
2018-03-05 22:02 ` Michael Lyle
2018-03-06 6:11 tang.junhui
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.