Skip to content

Commit ee4a36f

Browse files
Coly Liaxboe
authored andcommitted
bcache: use delayed kworker fo asynchronous devices registration
This patch changes the asynchronous registration kworker to a delayed kworker. There is probability queue_work() queues the async registration kworker to the same CPU (even though very little), then the process which writing sysfs interface to reigster bcache device may won't return immeidately. queue_delayed_work() in this patch will delay 10 jiffies before insert the kworker to run queue, which makes sure the registering process may always returns to user space in time. Fixes: 9e23ccf ("bcache: asynchronous devices registration") Signed-off-by: Coly Li <[email protected]> Cc: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent dcacbc1 commit ee4a36f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/md/bcache/super.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/genhd.h>
2020
#include <linux/idr.h>
2121
#include <linux/kthread.h>
22+
#include <linux/workqueue.h>
2223
#include <linux/module.h>
2324
#include <linux/random.h>
2425
#include <linux/reboot.h>
@@ -2380,7 +2381,7 @@ static bool bch_is_open(struct block_device *bdev)
23802381
}
23812382

23822383
struct async_reg_args {
2383-
struct work_struct reg_work;
2384+
struct delayed_work reg_work;
23842385
char *path;
23852386
struct cache_sb *sb;
23862387
struct cache_sb_disk *sb_disk;
@@ -2391,7 +2392,7 @@ static void register_bdev_worker(struct work_struct *work)
23912392
{
23922393
int fail = false;
23932394
struct async_reg_args *args =
2394-
container_of(work, struct async_reg_args, reg_work);
2395+
container_of(work, struct async_reg_args, reg_work.work);
23952396
struct cached_dev *dc;
23962397

23972398
dc = kzalloc(sizeof(*dc), GFP_KERNEL);
@@ -2421,7 +2422,7 @@ static void register_cache_worker(struct work_struct *work)
24212422
{
24222423
int fail = false;
24232424
struct async_reg_args *args =
2424-
container_of(work, struct async_reg_args, reg_work);
2425+
container_of(work, struct async_reg_args, reg_work.work);
24252426
struct cache *ca;
24262427

24272428
ca = kzalloc(sizeof(*ca), GFP_KERNEL);
@@ -2449,11 +2450,12 @@ static void register_cache_worker(struct work_struct *work)
24492450
static void register_device_aync(struct async_reg_args *args)
24502451
{
24512452
if (SB_IS_BDEV(args->sb))
2452-
INIT_WORK(&args->reg_work, register_bdev_worker);
2453+
INIT_DELAYED_WORK(&args->reg_work, register_bdev_worker);
24532454
else
2454-
INIT_WORK(&args->reg_work, register_cache_worker);
2455+
INIT_DELAYED_WORK(&args->reg_work, register_cache_worker);
24552456

2456-
queue_work(system_wq, &args->reg_work);
2457+
/* 10 jiffies is enough for a delay */
2458+
queue_delayed_work(system_wq, &args->reg_work, 10);
24572459
}
24582460

24592461
static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,

0 commit comments

Comments
 (0)