From patchwork Thu Sep 12 08:08:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 2876791 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9EED1BF43F for ; Thu, 12 Sep 2013 08:09:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 45377202DB for ; Thu, 12 Sep 2013 08:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CFBBA20257 for ; Thu, 12 Sep 2013 08:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754683Ab3ILIIa (ORCPT ); Thu, 12 Sep 2013 04:08:30 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:49357 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754218Ab3ILIII (ORCPT ); Thu, 12 Sep 2013 04:08:08 -0400 X-IronPort-AV: E=Sophos;i="4.90,889,1371052800"; d="scan'208";a="8502285" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 12 Sep 2013 16:04:30 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r8C87cWX015391 for ; Thu, 12 Sep 2013 16:07:40 +0800 Received: from localhost.localdomain ([10.167.226.57]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013091216051755-1449935 ; Thu, 12 Sep 2013 16:05:17 +0800 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: quwenruo@cn.fujitsu.com Subject: [PATCH v2 7/9] btrfs: Replace the fs_info->submit_workers with kernel workqueue. Date: Thu, 12 Sep 2013 16:08:22 +0800 Message-Id: <1378973304-11693-8-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1378973304-11693-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1378973304-11693-1-git-send-email-quwenruo@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/12 16:05:17, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/12 16:05:19, Serialize complete at 2013/09/12 16:05:19 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the submit worker with kernel workqueue. The submit_workers is different from other workers in the following things: 1) Requeue: This is quiet easy, just queue_work can handle it. 2) Initialize: The work_struct in btrfs_devices should be initialized carefully to prevent broken work_struct to be queued. Besides this, not much to worry about. Signed-off-by: Qu Wenruo --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 10 ++++------ fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 17 +++++++++-------- fs/btrfs/volumes.h | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 81aba0e..0cf4320 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1477,10 +1477,10 @@ struct btrfs_fs_info { * two */ struct btrfs_workers generic_worker; - struct btrfs_workers submit_workers; struct btrfs_workqueue_struct *workers; struct btrfs_workqueue_struct *delalloc_workers; + struct workqueue_struct *submit_workers; struct workqueue_struct *flush_workers; struct workqueue_struct *endio_workers; struct workqueue_struct *endio_meta_workers; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index fd795b6..ca2257d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1987,7 +1987,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_stop_workers(&fs_info->generic_worker); btrfs_destroy_workqueue(fs_info->delalloc_workers); btrfs_destroy_workqueue(fs_info->workers); - btrfs_stop_workers(&fs_info->submit_workers); + destroy_workqueue(fs_info->submit_workers); destroy_workqueue(fs_info->fixup_workers); destroy_workqueue(fs_info->endio_workers); destroy_workqueue(fs_info->endio_meta_workers); @@ -2470,10 +2470,8 @@ int open_ctree(struct super_block *sb, fs_info->flush_workers = alloc_workqueue("flush_delalloc", flags, max_active); - btrfs_init_workers(&fs_info->submit_workers, "submit", - min_t(u64, fs_devices->num_devices, - fs_info->thread_pool_size), - &fs_info->generic_worker); + fs_info->submit_workers = alloc_workqueue("submit", flags, + max_active); fs_info->caching_workers = alloc_workqueue("cache", flags, 2); fs_info->fixup_workers = alloc_workqueue("fixup", flags, 1); @@ -2500,11 +2498,11 @@ int open_ctree(struct super_block *sb, * return -ENOMEM if any of these fail. */ ret = btrfs_start_workers(&fs_info->generic_worker); - ret |= btrfs_start_workers(&fs_info->submit_workers); if (ret || !(fs_info->flush_workers && fs_info->endio_workers && fs_info->endio_meta_workers && fs_info->workers && fs_info->delalloc_workers && + fs_info->submit_workers && fs_info->endio_raid56_workers && fs_info->rmw_workers && fs_info->qgroup_rescan_workers && fs_info->endio_meta_write_workers && diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 771b98a..402b488 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1177,7 +1177,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size); btrfs_workqueue_set_max(fs_info->workers, new_pool_size); btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->submit_workers, new_pool_size); + workqueue_set_max_active(fs_info->submit_workers, new_pool_size); workqueue_set_max_active(fs_info->caching_workers, new_pool_size); workqueue_set_max_active(fs_info->fixup_workers, new_pool_size); workqueue_set_max_active(fs_info->endio_workers, new_pool_size); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 12eaf89..cb10e02 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -352,7 +352,7 @@ loop_lock: device->running_pending = 1; spin_unlock(&device->io_lock); - btrfs_requeue_work(&device->work); + queue_work(fs_info->submit_workers, &device->work); goto done; } /* unplug every 64 requests just for good measure */ @@ -376,7 +376,7 @@ done: blk_finish_plug(&plug); } -static void pending_bios_fn(struct btrfs_work *work) +static void pending_bios_fn(struct work_struct *work) { struct btrfs_device *device; @@ -421,7 +421,7 @@ static noinline int device_list_add(const char *path, } device->devid = devid; device->dev_stats_valid = 0; - device->work.func = pending_bios_fn; + INIT_WORK(&device->work, pending_bios_fn); memcpy(device->uuid, disk_super->dev_item.uuid, BTRFS_UUID_SIZE); spin_lock_init(&device->io_lock); @@ -507,7 +507,7 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig) rcu_assign_pointer(device->name, name); device->devid = orig_dev->devid; - device->work.func = pending_bios_fn; + INIT_WORK(&device->work, pending_bios_fn); memcpy(device->uuid, orig_dev->uuid, sizeof(device->uuid)); spin_lock_init(&device->io_lock); INIT_LIST_HEAD(&device->dev_list); @@ -652,6 +652,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) new_device->in_fs_metadata = 0; new_device->can_discard = 0; spin_lock_init(&new_device->io_lock); + INIT_WORK(&new_device->work, pending_bios_fn); list_replace_rcu(&device->dev_list, &new_device->dev_list); call_rcu(&device->rcu, free_device); @@ -1992,7 +1993,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) if (blk_queue_discard(q)) device->can_discard = 1; device->writeable = 1; - device->work.func = pending_bios_fn; + INIT_WORK(&device->work, pending_bios_fn); generate_random_uuid(device->uuid); spin_lock_init(&device->io_lock); device->generation = trans->transid; @@ -5087,8 +5088,8 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root, spin_unlock(&device->io_lock); if (should_queue) - btrfs_queue_worker(&root->fs_info->submit_workers, - &device->work); + queue_work(root->fs_info->submit_workers, + &device->work); } static int bio_size_ok(struct block_device *bdev, struct bio *bio, @@ -5313,7 +5314,7 @@ static struct btrfs_device *add_missing_dev(struct btrfs_root *root, list_add(&device->dev_list, &fs_devices->devices); device->devid = devid; - device->work.func = pending_bios_fn; + INIT_WORK(&device->work, pending_bios_fn); device->fs_devices = fs_devices; device->missing = 1; fs_devices->num_devices++; diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 8670558..bd849cc 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -91,7 +91,7 @@ struct btrfs_device { /* per-device scrub information */ struct scrub_ctx *scrub_device; - struct btrfs_work work; + struct work_struct work; struct rcu_head rcu; struct work_struct rcu_work;