55mb instead of 64mb ram

I setted IONSIZE to 0, but free linux memory shows about 55.3mb. Where is 64 mb? Maybe difference is left to RTOS, but I do not need it. How may I change settings to build image with 64mb ram available to linux? Thank you!


This is a companion discussion topic for the original entry at http://forum.sophgo.com/t/55mb-instead-of-64mb-ram/563

That is strange. What shell command are running to see that?

[root@milkv-duo]~# uname -a
Linux milkv-duo 5.10.4-tag- #1 PREEMPT Thu Mar 14 02:15:22 +05 2024 riscv64 GNU/Linux
[root@milkv-duo]~# cat /proc/meminfo
MemTotal:          56620 kB
MemFree:           32756 kB
MemAvailable:      37856 kB
Buffers:             932 kB
Cached:             5436 kB
SwapCached:            0 kB
Active:             4304 kB
Inactive:           4036 kB
Active(anon):         72 kB
Inactive(anon):     1980 kB
Active(file):       4232 kB
Inactive(file):     2056 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:        262140 kB
SwapFree:         262140 kB
Dirty:                12 kB
Writeback:             0 kB
AnonPages:          1976 kB
Mapped:             4004 kB
Shmem:                80 kB
KReclaimable:       2600 kB
Slab:               7280 kB
SReclaimable:       2600 kB
SUnreclaim:         4680 kB
KernelStack:         960 kB
PageTables:          384 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      290448 kB
Committed_AS:       5388 kB
VmallocTotal:   67108863 kB
VmallocUsed:        2404 kB
VmallocChunk:          0 kB
Percpu:               32 kB
CmaTotal:              0 kB
CmaFree:               0 kB
[root@milkv-duo]~# free -h
              total        used        free      shared  buff/cache   available
Mem:          55.3M       14.3M       32.2M       80.0K        8.8M       37.2M
Swap:        256.0M           0      256.0M

You’ll need to change this too: https://github.com/milkv-duo/duo-buildroot-sdk/blob/1d878b3d97517c8fff68ff03194d56b73c21cea5/build/boards/cv180x/cv1800b_milkv_duo_sd/memmap.py#L18

1 Like

I see about the same when I tried to recreate. It is plausible that you need to subtract kernel memory as well as RTOS memory from the 64 MB. But is the 8 MB drop you see excessive? How much free RAM do you observe, @kinsa?

2 Likes

You’ll not get the full 64Mb.

dmesg | grep Memory will show you the memory usage:

# dmesg | grep Memory
[    0.000000] Memory: 56848K/64768K available (3734K kernel code, 452K rwdata, 1600K rodata, 104K init, 195K bss, 7920K reserved, 0K cma-reserved)

Majority of the free mem is reserved. See the discussions here.

Note: I’m using the RTOS code.

2 Likes

Thank you very much for your clarifications!

Unfortunately, internet shows various sources of what it means exactly - reserved. I found 2 interesting:

  1. This is page structs. But if page size is 4092, and page struct size is 64, then it should take only 1 mb. More info: linux kernel - Reserved RAM: Determine the reason for reserved main memory? - Unix & Linux Stack Exchange
  2. This is buffer of SWIOTLB. More info: 32/64 bit, IOMMU and SWIOTLB in Linux | xillybus.com

To make SWIOTLB smaller, one recommends to specify it’s size in kernel parameter, e.g. swiotlb=1024 in link above.

Question: may you please tell me how to specify kernel parameters in MilkV’s Buildroot SDK?

p.s. Also other ideas for exact reasons of that lost 8mb (which are highlighted above as linux reserved memory) are welcome. Thank you!

Try changing here.

Or any files that defines OTHERBOOTARGS.

(I haven’t tested this though as I’m using my own buildroot environment.)

1 Like

Thank you very much, @kinsa!

My current conclusions are the following. In the text

> dmesg | grep Memory
Memory: 56468K/64768K available (3897K kernel code, 484K rwdata, 1707K rodata, 152K init, 210K bss, 8300K reserved, 0K cma-reserved)
  • it is stated that system has 64768K physical memory. It is becase 64768K + 768K = 65536K, where 768K is used for RTOS.
  • it is stated that 56468K of 64768K is available for use.
  • So 64768K - 56468K = 8300K is lost somewhere. This value is equal to reserved value of dmesg output. By the way it is calculated and printed in page_alloc.c file of kernel code.

It seems that these 8300K reserved is a sum of the following:

So we have explained 8059Kb = 6085Kb for kernel code and it’s data structures (handles, pipes, etc) + 1024Kb of struct page + 950Kb of min_free_bytes. And 241Kb lost for some other reasons that I cannot find.

p.s. I think that reserved wording for dmesg is incorrect and misleading. The better will be something like total used by kernel.

you should be able to track own most of the reserved memory using slabtop.

1 Like