From patchwork Thu Dec 10 17:31:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 7820571 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 207D0BEEE1 for ; Thu, 10 Dec 2015 17:31:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 25F7C20524 for ; Thu, 10 Dec 2015 17:31:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F81F20592 for ; Thu, 10 Dec 2015 17:31:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754712AbbLJRbM (ORCPT ); Thu, 10 Dec 2015 12:31:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39005 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752734AbbLJRbK (ORCPT ); Thu, 10 Dec 2015 12:31:10 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id B0850811D9; Thu, 10 Dec 2015 17:31:10 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBAHVA6F021453 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 10 Dec 2015 12:31:10 -0500 Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id tBAHVAYD001368; Thu, 10 Dec 2015 12:31:10 -0500 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id tBAHV9uW001364; Thu, 10 Dec 2015 12:31:10 -0500 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Thu, 10 Dec 2015 12:31:09 -0500 (EST) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: "James E.J. Bottomley" , "Martin K. Petersen" , Jens Axboe , Mike Snitzer , Jonathan Brassow cc: dm-devel@redhat.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 13/15] dm kcopyd: support copy offload In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 This patch adds copy offload support to dm-kcopyd. If copy offload fails, copying is performed using dm-io, just like before. There is a module parameter "copy_offload" that can be set to enable or disable this feature. It can be used to test performance of copy offload. Signed-off-by: Mikulas Patocka --- drivers/md/dm-kcopyd.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-3.18-rc3/drivers/md/dm-kcopyd.c =================================================================== --- linux-3.18-rc3.orig/drivers/md/dm-kcopyd.c 2014-11-05 18:09:23.000000000 +0100 +++ linux-3.18-rc3/drivers/md/dm-kcopyd.c 2014-11-05 18:13:04.000000000 +0100 @@ -96,6 +96,9 @@ static DEFINE_SPINLOCK(throttle_spinlock */ #define MAX_SLEEPS 10 +static bool copy_offload = true; +module_param(copy_offload, bool, S_IRUGO | S_IWUSR); + static void io_job_start(struct dm_kcopyd_throttle *t) { unsigned throttle, now, difference; @@ -358,6 +361,8 @@ struct kcopyd_job { sector_t progress; struct kcopyd_job *master_job; + + struct work_struct copy_work; }; static struct kmem_cache *_job_cache; @@ -709,6 +714,31 @@ static void submit_job(struct kcopyd_job } } +static void copy_offload_work(struct work_struct *work) +{ + struct kcopyd_job *job = container_of(work, struct kcopyd_job, copy_work); + sector_t copied; + + blkdev_issue_copy(job->source.bdev, job->source.sector, + job->dests[0].bdev, job->dests[0].sector, + job->source.count, + GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN, + NULL, NULL, &copied); + + job->source.sector += copied; + job->source.count -= copied; + job->dests[0].sector += copied; + job->dests[0].count -= copied; + + submit_job(job); +} + +static void try_copy_offload(struct kcopyd_job *job) +{ + INIT_WORK(&job->copy_work, copy_offload_work); + queue_work(job->kc->kcopyd_wq, &job->copy_work); +} + int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from, unsigned int num_dests, struct dm_io_region *dests, unsigned int flags, dm_kcopyd_notify_fn fn, void *context) @@ -733,10 +763,20 @@ int dm_kcopyd_copy(struct dm_kcopyd_clie job->num_dests = num_dests; memcpy(&job->dests, dests, sizeof(*dests) * num_dests); + job->fn = fn; + job->context = context; + job->master_job = job; + if (from) { job->source = *from; job->pages = NULL; job->rw = READ; + if (copy_offload && num_dests == 1 && + bdev_copy_offload(job->source.bdev) && + bdev_copy_offload(job->dests[0].bdev)) { + try_copy_offload(job); + return 0; + } } else { memset(&job->source, 0, sizeof job->source); job->source.count = job->dests[0].count; @@ -753,10 +793,6 @@ int dm_kcopyd_copy(struct dm_kcopyd_clie } } - job->fn = fn; - job->context = context; - job->master_job = job; - submit_job(job); return 0;