Many hosts immediately discard each free page guest reports.
This means that re-zeroing them in the guest after allocation
is redundant.

This series lets a page reporting device advertise that its completed
reports guarantee zero contents. It tracks that state through the buddy
allocator and uses it to skip clearing freshly allocated user folios.

The series is based on Linux 7.4-rc3, commit 666539eecdf4d.

This is the first part of the project. Further hugepage support, along with
the init_on_free and FPI_ZEROED additions suggested by Matthew Wilcox,
is left for follow-up work if this series is merged.

Patches 1-2 add PG_zeroed tracking and the page reporting device's zeroing
guarantee.

Patches 3-5 skip redundant zeroing in the PMD THP, order-0 (including
x86), and mTHP anonymous allocation paths.

Patch 6 adds VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED to negotiate this
with host.

Patch 7 adds a flush parameter with an approximate reporting budget for
deterministic testing.

For a 512 MiB anonymous allocation using MADV_POPULATE_WRITE in a 2 GiB,
one-vCPU KVM guest, ten samples per mode gave:

  task-clock              feature off          feature on
  PMD THP                 229.0 +/- 20.0 ms     74.7 +/- 35.8 ms
  order-0                 336.1 +/-  6.5 ms     99.2 +/- 19.3 ms

Assisted-by: LLM

Changes since v10:
- Rewritten along the lines suggested by Matthew Wilcox [1].

[1] https://lore.kernel.org/all/[email protected]/

Michael S. Tsirkin (7):
  mm: add PG_zeroed page flag and buddy merge tracking
  mm: page_reporting: support host-zeroed reported pages
  mm: skip zeroing in vma_alloc_anon_folio_pmd for pre-zeroed pages
  mm: skip zeroing of pre-zeroed order-0 user pages
  mm: skip zeroing in alloc_anon_folio for pre-zeroed pages
  virtio_balloon: add DEVICE_INIT_REPORTED feature
  mm: page_reporting: add flush parameter with page budget

 drivers/virtio/virtio_balloon.c     | 33 ++++++++++++++++++++--
 include/linux/highmem.h             | 29 +++++++++++++++++--
 include/linux/mm.h                  | 32 +++++++++++++++++----
 include/linux/page-flags.h          | 15 +++++++++-
 include/linux/page_reporting.h      |  8 ++++++
 include/uapi/linux/virtio_balloon.h |  1 +
 mm/huge_memory.c                    | 11 ++------
 mm/memory.c                         | 10 +------
 mm/page_alloc.c                     | 43 ++++++++++++++++++++++++-----
 mm/page_reporting.c                 | 43 +++++++++++++++++++++++++++++
 10 files changed, 189 insertions(+), 36 deletions(-)


base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
-- 
MST


Reply via email to