[CRIU] Re: [PATCH cr 05/11] restore: map private vma-s before forking children

Andrey Vagin avagin at parallels.com
Wed Oct 17 03:47:32 EDT 2012


On Tue, Oct 16, 2012 at 07:35:22PM +0400, Pavel Emelyanov wrote:
> >>> +static int map_private_vma(pid_t pid, struct vma_area *vma,
> >>> +			struct vma_area **pvma, struct list_head *pvma_list)
> >>> +{
> >>> +	struct vma_area *p = *pvma;
> >>> +
> >>> +	if (!vma_priv(&vma->vma))
> >>> +		return 0;
> >>> +
> >>> +	list_for_each_entry_continue(p, pvma_list, list) {
> >>> +		if (p->vma.start > vma->vma.start)
> >>> +			 break;
> >>> +
> >>> +		if (p->vma.end == vma->vma.end &&
> >>> +		    p->vma.start == vma->vma.start) {
> >>> +			pr_info("COW 0x%016lx-0x%016lx 0x%016lx vma\n",
> >>> +				vma->vma.start, vma->vma.end, vma->vma.pgoff);
> >>> +			vma->vma.shmid = p->vma.shmid;
> >>
> >> Two vmas, one in parent the other one in child with equal starts and ends
> >> are not necessarily shared.
> > 
> > It's not a big deal. A child compares pages contents and if they are
> > differ, the content is restored. If two vmas are not shared, this method can
> > makebenefit even in this case if they have two equal pages;).
> 
> It's a GREAT deal. Consider you have two tasks (parent and child) and 2 vmas (1 in each)
> with the same start and end, but that were created _independently_ by both (not inherited
> on fork). Then parent touches a page in it, while child does not. On restore you a) make
> these VMAs "shared" and b) do _not_ restore any child's pages. After this lnce child
> _reads_ from the vma it will read parent's data, while shouldn't.

Yes, you are right. Thanks. And this problem exists event if regions are shared,
becuase a parent can touch a page after fork...

Could we create a bit mask for each private vma, which will contain touched
pages. During restore we will drop all extra pages...

Instead of bit mask, /proc/pid/pagemap can be read.

> 
> >>
> >>> +		}


More information about the CRIU mailing list