mm/mmap: preallocate maple nodes for brk vma expansion

If the brk VMA is the last vma in a maple node and meets the rare criteria
that it can be expanded, then preallocation is necessary to avoid a
potential fs_reclaim circular lock issue on low resources.

At the same time use the actual vma start address (unaligned) when calling
vma_adjust_trans_huge().

Link: https://lkml.kernel.org/r/20221011160624.1253454-1-Liam.Howlett@oracle.com
Fixes: 2e7ce7d354 (mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap())
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reported-by: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Liam Howlett 2022-10-11 16:08:37 +00:00 коммит произвёл Andrew Morton
Родитель 7be1c1a3c7
Коммит 28c5609fb2
1 изменённых файлов: 6 добавлений и 12 удалений

Просмотреть файл

@ -2942,17 +2942,18 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
if (vma && if (vma &&
(!vma->anon_vma || list_is_singular(&vma->anon_vma_chain)) && (!vma->anon_vma || list_is_singular(&vma->anon_vma_chain)) &&
((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) { ((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) {
mas->index = vma->vm_start; mas_set_range(mas, vma->vm_start, addr + len - 1);
mas->last = addr + len - 1; if (mas_preallocate(mas, vma, GFP_KERNEL))
vma_adjust_trans_huge(vma, addr, addr + len, 0); return -ENOMEM;
vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0);
if (vma->anon_vma) { if (vma->anon_vma) {
anon_vma_lock_write(vma->anon_vma); anon_vma_lock_write(vma->anon_vma);
anon_vma_interval_tree_pre_update_vma(vma); anon_vma_interval_tree_pre_update_vma(vma);
} }
vma->vm_end = addr + len; vma->vm_end = addr + len;
vma->vm_flags |= VM_SOFTDIRTY; vma->vm_flags |= VM_SOFTDIRTY;
if (mas_store_gfp(mas, vma, GFP_KERNEL)) mas_store_prealloc(mas, vma);
goto mas_expand_failed;
if (vma->anon_vma) { if (vma->anon_vma) {
anon_vma_interval_tree_post_update_vma(vma); anon_vma_interval_tree_post_update_vma(vma);
@ -2993,13 +2994,6 @@ mas_store_fail:
vma_alloc_fail: vma_alloc_fail:
vm_unacct_memory(len >> PAGE_SHIFT); vm_unacct_memory(len >> PAGE_SHIFT);
return -ENOMEM; return -ENOMEM;
mas_expand_failed:
if (vma->anon_vma) {
anon_vma_interval_tree_post_update_vma(vma);
anon_vma_unlock_write(vma->anon_vma);
}
return -ENOMEM;
} }
int vm_brk_flags(unsigned long addr, unsigned long request, unsigned long flags) int vm_brk_flags(unsigned long addr, unsigned long request, unsigned long flags)