Dmesg: Difference between revisions

From Helpful
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 3: Line 3:
dmesg is a fixed-size ringbuffer in linux kernel memory, on the order of hundreds of KByte large.
dmesg is a fixed-size ringbuffer in linux kernel memory, on the order of hundreds of KByte large.


Ringbuffer means that once full, it rewrites old lines,
though you'll often see everything since boot (unless something starts spamming, e.g. filesystem code).




Both writing (printk()) and reading from dmesg (/dev/kmsg) is effectively privileged thing,
so it is not used for general purpose logging.
: (note that your [[userspace]] logger might well choose to read out dmesg and write it to its own logs)


Both
* writing to dmesg (printk()) and
* reading from dmesg (/dev/kmsg)
...is effectively privileged thing, so it is ''not'' used for general purpose logging.


Primarily some lower level details from the kernel; things that write to it include
Primarily some lower level details from the kernel; things that write to it include
* boot code  
* boot code  
* ongoing important evens like
* ongoing important events like:
* changes in connected devices
* changes in connected devices
* [[oom-kill]]er
* [[oom-kill]]er
* segfaults  
* segfaults  
* device errors
* device errors
* filesystem code noticing potential issues


Note that while it is privileged to read out,
your [[userspace]] logger might well choose to read out dmesg and write it to its own logs.
: (something like {{inlinecode|/var/log/dmesg}}, or in in the case of systemd, see e.g. {{inlinecode|journalctl -t kernel}})




Ringbuffer means that once full, it rewrites old lines.





Revision as of 17:29, 27 February 2024

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

dmesg is a fixed-size ringbuffer in linux kernel memory, on the order of hundreds of KByte large.

Ringbuffer means that once full, it rewrites old lines, though you'll often see everything since boot (unless something starts spamming, e.g. filesystem code).


Both

  • writing to dmesg (printk()) and
  • reading from dmesg (/dev/kmsg)

...is effectively privileged thing, so it is not used for general purpose logging.

Primarily some lower level details from the kernel; things that write to it include

  • boot code
  • ongoing important events like:
  • changes in connected devices
  • oom-killer
  • segfaults
  • device errors
  • filesystem code noticing potential issues


Note that while it is privileged to read out, your userspace logger might well choose to read out dmesg and write it to its own logs.

(something like /var/log/dmesg, or in in the case of systemd, see e.g. journalctl -t kernel)



That fixed size is usually on the order of dozens to hundreds of kilobytes. If

grep CONFIG_LOG_BUF_SHIFT /boot/config-`uname -r`

says something like

CONFIG_LOG_BUF_SHIFT=18

that means 256KiB (1<<18)

See also: