Linux virtualization list
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] virtio-pmem & device-dax: host-backed range discard via fallocate() / MADV_REMOVE
@ 2026-11-30  1:23 Sourav Panda
  2026-11-30  1:23 ` [RFC PATCH 1/5] dax/device: validate mmap offset alignment against dev_dax->align Sourav Panda
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Sourav Panda @ 2026-11-30  1:23 UTC (permalink / raw)
  To: djbw, vishal.l.verma, dave.jiang, alison.schofield,
	pankaj.gupta.linux, mst, jasowangio, eperezma, viro, brauner
  Cc: iweiny, jack, xuanzhuo, shuah, david, souravpanda, nvdimm,
	linux-cxl, virtualization, linux-fsdevel, linux-kselftest,
	linux-mm, linux-kernel

Device-dax on top of virtio-pmem is a cheap way to give an application
in a guest a large heap.  With 1G alignment the guest spends about 4K
of struct page per GiB instead of 16M, the mappings are PUD entries, and
the guest physical layout never changes.  What it cannot do is give
memory back: fallocate() on /dev/daxX.Y fails with -ENODEV, so once the
application has touched a page the host backs it until the device goes
away.

This series lets userspace punch holes in a device-dax instance, with
fallocate(FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE) or
madvise(MADV_REMOVE), and passes them to the host through a new
virtio-pmem discard request.  The host frees the backing, for example by
punching a hole in the backing file, and the range reads back as zeroes.

  Guest
  userspace     fallocate(PUNCH_HOLE) / madvise(MADV_REMOVE)
       |
       v
  vfs           vfs_fallocate()                              [patch 3]
       |
       v
  device-dax    dax_fallocate()                              [patch 4]
       |          1. block page faults on the device
       |          2. zap the align-sized mappings covering the range
       |          3. -EBUSY if any page is still referenced
       v
  libnvdimm     nvdimm_discard() -> nd_region->discard()     [patch 2]
       |
       v
  virtio-pmem   VIRTIO_PMEM_REQ_TYPE_DISCARD {offset, len}   [patch 2]
  =====|==============================================================
       v
  Host VMM      punch a hole in the backing file

The granularity of a discard is whatever the host can free, 2M for a
hugetlbfs-backed region say, and has nothing to do with the size of the
guest mappings.  Device-dax only has mappings of dev_dax->align, so a
discard zaps the entries that cover it and lets them fault back in at
full size.  Guest mappings are never split:

  guest mapping   |<------------------ 1 GiB ----------------->|
  host backing    | 2M | 2M | 2M | .. | 2M | 2M | .. | 2M | 2M |
                                        ^^
                    released to the host; zero-filled on next touch

Patch 1 fixes an existing bug in the mmap() offset check.  Patch 2 adds
the virtio-pmem request and a ->discard() hook on the nd_region, patch 3
lets a character device implement ->fallocate(), patch 4 is the
device-dax side and patch 5 a selftest.

Things I would like opinions on:

 - The virtio side needs a spec change, which I will send separately.
   The request guarantees zeroes on the next read, which virtio-blk
   DISCARD does not, so "discard" may be the wrong name for it.

 - virtio-mem solves a related problem, but it resizes kernel-managed
   RAM at the host's request.  Here the application owns the region and
   decides which ranges to release, without hot(un)plug and without
   giving up the 1G mappings.

 - On devices that can discard, page faults take a per-device percpu
   rwsem for read.  Patch 4 has the numbers behind that choice.

 - Nothing wipes a device when its last user exits.  A supervisor that
   hands a device to a new user is expected to punch out the whole range
   first.

Sourav Panda (5):
  dax/device: validate mmap offset alignment against dev_dax->align
  virtio_pmem: add VIRTIO_PMEM_F_DISCARD and region discard hook
  vfs: allow fallocate() on character devices implementing ->fallocate()
  dax/device: add fallocate() discard support
  selftests/dax: add devdax_discard tests

 Documentation/ABI/testing/sysfs-bus-dax      |  11 +
 drivers/dax/bus.c                            |  40 +++
 drivers/dax/bus.h                            |   5 +
 drivers/dax/dax-private.h                    |  39 +++
 drivers/dax/device.c                         | 211 +++++++++++++++-
 drivers/dax/pmem.c                           |  16 ++
 drivers/nvdimm/nd.h                          |   3 +
 drivers/nvdimm/nd_virtio.c                   | 170 +++++++++++--
 drivers/nvdimm/region_devs.c                 |  61 +++++
 drivers/nvdimm/virtio_pmem.c                 |  44 ++++
 drivers/nvdimm/virtio_pmem.h                 |  10 +-
 fs/open.c                                    |   8 +-
 include/linux/libnvdimm.h                    |  20 ++
 include/uapi/linux/virtio_pmem.h             |  49 +++-
 tools/testing/selftests/dax/.gitignore       |   2 +
 tools/testing/selftests/dax/Makefile         |   3 +-
 tools/testing/selftests/dax/devdax_discard.c | 250 +++++++++++++++++++
 17 files changed, 905 insertions(+), 37 deletions(-)
 create mode 100644 tools/testing/selftests/dax/.gitignore
 create mode 100644 tools/testing/selftests/dax/devdax_discard.c


base-commit: ebb7a8dc1e74c705daffe11c2faf38ec2628f838
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-30 18:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  1:23 [RFC PATCH 0/5] virtio-pmem & device-dax: host-backed range discard via fallocate() / MADV_REMOVE Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 1/5] dax/device: validate mmap offset alignment against dev_dax->align Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 2/5] virtio_pmem: add VIRTIO_PMEM_F_DISCARD and region discard hook Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 3/5] vfs: allow fallocate() on character devices implementing ->fallocate() Sourav Panda
2026-11-30 13:55   ` Jan Kara
2026-11-30 18:08     ` Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 4/5] dax/device: add fallocate() discard support Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 5/5] selftests/dax: add devdax_discard tests Sourav Panda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox