Re: [PATCH] mm/mmap: Check for RLIMIT_AS before unmapping

From: chrubis
Date: Fri Apr 12 2013 - 09:41:14 EST


Hi!
> > +static unsigned long count_vma_pages_range(struct mm_struct *mm,
> > + unsigned long addr, unsigned long end)
> > +{
> > + unsigned long nr_pages = 0;
> > + struct vm_area_struct *vma;
> > +
> > + /* Find first overlaping mapping */
> > + vma = find_vma_intersection(mm, addr, end);
> > + if (!vma)
> > + return 0;
> > +
> > + nr_pages = (min(end, vma->vm_end) -
> > + max(addr, vma->vm_start)) >> PAGE_SHIFT;
>
> urgh, these things always make my head spin. Is it guaranteed that
> end, vm_end, addr and vm_start are all multiples of PAGE_SIZE? If not,
> we have a problem don't we?

Yes, it takes a little of concentration before one can say what the code
does, unfortunatelly this is the most readable variant I've came up
with.

The len is page aligned right at the start of the do_mmap_pgoff() (end
is addr + len). The addr should be aligned in the get_unmapped_area()
although the codepath is more complicated to follow, but it seems to end
up in one of the arch_get_unmapped_area* and these makes sure the
address is aligned.

Moreover mmap() manual page says that the addr passed to mmap() is page
aligned (although I tend to check the code rather than the docs).

And for the vmas I belive these are page aligned by definition, correct
me if I'm wrong.

--
Cyril Hrubis
chrubis@xxxxxxx
--
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/