Re: [PATCH] mm: Ignore VM_SOFTDIRTY on VMA merging, v2

From: Cyrill Gorcunov
Date: Thu Jan 23 2014 - 16:45:19 EST


On Thu, Jan 23, 2014 at 01:02:35PM -0800, Andrew Morton wrote:
> On Thu, 23 Jan 2014 19:14:45 +0400 Cyrill Gorcunov <gorcunov@xxxxxxxxx> wrote:
>
> > VM_SOFTDIRTY bit affects vma merge routine: if two VMAs has all
> > bits in vm_flags matched except dirty bit the kernel can't longer
> > merge them and this forces the kernel to generate new VMAs instead.
>
> Do you intend to alter the brk() and binprm code to set VM_SOFTDIRTY?

brk() will be "dirtified" now with this merge fix.
brk
do_brk
out:
...
vma->vm_flags |= VM_SOFTDIRTY;

this will work even if vma get merged, the problem was that earlier
we tried to merge without VM_SOFTDIRTY flag. And matcher failed.

do_brk
flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
vma = vma_merge(mm, prev, addr, addr + len, flags,
NULL, NULL, pgoff, NULL);
if (vma)
goto out;
...
out:
...
vma->vm_flags |= VM_SOFTDIRTY;

That said I'm not really sure now if I should alert @flags in code above.
Should I add VM_SOFTDIRTY into @flags for clarity?

Same for binprm -- the vma allocated for bprm->vma is dirtified
__bprm_mm_init
vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;

then setup_arg_pages calls mprotect_fixup with @vm_flags having dirty bit
set thus it'll be propagated to vma

mprotect_fixup
...
vma->vm_flags = newflags;

the @newflags will have dirty bit set from caller code.

Or you mean something else which I'm missing?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/