|
Using Linux with (more than) 1GB of RAMThis HOWTO is obsoleted by kernel 2.3.24Recently more and more people have been trying to use Linux on x86 hardware with more than 1 gigabyte of RAM and no knowledge of the innards of the MM subsystem whatsoever. If you are (or aspire to be) one of those people, but you do need instantaneous success with the install of Linux on your 1 GB system, then this document is for you... This document applies to Linux versions 2.0 and 2.1 equally. The document is divided in 4 parts, if you don't want to fool around with the kernel source and only have 1GB of memory installed, you might want to skip the first part and take the easy way out :) Update:Kernels 2.2.11 and 2.3.9 and onwards support 2GB of RAM out of the box, you can just select a special config option and it'll work. Support for more than 2GB of RAM is in the works and will probably be in kernel version 2.4.Since kernel 2.3.24, Linux supports up to 64 GB of physical memory and up to several TB of swap on the x86 platform. This means that this howto is now obsolete. The easiest way to use more than 1GB of memory is to get a newer kernel and run that.
Technical backgroundSince the x86 is a 32 bit machine, we are confined to 4 GB of address space. Because of specific x86 MMU weaknesses (I've heard rumours that SPARC/32 doesn't have this problem) we have to split up this space between virtual and physical space. This means that when we choose a larger physical space (to support more RAM) the maximum size of an individual program gets smaller.Linux currenly uses a 3:1 virtual:physical split, meaning that the kernel can use a maximum of 1 GB (minus 64 MB administrational overhead) RAM and the maximum program size is 3 GB (some object-oriented databases need this). You can change this to something else (eg. a 2:2 split if you have 2 GB of RAM), but enlarging the physical space means restricting the maximum size of your programs. The main reason that Linux uses a 3:1 split is that it gives us 3 GB of virtual address space per process and most processes run faster when they have a lot of virtual space to fool around in (no need to constantly reshuffle data around to fit in other stuff). Another reason is that we've always done this and there may be some old programs around that break when we change it. Besides, large machines are (should be) administrated by clueful sysadmins who can hack the kernel to fix things... Easy workaround for 1 GB machinesOK, so you've only got one of those wimpy 1 GB machines and you simply aren't up to hacking the kernel? Don't worry. Follow this easy recipy to get 960 MB of useable memory... The trick is simple, you just tell your kernel that you have 960 MB of memory. You can do this by giving it the "mem=960MB" from the LILO prompt. To do this automatically, you can add the argument to the "append" line in /etc/lilo.conf, like this:# Start LILO global section boot = /dev/hda append = "mem=960M" #compact # faster, but won't work on all systems. delay = 50 The 64 MB 'gap' we leave is there to allow Linux a bit of space for internal administration. If you feel adventurous, you can reduce the gap and try higher values (Note: newer 2.1 kernels don't allow this!). Success has been reported with values of up to 1014 MB. The obvious downside to this tweaking is reduced system stability. Don't do this unless you don't mind your machine crashing on you and your lusers, who will be storming your office hordes at a time as soon as they find out they lost their work because you felt adventurous... Yes, you must truly be adventurous to risk system stability for an extra 40 MBs of RAM :) Fixing the problemTo fix the problem, you need to follow these directions in linux/include/asm-i386/page.h:/* * This handles the memory map.. We could make this a config * option, but too many people screw it up, and too few need * it. * * A __PAGE_OFFSET of 0xC0000000 means that the kernel has * a virtual address space of one gigabyte, which limits the * amount of physical memory you can use to about 950MB. If * you want to use more physical memory, change this define. * * For example, if you have 2GB worth of physical memory, you * could change this define to 0x70000000, which gives the * kernel slightly more than 2GB of virtual memory (enough to * map all your physical memory + a bit extra for various * io-memory mappings) * * IF YOU CHANGE THIS, PLEASE ALSO CHANGE * * arch/i386/vmlinux.lds * * which has the same constant encoded.. */ #define __PAGE_OFFSET (0xC0000000) And here is the bit in linux/arch/i386/vmlinux.lds, the 0xC0000000 is right at the top of the file and specifies the address at which the kernel is linked (patching up the kernel at run-time is very much non-trivial on x86, so that's not much of an option). /* ld script to make i386 Linux kernel * Written by Martin Mares You have to remember that every bit of space you add to the physical address space is substracted from the virtual address space, so a bit of restraint is advised... NOTE: due to a bug with address conversion you can only specify a Page Offset in which all of the most significant bits are set and none of the less signficant bits are set. That is, your address must be of the binary form 1+0+. This limits the maximum physical memory to 2 GB (0x80000000) - K. For example: Max Phys Page Offset Page Offset Memory (hex) (binary) 2GB - K 0x80000000 1000 0000 0000 0000 ... 1GB - K 0xC0000000 1100 0000 0000 0000 ... 512MB - K 0xE0000000 1110 0000 0000 0000 ... 256MB - K 0xF0000000 1111 0000 0000 0000 ... The value of 'K' varies somewhat, but typically 64M is considered to be
adequate. This is the part of the Phys address space that's used for
kernel virtual memory and is what gives rise to the "rule of thumb" about
setting mem=960M ( == 1024M - 64M) when Page Offset is 0xC0000000.
Other considerations for large systems
If you have any questions, suggestions or information about the stuff in this page - or the page itself - please write to me... succes, Rik van Riel. |