sifive / freedom-u-sdk

Freedom U Software Development Kit (FUSDK)
272 stars 126 forks source link

Out of memory when running tasks on riscv64-linux on qemu #146

Closed yslys closed 3 years ago

yslys commented 3 years ago

Hi all,

I have successfully set up the environment running on qemu with demo-coreip-cli - the basic command line image.

I have a project that wants to build inside the environment, but the build process is always killed due to out of memory, which is shown below:

[  4%] Building CXX object third_party/glog/CMakeFiles/glog.dir/src/logging.cc.o
[ 1305.619612] cc1plus invoked oom-killer: gfp_mask=0x100cca(GFP_HIGHUSER_MOVABLE), order=0, oom_score_adj=0
[ 1305.621737] CPU: 0 PID: 982 Comm: cc1plus Tainted: G        W         5.10.25-yocto-standard #1
[ 1305.622366] Call Trace:
[ 1305.622928] [<ffffffe0002038f6>] walk_stackframe+0x0/0xcc
[ 1305.623231] [<ffffffe000a76b46>] show_stack+0x40/0x4c
[ 1305.623380] [<ffffffe000a7debe>] dump_stack+0x7c/0x96
[ 1305.623610] [<ffffffe000a78d86>] dump_header+0x4a/0x1e8
[ 1305.624278] [<ffffffe00032c722>] oom_kill_process+0x1ae/0x1b0
[ 1305.624676] [<ffffffe00032d00e>] out_of_memory+0xd6/0x2f0
[ 1305.624982] [<ffffffe000372caa>] __alloc_pages_slowpath.constprop.0+0x974/0xab2
[ 1305.625484] [<ffffffe00037304c>] __alloc_pages_nodemask+0x264/0x29a
[ 1305.625958] [<ffffffe0003281a6>] pagecache_get_page+0xd8/0x2bc
[ 1305.626326] [<ffffffe0003296d2>] filemap_fault+0x4fe/0x79a
[ 1305.626741] [<ffffffe0004504a2>] ext4_filemap_fault+0x38/0x54
[ 1305.627098] [<ffffffe000359f74>] __do_fault+0x32/0xba
[ 1305.627409] [<ffffffe00035cfe2>] handle_mm_fault+0x640/0xb3e
[ 1305.627765] [<ffffffe00020792a>] do_page_fault+0xee/0x2ec
[ 1305.628158] [<ffffffe000201b8c>] ret_from_exception+0x0/0xc
[ 1305.632963] Mem-Info:
[ 1305.633345] active_anon:84 inactive_anon:30024 isolated_anon:0
[ 1305.633345]  active_file:162 inactive_file:189 isolated_file:0
[ 1305.633345]  unevictable:0 dirty:0 writeback:0
[ 1305.633345]  slab_reclaimable:2760 slab_unreclaimable:3487
[ 1305.633345]  mapped:385 shmem:6300 pagetables:284 bounce:0
[ 1305.633345]  free:1049 free_pcp:36 free_cma:0
[ 1305.635431] Node 0 active_anon:336kB inactive_anon:120096kB active_file:648kB inactive_file:756kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:1540kB dirty:0kB writeback:0kB shmem:25200kB writeback_tmp:0kB kernel_stack:1168kB all_unreclaimable? no
[ 1305.637198] DMA32 free:4196kB min:1644kB low:2052kB high:2460kB reserved_highatomic:0KB active_anon:336kB inactive_anon:120096kB active_file:648kB inactive_file:756kB unevictable:0kB writepending:0kB present:260096kB managed:169372kB mlocked:0kB pagetables:1136kB bounce:0kB free_pcp:144kB local_pcp:144kB free_cma:0kB
[ 1305.638281] lowmem_reserve[]: 0 0 0
[ 1305.638801] DMA32: 393*4kB (UME) 106*8kB (UME) 58*16kB (UE) 17*32kB (UE) 5*64kB (UE) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 4212kB
[ 1305.639793] 6651 total pagecache pages
[ 1305.640118] 0 pages in swap cache
[ 1305.640347] Swap cache stats: add 0, delete 0, find 0/0
[ 1305.640598] Free swap  = 0kB
[ 1305.640743] Total swap = 0kB
[ 1305.640936] 65024 pages RAM
[ 1305.641070] 0 pages HighMem/MovableOnly
[ 1305.641190] 22681 pages reserved
[ 1305.641463] Tasks state (memory values in pages):
[ 1305.641684] [  pid  ]   uid  tgid total_vm      rss pgtables_bytes swapents oom_score_adj name
[ 1305.642154] [    104]   997   104      647       59    28672        0             0 rpcbind
[ 1305.642498] [    122]     0   122     1823      775    36864        0             0 haveged
[ 1305.642935] [    123]     0   123     8041      216    49152        0          -250 systemd-journal
[ 1305.643412] [    124]     0   124     3258      234    32768        0         -1000 systemd-udevd
[ 1305.647157] [    220]   995   220     1374      102    32768        0             0 systemd-resolve
[ 1305.647472] [    262]     0   262      398       29    20480        0             0 atd
[ 1305.647717] [    269]     0   269      525       64    24576        0             0 crond
[ 1305.648246] [    274]   999   274      803      124    28672        0          -900 dbus-daemon
[ 1305.648627] [    284]     0   284     1349      118    28672        0             0 systemd-logind
[ 1305.648948] [    291]     0   291    19079       78    32768        0             0 chronyd
[ 1305.649197] [    292]     0   292    59053      435    69632        0             0 NetworkManager
[ 1305.649631] [    297] 64371   297      409       22    20480        0             0 ninfod
[ 1305.649919] [    298] 61563   298      375       20    24576        0             0 rdisc
[ 1305.650202] [    301]     0   301     1525       52    32768        0             0 xinetd
[ 1305.650524] [    303]     0   303     1134       27    28672        0             0 agetty
[ 1305.650811] [    305] 65534   305      441       36    24576        0             0 dnsmasq
[ 1305.651099] [    306]     0   306      812      108    24576        0             0 login
[ 1305.651389] [    312]     0   312     1303       82    32768        0             0 systemd-userdbd
[ 1305.651890] [    317]     0   317     1696      237    32768        0             0 systemd
[ 1305.652257] [    318]     0   318     2131      468    40960        0             0 (sd-pam)
[ 1305.652571] [    323]     0   323      955      382    28672        0             0 sh
[ 1305.652857] [    966]     0   966     1306       83    32768        0             0 systemd-userwor
[ 1305.653115] [    967]     0   967     1306       83    32768        0             0 systemd-userwor
[ 1305.653598] [    968]     0   968     1306       83    32768        0             0 systemd-userwor
[ 1305.653760] [    969]     0   969      454       82    20480        0             0 make
[ 1305.653936] [    972]     0   972      454       89    20480        0             0 make
[ 1305.654085] [    979]     0   979      454       78    24576        0             0 make
[ 1305.654229] [    981]     0   981      819       23    24576        0             0 c++
[ 1305.654396] [    982]     0   982    25897    19660   229376        0             0 cc1plus
[ 1305.654821] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-0.slice/session-c1.scope,task=cc1plus,pid=982,uid=0
[ 1305.655925] Out of memory: Killed process 982 (cc1plus) total-vm:103588kB, anon-rss:77900kB, file-rss:740kB, shmem-rss:0kB, UID:0 pgtables:224kB oom_score_adj:0
[ 1305.691222] oom_reaper: reaped process 982 (cc1plus), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [third_party/glog/CMakeFiles/glog.dir/build.make:95: third_party/glog/CMakeFiles/glog.dir/src/logging.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:287: third_party/glog/CMakeFiles/glog.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

I executed the free command, and it shows the following:

root@qemuriscv64:~/hmc/src/build# free
               total        used        free      shared  buff/cache   available
Mem:          169372       48192       68756       24952       52424       89644
Swap:              0           0           0

I assume it is because of lack of memory in the emulated system. But I am not sure.

May I know if there is a way to configure the memory to make it larger when executing the MACHINE=qemuriscv64 bitbake demo-coreip-cli command? Thanks in advance.

If my understanding is wrong, feel free to correct me.

jim-wilson commented 3 years ago

You can pass qemu args to runqemu to change the memory allocated. https://docs.yoctoproject.org/dev-manual/qemu.html and see section 4.9. So adding qemuparams="-m 1024" will give you 1G of memory. -m 256 is the default.

The default is set in openembedded-code/meta/classes/qemuboot.bbclass on the QB_MEM line. You can change it there, rerun bitbake, and then you don't need to pass extra arguments. Depending on what you are building, it is possible that QB_MEM might be overridden in other files, some image files override it for instance.

yslys commented 3 years ago

Thanks Jim, your solution perfectly solves the issue, and I would close this issue.