Hi, Currently, guest_memfd doesn't update inode's i_blocks or i_bytes at all. Hence, st_blocks in the struct populated by a userspace fstat() call on a guest_memfd will always be 0. This patch series makes guest_memfd track the amount of memory allocated on an inode, which allows fstat() to accurately report that on requests from userspace.
The inode's i_blocks and i_bytes fields are updated when the folio is associated or disassociated from the guest_memfd inode, which are at allocation and truncation times respectively. RFC v3 uses the .invalidate_folio() callback to update accounting in inode fields at truncation time, and sets AS_RELEASE_ALWAYS for guest_memfd mappings to enable .invalidate_folio() for guest_memfd. RFC v3 series is based on kvm-x86/next. + RFC v2: Removed a full custom implementation of .evict_inode for guest_memfd in favor of adding .unaccount_folio callback. + https://lore.kernel.org/all/[email protected]/T/ + RFC v1: https://lore.kernel.org/all/[email protected]/T/ Signed-off-by: Ackerley Tng <[email protected]> --- Ackerley Tng (4): KVM: guest_memfd: Track amount of memory allocated on inode KVM: guest_memfd: Set release always on guest_memfd mappings KVM: selftests: Wrap fstat() to assert success KVM: selftests: Test that st_blocks is updated on allocation tools/testing/selftests/kvm/guest_memfd_test.c | 32 +++++++++++++++------- tools/testing/selftests/kvm/include/kvm_syscalls.h | 2 ++ virt/kvm/guest_memfd.c | 15 ++++++++++ 3 files changed, 39 insertions(+), 10 deletions(-) --- base-commit: 5128b972fb2801ad9aca54d990a75611ab5283a9 change-id: 20260225-gmem-st-blocks-733f35d10211 Best regards, -- Ackerley Tng <[email protected]>

