Function Report

Linux Kernel (v4.4)

Source File:mm\mmap.c Create Date:2016-01-14 12:34:11
Last Modify:2016-01-11 07:01:32 Copyright©Brick
home page Tree
Annotate the kernelChinese

Function Name:vma_merge

Function:struct vm_area_struct * vma_merge(struct mm_struct *mm, struct vm_area_struct *prev, unsigned long addr, unsigned long end, unsigned long vm_flags, struct anon_vma *anon_vma, struct file *file, unsigned long pgoff, struct mempolicy *policy, struct vm_userfaultfd_ctx vm_userfaultfd_ctx)

Return Type:struct vm_area_struct *

Parameter:

Type Parameter NameRemarks
struct mm_struct * mm
struct vm_area_struct * prev
unsigned long addr
unsigned long end
unsigned long vm_flags
struct anon_vma * anon_vma
struct file * file
unsigned long pgoff
struct mempolicy * policy
struct vm_userfaultfd_ctx vm_userfaultfd_ctx

Function description:Given a mapping request(addr,end,vm_flags,file,pgoff), figure out whether that can be merged with its predecessor or its successor. Or both(it neatly fills a hole).

1043  pglen = end - addr >> determines the page size
1051  If vm_flags & Special vmas that are non-mergable, non-mlock()able. Note: mm/huge_memory.c VM_NO_THP depends on this definition. then Returning NULL
1054  If prev then next = linked list of VM areas per task, sorted by address
1056  Else next = list of VMAs
1058  area = next
1059  If next && The first byte after our end address within vm_mm. == end then next = linked list of VM areas per task, sorted by address
1069  If prev && The first byte after our end address within vm_mm. == addr && mpol_equal(vma_policy, policy) && Return true if we can merge this(vm_flags,anon_vma,file,vm_pgoff) beyond(at a higher virtual address and file offset than) the vma. then
1084  Else We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that is already present in an i_mmap tree without adjusting the tree
1087  If result of We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that is already present in an i_mmap tree without adjusting the tree then Returning NULL
1089  khugepaged_enter_vma_merge(prev, vm_flags)
1090  Returning prev
1100  If next && end == Our start address within vm_mm. && mpol_equal(policy, vma_policy) && Return true if we can merge this(vm_flags,anon_vma,file,vm_pgoff) in front of(at a lower virtual address and file offset than) the vma. then
1101  If prev && addr < The first byte after our end address within vm_mm. then We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that is already present in an i_mmap tree without adjusting the tree
1104  Else We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that is already present in an i_mmap tree without adjusting the tree
1107  If result of We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that is already present in an i_mmap tree without adjusting the tree then Returning NULL
1109  khugepaged_enter_vma_merge(area, vm_flags)
1110  Returning area
1113  Returning NULL
Caller
Function NameFunction description
mlock_fixup handle mlock[all]/munlock[all] requests.
mmap_region
do_brkthis is really a simplified"do_mmap". it only handles anonymous maps. eventually we may be able to do some brk-specific accounting here.
copy_vmaCopy the vma structure to a new location in the same mm, prior to moving page table entries, to effect an mremap move.
mprotect_fixup
madvise_behaviorWe can potentially split a vm area into separate areas, each area with its own behavior.
mbind_rangeStep 2: apply policy to a range and do splits.
userfaultfd_release
userfaultfd_register
userfaultfd_unregister