[CRIU] [RFC 1/2] pagemap: Introduce pagemap cache
Cyrill Gorcunov
gorcunov at gmail.com
Thu Feb 13 03:55:25 PST 2014
On Thu, Feb 13, 2014 at 03:40:37PM +0400, Pavel Emelyanov wrote:
> > +static int pmc_fill_cache(pmc_t *pmc, unsigned long from)
> > +{
> > + size_t size_map, size_chunk, nr_vmas = 0;
> > + size_t size_left = PAGEMAP_MAP_SIZE;
> > + struct vma_area *vma, *prev = NULL;
> > + unsigned long size_cov = 0;
> > + unsigned long size_gap = 0;
> > +
> > + pmc->start = from;
>
> The from should be 2MB-aligned value.
The VMAs addresses are always 4K aligned as minimum, how to cache
addresses which are not 2M aligned?
> > + pmc->end = from + PAGEMAP_MAP_SIZE;
> > +
> > + pr_trace("pmc_fill_cache %lx-%lx\n", pmc->start, pmc->end);
> > +
> > + vma = pmc_lookup_vma(pmc, from);
>
> The vma can be passed down by the caller. And the pmc api would look like
>
> u64 pagemap_read(unsigned long vaddr, struct vm_area_struct *vma)
>
> Where vma is the area from which to continue caching in case we've missed it.
I don't see much point in it. When we init cache we pass VMA list header
which we remember (which in turn implies that VMA list is consistent when
we use cache). Because we dump VMAs in sequent order the cache can find
by self which VMA belongs to address passed by a caller.
> > +
> > + /* Cache might be partially filled */
> > + pmc->end = from + size_cov;
> > +
> > + size_map = PAGEMAP_PFN_OFF(pmc->end - pmc->start);
>
> I don't get the arithmetic above. What is it about? You should calculate the
> total length of vmas withing the 2MB chunk you're about to read and if this
> value is less than X (X should be estimated constant) then just read the vma
> length. The above maths seem to do more than that.
The cache migh be partially filled. That is how
- when we start filling the 2M cache at first we cache first chunk
(note the VMA we're caching might be greater than 2M in size so
we cache it one chunk by another).
- another scenario -- the vma we've cached is small and there is space
left in cache -- we lookup over forward VMAs to find if there VMAs
which can fit the rest of the cache by whole (ie the next VMA must
be small enough to fit the rest of 2M cache). So we can say 4 small
VMAs which fit the 2M cache but their summary size is less than 2M.
Thus at the final we count how many bytes in cache is filled, for
statistics purpose.
More information about the CRIU
mailing list