Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3161362rwl; Thu, 13 Apr 2023 17:04:08 -0700 (PDT) X-Google-Smtp-Source: AKy350YVfA2YBOKYXtCGt9Gw6LiCfVzzubstTdFSl2ktH816Xf3Rh/i0oyUOCeklM8TBwfWZ9X2d X-Received: by 2002:a05:6e02:10c7:b0:313:c32b:de26 with SMTP id s7-20020a056e0210c700b00313c32bde26mr2170886ilj.9.1681430648316; Thu, 13 Apr 2023 17:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681430648; cv=none; d=google.com; s=arc-20160816; b=bIjfsXONVazp/83xmmdu7jG+0nb3lmmAQp0YpoAVeqIKgyJf3CHxVosNLMkzhPtXuI eAt4dRTzcJ2d+uxUxfBcZAJ0ro4kcJJDGjAnr0KX2PHsH59Up5N3O3SE8AofRca8dqGS 3b74FOHOwjyPsf+aRjpa0dLTOjSXkFyF4Di3bpR0pP8/cyzndCAR12n4R0ssosa6FBch ymavO7eefpaP+Jk+FYiU53U2cBH2I9/aWcsqJbdlVwg2smB2kVhXsOTJpL9uGdhXMqAO V+chov3kRKsZu1DFQcyZzQ1MjuOWt7LMDroNHa3aXGC63jGIKd/tl2+GVr9huBh+05M/ I8eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o7P9g3Nl+EfrrL2NO6MRAt6Dye4XvqSU4otNxeRaGZY=; b=GoZO+AW3ecV9OWqos0JCnF/Dmj4aUVnpRMwBXRgNNZruoZG+FfFyWvXDZlkM0xH8s+ v+jKlfsUXBUFr53uGNNRp7RvXxzD0JqLm5h4gULtRronTRQL+GBmesJif9eeys8MXGqY Y97N2vkOU3FJVejpJj/wLn+UEsDG5qbxm8cwfLAqZVN0FfxI2F6CAzs8T3JiviYnN/5/ /KzoxUoQw2sLkIVlT6NkuFmjvOC/0/RvtdoJEHgvrljQFyxC6Bkohgw9LtjoLHvs7vZS E/S/sqvH683N/58Yz8U4/eWkutT6+UcXW+kvXObwJdODNplDRlxmLCzpHVkSF2un7zSD PyHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IRUYl+sc; 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 y22-20020a05663824d600b003afc252a6f0si3534587jat.96.2023.04.13.17.03.21; Thu, 13 Apr 2023 17:04:08 -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=IRUYl+sc; 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 S230097AbjDNACn (ORCPT + 99 others); Thu, 13 Apr 2023 20:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbjDNACm (ORCPT ); Thu, 13 Apr 2023 20:02:42 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BCEF3C15 for ; Thu, 13 Apr 2023 17:02:40 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id la3so16595822plb.11 for ; Thu, 13 Apr 2023 17:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681430559; x=1684022559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o7P9g3Nl+EfrrL2NO6MRAt6Dye4XvqSU4otNxeRaGZY=; b=IRUYl+scWxtKHfQzW1OJHJIuR3Z3RkNtZXSk2D4iGYiWRM+zh5hAWdHpMYLUNWFNrn mLzFrKWjDYCRBZ5ukbWyr/5DVDpw5GvHFJGO31u9DPxe2rdJMyTCo4TGQJruwa45+WfG 0zMUArth2/a1WFpBOeA4+r+QFJJ+At0aSepqs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681430559; x=1684022559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o7P9g3Nl+EfrrL2NO6MRAt6Dye4XvqSU4otNxeRaGZY=; b=Q3NsGOhONHJ7e3OzOFZT8Gs2/6mzBpJU/BBIQ3/4b2eFqKCzAGzBAfLAx78Q+nW13f 6+cVVQsj3h/vEbBldb9ckYkF5gJC6sJeEuew+V6I9j+SRv9kXoMONMLtoOFkDoeAV6aW Ws82AWtcEvkwkmVKCXabvXtMaL0pKVHqxSlYnZMnv1KZCE94xQdxaai4ggymocADpxIO zcU3/0e9co0TgTDynt/ZicdTB4PnhiXK9cMYqgnk0N9WKU+AfELuhlATJI/O7MloGeo0 xlbniKfS+g/fNG6ScB5ihKXCwgsiJm1xJejVuEbRY8wXbVuMUtn+gcodKgcb363LpIy1 CbDw== X-Gm-Message-State: AAQBX9dsA3vG92k/T/SnfMbDyrkN0qMHr/Nmkmow+naOuworbNRu0/Ar KJOTsABedc4uUVHquiArJKN4JQ== X-Received: by 2002:a17:90b:2692:b0:246:f5a3:e942 with SMTP id pl18-20020a17090b269200b00246f5a3e942mr9234592pjb.18.1681430559599; Thu, 13 Apr 2023 17:02:39 -0700 (PDT) Received: from sarthakkukreti-glaptop.corp.google.com ([2620:15c:9d:200:72cc:7fa5:adcb:7c02]) by smtp.gmail.com with ESMTPSA id u18-20020a17090a891200b002470f179b92sm2212939pjn.43.2023.04.13.17.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 17:02:39 -0700 (PDT) From: Sarthak Kukreti To: 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 Cc: Jens Axboe , "Michael S. Tsirkin" , Jason Wang , Stefan Hajnoczi , Alasdair Kergon , Mike Snitzer , Christoph Hellwig , Brian Foster , Theodore Ts'o , Andreas Dilger , Bart Van Assche , Daniil Lunev , "Darrick J. Wong" Subject: [PATCH v3 0/3] Introduce provisioning primitives for thinly provisioned storage Date: Thu, 13 Apr 2023 17:02:16 -0700 Message-ID: <20230414000219.92640-1-sarthakkukreti@chromium.org> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog In-Reply-To: <20221229071647.437095-1-sarthakkukreti@chromium.org> References: <20221229071647.437095-1-sarthakkukreti@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,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 Hi, This patch series adds a mechanism to pass through provision requests on stacked thinly provisioned block devices. The linux kernel provides several mechanisms to set up thinly provisioned block storage abstractions (eg. dm-thin, loop devices over sparse files), either directly as block devices or backing storage for filesystems. Currently, short of writing data to either the device or filesystme, there is no way for users to pre-allocate space for use in such storage setups. Consider the following use-cases: 1) Suspend-to-disk and resume from a dm-thin device: In order to ensure that the underlying thinpool metadata is not modified during the suspend mechanism, the dm-thin device needs to be fully provisioned. 2) If a filesystem uses a loop device over a sparse file, fallocate() on the filesystem will allocate blocks for files but the underlying sparse file will remain intact. 3) Another example is virtual machine using a sparse file/dm-thin as a storage device; by default, allocations within the VM boundaries will not affect the host. 4) Several storage standards support mechanisms for thin provisioning on real hardware devices. For example: a. The NVMe spec 1.0b section 2.1.1 loosely talks about thin provisioning: "When the THINP bit in the NSFEAT field of the Identify Namespace data structure is set to ‘1’, the controller ... shall track the number of allocated blocks in the Namespace Utilization field" b. The SCSi Block Commands reference - 4 section references "Thin provisioned logical units", c. UFS 3.0 spec section 13.3.3 references "Thin provisioning". In all the above situations, currently, the only way for pre-allocating space is to issue writes (or use WRITE_ZEROES/WRITE_SAME). However, that does not scale well with larger pre-allocation sizes. This patchset introduces primitives to support block-level provisioning (note: the term 'provisioning' is used to prevent overloading the term 'allocations/pre-allocations') requests across filesystems and block devices. This allows fallocate() and file creation requests to reserve space across stacked layers of block devices and filesystems. Currently, the patchset covers a prototype on the device-mapper targets, loop device and ext4, but the same mechanism can be extended to other filesystems/block devices as well as extended for use with devices in 4 a-c. Patch 1 introduces REQ_OP_PROVISION as a new request type. The provision request acts like the inverse of a discard request; instead of notifying lower layers that the block range will no longer be used, provision acts as a request to lower layers to provision disk space for the given block range. Real hardware storage devices will currently disable the provisioing capability but for the standards listed in 4a.-c., REQ_OP_PROVISION can be overloaded for use as the provisioing primitive for future devices. Patch 2 implements REQ_OP_PROVISION handling for some of the device-mapper targets. Device-mapper targets will usually mirror the support of underlying devices. This patch also enables the use of fallocate in mode == 0 for block devices. Patch 3 wires up the loop device handling of REQ_OP_PROVISION and calls fallocate() with mode 0 on the underlying file/block device. Testing: -------- - Tested on a VM running a 6.2 kernel. - Preallocation of dm-thin devices: As expected, avoiding the need to zero out thinly-provisioned block devices to preallocate space speeds up the provisioning operation significantly: The following was tested on a dm-thin device set up on top of a dm-thinp with skip_block_zeroing=true. A) Zeroout was measured using `fallocate -z ...` B) Provision was measured using `fallocate -p ...`. Size Time A B 512M real 1.093 0.034 user 0 0 sys 0.022 0.01 1G real 2.182 0.048 user 0 0.01 sys 0.022 0 2G real 4.344 0.082 user 0 0.01 sys 0.036 0 4G real 8.679 0.153 user 0 0.01 sys 0.073 0 8G real 17.777 0.318 user 0 0.01 sys 0.144 0 Changelog: V3: - Drop FALLOC_FL_PROVISION and use mode == 0 for provision requests. - Drop fs-specific patches; will be sent out in a follow up series. - Fix missing shared block handling for thin snapshots. V2: - Fix stacked limit handling. - Enable provision request handling in dm-snapshot - Don't call truncate_bdev_range if blkdev_fallocate() is called with FALLOC_FL_PROVISION. - Clarify semantics of FALLOC_FL_PROVISION and why it needs to be a separate flag (as opposed to overloading mode == 0). Sarthak Kukreti (3): block: Introduce provisioning primitives dm: Add support for block provisioning loop: Add support for provision requests block/blk-core.c | 5 ++ block/blk-lib.c | 53 ++++++++++++++++ block/blk-merge.c | 18 ++++++ block/blk-settings.c | 19 ++++++ block/blk-sysfs.c | 8 +++ block/bounce.c | 1 + block/fops.c | 14 +++-- drivers/block/loop.c | 42 +++++++++++++ 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 | 110 +++++++++++++++++++++++++++++++--- drivers/md/dm.c | 4 ++ include/linux/bio.h | 6 +- include/linux/blk_types.h | 5 +- include/linux/blkdev.h | 16 +++++ include/linux/device-mapper.h | 11 ++++ 18 files changed, 333 insertions(+), 16 deletions(-) -- 2.40.0.634.g4ca3ef3211-goog