a question about function arch_get_unmapped_area in memory management(linux)
in the book of http://www.ecsl.cs.sunysb.edu/elibrary/linux/mm/mm.pdf page 202~203
if (addr) {
addr = PAGE_ALIGN(addr);
vma = find_vma(current->mm, addr);
if (TASK_SIZE - len >= addr &&
(!vma || addr + len <= vma->vm_start))
return addr;
}
If addr is non-zero, we align it to a page boundary. We call the function find vma() to see if the given address is contained in an existing VMA. If it is not contained in any VMA and the end of the mapping is wit开发者_StackOverflowhin the process address space, we return the address.
My question is:
why we check addr + len <= vma->vm_start? how is it possible addr + len <= vma->vm_start? if an addr is found in a vma, then addr > vm_start, right? if len is positive (should be,right), so how could addr + len <= vma->vm_start?The answer is made clear if you look at the remark in the source of find_vma:
/* Look up the first VMA which satisfies addr < vm_end, NULL if none. */
So, find_vma() might return a vma that doesn't actually map the address, hence the check.
精彩评论