Can a 32-bit OS machine use up all 8GB RAM + 20GB page file?

98

44

What I understand about 32-bit OS is, the address is expressed in 32 bits, so at most the OS could use 232 = 4G memory space -- I assume the unit is bytes, so 4GB.

Does this mean if any machine with a 32-bit OS (be it Windows or Unix) has more than 4GB total of RAM + page file on hard disk, for example 8GB RAM and 20GB page file, its memory will never be "used up"?

By "used up" I mean that increasing RAM or page file won't help the performance; of course, it's always possible an application will keep requesting memory from the OS but failing.

Similarly, if this 32-bit OS machine has 2GB RAM and 2GB page file, increasing the page file size won't help the performance. Is this true?

athos

Posted 2011-12-13T12:59:38.767

Reputation: 1 954

2As a side note, if you happen to have more then 4GB of RAM, and only a 32 bit OS, you can make a RAM Disk. This is a hard drive in your RAM, and you can use the unused/unaddressed RAM to place it in. – Simon Verbeke – 2011-12-13T13:33:10.493

10You can't. A ramdisk still has to be created throught the OS, if the OS can't use the memory you can't create a ramdisk there either. (Unless your bios can create a ramdisk, which is rare). – AVee – 2011-12-15T08:17:30.863

1The short answer is "yes". Although usually a process is given a 32 bit address space to use, the OS itself can use more than that (either by bank switching like we did in the 80s or by address extension tricks school as Intel's PAE. Also, remember you run more than one program at a time, which may be composed of more than one process (Chrome puts tabs in different processes). And the OS itself will use the memory for things like caching data from local fixed disks so that you experience faster access to data already used. – rbanffy – 2012-07-14T13:20:07.257

Answers

145

What I understand about 32-bit OS is, the address is expressed in 32 bits, so at most the OS could use 2^32 = 4GB memory space

The most that the process can address is 4GB. You are potentially confusing memory with address space. A process can have more memory than address space. That is perfectly legal and quite common in video processing and other memory intensive applications. A process can be allocated dozens of GB of memory and swap it into and out of the address space at will. Only 2 GB can go into the user address space at a time.

If you have a four-car garage at your house, you can still own fifty cars. You just can't keep them all in your garage. You have to have auxiliary storage somewhere else to store at least 46 of them; which cars you keep in your garage and which ones you keep in the parking lot down the street is up to you.

Does this mean any 32-bit OS, be it Windows or unix, if the machine has RAM + page file on hard disk more than 4GB, for example 8GB RAM and 20GB page file, there will never be "memory used up"?

Absolutely it does not mean that. A single process could use more memory than that! Again the amount of memory a process uses is almost completely unrelated to the amount of virtual address space a process uses. Just like the number of cars you keep in your garage is completely unrelated to the number of cars you own.

Moreover, two processes can share non-private memory pages. If twenty processes all load the same DLL, the processes all share the memory pages for that code. They don't share virtual memory address space, they share memory.

My point, in case it is not clear, is that you should stop thinking of memory and address space as the same thing, because they're not the same thing at all.

if this 32-bit OS machine has 2GB RAM and 2GB page file, increasing the page file size won't help the performance. Is this true?

You have fifty cars and a four-car garage, and a 100 car parking lot down the street. You increase the size of the parking lot to 200 spots. Do any of your cars get faster as a result of you now having 150 extra parking spaces instead of 50 extra parking spaces?

Eric Lippert

Posted 2011-12-13T12:59:38.767

Reputation: 1 816

Great answer. I'm surprised this hasn't been made a community wiki. The misconception of address space and memory space has been a common one considering the rapid acceptance of x64 Windows. You should also link your blog post regarding this subject. http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx

– surfasb – 2011-12-13T18:04:38.297

"A process can have more memory than address space." Very true, but misleading. The ability to do this is highly operating-system dependent, and requires that the underlying hardware/OS has explicit support for these calls. There is no "universal" method to extend a processes' available memory past the virtual address space. Again though, these constructs exist on virtually every modern operating system (save for those used in embedded systems). – Breakthrough – 2011-12-13T18:12:58.233

26I find this answer to not address the question at hand and almost is deceptive at points. – Rig – 2011-12-13T19:49:25.233

48@Rig: Awesome, I am glad to hear your constructive criticism. Now's your chance to write a better answer and show us the sort of answer you think is less deceptive and more pertinent. – Eric Lippert – 2011-12-13T20:40:09.907

1@Eric: A process can allocate dozens of GB of memory and swap it into and out of address space at will. This is counter to everything I've learned about memory. My understanding is (was?), a 32-bit user-level process can never address more than 4GB of virtual address-space, and since each virtual-address page must refer to some physical-address page, this means it can't ever address more than 4GB of physical-memory either. If this is not true, how does the process address the extra memory - is there some OS-specific API? What would the code look like in Windows? – BlueRaja - Danny Pflughoeft – 2011-12-13T22:35:41.083

2@BlueRaja: A 32 bit process can never address more than 4GB of virtual address space, but it can allocate arbitrarily much. Again, go back to my analogy. You can reserve a parking spot (page) in the lot (page file). Whether you put a car in it or not is your business; the spot is reserved for your use. If you want to get at the car but your garage (virtual memory) is full, then you drive a car (page) from the garage to the lot, and drive a different car from the lot to the garage. – Eric Lippert – 2011-12-13T22:55:11.637

4@BlueRaja: I suspect that you are confusing physical memory with memory. Physical memory is just an optimization that permits faster access to memory. Just as processor caches are an optimization that permit faster access to memory. Memory is for all intents and purposes space reserved in the page file. Whether a given page in the page file is (1) mapped to a virtual memory address or (2) copied from disk to physical memory is irrelevant to the question of whether it is allocated or not. – Eric Lippert – 2011-12-13T22:57:49.670

4

@BlueRaja: Raymond Chen's article on the subject might help. He shows how to allocate 4GB out of the page file; that is memory that the process owns. The process cannot address the whole thing at once of course, but it can address any page by mapping a page into an unused VM page, using it for a while, and then discarding it. http://blogs.msdn.com/b/oldnewthing/archive/2004/08/10/211890.aspx

– Eric Lippert – 2011-12-13T22:59:44.597

@Eric: Thanks, that explains it - I never realized you could request memory from Windows without Windows giving it a virtual-address. – BlueRaja - Danny Pflughoeft – 2011-12-13T23:46:48.677

2@BlueRaja: You're probably used to just calling VirtualAlloc, and of course that gives you memory mapped to virtual memory. But memory-mapped files are memory too, and you can make a memory-mapped file that is only partially mapped into virtual memory. – Eric Lippert – 2011-12-13T23:49:34.760

1Although some 32 bit operating systems can use more than 4GB memory, not all can. On recent x86 chips it's a restriction of the operating system. Windows XP is limited to a little under 4GB, whereas Windows 2003 Server (also 32 bit) can use much more. But this is all specific to x86 processors. On some chips, there is no support for virtual addressing, so either you resort to hardware hacks or you live within the 32 (or however many) bits limit. – Steve314 – 2011-12-14T08:59:09.613

Actually, the 32bits = 4GB limit was true for operating systems as well before PAE was introduced (back in 1995!). When it comes to memory limits on Windows this is a really interesting read: http://www.geoffchappell.com/notes/windows/license/memory.htm With a bit of hacking you can make a 32bits windows use more then 4GB...

– AVee – 2011-12-14T21:02:28.877

3This answer would have been clearer, Eric, if you had stated explicitly that Windows (and other OSes) allow you to “reserve” memory without actually having it in your virtual address space, and to then answer the obvious question “then how do you address it?”. I think the answer to that is “there is some sort of Page ID that you use to refer to it in order to page it into the virtual address space, and then you can address it there”, but I don’t know, and your answer doesn’t say :) – Timwi – 2012-10-24T15:20:29.587

68

It is true that the CPU can only address maximum 4Gb of RAM. However, current CPU's use an MMU (Memory management unit) to translate process-specific memory addresses into physical memory addresses.

This MMU is used for all sorts of different tricks, from memory isolation (process A cannot manipulate memory of process B) to memory sharing (process A can access the same physical memory region as process B and can exchange data this way).

Although 32-bit CPU's only support 4Gb of memory per process, it can address up to 64Gb of RAM when using Physical Address Extension. This allows process A to use the first 4Gb of memory, while process B uses the next 4Gb. In total, more than 4Gb of physical memory is used, but the total amount of memory a single process uses is still capped at 4Gb.

PAE is supported on Linux since kernel version 2.3.23 and on some 32-bit flavours of Windows Server, but not on 32-bit Windows XP, Vista or 7.

If your CPU does not support PAE you will be limited to 4GB of physical memory (or less depending on other factors).

Please note your operating system can still evict parts of physical memory to the disk (page file) regardless of the CPU supporting PAE. This ensures you can start multiple processes who use more than 4Gb combined. The only impact PAE has is whether you can keep the 4Gb of process B in physical memory while running process A.

Dave Webb

Posted 2011-12-13T12:59:38.767

Reputation: 10 126

@DanNeely: You wrote "on win32 with the /3gb switch set they can access 3GB of ram." No. No. No! The /3GB switch allows them to access up to 3 GB of virtual address space. It has nothing directly to do with RAM. A 32-bit app can access 3 GB or even more than 4 GB of RAM (on a system that supports it) even if it's limited to 2 GB user mode address space. – Jamie Hanrahan – 2017-07-01T01:28:12.387

does it mean if it does not support, then what i said above it correct? – None – 2011-12-13T13:03:01.823

11

Windows XP does support PAE (starting with SP2, I think), but ignores RAM beyond 4GB even when the machine supports PAE; see here. It's used for hardware-based Data Execution Prevention — the NX/XD bit is available only in a PAE page table entry, not a "regular" page table entry.

– Wyzard – 2011-12-13T13:23:10.123

Chipset can also be a limiting factor of how much memory can be supported/used regardless of which OS or hack you choose. – Moab – 2011-12-13T13:53:36.867

5I'd add that the reason why consumer versions of 32bit windows don't support >4GB of ram was that a significant number of hardware drives were found not to work correctly with that much memory; and since at the time >4GB of ram was extremely rare outside of servers/ultra high end workstations that most of the companies who maintained the drivers were uninterested in spending money to update drivers that would only be used by 0.1% of their customer base. – Dan is Fiddling by Firelight – 2011-12-13T14:06:28.387

@DanNeely actually, there is a Windows 7 kernel hack to allow you to use more than 4GB of RAM under the 32-bit version. It's directly compatible with most 32-bit drivers, and I never ran into any issues when I used it. That being said, I did notice (back when Win7 was in the beta) some drivers that mentioned BSODs if you had more then 2 or 4 gigabytes of memory installed (I saw drivers that had issues with both). Post-beta, I never saw a driver that had this issue.

– Breakthrough – 2011-12-13T15:13:23.617

If you have a need for more then 4GB of memory there is no reason not to use a 64-bit operating system. The only reason might be is if your dealing with hardware that does not have a signed 64-bit driver. A 32-bit application is unware it is running on a 64-bit operating system. Furthermore I do believe starting with Vista, if you happen to have more then 4GB of memory installed, you would address hardware outside of the 3.5GB range, this normally allowed you to get 300-500MB of additional addressable space. – Ramhound – 2011-12-13T15:36:20.513

@Breakthrough A 3rd party hack is not the same thing as the OS supporting a feature. Also, by now most of the bad driver codebases were probably fixed (or for obsolete hardware) in the process of making them x64 compatible (something else that many consumer driver devs balked at in the XP era); and since MS would get 99% of the blame for crashes the fraction of drivers failing catastrophically probably wouldn't need to be huge for them to opt against the feature. – Dan is Fiddling by Firelight – 2011-12-13T15:36:34.570

@Ramhound there's a way for 32 apps to determine if they're running on win32 or win64. If they indicate that they support unsigned pointers, on win32 with the /3gb switch set they can access 3GB of ram. On win64 they can allocate just under 4GB because almost all the OS items are mapped to addresses >2^32 (A few, IIRC mostly BIOS related, items can't be mapped higher so there are a few small holes in the 32bit address space.) – Dan is Fiddling by Firelight – 2011-12-13T15:40:33.500

7

@DanNeely the OS does have support for the memory, it's limited due to licensing issues. While I agree that this is a third-party hack, it's only for consumer variants of Windows. Server-based Windows distributions, starting from Windows 2000, have had support for more than 4GB of memory (ref. the first link).

– Breakthrough – 2011-12-13T15:42:19.347

@Breakthrough Almost every difference between Windows Starter and Enterprise is set by one or more flags in the OS. Geoff said he didn't know why the restriction was there; but it was mentioned in his blog "All that’s required [for PAE] is a general awareness that physical memory addresses may be wider than 32 bits..." I never bookmarked it, but according to an MS blog some vendors not following this documentation (and crashing with >4GB of ram) was why PAE was never enabled in consumer windows. MS could enforce it for certified drivers; but only enterprise demanded them. – Dan is Fiddling by Firelight – 2011-12-13T18:32:01.407

@DanNeely PAE is enabled on all consumer variants of Windows. The memory limit is a software-imposed limit, which is completely different from PAE.

– Breakthrough – 2011-12-13T21:21:23.127

I was hitting the length limit and condensing to make it all fit. While PAE and >4gb are not strictly equivalent, they're commonly used equivalently because the latter is the one major user facing feature; and in the context of this discussion is the feature of PAE that bad drivers will cause OS crashes from. – Dan is Fiddling by Firelight – 2011-12-13T22:05:37.167

15

Speaking specifically about 32-bit Windows variants, they have had support for more than 4GB of RAM since Windows 2003 variants (and you can also get a kernel hack for Windows 7 to allow you to use all of your RAM in 32-bit). However, this comes at a cost, as you outlined in the first part of your question.

In a 32-bit operating system, the size of a pointer (memory address) is the same as the word length of the CPU, 32-bits, which allows (as you mentioned) a 2^32 = 4GB memory space. Windows also takes a "virtual memory" approach for applications, so each application has it's own memory space.

Since each pointer is only 32-bits wide, each application's pointers can only address up to 4GB of memory, even though the system can support more then 4GB of RAM. As far as I know, this is the only caveat to using more than 4GB of RAM in a 32-bit operating system. In total, you can have many applications using more than 4GB of RAM combined, but any one particular process can only allocate/access up to 4GB.


Back to your question, let's say you have a program that uses 2GB of RAM. If you have 10 instances of this program, that's 20GB. All 8GB of your RAM will be used up, as well as another 12GB of the pagefile. So yes, under 32-bit operating systems, it is more than possible to use up this memory.

if this 32-bit OS machine has 2GB RAM and 2GB page file, increasing the page file size won't help the performance. is this true?

Increasing the pagefile size will usually not increase performance (unless your RAM and pagefile are set to the absolute minimum, or set so low your computer constantly thrashes). It will, however, prevent your computer from running out of (virtual) memory. Whenever anything needs to be purged to the pagefile, you're already taking a huge performance hit (since the hard drive is orders of magnitude slower then your RAM).

Breakthrough

Posted 2011-12-13T12:59:38.767

Reputation: 32 927

Of the 4GB of address space that each process gets, only 2GB is actually available for the program to use; the other 2GB is reserved for use by the kernel. The /3GB boot option can allow some programs to use more RAM.

– Wyzard – 2011-12-13T13:30:43.347

1

@Breakthrough: "Increasing the pagefile size will never increase performance" I don't think this is true. For example, if there is more swap, the OS can more aggressively swap out unused program data, and use the free RAM for e.g. disk caching. In some configurations, this may yield better performance. There is a nice answer on ServerFault on why a pagefile is important, which touches on these issues: http://serverfault.com/questions/23621/any-benefit-or-detriment-from-removing-a-pagefile-on-an-8gb-ram-machine/23684#23684

– sleske – 2011-12-13T13:47:13.933

2

Be careful of blanket statements like "Increasing the pagefile size will never increase performance", it is perfectly possible for a page file that is too small to result in more disk thrashing than having a larger page file! See answers and comments in this question.

– Mark Booth – 2011-12-13T14:21:36.300

1@sleske Good point, I updated it to be more of a "usually not" type of thing. While I agree it may make a huge difference in a server, for most people, the point I was trying to get across is that they would be better off just getting more RAM (since when you're paging, performance is pretty much as slow as it can get). – Breakthrough – 2011-12-13T15:11:06.213

-1

When a processor is said to be 32-bit, it means it can operate with 32-bit numbers using a single instruction. This has little to do with the width of its address bus, which on Intel architecture is 36-bit since Pentium Pro released in 1995.

The famous 4GB limitation comes from the fact that most PC software uses Flat memory model where each byte of memory can be addressed by a pointer. Since a pointer should fit in a register to be used, and registers are 32-bits wide, you're limited to 4GB.

Dmitry Grigoryev

Posted 2011-12-13T12:59:38.767

Reputation: 7 505

This is incorrect, as pointed out in other earlier answers above. – ChrisInEdmonton – 2015-06-17T14:02:03.087

Could you point out one particular fact that I got wrong? – Dmitry Grigoryev – 2015-06-18T08:05:19.767

1A single process can use more than 4 GB. Specifically, previous answers point out "A process can have more memory than address space". – ChrisInEdmonton – 2015-06-18T12:15:09.330

That's impossible! How can a process have memory for which there is no address? – Dmitry Grigoryev – 2015-06-18T12:19:19.070

2

See for example, http://blog.superuser.com/2011/04/23/want-lots-of-ram-stop-using-32-bits/ Now, certainly, you can't use more than 4 GB simultaneously, but a single process can unmap and remap the memory, so can make use of more than 4 GB in a single process, there's just a bit of bookkeeping. That blog post is rather Windows-specific. I've run database servers with > 4 GB of memory allocated, on 32-bit Linux installs. These days, of course, you'd just run 64-bit Linux.

– ChrisInEdmonton – 2015-06-18T14:16:48.057

1OK, my apologies. I didn't think about the possibility to mmap extra memory. – Dmitry Grigoryev – 2015-06-18T14:31:03.983