Update Question 18.16:

- Restrict the question and answer to i386
- Remove description of the original hack since changing the size of
  kernel address space is much easier these days (fortunately)
- Mention KVA value for PAE
- Add ZFS as a possible cause of doing this (stolen from the wiki)

Reviewed by:  trhodes
Approved by:  gabor
This commit is contained in:
Gabor Pali 2008-07-05 03:24:26 +00:00
parent a76c19775c
commit b9fcc3d59c
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/head/; revision=32490

View file

@ -10896,75 +10896,25 @@ panic: page fault</programlisting>
<qandaentry>
<question id="change-kernel-address-space">
<para>How can I increase or reduce the kernel address space?</para>
<para>How can I increase or reduce the kernel address space on i386?</para>
</question>
<answer>
<para>By default, the kernel address space is 256 MB on
FreeBSD 3.X and 1 GB on FreeBSD 4.X. If you run a
network-intensive server (e.g. a large FTP or HTTP server),
you might find that 256 MB is not enough.</para>
<para>By default, the kernel address space is 1&nbsp;GB
(2&nbsp;GB for PAE) for i386. If you run a
network-intensive server (e.g. a large FTP or HTTP server),
or you want to use ZFS, you might find that is not
enough.</para>
<para>So how do you increase the address space? There are two
aspects to this. First, you need to tell the kernel to reserve
a larger portion of the address space for itself. Second, since
the kernel is loaded at the top of the address space, you need
to lower the load address so it does not bump its head against
the ceiling.</para>
<para>Add the following line to your kernel configuration file
to increase available space and rebuild your kernel:</para>
<para>The first goal is achieved by increasing the value of
<literal>NKPDE</literal> in
<filename>src/sys/i386/include/pmap.h</filename>. Here is what
it looks like for a 1 GB address space:</para>
<programlisting>options KVA_PAGES=<replaceable>N</replaceable></programlisting>
<programlisting>#ifndef NKPDE
#ifdef SMP
#define NKPDE 254 /* addressable number of page tables/pde's */
#else
#define NKPDE 255 /* addressable number of page tables/pde's */
#endif /* SMP */
#endif</programlisting>
<para>To find the correct value of <literal>NKPDE</literal>,
divide the desired address space size (in megabytes) by four,
then subtract one for UP and two for SMP.</para>
<para>To achieve the second goal, you need to compute the
correct load address: simply subtract the address space size
(in bytes) from 0x100100000; the result is 0xc0100000 for a 1
GB address space. Set <symbol>LOAD_ADDRESS</symbol> in
<filename>src/sys/i386/conf/Makefile.i386</filename> to that
value; then set the location counter in the beginning of the
section listing in
<filename>src/sys/i386/conf/kernel.script</filename> to the
same value, as follows:</para>
<programlisting>OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(btext)
SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/obj/elf/home/src/tmp/usr/i386-unknown-freebsdelf/lib);
SECTIONS
{
/* Read-only sections, merged into text segment: */
. = 0xc0100000 + SIZEOF_HEADERS;
.interp : { *(.interp) }</programlisting>
<para>Then reconfig and rebuild your kernel. You will
probably have problems with &man.ps.1; &man.top.1; and the
like; <command>make world</command> should take care of it
(or a manual rebuild of <filename>libkvm</filename>,
&man.ps.1; and &man.top.1; after copying the patched
<filename>pmap.h</filename> to
<filename>/usr/include/vm/</filename>.</para>
<para>NOTE: the size of the kernel address space must be a
multiple of four megabytes.</para>
<para>[&a.dg; adds: <emphasis>I think the kernel address space
needs to be a power of two, but I am not certain about that. The
old(er) boot code used to monkey with the high order address bits
and I think expected at least 256MB
granularity.]</emphasis></para>
<para>To find the correct value of
<replaceable>N</replaceable>, divide the desired address
space size (in megabytes) by four. (For example, it is
<literal>512</literal> for 2&nbsp;GB.)</para>
</answer>
</qandaentry>
</qandaset>