diff mbox

[v3] bcache: gc does not work when triggering by manual

Message ID 1507603489-30999-1-git-send-email-tang.junhui@zte.com.cn (mailing list archive)
State New, archived
Headers show

Commit Message

tang.junhui@zte.com.cn Oct. 10, 2017, 2:44 a.m. UTC
From: Tang Junhui <tang.junhui@zte.com.cn>

I try to execute the following command to trigger gc thread:
[root@localhost internal]# echo 1 > trigger_gc
But it does not work, I debug the code in gc_should_run(), It works only
if in invalidating or sectors_to_gc < 0. So set sectors_to_gc to -1 to
meet the condition when we trigger gc by manual command.

Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
---
 drivers/md/bcache/sysfs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Michael Lyle Oct. 10, 2017, 3:32 a.m. UTC | #1
On 10/09/2017 07:44 PM, tang.junhui@zte.com.cn wrote:
> From: Tang Junhui <tang.junhui@zte.com.cn>
> 
> I try to execute the following command to trigger gc thread:
> [root@localhost internal]# echo 1 > trigger_gc
> But it does not work, I debug the code in gc_should_run(), It works only
> if in invalidating or sectors_to_gc < 0. So set sectors_to_gc to -1 to
> meet the condition when we trigger gc by manual command.
> 
> Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>

Reviewed-by: Michael Lyle <mlyle@lyle.org>

Thanks!   -mpl
Coly Li Oct. 10, 2017, 6:12 a.m. UTC | #2
On 2017/10/10 上午10:44, tang.junhui@zte.com.cn wrote:
> From: Tang Junhui <tang.junhui@zte.com.cn>
> 
> I try to execute the following command to trigger gc thread:
> [root@localhost internal]# echo 1 > trigger_gc
> But it does not work, I debug the code in gc_should_run(), It works only
> if in invalidating or sectors_to_gc < 0. So set sectors_to_gc to -1 to
> meet the condition when we trigger gc by manual command.
> 
> Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>

Hi Junhui,

This patch is in mainline kernel v4.14 already, there is the upstream
patch head,

commit 0b43f49dc4d6d3789e936731dc16af94cb57d568
Author: Tang Junhui <tang.junhui@zte.com.cn>
Date:   Wed Sep 6 14:25:55 2017 +0800

    bcache: gc does not work when triggering by manual command

    I try to execute the following command to trigger gc thread:
    [root@localhost internal]# echo 1 > trigger_gc
    But it does not work, I debug the code in gc_should_run(), It works only
    if in invalidating or sectors_to_gc < 0. So set sectors_to_gc to -1 to
    meet the condition when we trigger gc by manual command.

    (Code comments aded by Coly Li)

    Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
    Reviewed-by: Coly Li <colyli@suse.de>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>


> ---
>  drivers/md/bcache/sysfs.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
> index b3ff57d..bef776d 100644
> --- a/drivers/md/bcache/sysfs.c
> +++ b/drivers/md/bcache/sysfs.c
> @@ -614,8 +614,16 @@ STORE(__bch_cache_set)
>  		bch_cache_accounting_clear(&c->accounting);
>  	}
>  
> -	if (attr == &sysfs_trigger_gc)
> +	if (attr == &sysfs_trigger_gc) {
> +		/* 
> +		  * Satisfy the gc condition by setting sectors_to_gc under 0,
> +		  * sectors_to_gc may also be decreased under 0 in 
> +		  * bch_data_insert_start() and gc would be triggered again,
> +		  * but the race is rare, and harmless, so we can ignore it
> +		  */
> +		atomic_set(&c->sectors_to_gc, -1);
>  		wake_up_gc(c);
> +	}
>  
>  	if (attr == &sysfs_prune_cache) {
>  		struct shrink_control sc;
>
diff mbox

Patch

diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index b3ff57d..bef776d 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -614,8 +614,16 @@  STORE(__bch_cache_set)
 		bch_cache_accounting_clear(&c->accounting);
 	}
 
-	if (attr == &sysfs_trigger_gc)
+	if (attr == &sysfs_trigger_gc) {
+		/* 
+		  * Satisfy the gc condition by setting sectors_to_gc under 0,
+		  * sectors_to_gc may also be decreased under 0 in 
+		  * bch_data_insert_start() and gc would be triggered again,
+		  * but the race is rare, and harmless, so we can ignore it
+		  */
+		atomic_set(&c->sectors_to_gc, -1);
 		wake_up_gc(c);
+	}
 
 	if (attr == &sysfs_prune_cache) {
 		struct shrink_control sc;