Linux get_user_pages 保证页面不会被调换吗?

Does Linux get_user_pages guarantee pages will not be swapped?

假设我在用户 space 的缓冲区上调用了 get_user_pages。我知道这基本上 "fault" 所有页面以确保它们存在于 RAM 中。

但是,这是否保证它们会留在 RAM 中而不被换出?

这是我在 4.19.69 内核上尝试的一些代码的简单示例:

down_read(&current->mm->mmap_sem);
rc = get_user_pages(
    start,          //start virtual address
    1,              //number of pages
    FOLL_WRITE,     //flags, see FOLL_* in mm.h
    &p,             //destination page* array
    NULL            //destination vma* array (unneeded)
);
up_read(&current->mm->mmap_sem);

if (rc <= 0) {
    printk(KERN_ERR "Could not get user page :(\n");
    return rc;
}

printk(KERN_INFO "Page is %sreserved\n", PageReserved(p) ? "" : "not ");

根据 dmesg 消息,页面未标记为保留。假设我开始了一个 DMA 传输 to/from 这个(物理)页面。这是否意味着 Linux 可能会在 DMA 硬件为 运行 时将其换出到磁盘?如果是这样,保证页面保持不变的正确方法是什么?

get_user_pages() has a comment referring to get_user_pages_remote(). The latter's doc says:

get_user_pages_remote() - pin user pages in memory

因此,在您使用例如取消固定它们之前,它们不会被交换。 put_user_pages().