diff options
author | Xiaoyao Li <xiaoyao.li@intel.com> | 2024-03-20 03:39:07 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2024-04-23 17:35:26 +0200 |
commit | b2e9426c04fdd32d93a3a37db6b0c2e67c88c335 (patch) | |
tree | a9834ac90f0493c8a24502d2c6f1c7c97667aa6a /system | |
parent | 852f0048f3ea9f14de18eb279a99fccb6d250e8f (diff) |
physmem: Introduce ram_block_discard_guest_memfd_range()
When memory page is converted from private to shared, the original
private memory is back'ed by guest_memfd. Introduce
ram_block_discard_guest_memfd_range() for discarding memory in
guest_memfd.
Based on a patch by Isaku Yamahata <isaku.yamahata@intel.com>.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Message-ID: <20240320083945.991426-12-michael.roth@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'system')
-rw-r--r-- | system/physmem.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/system/physmem.c b/system/physmem.c index 5ebcf5be11..c3d04ca921 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3721,6 +3721,29 @@ err: return ret; } +int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t start, + size_t length) +{ + int ret = -1; + +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE + ret = fallocate(rb->guest_memfd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + start, length); + + if (ret) { + ret = -errno; + error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx (%d)", + __func__, rb->idstr, start, length, ret); + } +#else + ret = -ENOSYS; + error_report("%s: fallocate not available %s:%" PRIx64 " +%zx (%d)", + __func__, rb->idstr, start, length, ret); +#endif + + return ret; +} + bool ramblock_is_pmem(RAMBlock *rb) { return rb->flags & RAM_PMEM; |