rv32emu
rv32emu copied to clipboard
Crash when the memory on host is insufficient
I was testing on multipass (a lightweight VM manager for Linux, Windows and macOS). The VM was running on a MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports), the configuration was as follows:
<Host>
Processors: 2.3 GHz Dual-Core Intel Core i5
Memory: 8 GB 2133 MHz LPDDR3
<VM>
Distribution: multipass
local cpu: 4
local memory: 4.0GiB
$ free -h
total used free shared buff/cache available
Mem: 3.8Gi 212Mi 2.1Gi 0.0Ki 1.5Gi 3.3Gi
Swap: 0B 0B 0B
I was testing hello.elf, but this problem happened to all the other binaries.
The steps to reproduce are as follows:
$> ./build/rv32emu ./build/hello.elf
rv32emu: src/riscv.c:199: rv_create: Assertion `attr->mem' failed.
Aborted (core dumped)
The core file is as follows. coredump.zip
By conducting the postmortem analysis, I realized it was because I did not have sufficient memory for mmap, and the MEM_SIZE is hard-coded to 2^32 - 1 (4GB).
#449 is just an idea. Perhaps allowing user to config accordingly is the most intuitive way to solve this problem.
Maybe modifying the setting of the overcommit fix this problem? Try echo 1 | sudo tee /proc/sys/vm/overcommit_memory.
@qwe661234, Check the necessary and desirable memory region required by mmap.
Alternatively, we could adopt the approach used by the mmap_allocator, a memory allocator based on mmap that allows users to allocate dynamic memory in the mmap region. This could particularly benefit processes with limited swap space, such as those running in restricted containers or virtual machines, by utilizing kernel-managed file cache for swapping.
Check its mmap_maptemp function.