Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp357583rwl; Thu, 30 Mar 2023 17:32:55 -0700 (PDT) X-Google-Smtp-Source: AKy350bwN4AApONRIJQZRoIv0093h2Gh/qB2M3AsMpWKy95MF+4CY/ICdzfVqIPb4ChCmWUZQjBa X-Received: by 2002:aa7:c989:0:b0:502:243b:26f8 with SMTP id c9-20020aa7c989000000b00502243b26f8mr23214764edt.8.1680222774843; Thu, 30 Mar 2023 17:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680222774; cv=none; d=google.com; s=arc-20160816; b=oS96ohN0CKMtxm0L/wL7WilRXIDlR9wmSAZ5wUf6FFRxr/2XIQyCn4FFO3zk4A+OJr R9ZXC2odlZQjPhqVQeED6HwAlewsFIOJfs+sSRQBpwfcHoUqRCIjF75qo4l6LisEwMd8 WhlwiFWrPl5lejA8UHmDy421Gr9sxvECOeYJrS+baVCTWB6jceBFO5bMARas1Jt2fwbc 8MWDeW51rwkjAyTamYTGVE64pHtMAFlZKpXisf2ihizvcdbde7JywvDakF2C6P/UicPv JUllgtayVhEE/OS5pkMFHx5v0k1HfaI1yA3U4zYiQdn3pBAWyh2BoO1rztaahCi2mlLs LGAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=s3r5eQncDU04l860YNWqLD6wbbCGIfGDlp9mbjOhdOU=; b=eek0DzopkjNlK2ph6lY70nPHKADJkwNSqwbY8mGuqmHDRC3ko8ELkSHYeKzU710m50 nryEKhtel850y79q62qttJTxZAWSg78OXomwTjTcQd1krQNGOufd2a699uQKQqG4q3qE R4E+D03L5KzsbeMEaeCwu3Z4tQabUXFkLT7JNWI3FfWzoi4zTGBIlpc4GXviNLY1+5Yd X47cxbNPQfYCPmKsgIWhjr3HtBm8B5uY+vkxqz5hmnOtEM9MRFShxGNY3aNHBvBIhUdL rehrFFc9YJOvwX4JLw7Fl6ZzjK3DmSEmga0erUSBrgwAieJiB5eqL5E8Ac6DpE3dMjOt PLPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dQ93Wk+K; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020aa7dc0a000000b004acbeceab83si820507edu.448.2023.03.30.17.32.30; Thu, 30 Mar 2023 17:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dQ93Wk+K; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbjCaAap (ORCPT + 99 others); Thu, 30 Mar 2023 20:30:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjCaAan (ORCPT ); Thu, 30 Mar 2023 20:30:43 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24CA71024E for ; Thu, 30 Mar 2023 17:30:35 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id eg48so83351956edb.13 for ; Thu, 30 Mar 2023 17:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1680222633; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=s3r5eQncDU04l860YNWqLD6wbbCGIfGDlp9mbjOhdOU=; b=dQ93Wk+Ks0MpqcGc+XVhyiMMrBUMuOTlnyUdvZTqVp0bN0Nmlc332OAwEYAAl4bdOb rMvMFpmV/ShWfjSwJCQQlIG8eLhnJAG6GIFRRac4zR3uNqv31lS4gB+893Ba8gr7luBu NYPe2fAf2Jbhe561F22ak4DIq2XkXoPQMnFZA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680222633; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s3r5eQncDU04l860YNWqLD6wbbCGIfGDlp9mbjOhdOU=; b=3+KnEQp1b4zbqtQ0xomiz3sQTNO/b/l3omujlbQCNJiytWhXZCJLmEsTJgzi/EDgzC H7DOWzOCvUTyO+40zBnsa0gP0BAFwRgCglCClwuB1lO/sL1cPAZDNxuaDjKuTqvZSfxf MVn2ujF+eO1NAN0OSi2KajVBsS+BY2diWhs8HUdESYTsfBHiUYY7COUr8PxhakF3aVb3 +o+vTmqpYPcL3wLXzMVour5xhC3KkWTi59Ph0Kca5z1jPHQXmkoyXm7xU234uPDJL/ja Rv61oMg7SrPAIIWNraF8Ej3+YMV0zQOY2HGkSyxRxiMM6suJJ/9vSjfI2bk+nhv8cXME md0A== X-Gm-Message-State: AAQBX9e4xGwcwLJX9qZ2PnaxZjW4bxcrXqvCX/7Fl0XEfBMziU/uXPjb cPlVx1aTd4np4Fb++58jSLqQ2XrX4S1GZLknxSpUTw== X-Received: by 2002:a17:907:d687:b0:93d:a14f:c9b4 with SMTP id wf7-20020a170907d68700b0093da14fc9b4mr12727665ejc.2.1680222633437; Thu, 30 Mar 2023 17:30:33 -0700 (PDT) MIME-Version: 1.0 References: <20221229081252.452240-1-sarthakkukreti@chromium.org> <20221229081252.452240-3-sarthakkukreti@chromium.org> In-Reply-To: From: Sarthak Kukreti Date: Thu, 30 Mar 2023 17:30:22 -0700 Message-ID: Subject: Re: [PATCH v2 2/7] dm: Add support for block provisioning To: Brian Foster Cc: sarthakkukreti@google.com, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , "Theodore Ts'o" , Andreas Dilger , Bart Van Assche , Daniil Lunev , "Darrick J. Wong" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Jan 5, 2023 at 6:42=E2=80=AFAM Brian Foster wr= ote: > > On Thu, Dec 29, 2022 at 12:12:47AM -0800, Sarthak Kukreti wrote: > > Add support to dm devices for REQ_OP_PROVISION. The default mode > > is to pass through the request and dm-thin will utilize it to provision > > blocks. > > > > Signed-off-by: Sarthak Kukreti > > --- > > drivers/md/dm-crypt.c | 4 +- > > drivers/md/dm-linear.c | 1 + > > drivers/md/dm-snap.c | 7 +++ > > drivers/md/dm-table.c | 25 ++++++++++ > > drivers/md/dm-thin.c | 90 ++++++++++++++++++++++++++++++++++- > > drivers/md/dm.c | 4 ++ > > include/linux/device-mapper.h | 11 +++++ > > 7 files changed, 139 insertions(+), 3 deletions(-) > > > ... > > diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c > > index 64cfcf46881d..ab3f1abfabaf 100644 > > --- a/drivers/md/dm-thin.c > > +++ b/drivers/md/dm-thin.c > ... > > @@ -1980,6 +1992,70 @@ static void process_cell(struct thin_c *tc, stru= ct dm_bio_prison_cell *cell) > > } > > } > > > > +static void process_provision_cell(struct thin_c *tc, struct dm_bio_pr= ison_cell *cell) > > +{ > > + int r; > > + struct pool *pool =3D tc->pool; > > + struct bio *bio =3D cell->holder; > > + dm_block_t begin, end; > > + struct dm_thin_lookup_result lookup_result; > > + > > + if (tc->requeue_mode) { > > + cell_requeue(pool, cell); > > + return; > > + } > > + > > + get_bio_block_range(tc, bio, &begin, &end); > > + > > + while (begin !=3D end) { > > + r =3D ensure_next_mapping(pool); > > + if (r) > > + /* we did our best */ > > + return; > > + > > + r =3D dm_thin_find_block(tc->td, begin, 1, &lookup_result= ); > > Hi Sarthak, > > I think we discussed this before.. but remind me if/how we wanted to > handle the case if the thin blocks are shared..? Would a provision op > carry enough information to distinguish an FALLOC_FL_UNSHARE_RANGE > request from upper layers to conditionally provision in that case? > I think that should depend on how the filesystem implements unsharing: assuming that we use provision on first allocation, unsharing on xfs should result in xfs calling REQ_OP_PROVISION on the newly allocated blocks first. But for ext4, we'd fail UNSHARE_RANGE unless provision (instead of noprovision, provision_on_alloc), in which case, we'd send REQ_OP_PROVISION. Best Sarthak Sarthak > Brian > > > + switch (r) { > > + case 0: > > + begin++; > > + break; > > + case -ENODATA: > > + bio_inc_remaining(bio); > > + provision_block(tc, bio, begin, cell); > > + begin++; > > + break; > > + default: > > + DMERR_LIMIT( > > + "%s: dm_thin_find_block() failed: error = =3D %d", > > + __func__, r); > > + cell_defer_no_holder(tc, cell); > > + bio_io_error(bio); > > + begin++; > > + break; > > + } > > + } > > + bio_endio(bio); > > + cell_defer_no_holder(tc, cell); > > +} > > + > > +static void process_provision_bio(struct thin_c *tc, struct bio *bio) > > +{ > > + dm_block_t begin, end; > > + struct dm_cell_key virt_key; > > + struct dm_bio_prison_cell *virt_cell; > > + > > + get_bio_block_range(tc, bio, &begin, &end); > > + if (begin =3D=3D end) { > > + bio_endio(bio); > > + return; > > + } > > + > > + build_key(tc->td, VIRTUAL, begin, end, &virt_key); > > + if (bio_detain(tc->pool, &virt_key, bio, &virt_cell)) > > + return; > > + > > + process_provision_cell(tc, virt_cell); > > +} > > + > > static void process_bio(struct thin_c *tc, struct bio *bio) > > { > > struct pool *pool =3D tc->pool; > > @@ -2200,6 +2276,8 @@ static void process_thin_deferred_bios(struct thi= n_c *tc) > > > > if (bio_op(bio) =3D=3D REQ_OP_DISCARD) > > pool->process_discard(tc, bio); > > + else if (bio_op(bio) =3D=3D REQ_OP_PROVISION) > > + process_provision_bio(tc, bio); > > else > > pool->process_bio(tc, bio); > > > > @@ -2716,7 +2794,8 @@ static int thin_bio_map(struct dm_target *ti, str= uct bio *bio) > > return DM_MAPIO_SUBMITTED; > > } > > > > - if (op_is_flush(bio->bi_opf) || bio_op(bio) =3D=3D REQ_OP_DISCARD= ) { > > + if (op_is_flush(bio->bi_opf) || bio_op(bio) =3D=3D REQ_OP_DISCARD= || > > + bio_op(bio) =3D=3D REQ_OP_PROVISION) { > > thin_defer_bio_with_throttle(tc, bio); > > return DM_MAPIO_SUBMITTED; > > } > > @@ -3355,6 +3434,8 @@ static int pool_ctr(struct dm_target *ti, unsigne= d argc, char **argv) > > pt->low_water_blocks =3D low_water_blocks; > > pt->adjusted_pf =3D pt->requested_pf =3D pf; > > ti->num_flush_bios =3D 1; > > + ti->num_provision_bios =3D 1; > > + ti->provision_supported =3D true; > > > > /* > > * Only need to enable discards if the pool should pass > > @@ -4053,6 +4134,7 @@ static void pool_io_hints(struct dm_target *ti, s= truct queue_limits *limits) > > blk_limits_io_opt(limits, pool->sectors_per_block << SECT= OR_SHIFT); > > } > > > > + > > /* > > * pt->adjusted_pf is a staging area for the actual features to u= se. > > * They get transferred to the live pool in bind_control_target() > > @@ -4243,6 +4325,9 @@ static int thin_ctr(struct dm_target *ti, unsigne= d argc, char **argv) > > ti->num_discard_bios =3D 1; > > } > > > > + ti->num_provision_bios =3D 1; > > + ti->provision_supported =3D true; > > + > > mutex_unlock(&dm_thin_pool_table.mutex); > > > > spin_lock_irq(&tc->pool->lock); > > @@ -4457,6 +4542,7 @@ static void thin_io_hints(struct dm_target *ti, s= truct queue_limits *limits) > > > > limits->discard_granularity =3D pool->sectors_per_block << SECTOR= _SHIFT; > > limits->max_discard_sectors =3D 2048 * 1024 * 16; /* 16G */ > > + limits->max_provision_sectors =3D 2048 * 1024 * 16; /* 16G */ > > } > > > > static struct target_type thin_target =3D { > > diff --git a/drivers/md/dm.c b/drivers/md/dm.c > > index e1ea3a7bd9d9..4d19bae9da4a 100644 > > --- a/drivers/md/dm.c > > +++ b/drivers/md/dm.c > > @@ -1587,6 +1587,7 @@ static bool is_abnormal_io(struct bio *bio) > > case REQ_OP_DISCARD: > > case REQ_OP_SECURE_ERASE: > > case REQ_OP_WRITE_ZEROES: > > + case REQ_OP_PROVISION: > > return true; > > default: > > break; > > @@ -1611,6 +1612,9 @@ static blk_status_t __process_abnormal_io(struct = clone_info *ci, > > case REQ_OP_WRITE_ZEROES: > > num_bios =3D ti->num_write_zeroes_bios; > > break; > > + case REQ_OP_PROVISION: > > + num_bios =3D ti->num_provision_bios; > > + break; > > default: > > break; > > } > > diff --git a/include/linux/device-mapper.h b/include/linux/device-mappe= r.h > > index 04c6acf7faaa..b4d97d5d75b8 100644 > > --- a/include/linux/device-mapper.h > > +++ b/include/linux/device-mapper.h > > @@ -333,6 +333,12 @@ struct dm_target { > > */ > > unsigned num_write_zeroes_bios; > > > > + /* > > + * The number of PROVISION bios that will be submitted to the tar= get. > > + * The bio number can be accessed with dm_bio_get_target_bio_nr. > > + */ > > + unsigned num_provision_bios; > > + > > /* > > * The minimum number of extra bytes allocated in each io for the > > * target to use. > > @@ -357,6 +363,11 @@ struct dm_target { > > */ > > bool discards_supported:1; > > > > + /* Set if this target needs to receive provision requests regardl= ess of > > + * whether or not its underlying devices have support. > > + */ > > + bool provision_supported:1; > > + > > /* > > * Set if we need to limit the number of in-flight bios when swap= ping. > > */ > > -- > > 2.37.3 > > >