ioctl_pagemap_scan(2)
π ioctl_pagemap_scan β bestie edition
okay so this is a page from the System Calls Manual (section 2, obvi) and it's literally about getting and/or clearing page flags. come learn with me π«Ά
β¨ NAME β¨
ioctl_pagemap_scan β get and/or clear page flags
π LIBRARY π
Standard C library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <linux/fs.h> /* Definition of struct pm_scan_arg,
struct page_region, and PAGE_IS_* constants */
#include <sys/ioctl.h>
int ioctl(int pagemap_fd, PAGEMAP_SCAN, struct pm_scan_arg *arg);
π¦ DESCRIPTION π¦
So this ioctl(2) is your girl for getting and optionally clearing some specific flags from page table entries. the tea gets returned with PAGE_SIZE granularity, so don't expect anything finer than that, bestie.
Now listen, if you wanna start tracking the written state (that's the flag, mwah) of a page or a range of memory, you gotta have UFFD_FEATURE_WP_ASYNC enabled by the UFFDIO_API ioctl(2) on userfaultfd, and the memory range has to be registered with the UFFDIO_REGISTER ioctl(2) in UFFDIO_REGISTER_MODE_WP mode. no shortcuts, it's giving prerequisites π
π Supported page flags
these page table entry flags are the ones that get a seat at the table:
PAGE_IS_WPALLOWEDβ the page has asynchronous write-protection enabled. iconic.PAGE_IS_WRITTENβ the page has been written to from the time it was write protected.PAGE_IS_FILEβ the page is file backed.PAGE_IS_PRESENTβ the page is present in the memory.PAGE_IS_SWAPPEDβ the page is swapped.PAGE_IS_PFNZEROβ the page has zero PFN.PAGE_IS_HUGEβ the page is THP or Hugetlb backed.
π« Supported operations
the get operation is always performed if the output buffer is specified. the other operations are as follows:
PM_SCAN_WP_MATCHINGβ write protect the matched pages.PM_SCAN_CHECK_WPASYNCβ abort the scan when a page is found which doesn't have the Userfaultfd Asynchronous Write protection enabled.
π The struct pm_scan_arg argument
struct pm_scan_arg {
__u64 size;
__u64 flags;
__u64 start;
__u64 end;
__u64 walk_end;
__u64 vec;
__u64 vec_len;
__u64 max_pages
__u64 category_inverted;
__u64 category_mask;
__u64 category_anyof_mask
__u64 return_mask;
};
sizeβ set this bad boy to the size of the structure in bytes, likesizeof(struct pm_scan_arg). don't freestyle it.flagsβ the operations you wanna perform go right here.startβ the starting address of the scan lives here.endβ and the ending address of the scan lives here.walk_endβ the kernel hands you back the scan's ending address in this one. ifwalk_endequalsend, that means the scan completed on the entire range. slay, full coverage β¨vecβ the address of thepage_regionarray for output. and that struct is:
struct page_region {
__u64 start;
__u64 end;
__u64 categories;
};
vec_lenβ the length of thepage_regionstruct array.max_pagesβ the optional limit for the number of output pages you need.category_invertedβPAGE_IS_*categories whose values match if0instead of1. yes, inverted, we love a plot twist πcategory_maskβ skip pages for which anyPAGE_IS_*category doesn't match.category_anyof_maskβ skip pages for which noPAGE_IS_*category matches.return_maskβPAGE_IS_*categories that are to be reported inpage_region.
π₯ RETURN VALUE π₯
if it goes wrong, -1 comes back and errno gets set to tell you exactly what went down.
π ERRORS π
error codes can be one of these (but not limited to, so don't come for me):
EINVALβ invalid arguments, i.e. invalid size of the argument, invalid flags, invalid categories, thestartaddress isn't aligned withPAGE_SIZE, orvec_lenis specified whenvecisNULL.EFAULTβ invalidargpointer, invalidvecpointer, or invalid address range specified bystartandend.ENOMEMβ no memory is available. tragic.EINTRβ Fetal signal is pending.
β STANDARDS β
Linux. periodt.
π§ HISTORY π§
Linux 6.7. she's new here but she's already that girl.
π SEE ALSO π
okay bestie that's the whole page π this was Linux man-pages 6.7, dated 2024-01-28, and yes we read the whole thing, no skimming, main character energy only πβ¨
π¦ where this page comes from
- ubuntu noble: manpages-dev 6.7-2
- π the page's license: Linux-man-pages-copyleft
- Copyright (C) 2023 Collabora
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms