Re: Memory allocation

Wayne Whitney (whitney@math.berkeley.edu)
Tue, 27 Feb 2001 09:51:25 -0800


In mailing-lists.linux-kernel, you wrote:

>I encountered with problem: one process can not allocate more then 2Gb of
>memory.

This is a problem that I have run into myself. I am no kernel expert,
but I think I understand how this issue. Here is how the standard
kernel maps the 4Gb 32-bit address space from the process's point of
view:

128MB program executable mapped (twice)
128MB + program heap
1GB mmap() starts here
3GB kernel

You can see this for yourself by looking at /proc/pid/maps, where pid
is the PID of the process in question.

Now glibc()'s malloc uses mmap() for 'large' allocations, so you get
2GB maximum memory. The way around this is to change the various
numbers in the left-hand column.

For example, you can try the patch per-process-3.5G-IA32-no-PAE-1, at
/pub/linux/kernel/people/andrea/patches/v2.4/2.4.0-test11-pre5/ on
ftp.kernel.org. This will make the kernel space start at 3.5G (so
that CONFIG_4G is required to use more than 384MB of physical RAM) and
the mmap() space start at 224MB, giving 3G288MB of address space for
mmap(). Note that only 96MB is then available for {two copies of your
executable plus your program heap}.

This is more or less the most you can do, but your needs may be best
suited by something in between. The above patch is quite short, so it
is easy to figure out how to do that. The only hidden restriction is
that the size of the kernel space must be a power of 2: 2GB, 1GB,
512MB, etc. As explained to me, this is so that the kernel can easily
test a pointer to see whether it is to kernel space or user space.

Cheers,
Wayne

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/