sizes of RAM, of virtual memory and of swap for 32-bit OS

0

If I understand correctly, a 32-bit OS (Ubuntu) can only address 4GiB memory, so RAM with size larger than 4Gib will only be used 4Gib of itself and the rest is a waste.

I am now confused about this situation for RAM with similar one for virtual memory and for swap.

  1. with virtual memory being swap + RAM, if the size of the virtual memory exceeds 4Gib, will the exceeding part be a waste for the 32-bit OS?
  2. if I now have to choose the size for my swap partition, is it a factor to consider that the 32-bit OS can only address 4GiB memory? Does the size of swap have to be chosen with respect to the 4Gib addressible limitation? Will the swap exceeding 4GiB always be a waste?

  3. is virtual memory equal to RAM and swap? or can virtual memory use space on the hard drive outside the swap partition?

Thanks and regards!

Tim

Posted 2011-01-02T02:26:04.240

Reputation: 12 647

"If I understand correctly, a 32-bit OS (Ubuntu) can only address 4GiB memory" Sorry but this is flatly wrong. With PAE a 32-bit OS can address much more than 4 GiB of RAM. The 32-bit of the OS limits only virtual address space. – Jamie Hanrahan – 2016-08-28T05:00:40.173

Answers

2

The 32-bitness of the CPU only applies towards process memory and physical memory; the OS maintains its own CPU-independent structures for mapping the swap to the various processes. As much swap as the OS can handle can be used regardless of the bit depth of the CPU.

Strictly speaking, "virtual memory" is the space a process can access. Some of it can be mapped to either swap or storage via mmap(2).

Ignacio Vazquez-Abrams

Posted 2011-01-02T02:26:04.240

Reputation: 100 516

Thanks, Ignacio! What is the difference between the bit depth of the CPU and the bit depth of the OS? Do they have to agree with each other? Can a 32-bit OS be installed with a 64-bit CPU? – Tim – 2011-01-02T02:43:25.310

There's actually three bit depths you need to worry about: the CPU, the OS, and the program. For X86-64, they can come in 64/64/64, 64/64/32, and 64/32/32. Other 64-bit architectures are a little less forgiving, requiring a 64-bit OS even though they can use 32-bit programs. – Ignacio Vazquez-Abrams – 2011-01-02T02:56:16.020

Thanks again! I happened to find at http://tldp.org/HOWTO/Partition/requirements.html :"the maximum size of a swap partition is architecture-dependent. For i386, it is "officially" 2Gb. It is 128Gb on alpha, 1Gb on sparc, and 3Tb on sparc64. An opteron on the 2.6 kernel can write to a 16 Tb swap partition. " Does it mean the size of the swap is limited by the bit-depths of both CPU and OS?

– Tim – 2011-01-02T20:47:39.553

1

If I understand correctly, a 32-bit OS (Ubuntu) can only address 4GiB memory, so RAM with size larger than 4Gib will only be used 4Gib of itself and the rest is a waste.

That's not correct. You are correct that a 32-bit OS can only address 4GiB of virtual memory at a time. But that has nothing to do with physical memory. 32-bit OSes can address more than 4GiB of physical memory using, for example, PAE.

with virtual memory being swap + RAM, if the size of the virtual memory exceeds 4Gib, will the exceeding part be a waste for the 32-bit OS?

Virtual memory is a technique for creating things that look like memory that don't actually map to physical RAM. Mapped virtual memory cannot exceed 4GiB on a 32-bit OS. However, windowing can be used to allow more than 4GiB of virtual memory to be addressed, though not all of it at once.

if I now have to choose the size for my swap partition, is it a factor to consider that the 32-bit OS can only address 4GiB memory? Does the size of swap have to be chosen with respect to the 4Gib addressible limitation? Will the swap exceeding 4GiB always be a waste?

No, because the 32-bit OS limit is about how much virtual memory it can address at once. Say you're running eight processes and each of them want to use 1GiB of virtual memory. That's fine and doesn't hit any limitations, but that might require more than 4GiB of swap.

is virtual memory equal to RAM and swap? or can virtual memory use space on the hard drive outside the swap partition?

Virtual memory is limited by issues that have nothing to do with how much RAM or swap you have. Mapped files are virtual memory. Paging uses space outside the swap partition to store clean pages and space in the swap partition to store dirty pages. Ideally, the system can page both clean and dirty pages, as this gives it the most flexibility.

David Schwartz

Posted 2011-01-02T02:26:04.240

Reputation: 58 310

1

Swap does not fail to handle post-4GB addresses, that limitation applies to mapping physical memory, even in a 32-bit environment (it's not addressed in the same way).

As for the amount of swap, there is a common myth that it should be twice as large as your physical RAM size, that's simply not really needed -- swap was much more of a critical component back in the days when 512MB RAM was the standard, but nowadays it has much more of a "back seat" function, if you want to call it that. If you use hibernate you should make sure that you have at least physical RAM + a bit more (maybe an excess of 512MB if you want to be cautious).

With that said, better safe than sorry. If you have the space free, considering using a moderately sized swap size (maybe 1.5x your physical).

Matthieu Cartier

Posted 2011-01-02T02:26:04.240

Reputation: 3 422

Thanks! Why are these numbers "an excess of 512MB" or "1.5x your physical"? Which of the two is to follow? – Tim – 2011-01-02T20:50:15.323

Well, you're unlikely to get performance issues from having too large of a swap size, so it's better to go with whichever of those is larger, if that's not inconvenient. – Matthieu Cartier – 2011-01-03T11:06:49.107