Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Mar 2006 16:42:11 +0100 (CET)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-stable@FreeBSD.ORG
Subject:   Re: swap at beginning of slice - danger?
Message-ID:  <200603151542.k2FFgBSY038014@lurza.secnetix.de>
In-Reply-To: <20060315161248.L47405@atlantis.atlantis.dp.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
Dmitry Pryanishnikov <dmitry@atlantis.dp.ua> wrote:
 > Oliver Fromme wrote:
 > > >  # bsdlabel ad0s1 | fgrep b:
 > > >    b:  2097152        0      swap
 > > > 
 > > > Previously, on a 4.11 system, swapinfo said that swap size was less than
 > > > size of b: partition on a slice - it was ok, as boot sectors are
 > > > located at beginning of slice. But now, sizes match exactly. What
 > > > changed and is it dangerous nowadays to have swap partition at offset 0 ?
 > > 
 > > The code in sys/swap_pager.c does not touch the first two
 > > blocks, where blocks are measured in PAGE_SIZE units.
 > > The smallest page size supported on FreeBSD architectures
 > > is 4 KB (on i386), so that's at least 2 * 4k, which is 16
 > > sectors on the disk.  That's enough to skip MBR, disklabel
 > > and boot blocks.
 > 
 >   You're right about RELENG_5 (and CURRENT).

And RELENG_6, of course.

 > However I don't see any equivalent code in RELENG_4.

RELENG_4 doesn't touch the first <n> sectors of the swap
partition either.  See the calculations for vsbase in
vm/vm_swap.c in the swaponvp() function.

Apart from that, RELENG_4 is pretty much dead, as far as
development is concerned, so nobody would suddenly change
how partitions are laid out by default.

 > Neither can I find where it's documented,
 > and thus any guarantees that it won't disappear tomorrow ;(

The comment in the source clearly state _why_ the first
two blocks of the swap partition are excluded, so no
developper will rip that out.  UFS skips the first 16
sectors, too -- that won't change either, and nobody is
really worried about it.

By the way, the first partition on a disk is usually the
root partition, not the swap partition.  So the problem
could arise only in unusual circumstances.

 > > In other words:  You're save.  No danger.  No need to worry.
 > 
 > In this particular case - yes.

If you create a swap partition intentionally at the start
of a disk (for whatever reason), and if you're paranoid,
then make sure it starts at offset 16, not 0.

But even with offset 0 you're save.

Best regards
   Oliver

-- 
Oliver Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"In My Egoistical Opinion, most people's C programs should be indented
six feet downward and covered with dirt."
        -- Blair P. Houghton



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200603151542.k2FFgBSY038014>