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

Pavel Emelyanov xemul at parallels.com
Tue Oct 16 11:35:22 EDT 2012


>>> +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.

>>
>>> +		}


More information about the CRIU mailing list