mbox series

[v3,0/3] Introduce provisioning primitives for thinly provisioned storage

Message ID 20230414000219.92640-1-sarthakkukreti@chromium.org (mailing list archive)
Headers show
Series Introduce provisioning primitives for thinly provisioned storage | expand

Message

Sarthak Kukreti April 14, 2023, 12:02 a.m. UTC
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(-)

Comments

Sarthak Kukreti April 20, 2023, 12:48 a.m. UTC | #1
Next revision of adding support for block provisioning requests.

Changes from v4:
- Add fix for block devices invalidating pagecache if blkdev_fallocate()
  is called with an invalid mode.
- s/max_provision_sectors/provision_max_bytes in sysfs.

Sarthak Kukreti (5):
  block: Don't invalidate pagecache for invalid falloc modes
  block: Introduce provisioning primitives
  dm: Add block provisioning support
  dm-thin: Add REQ_OP_PROVISION support
  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             |  9 +++++
 block/bounce.c                |  1 +
 block/fops.c                  | 28 +++++++++-----
 drivers/block/loop.c          | 42 ++++++++++++++++++++
 drivers/md/dm-crypt.c         |  5 ++-
 drivers/md/dm-linear.c        |  2 +
 drivers/md/dm-snap.c          |  8 ++++
 drivers/md/dm-table.c         | 23 +++++++++++
 drivers/md/dm-thin.c          | 73 ++++++++++++++++++++++++++++++++---
 drivers/md/dm.c               |  6 +++
 include/linux/bio.h           |  6 ++-
 include/linux/blk_types.h     |  5 ++-
 include/linux/blkdev.h        | 16 ++++++++
 include/linux/device-mapper.h | 17 ++++++++
 18 files changed, 318 insertions(+), 18 deletions(-)
Sarthak Kukreti May 6, 2023, 6:29 a.m. UTC | #2
Hi,

This patch series covers iteration 6 of adding support for block
provisioning requests.

Changes from v5:
- Remove explicit supports_provision from dm devices.
- Move provision sectors io hint to pool_io_hint. Other devices
  will derive the provisioning limits from the stack.
- Remove artifact from v4 to omit cell_defer_no_holder for
  REQ_OP_PROVISION.
- Fix blkdev_fallocate() called with invalid fallocate
  modes to propagate errors correctly.

Sarthak Kukreti (5):
  block: Don't invalidate pagecache for invalid falloc modes
  block: Introduce provisioning primitives
  dm: Add block provisioning support
  dm-thin: Add REQ_OP_PROVISION support
  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             |  9 +++++
 block/bounce.c                |  1 +
 block/fops.c                  | 31 +++++++++++++---
 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         | 23 ++++++++++++
 drivers/md/dm-thin.c          | 70 +++++++++++++++++++++++++++++++++--
 drivers/md/dm.c               |  6 +++
 include/linux/bio.h           |  6 ++-
 include/linux/blk_types.h     |  5 ++-
 include/linux/blkdev.h        | 16 ++++++++
 include/linux/device-mapper.h | 17 +++++++++
 18 files changed, 319 insertions(+), 14 deletions(-)
Darrick J. Wong May 12, 2023, 6:28 p.m. UTC | #3
On Fri, May 05, 2023 at 11:29:04PM -0700, Sarthak Kukreti wrote:
> Hi,
> 
> This patch series covers iteration 6 of adding support for block
> provisioning requests.

I didn't even notice there was a v6.  Could you start a fresh thread
when you bump the revision count, please?

--D

> Changes from v5:
> - Remove explicit supports_provision from dm devices.
> - Move provision sectors io hint to pool_io_hint. Other devices
>   will derive the provisioning limits from the stack.
> - Remove artifact from v4 to omit cell_defer_no_holder for
>   REQ_OP_PROVISION.
> - Fix blkdev_fallocate() called with invalid fallocate
>   modes to propagate errors correctly.
> 
> Sarthak Kukreti (5):
>   block: Don't invalidate pagecache for invalid falloc modes
>   block: Introduce provisioning primitives
>   dm: Add block provisioning support
>   dm-thin: Add REQ_OP_PROVISION support
>   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             |  9 +++++
>  block/bounce.c                |  1 +
>  block/fops.c                  | 31 +++++++++++++---
>  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         | 23 ++++++++++++
>  drivers/md/dm-thin.c          | 70 +++++++++++++++++++++++++++++++++--
>  drivers/md/dm.c               |  6 +++
>  include/linux/bio.h           |  6 ++-
>  include/linux/blk_types.h     |  5 ++-
>  include/linux/blkdev.h        | 16 ++++++++
>  include/linux/device-mapper.h | 17 +++++++++
>  18 files changed, 319 insertions(+), 14 deletions(-)
> 
> -- 
> 2.40.1.521.gf1e218fcd8-goog
>