Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

get_user_pages(9) [suse man page]

GET_USER_PAGES(9)					    Memory Management in Linux						 GET_USER_PAGES(9)

NAME
get_user_pages - pin user pages in memory SYNOPSIS
int get_user_pages(struct task_struct * tsk, struct mm_struct * mm, unsigned long start, int nr_pages, int write, int force, struct page ** pages, struct vm_area_struct ** vmas); ARGUMENTS
tsk task_struct of target task mm mm_struct of target mm start starting user address nr_pages number of pages from start to pin write whether pages will be written to by the caller force whether to force write access even if user mapping is readonly. This will result in the page being COWed even in MAP_SHARED mappings. You do not want this. pages array that receives pointers to the pages pinned. Should be at least nr_pages long. Or NULL, if caller only intends to ensure the pages are faulted in. vmas array of pointers to vmas corresponding to each page. Or NULL if the caller does not require them. DESCRIPTION
Returns number of pages pinned. This may be fewer than the number requested. If nr_pages is 0 or negative, returns 0. If no pages were pinned, returns -errno. Each page returned must be released with a put_page call when it is finished with. vmas will only remain valid while mmap_sem is held. Must be called with mmap_sem held for read or write. get_user_pages walks a process's page tables and takes a reference to each struct page that each user address corresponds to at a given instant. That is, it takes the page that would be accessed if a user thread accesses the given user virtual address at that instant. This does not guarantee that the page exists in the user mappings when get_user_pages 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. If write=0, the page must not be written to. If the page is written to, set_page_dirty (or set_page_dirty_lock, as appropriate) must be called after the page is finished with, and before put_page is called. get_user_pages 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. COPYRIGHT
Kernel Hackers Manual 2.6. July 2010 GET_USER_PAGES(9)

Check Out this Related Man Page

SF_BUF(9)						   BSD Kernel Developer's Manual						 SF_BUF(9)

NAME
sf_buf -- manage temporary kernel address space mapping for memory pages SYNOPSIS
#include <sys/sf_buf.h> struct sf_buf * sf_buf_alloc(struct vm_page *m, int flags); void sf_buf_free(struct sf_buf *sf); vm_offset_t sf_buf_kva(struct sf_buf *sf); struct vm_page * sf_buf_page(struct sf_buf *sf); DESCRIPTION
The sf_buf interface, historically the sendfile(2) buffer interface, allows kernel subsystems to manage temporary kernel address space map- pings for physical memory pages. On systems with a direct memory map region (allowing all physical pages to be visible in the kernel address space at all times), the struct sf_buf will point to an address in the direct map region; on systems without a direct memory map region, the struct sf_buf will manage a temporary kernel address space mapping valid for the lifetime of the struct sf_buf. Call sf_buf_alloc() to allocate a struct sf_buf for a physical memory page. sf_buf_alloc() is not responsible for arranging for the page to be present in physical memory; the caller should already have arranged for the page to be wired, i.e., by calling vm_page_wire(9). Several flags may be passed to sf_buf_alloc(): SFB_CATCH Cause sf_buf_alloc() to abort and return NULL if a signal is received waiting for a struct sf_buf to become available. SFB_NOWAIT Cause sf_buf_alloc() to return NULL rather than sleeping if a struct sf_buf is not immediately available. SFB_CPUPRIVATE Cause sf_buf_alloc() to only arrange that the temporary mapping be valid on the current CPU, avoiding unnecessary TLB shoot- downs for mappings that will only be accessed on a single CPU at a time. The caller must ensure that accesses to the virtual address occur only on the CPU from which sf_buf_alloc() was invoked, perhaps by using sched_pin(). Call sf_buf_kva() to return a kernel mapped address for the page. Call sf_buf_page() to return a pointer to the page originally passed into sf_buf_alloc(). Call sf_buf_free() to release the struct sf_buf reference. The caller is responsible for releasing any wiring they have previously acquired on the physical page; sf_buf_free() releases only the temporary kernel address space mapping, not the page itself. Uses of this interface include managing mappings of borrowed pages from user memory, such as in zero-copy socket I/O, or pages of memory from the buffer cache referenced by mbuf external storage for sendfile(2). SEE ALSO
sendfile(2), vm_page_wire(9) AUTHORS
The struct sf_buf API was designed and implemented by Alan L. Cox. This manual page was written by Robert N. M. Watson. BSD
January 28, 2007 BSD
Man Page