rv32emu icon indicating copy to clipboard operation
rv32emu copied to clipboard

Crash when the memory on host is insufficient

Open tony2037 opened this issue 1 year ago • 4 comments
trafficstars

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).

tony2037 avatar May 27 '24 06:05 tony2037

#449 is just an idea. Perhaps allowing user to config accordingly is the most intuitive way to solve this problem.

tony2037 avatar May 27 '24 07:05 tony2037

Maybe modifying the setting of the overcommit fix this problem? Try echo 1 | sudo tee /proc/sys/vm/overcommit_memory.

vacantron avatar May 28 '24 06:05 vacantron

@qwe661234, Check the necessary and desirable memory region required by mmap.

jserv avatar Jun 03 '24 08:06 jserv

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.

jserv avatar Jun 03 '24 12:06 jserv