brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: slabtop -o shows which kernel cache is eating your memory

Memory
~/tips/tip-performance-slabtop-once

sudo slabtop -o -s c

List the biggest kernel slab caches once, sorted by size, when memory goes missing.

When free memory shrinks and no process explains it, the kernel itself may be holding it in its slab caches. slabtop lists those, which is a good thing to know about when a server looks strangely full.

slabtop shows kernel slab cache information, with the biggest caches at the top and a header with slab layer statistics. The simplest use is once, sorted by cache size:

sudo slabtop -o -s c

-o prints the output once and exits. -s picks the sort key, and c sorts by cache size. Other keys include a for active objects, l for the number of slabs, s for object size and n for name. The default is o, the number of objects. Add –human to get sizes scaled from B up to Pi instead of KiB. For a live view leave out -o and use -d to set the refresh time in seconds (the default is 3), and press q to quit. -d can’t be combined with -o.

It reads /proc/slabinfo, so if you see a permission error, run it with sudo.

Two caveats from the man page. The CACHE SIZE column is not accurate: it gives an upper limit on the memory used by a cache. And the header tracks how many bytes of slabs are in use, which the page says is not a measure of physical memory. For that, the Slab field in /proc/meminfo is the one to read.

I’d use slabtop to find a name worth searching for, like a cache that keeps growing, and then check the Slab line in /proc/meminfo before drawing any conclusion.

Further reading: slabtop(1) manual page

More Memory tips lsmem --summary for f in /proc/[0-9]*/status; do sudo apt install smem sudo pmap -x 1234 sudo systemctl edit indexer.service All Memory tips (12) All topics

Link