mmap MAP_NORESERVE of 2^42 bytes consumes 16Gb of actual RAM
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
QEMU |
Expired
|
Undecided
|
Unassigned |
Bug Description
Run this program:
#include <sys/mman.h>
#include <stdio.h>
int main() {
for (int i = 30; i <= 44; i++) {
}
}
(tried qemu-x86_64 and qemu-aarch64, 4.2.1 and trunk/5.1.50)
On each iteration qemu will consume 2x more physical RAM,
e.g. when mapping 2^42 it will have RSS of 16Gb.
On normal linux it works w/o consuming much RAM, due to MAP_NORESERVE.
Also: qemu -strace prints 0 instead of the correct size starting from size=2^32
and prints -2147483648 for size=2^31.
mmap(0x00006000
mmap(0x00006000
mmap(0x00006000
tags: | added: linux-user mmap tcg |
Without actually looking, an allocation of 2**42 (4PB) requires
2**30 (1G) pages, and thus 1G page table entries, so 16GB memory
allocation sounds about right for qemu's internal page table allocation.
We need to change data structures for representing guest memory,
probably akin to the kernel's VMAs.