A question on vma_address()

Perr Zhang strongbox8 at zoho.com
Mon Oct 16 11:54:47 EDT 2017


I am reading codes on reverse mapping.
The code of vma_address() was last changed at 2017-02-24 17:46:55 -0800

The link of the commit is:
     https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a8fa41ad

The definition of vma_address():
    http://elixir.free-electrons.com/linux/latest/source/mm/internal.h#L343

The code of vma_address() looks like this:
------------------------------------------------------------------------------------
static inline unsigned long
__vma_address(struct page *page, struct vm_area_struct *vma)
{
	pgoff_t pgoff = page_to_pgoff(page);
	return vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
}

static inline unsigned long
vma_address(struct page *page, struct vm_area_struct *vma)
{
	unsigned long start, end;

	start = __vma_address(page, vma);
	...
	return max(start, vma->vm_start);
}
------------------------------------------------------------------------------------
This function is only called by rmap_walk_file() and rmap_walk_anon() which
ensure the page used by vma_address() is in an anon_vma or in an address_space.

Why  should we use the function max() on 'start' and 'vma->vm_start'?
Could the 'start' be less than 'vma->vm_start'?  If it is so, isn't it wrong to just 
return vma->vm_start but report an error?




More information about the Kernelnewbies mailing list