0

I am working on an embedded Linux system with kernel 5.10.24. And there is 96MB DRAM in system.
When system boots up, I checked the memory usage and got followings.

# dmesg | grep "kernel code"
[    0.000000] Memory: 85888K/131072K available (7885K kernel code, 692K rwdata, 1284K rodata, 560K init, 336K bss, 45184K reserved, 0K cma-reserved)
# free -m
              total        used        free      shared  buff/cache   available
Mem:             84          56           1           0          26          25
Swap:             0           0           0
#
#
# cat /proc/meminfo
MemTotal:          86448 kB
MemFree:            1992 kB
MemAvailable:      25948 kB
Buffers:               0 kB
Cached:            26896 kB
SwapCached:            0 kB
Active:             9632 kB
Inactive:          39064 kB
Active(anon):         72 kB
Inactive(anon):    21796 kB
Active(file):       9560 kB
Inactive(file):    17268 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:         21852 kB
Mapped:             7664 kB
Shmem:                68 kB
KReclaimable:        696 kB
Slab:               8632 kB
SReclaimable:        696 kB
SUnreclaim:         7936 kB
KernelStack:         608 kB
PageTables:          400 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:       43224 kB
Committed_AS:     146992 kB
VmallocTotal:    1048372 kB
VmallocUsed:        4156 kB
VmallocChunk:          0 kB
Percpu:              200 kB

From the free -m output, I know there is 25MB memory available.
I can figure out the memory usage for user space, but how to know how much memory is used in kernel space?

I read some blogs and SO, and found that Buffers and Slab in /proc/meminfo are memory used by kernel.

By adding them up, there is still difference!
So how to find out the memory used by kernel space? Are Buffers and Slab in /proc/meminfo enough for checking the memory usage in kernel space?

1 Answer 1

1

The kernel memory usage is not only limited to Buffers and Slab. It also includes other components like kernel code, kernel data, and kernel stack.

You may calculate the kernel memory usage with the following components:

Kernel code (from dmesg output): 7885 KB
rwdata (from dmesg output): 692 KB
rodata (from dmesg output): 1284 KB
init (from dmesg output): 560 KB
bss (from dmesg output): 336 KB
Slab (from /proc/meminfo): 8632 KB
KernelStack (from /proc/meminfo): 608 KB

Now, add them up:

7885 + 692 + 1284 + 560 + 336 + 8632 + 608 = 19997 KB

So, the kernel is using approximately 19,997 KB or around 19.5 MB of memory. Keep in mind that this is an approximation and may not account for every single byte of memory used by the kernel. The memory usage can also change during runtime as the kernel allocates and deallocates memory dynamically.

1
  • I got your point, that is what I want. Just to confirm, the memtotal in /proc/meminfo should be 96MB - 7885K-692K-1284K-560K-336K = 84MB, right? If so, after kernel boots up the memory newly taken over in kernel space is the sum of Slab, KernelStack and Buffers?
    – wangt13
    Apr 24, 2023 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .