Subject: Mini kernel core dump facility for NetBSD
To: None <tech-kern@NetBSD.org, port-i386@NetBSD.org>
From: Devon H. O'Dell <firstname.lastname@example.org>
Date: 12/05/2007 18:28:56
We're moving over to NetBSD here at work and are getting to the point
where we need a minidump facility in NetBSD. I backported minidumps from
FreeBSD 7 to FreeBSD 4 about a year ago for our systems, but it was a
lot of code to change (I believe the diff in total ended up being >4000
lines). So I decided to take a different approach this time, and I've
been discussing this largely with joerg@ and a bit with tls@.
The current status is that the kernel portion dumps and I am pretty sure
it's dumping the right stuff (though I haven't touched libkvm / savecore
so I'm not sure whether the data is absolutely correct yet, and I also
haven't tried dd'ing the dump partition either). The kernel portion
operates on the following premise:
A machdep sysctl is introduced (machdep.do_minidump) that toggles
minidumps on or off for a kernel crash. A full core dump is legitimately
desirable in many cases, so there's no reason to replace that code.
A pass is done over all pages in KVA and pages with actual physical
mappings are marked in a bitmap (each bit representing a page in
physical memory; 128MB of physical memory can be represented in a page).
The bitmaps are allocated early on, in cpu_startup(), so that minidumps
can be made available for the majority of the system startup. This
bitmap is dumped to the disk, right after the dump header.
Pass 2 iterates through all memory segments in mem_clusters, and through
each page in those segments determining whether those pages were marked
as active to the kernel or not. If they are, that page is dumped. If
not, nothing is dumped. This has resulted in ridiculously small dumps
(the first one I took was made after the system had freshly booted and
I'd like to ask people with a bit more experience than I in the VM/pmap
systems to take a look at the patch, let me know where I could make
improvements and, most importantly, if I'm missing anything vital (this
is really the first anything that I've done with the NetBSD kernel). A
patch is available at:
Following this, modifications need to be made to savecore and libkvm to
understand the new dump format, which may be quite a bit of work since
there's no real index.
Devon H. O'Dell