Product SiteDocumentation Site

3.4.13. getFreePages

This method queries the host system for free pages of specified size. For the input, the pages argument is a Python list of page sizes that caller is interested in (the size unit is kilobytes, so e.g. pass 2048 for 2MB), then the start argument refers to the first NUMA node that info should be collected from, and cellcount argument tells how many consecutive nodes should be queried. The function returns a Python list containing an indicator of whether or not pages of the specified input sizes are available.
An error will be thrown if the host system does not support memory pages of the size requested.

Example 3.24. Using getFreePages

# Example-24.py
#!/usr/bin/env python3
import sys
import libvirt

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

pages = [2048]
start = 0
cellcount = 4
buf = conn.getFreePages(pages, start, cellcount)

i = 0
for page in buf:
    print("Page Size: " + str(pages[i]) + " Available pages: " + str(page))
    ++i

conn.close()
exit(0)