Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp522088ybh; Wed, 15 Jul 2020 08:11:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6wbbJimNljk2ZsxtoukFc3pwSXEVGlGlO8WlMObxWQ6HYOhAkTr2qrnDEFSa43Sxu5Xp1 X-Received: by 2002:a17:906:71d4:: with SMTP id i20mr10229636ejk.533.1594825871800; Wed, 15 Jul 2020 08:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594825871; cv=none; d=google.com; s=arc-20160816; b=SbRs/0UJC0DIdeCLDCOu4LnFtbq+bHmRUm7vfXmjgD0MxfW9Kvtg/2XlqdTveRQ1aP DZ+4xxid+tlpZhn1WlzhumYUEuNYGpawsUl77qm+uaKHTepnfBkXsZtmu+FD9rP0I5Q1 x0BDjBKMPj0mfbF9p1YObjYu6i+a+bjuPXLUIn3JvkZyKtYY1ln/VeO8t8vWvHvz7BWn 3vllUAqUFi0SGMEPnkiYwd9ag0WaAlWV/crE7e3K+IggIt73dXIDHnJO2xmow47uJyWE ETAA7bp6GLKG+XX2y7MnkvZ6h1YtHztZLHIugAXORsndlA4456YC5VlFsrtMWzzCvPvS Ghxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:mime-version:user-agent:date:message-id :cc:to:subject:from:dkim-signature; bh=nGLt9EKk198EdWzg50X+8wpdgF4yG6/fnWmLQefveYg=; b=ut1DXKeJ/N/sF0xxdq55xsdxOyD4lxDqabLljoW0fF3vNwJvRDxFfJ8kuHci5zHH4p HfzxGh2CTf2O685lfdhuON4ia/66RAOhAkt4m1nQkANvLlm+JaRQ69WQy9zjL5BtAn7f bN3yIPUGis2lZaSmgKe+OCtWvoSydo/HuXLbjElOxiTBl4NSA/xuSjuQ+mAKfhptXYyX r4xyTT3TpGrgWkPWyydBF0gn7aKCox1cIu80E+thG6rh/UgMAPNOwfrDJTfh/tdT/vZl M3x7TFsce+A4WXLKxbvGYqvBF3p9qfVbAwZve7ADBTg5rhdSvYsT5L3csBrjMd1hOb2K /Huw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=Ov0fgQ2W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si1369188ejz.398.2020.07.15.08.10.48; Wed, 15 Jul 2020 08:11:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=Ov0fgQ2W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732078AbgGOOGz (ORCPT + 99 others); Wed, 15 Jul 2020 10:06:55 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:41434 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729996AbgGOOGz (ORCPT ); Wed, 15 Jul 2020 10:06:55 -0400 X-Greylist: delayed 1414 seconds by postgrey-1.27 at vger.kernel.org; Wed, 15 Jul 2020 10:06:54 EDT Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06FDfrMQ147465; Wed, 15 Jul 2020 13:43:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : subject : to : cc : message-id : date : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=nGLt9EKk198EdWzg50X+8wpdgF4yG6/fnWmLQefveYg=; b=Ov0fgQ2Wz8iz5c8ljjYR15inEJdjeweavANYIPxDSqaHoiUf4U/rIfbQnK25zq7sZaNu JN4X3fpyDctO/V3Fkw5RgKrN5g8cS2bTLDe2RlvSpFguh7t9vlJ95lX5UQGIDd+qUG/h 1NHSIXGNqYEQ+EcCYNlpq6w0n1nZULFAceC18atzRyyriXQZuywedcx7HDIMeTkbXL3d 5QIKXvD/Y0QTo8L4YKstIjJcet7BCJMWQhlW3Za4OREGf6TxkEPHWACnLMpYc1Xhv9yd ZPltPPsIdqvByq40RSEvBzS+G2ARLTQxqMVRn1fl159nbebngtfdhvDxldeRLjq1DeM7 PQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 327s65hq8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 15 Jul 2020 13:43:17 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06FDbbBs151259; Wed, 15 Jul 2020 13:43:17 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 327qb7mfpf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jul 2020 13:43:16 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06FDhGMJ025016; Wed, 15 Jul 2020 13:43:16 GMT Received: from [192.168.1.106] (/47.220.71.223) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 15 Jul 2020 06:43:16 -0700 From: John Donnelly Subject: [PATCH [linux-4.14.y]] dm cache: submit writethrough writes in parallel to origin and cache To: Linux Kernel Mailing List Cc: john.p.donnelly@oracle.com, snitzer@redhat.com Message-ID: <169d0415-0a91-8fcb-b796-7dbd05a9831c@oracle.com> Date: Wed, 15 Jul 2020 08:43:15 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9682 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=835 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 suspectscore=2 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007150111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9682 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 phishscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 clxscore=1015 bulkscore=0 mlxlogscore=826 impostorscore=0 suspectscore=2 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007150112 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Snitzer Discontinue issuing writethrough write IO in series to the origin and then cache. Use bio_clone_fast() to create a new origin clone bio that will be mapped to the origin device and then bio_chain() it to the bio that gets remapped to the cache device. The origin clone bio does _not_ have a copy of the per_bio_data -- as such check_if_tick_bio_needed() will not be called. The cache bio (parent bio) will not complete until the origin bio has completed -- this fulfills bio_clone_fast()'s requirements as well as the requirement to not complete the original IO until the write IO has completed to both the origin and cache device. Signed-off-by: Mike Snitzer (cherry picked from commit 2df3bae9a6543e90042291707b8db0cbfbae9ee9) Fixes: 705559706d62038b74c5088114c1799cf2c9dce8 (dm bio record: save/restore bi_end_io and bi_integrity, version 4.14.188) 70555970 introduced a mkfs.ext4 hang on a LVM device that has been modified with lvconvert --cachemode=writethrough. Signed-off-by: John Donnelly Tested-by: John Donnelly Reviewed-by: Somasundaram Krishnasamy conflict: drivers/md/dm-cache-target.c - Corrected syntax of writethrough_mode(&cache->feature) that was caught by arm compiler. cc: stable@vger.kernel.org cc: snitzer@redhat.com --- drivers/md/dm-cache-target.c | 54 ++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index 69cdb29ef6be..8241b7c36655 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c @@ -450,6 +450,7 @@ struct cache { struct work_struct migration_worker; struct delayed_work waker; struct dm_bio_prison_v2 *prison; + struct bio_set *bs; mempool_t *migration_pool; @@ -868,16 +869,23 @@ static void check_if_tick_bio_needed(struct cache *cache, struct bio *bio) spin_unlock_irqrestore(&cache->lock, flags); } -static void remap_to_origin_clear_discard(struct cache *cache, struct bio *bio, - dm_oblock_t oblock) +static void __remap_to_origin_clear_discard(struct cache *cache, struct bio *bio, + dm_oblock_t oblock, bool bio_has_pbd) { - // FIXME: this is called way too much. - check_if_tick_bio_needed(cache, bio); + if (bio_has_pbd) + check_if_tick_bio_needed(cache, bio); remap_to_origin(cache, bio); if (bio_data_dir(bio) == WRITE) clear_discard(cache, oblock_to_dblock(cache, oblock)); } +static void remap_to_origin_clear_discard(struct cache *cache, struct bio *bio, + dm_oblock_t oblock) +{ + // FIXME: check_if_tick_bio_needed() is called way too much through this interface + __remap_to_origin_clear_discard(cache, bio, oblock, true); +} + static void remap_to_cache_dirty(struct cache *cache, struct bio *bio, dm_oblock_t oblock, dm_cblock_t cblock) { @@ -971,23 +979,25 @@ static void writethrough_endio(struct bio *bio) } /* - * FIXME: send in parallel, huge latency as is. * When running in writethrough mode we need to send writes to clean blocks - * to both the cache and origin devices. In future we'd like to clone the - * bio and send them in parallel, but for now we're doing them in - * series as this is easier. + * to both the cache and origin devices. Clone the bio and send them in parallel. */ -static void remap_to_origin_then_cache(struct cache *cache, struct bio *bio, - dm_oblock_t oblock, dm_cblock_t cblock) +static void remap_to_origin_and_cache(struct cache *cache, struct bio *bio, + dm_oblock_t oblock, dm_cblock_t cblock) { - struct per_bio_data *pb = get_per_bio_data(bio, PB_DATA_SIZE_WT); + struct bio *origin_bio = bio_clone_fast(bio, GFP_NOIO, cache->bs); - pb->cache = cache; - pb->cblock = cblock; - dm_hook_bio(&pb->hook_info, bio, writethrough_endio, NULL); - dm_bio_record(&pb->bio_details, bio); + BUG_ON(!origin_bio); - remap_to_origin_clear_discard(pb->cache, bio, oblock); + bio_chain(origin_bio, bio); + /* + * Passing false to __remap_to_origin_clear_discard() skips + * all code that might use per_bio_data (since clone doesn't have it) + */ + __remap_to_origin_clear_discard(cache, origin_bio, oblock, false); + submit_bio(origin_bio); + + remap_to_cache(cache, bio, cblock); } /*---------------------------------------------------------------- @@ -1873,7 +1883,7 @@ static int map_bio(struct cache *cache, struct bio *bio, dm_oblock_t block, } else { if (bio_data_dir(bio) == WRITE && writethrough_mode(&cache->features) && !is_dirty(cache, cblock)) { - remap_to_origin_then_cache(cache, bio, block, cblock); + remap_to_origin_and_cache(cache, bio, block, cblock); accounted_begin(cache, bio); } else remap_to_cache_dirty(cache, bio, block, cblock); @@ -2132,6 +2142,9 @@ static void destroy(struct cache *cache) kfree(cache->ctr_args[i]); kfree(cache->ctr_args); + if (cache->bs) + bioset_free(cache->bs); + kfree(cache); } @@ -2589,6 +2602,13 @@ static int cache_create(struct cache_args *ca, struct cache **result) cache->features = ca->features; ti->per_io_data_size = get_per_bio_data_size(cache); + if (writethrough_mode(&cache->features)) { + /* Create bioset for writethrough bios issued to origin */ + cache->bs = bioset_create(BIO_POOL_SIZE, 0, 0); + if (!cache->bs) + goto bad; + } + cache->callbacks.congested_fn = cache_is_congested; dm_table_add_target_callbacks(ti->table, &cache->callbacks); -- 2.26.2