Inspect slab logs in dmesg
In this final step, you will learn how to check the kernel message buffer for messages related to the slab allocator using the dmesg
command. The kernel message buffer stores messages produced by the kernel during boot and runtime. These messages can include information about hardware, device drivers, and kernel subsystems like the slab allocator.
The dmesg
command is used to print or control the kernel ring buffer. This buffer contains messages from the kernel, which are often useful for debugging and troubleshooting.
To view the entire kernel message buffer, you can simply run dmesg
:
dmesg
However, the output can be very long. To find messages specifically related to the slab allocator, you can pipe the output of dmesg
to the grep
command and search for keywords like "slab" or "SLUB" (SLUB is a modern slab allocator implementation).
Type the following command in your terminal and press Enter:
dmesg | grep -i "slab\|slub"
Let's break down this command:
dmesg
: Prints the kernel message buffer.
|
: This is a pipe, which sends the output of the command on the left as input to the command on the right.
grep
: A command-line utility for searching plain-text data sets for lines that match a regular expression.
-i
: This option makes the search case-insensitive, so it will match "slab", "SLAB", "slub", "SLUB", etc.
"slab\|slub"
: This is the search pattern. slab
searches for the word "slab", \|
acts as an OR operator, and slub
searches for the word "slub".
The output will show any lines from the kernel message buffer that contain "slab" or "slub" (case-insensitive). You might see messages related to the initialization of the slab allocator during boot, or potential warnings or errors if there are issues.
[ 0.000000] kmem_cache_init
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] SLUB: TotalObjects=0, ObjectsPerSpan=0, SpansPerChunk=0
[ 0.000000] SLUB: min_objects.limit=0, min_objects.batchcount=0
[ 0.000000] SLUB: tunables.limit=0, tunables.batchcount=0, tunables.sharedfactor=0
[ 0.000000] SLUB: Not setting slab_nomerge.
[ 0.000000] SLUB: Not setting slab_debug.
[ 0.000000] SLUB: Not setting slab_max_order.
[ 0.000000] SLUB: Not setting slab_alias_debug.
[ 0.000000] SLUB: Not setting slab_pad.
[ 0.000000] SLUB: Not setting slab_red_zone.
[ 0.000000] SLUB: Not setting slab_poison.
[ 0.000000] SLUB: Not setting slab_freelist_debug.
[ 0.000000] SLUB: Not setting slab_freelist_random.
[ 0.000000] SLUB: Not setting slab_freelist_hardened.
[ 0.000000] SLUB: Not setting slab_trace.
[ 0.000000] SLUB: Not setting slab_reclaim_account.
[ 0.000000] SLUB: Not setting slab_way.
[ 0.000000] SLUB: Not setting slab_sizes.
[ 0.000000] SLUB: Not setting slab_caches.
[ 0.000000] SLUB: Not setting slab_test.
[ 0.000000] SLUB: Not setting slab_order.
[ 0.000000] SLUB: Not setting slab_debug_objects.
[ 0.000000] SLUB: Not setting slab_debug_memcg.
[ 0.000000] SLUB: Not setting slab_debug_check_objects.
[ 0.000000] SLUB: Not setting slab_debug_check_freelist.
[ 0.000000] SLUB: Not setting slab_debug_check_alloc.
[ 0.000000] SLUB: Not setting slab_debug_check_free.
[ 0.000000] SLUB: Not setting slab_debug_check_redzone.
[ 0.000000] SLUB: Not setting slab_debug_check_poison.
[ 0.000000] SLUB: Not setting slab_debug_check_trace.
[ 0.000000] SLUB: Not setting slab_debug_check_reclaim_account.
[ 0.000000] SLUB: Not setting slab_debug_check_way.
[ 0.000000] SLUB: Not setting slab_debug_check_sizes.
[ 0.000000] SLUB: Not setting slab_debug_check_caches.
[ 0.000000] SLUB: Not setting slab_debug_check_test.
[ 0.000000] SLUB: Not setting slab_debug_check_order.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_objects.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_memcg.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_objects.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_freelist.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_alloc.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_free.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_redzone.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_poison.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_trace.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_reclaim_account.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_way.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_sizes.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_caches.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_test.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_order.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_debug_objects.
[ 0.000000] SLUB: Not setting slab_debug_check_debug_check_debug_memcg.
This command is a powerful way to filter kernel messages and find relevant information for troubleshooting specific kernel subsystems.
You have now learned how to inspect slab statistics, verify related kernel parameters, and check kernel logs for slab-related messages. These are fundamental skills for understanding and diagnosing memory usage in Linux.
Click Continue to complete this lab.