Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Nov 2006 00:23:10 +0300
From:      Ruslan Ermilov <ru@FreeBSD.org>
To:        Scott Long <scottl@FreeBSD.org>, Peter Wemm <peter@FreeBSD.org>
Cc:        amd64@FreeBSD.org, i386@FreeBSD.org
Subject:   NKPT comments are misleading
Message-ID:  <20061111212310.GE11896@rambler-co.ru>

next in thread | raw e-mail | index | archive | help

--9l24NVCWtSuIVIod
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi,

I've been recently playing with loading i386 kernels with an
unusually large code segment (like 74MB ;).  I ended up
bumping a NKPT following suggestion from jhb@, but these
comments didn't look sane to me.

: amd64/include/pmap.h-/* Initial number of kernel page tables */
: amd64/include/pmap.h:#ifndef NKPT
: amd64/include/pmap.h:#define    NKPT            240     /* Enough for 16G=
B (2MB page tables) */
: amd64/include/pmap.h-#endif
: --
: i386/include/pmap.h-/* Actual number of kernel page tables */
: i386/include/pmap.h:#ifndef NKPT
: i386/include/pmap.h-#ifdef PAE
: i386/include/pmap.h:#define     NKPT            240     /* Enough for 16G=
B (2MB page tables) */
: i386/include/pmap.h-#else
: i386/include/pmap.h:#define     NKPT            30      /* Enough for 4GB=
 (4MB page tables) */
: i386/include/pmap.h-#endif
: i386/include/pmap.h-#endif

On FreeBSD6/amd64, "struct vm_page" is 112 bytes, so to map 16GB
of RAM we'd need to map a vm_page_array of size (16G/4K)*112=3D448M,
and that requires 448M/2MB =3D 224 page tables.  Add to that the
kernelsize/2MB to map a kernel, plus some minor extra, and you get
the required NKPT value.  So the comment is mostly right for
FreeBSD6/amd64.

But on FreeBSD7/amd64 "struct vm_page" is already 120 bytes, and
on FreeBSD7/i386 it's 72/76 for non-PAE/PAE, and 68/72 for FreeBSD6.
The actual numbers are:

: FreeBSD6/amd64 requires 224 PTs to map 16G of RAM
: FreeBSD7/amd64 requires 240 PTs to map 16G of RAM
: FreeBSD7/i386 non-PAE requires 18 PTs to map 4G of RAM
: FreeBSD7/i386 PAE requires 152 PTs to map 16G of RAM
: FreeBSD7/i386 non-PAE requires 17 PTs to map 4G of RAM
: FreeBSD7/i386 PAE requires 144 PTs to map 16G of RAM

As you can see, the comments in i386/include/pmap.h don't make
much sense, neither none of four combination of FreeBSD6/7 and
PAE/non-PAE.  This is because (I think) it was blindly copied
=66rom AMD64 incorrectly assuming "struct vm_page" has the same
size.

Also, for i386 it says "actual number of kernel page tables"
where it should say "initial number of kernel page tables";
the actual number of page tables (nkpt) can later grow if
necessary.

The comments are also applicable to a normal-sized kernels
only.  E.g., mapping a 7M i386 non-PAE kernel only requires
2 PTs, but a 74M kernel already "eats" 19 PTs.  (It requires
less by using 4M pages when PSE is in use, but the rest is
still wasted because vtopte() doesn't "know" about PSE.)
So, these comments don't account for the possible larger
kernel size, or assume a default kernel size.  In the latter
case, this should be documented.  The i386/non-PAE is
especially fragile.


Cheers,
--=20
Ruslan Ermilov
ru@FreeBSD.org
FreeBSD committer

--9l24NVCWtSuIVIod
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (FreeBSD)

iD8DBQFFVj8+qRfpzJluFF4RAgjkAKCR3nFyg72pEL3S0SJWx8lPD6MENACdHlYe
G10/e59AGoalyl9kFNiUsu0=
=wnn1
-----END PGP SIGNATURE-----

--9l24NVCWtSuIVIod--



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