get_user_pages_remote(9)
β¨ get_user_pages_remote(9) β¨
ok okay so we're in the Kernel API Manual bestie, and this one is literally called get_user_pages_remote β it's the "pin user pages in memory" girlie π
πΈ SYNOPSIS πΈ
long get_user_pages_remote (struct mm_struct *mm , unsigned long start ,
unsigned long nr_pages , unsigned int gup_flags , struct page **pages ,
int *locked );
like, that's the whole signature, no notes π
π ARGUMENTS π
mmβ themm_structof the target mm. that's the address space we're snooping around in πstartβ the starting user address. where the lil adventure begins β¨nr_pagesβ how many pages fromstartwe're pinning. the page count, the vibe count π¦gup_flagsβ flags that modify the lookup behaviour. this is where you get to customise π¨pagesβ the array that receives pointers to the pages pinned. should be at leastnr_pageslong. orNULL, if the caller only intends to ensure the pages are faulted in π«Άlockedβ pointer to the lock flag that says whether the lock is held, and subsequently whetherVM_FAULT_RETRYfunctionality can be utilised. the lock must initially be held β no cap, that's a requirement π€
π DESCRIPTION π
so it returns either the number of pages pinned (which may be less than the number requested π) or an error. the deets on the return value:
- if
nr_pagesis0, returns0. - if
nr_pagesis>0but no pages were pinned, returns-errno. - if
nr_pagesis>0and some pages were pinned, returns the number of pages pinned. again, this may be less thannr_pages. she's allowed to under-deliver, it's fine π
the caller is responsible for releasing the returned pages, via put_page. that's on you, bestie, don't forget π₯
must be called with mmap_lock held for read or write. periodt.
get_user_pages_remote walks a process's page tables and takes a reference to each struct page that each user address corresponds to at a given instant. like, it takes the page that would be accessed if a user thread accesses the given user virtual address at that instant. a lil snapshot πΈ
this does not guarantee that the page exists in the user mappings when get_user_pages_remote returns, and there may even be a completely different page there in some cases (eg. if mmapped pagecache has been invalidated and subsequently re-faulted). however, it does guarantee that the page won't be freed completely. and mostly callers simply care that the page contains data that was valid at some point in time. typically, an IO or similar operation cannot guarantee anything stronger anyway because locks can't be held over the syscall boundary. it's giving "best we can do" energy π
ifgup_flags & FOLL_WRITE == 0, the page must not be written to. if the page is written to,set_page_dirty(orset_page_dirty_lock, as appropriate) must be called after the page is finished with, and beforeput_pageis called. write that down π
get_user_pages_remote is typically used for fewer-copy IO operations, to get a handle on the memory by some means other than accesses via the user virtual addresses. the pages may be submitted for DMA to devices or accessed via their kernel linear mapping (via the kmap APIs). care should be taken to use the correct cache flushing APIs. π§
see also get_user_pages_fast, for performance critical applications β‘
π big note:get_user_pages_remoteshould be phased out in favor ofget_user_pages_locked|unlockedorget_user_pages_fast. nothing should useget_user_pages_remotebecause it cannot passFAULT_FLAG_ALLOW_RETRYtohandle_mm_fault. she's deprecated, your honor ππ
π¦ SEE ALSO π¦
kernel file ./mm/gup.c β and the whole friend group:
try_grab_folio(9)unpin_user_page(9)unpin_folio(9)folio_add_pin(9)unpin_user_pages_dirty_lock(9)unpin_user_page_range_dirty_lock(9)unpin_user_pages(9)unpin_user_folio(9)unpin_folios(9)try_grab_folio_fast(9)follow_page_mask(9)__get_user_pages(9)fixup_user_fault(9)populate_vma_page_range(9)fault_in_writeable(9)fault_in_subpage_writeable(9)fault_in_readable(9)get_dump_page(9)get_user_pages(9)get_user_pages_fast_only(9)get_user_pages_fast(9)pin_user_pages_fast(9)pin_user_pages_remote(9)pin_user_pages(9)memfd_pin_folios(9)folio_add_pins(9)
that's the whole page, bestie, no crumbs left π this one came from the source dir ./mm and it's dated October 2026 β so like, future vibes only πβ¨ byeee π«Άπ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms