Small bug when calculating free memory

The admin interface shows

7.46 GB
96.1% free

while

$ free -m

         total        used        free      shared  buff/cache   available
Mem:      7636         289        2171         613        5175        6610

So it seems the formula used is

(free + buff_cache) / total

and it should be

available / total

or 86.6% in this case

I don’t know if it’s the exact same in Linux, but in Windows the cache is made up of files from disk. As such, this memory is considered available, as it can be freed up quickly if needed. Basically it’s just loading files into memory because it has the room and it’s faster. In this context, considering that memory “available” is correct.

Please provide the output from cat /proc/meminfo along with free and a screenshot from the DVR (so that we have all of the pieces of info at the same time).

RAM
7.46 GB
96.1% free

pi@raspberrypi:~ $ cat /proc/meminfo
MemTotal: 7820244 kB
MemFree: 1235692 kB
MemAvailable: 6769428 kB
Buffers: 35392 kB
Cached: 6171900 kB
SwapCached: 2780 kB
Active: 4139800 kB
Inactive: 2279180 kB
Active(anon): 536168 kB
Inactive(anon): 306248 kB
Active(file): 3603632 kB
Inactive(file): 1972932 kB
Unevictable: 1952 kB
Mlocked: 1956 kB
SwapTotal: 102396 kB
SwapFree: 1364 kB
Dirty: 6036 kB
Writeback: 0 kB
AnonPages: 211284 kB
Mapped: 212768 kB
Shmem: 629132 kB
KReclaimable: 81140 kB
Slab: 110040 kB
SReclaimable: 81140 kB
SUnreclaim: 28900 kB
KernelStack: 3368 kB
PageTables: 5188 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 4012516 kB
Committed_AS: 1528040 kB
VmallocTotal: 259522560 kB
VmallocUsed: 9556 kB
VmallocChunk: 0 kB
Percpu: 688 kB
CmaTotal: 65536 kB
CmaFree: 55252 kB

pi@raspberrypi:~ $ free
       total        used        free      shared  buff/cache   available
Mem: 7820244      297108     1126184      629804     6396952     6767768
Swap: 102396      101032        1364

Please submit diagnostics on your DVR and let me know when you've done it.

e3419217-f7e0-411a-a05a-df8c00102283

Our implementation of the free memory percentage is:

100.0 - (used / total * 100.0)

You can see from procps that used already takes buffers and caches into account:

The implementation we use does the same:

That's what I quoted in my original post and it is wrong. The DVR software is tiny but not that tiny. According to the info from the admin page I could boot the kernel with

mem=300M

parameter to restrict the amount of total memory.

It probably wouldn't end well.

Sometimes common sense trumps internet experts.

You're going to need to have a bit more humility when you're wrong if you want people to engage with you.

7 Likes

What makes you say that? The kernel makes the amount of memory available already. Second guessing kernel intentions is not a good idea and results in funny stats. Every time something is pointed out you take umbrage instead of considering correction. How is reporting 300MB memory usage not wrong?