Unsigned long vm_pgoff to vm_area_struct

I was reading the Linux device drivers memory management section and I came across vm_area_struct . The structure has a forffset field, namely unsigned long vm_pgoff .

I have checked the comment for a member like /* Offset (within vm_file) in PAGE_SIZE units, *not* PAGE_CACHE_SIZE */

. I'm not really sure if this is an offset in the vma scope or an offset to the side of a memory mapped file.

And I saw that the driver mmap implementation code has the following line to recalculate the offset by shifting the item by the PAGE_SHIFT bit .

unsigned long off = vma->vm_pgoff << PAGE_SHIFT;

      

I can't figure out the same thing and any help on this would be great.

+3


source to share


2 answers


In the source code ( mm.h file ) the functions

 static inline unsigned long do_mmap(struct file *file, unsigned long addr,
unsigned long len, unsigned long prot,
unsigned long flag, unsigned long offset)

      



I found an expression offset >> PAGE_SHIFT

(right shift) that is used as a pgoff

parameter do_mmap_pgoff

, so obviously to "restore" the original value offset

we need to do Left Shift with the same PAGE_SHIFT

(how lowmem_page_address

does the function do it).

+1


source


According to the book Linux Device Drivers, 3rd Edition ,

unsigned long vm_pgoff;

Offset of the region in the file, in pages. When a file or device is displayed, this is the file position of the first page displayed in this area.



So this is the offset, as measured by the number of pages, in the file / device. So the first page in vm_area is the "vm_pgoff" page of the file / device.

The mm_types.h file says the same thing.

+4


source







All Articles