[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v7 0/4] unmap_page_range optimisation


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Date: Wed, 2 Dec 2026 18:25:32 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=McvDnr9SsWyQY//SaoJWPNRnDFLVUCDaxnNqFkp3PM0=; b=ZX9N2ZyB/NAAM7w1sVI7+Vyt6K5TVPClnxle92pGGeKI/WIh/aWQCiZeI5+XI7tV2O63M/fhQHXl8DIv+XPKCEMun9GiFVOrCM2dpQ4XN/9Qwvt8PZThLj/68B61+pj+lxlnMhCu+cgzzPuHIn/2CawWQHwBie/uEi1o0T9C4i6kEaWlEkEG+/AjoUL51tSUVrCbL00Mt+5xcrBzoNhjFH8y0/6VV/pILi6IFlppRy76p07JuhPyG7e0mFS6bmsABezuIbz9RJV6dRCz+69i2FMeqk2htIHnUmYR+0A0t7Po1/s/8byR5Q7Zy2HnPCDhw0nBan4NTEES4AUWsmA5DQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iocgkyn5hgFsYAODZhrM8yMzizUeOndkLvAOJ/AFCjFG0WzLGDrZB/zRXHIddF1X5YbJLWcRxg9Lz+x4+rIwmQ48EfrpgIXbFoeW6qEz+neVKetN/ou6zIfZwHMexMB7m4X5PEGuSIqGU1QcaNjWz7vKwmrMHWazg+diZxDP/aj5UUkiT/lXAztTKXE2RF/kLAn6HGSgSlDYwUeNNsgUamI0m8ztAzm82gHOK3fURCt9hAxh4hv7GZ4YjE9smlmgWKtzaOh3GSseO5OVcDPB96eQotqX6oeMx6YeGZCZmi+6fVlqOer5xu49w0gPHMg9WvDD7cBkbSWMrxliHtvUPg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: jbeulich@xxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger@xxxxxxxxxxxxxx, teddy.astie@xxxxxxxxxx, Kevin Lampis <kevin.lampis@xxxxxxxxxx>
  • Delivery-date: Wed, 02 Dec 2026 18:25:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

https://lore.kernel.org/xen-devel/20260727150615.1373200-1-kevin.lampis@xxxxxxxxxx/

Previous discussion:
RFC: unmap_page_range optimisation (avoiding emulation faults during VM 
migration)
https://lore.kernel.org/xen-devel/16133EFF-88FF-467F-B78F-E96EB148C3A5@xxxxxxxxxx/

This series adds a new MMU_PT_UPDATE_SWAP sub-op to the mmu_update hypercall
which Linux can use from a new pte_get_and_clear pv-op to significantly improve
the performance of unmap_page_range.

A microbenchmark[1] which allocates a large number of pages and then clears
them shows a performance increase from 1100ms to 640ms using the
new pte_get_and_clear pv-op.

Further profiling the microbenchmark with bpftrace[2] shows that Linux calls
unmap_page_range() 23 times with an average execution time of 48ms
dropping to 28ms when using the new operation.

Changes in v7:
- Review comments for patches 1 and 2

Changes in v6:
- De-duplicate code in mm.c/mm.h
- No changes to Linux or XTF patches

Changes in v5:
- New Xen patch x86: rearrange how mod_l*_entry() functions call UPDATE_ENTRY
- New XTF patch (XTF) Add test mmu-pt-update-swap
- Review comments

Changes in v4:
- Review comments

Changes in v3:
- Extend swap to work with l2/l3/l4 PTEs and any value not just 0
- Other review comments

Changes in v2:
- Add a sub-op to mmu_update instead of new hypercall
- Add Linux patch
- Other review comments

[1] microbenchmark
#include <err.h>
#include <sys/mman.h>
#include <time.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>

static uint64_t nsec(void)
{
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    return (uint64_t)ts.tv_sec * 1e9 + ts.tv_nsec;
}

int main(int argc, char **argv)
{
    const size_t len = 1024UL * 1024 * 1024 * 4;
    const long pagesz = sysconf(_SC_PAGESIZE);

    char *p = mmap(NULL, len,
                   PROT_READ | PROT_WRITE,
                   MAP_PRIVATE | MAP_ANONYMOUS,
                   -1, 0);
    if ( p == MAP_FAILED )
        err(1, "mmap");

    /* Fault every page in */
    for (size_t i = 0; i < len; i += pagesz)
        p[i] = 1;

    uint64_t start = nsec();

    if ( madvise(p, len, MADV_DONTNEED) )
        err(1, "madvise");

    uint64_t end = nsec();

    printf("MADV_DONTNEED on %zu MB took %.3f ms\n",
           len / 1024 / 1024,
           (end - start) / 1e6);

    munmap(p, len);
    return 0;
}

[2] bpftrace
bpftrace -e '
kprobe:unmap_page_range
/comm == "a.out"/
{
    @start[tid] = nsecs;
}

kretprobe:unmap_page_range
/@start[tid] && comm == "a.out"/
{
    $delta = nsecs - @start[tid];
    @count = count();
    @total = sum($delta);
    delete(@start[tid]);
}

interval:s:10
{
    printf("avg call time = %d ns (%d calls)\n",
           (@total / @count), (uint64)@count);
    exit();
}'

Kevin Lampis (4):
  x86: extend mod_l*_entry() to optionally return the old PTE value
  x86: extend do_mmu_update() to support returning the old PTE value
  (Linux) xen: Add new Xen pv-op pte_get_and_clear.
  (XTF) Add test mmu-pt-update-swap

 xen/arch/x86/mm.c             | 91 +++++++++++++++++++++++++++--------
 xen/arch/x86/pv/mm.h          | 28 +++++++++--
 xen/common/kernel.c           |  1 +
 xen/include/public/features.h |  3 ++
 xen/include/public/xen.h      |  1 +
 5 files changed, 100 insertions(+), 24 deletions(-)

-- 
2.52.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.