This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][RFC] Allow explicit shrinking of arena heaps using anenvironment variable
- From: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>
- To: Rich Felker <dalias at aerifal dot cx>
- Cc: libc-alpha at sourceware dot org
- Date: Sun, 5 Aug 2012 06:54:56 -0400
- Subject: Re: [PATCH][RFC] Allow explicit shrinking of arena heaps using anenvironment variable
- References: <20120720223800.GB26330@sunsite.ms.mff.cuni.cz><20120720224417.E8BEF2C0CA@topped-with-meat.com> <20120721061814.GC26330@sunsite.ms.mff.cuni.cz><20120721133217.GY544@brightrain.aerifal.cx> <20120725183634.E0C5F2C0B1@topped-with-meat.com><CAHGf_=qCMy6K1MD4miN65GkMSumYTtH23xoFrfmCuh=WjybAVA@mail.gmail.com><20120730230006.355f9b67@spoyarek> <5016D012.5000101@gmail.com><20120730191758.GX544@brightrain.aerifal.cx> <CAHGf_=rRm4B4YCZKgos5hWN_QTYV76fAxcegO7D3x=4_A88Rvw@mail.gmail.com><20120731132705.GZ544@brightrain.aerifal.cx>
>> > The choices are not mmap(MAP_FIXED) vs madvise(MADV_DONTNEED). They
>> > are mmap(MAP_FIXED) vs madvise(MADV_DONTNEED) followed by
>> > mprotect(PROT_NONE).
>>
>> If PROT_NONE is must one, I don't see any reason to don't take
>> mmap(MAP_FIXED).
>>
>> but..
>> Why do we need PROT_NONE? just for /proc/maps?
>
> I think this is about the third or forth time I've explained it now.
> PROT_NONE is needed to actually free the memory for other processes to
> use. MADV_DONTNEED frees the physical memory (eliminates dirty pages
> and thus prevents costly swapping of worthless data), but it does not
> free the commit charge because the pages are still potentially
> writable and thus not permanently backed by the zero page even though
> they initially just reference it.
I don't have any knowledge of hurd. then I'd like to explain Linux behavior.
On Linux, both MADV_DONTNEED and mprotect don't decommit virtual memory charge.
Only munmap (included implicit munmap by MAP_FIXED) makes decommit.
As far as I know, this behavior has 10+ years history.
see below comment in linux/mm/mprotect.c
------------------------------------
int
mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
unsigned long start, unsigned long end, unsigned long newflags)
{
(snip)
/*
* If we make a private mapping writable we increase our commit;
* but (without finer accounting) cannot reduce our commit if we
* make it unwritable again. hugetlb mapping were accounted for
* even if read-only so there is no need to account for them here
*/
if (newflags & VM_WRITE) {
if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_HUGETLB|
VM_SHARED|VM_NORESERVE))) {
charged = nrpages;
if (security_vm_enough_memory_mm(mm, charged))
return -ENOMEM;
newflags |= VM_ACCOUNT;
}
}