Re: Maximum swap space?

William Lee Irwin III
2003-06-07T20:38:31Z

On Sat, Jun 07, 2003 at 01:24:32PM -0700, Andrew Morton wrote:
> The limit is now 16 swapfiles/devices, because one pte bit got
> stolen for nonlinear VMA pte's.
> I'm not sure where the 2G limit comes from?

i386 has:
#define __swp_type(x) (((x).val >> 1) & 0x1f)
#define __swp_offset(x) ((x).val >> 8)
#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offse
t) << 8) })
#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low })
#define __swp_entry_to_pte(x) ((pte_t) { (x).val })

These limits could be slightly relaxed by the kernel with some slightly
more complex bit twiddlings to recover up to 6 bits of the lower byte
of a non-present PTE for 64 swapfiles. The limitation on size seems to
be in userspace. It appears the kernel has 24 bits for offsets in 4KB
units, for up to something approaching 64GB swapfiles. Andi Kleen tells
me newer distributions have fixed the mkswap(8) userspace limitation.
So non-PAE x86 should be able to do 4TB of aggregate swapspace modulo
vmallocspace and/or ZONE_NORMAL exhaustion from swap maps. Also, PAE
should be able to do 64TB of aggregate swapspace (modulo vmallocespace)
since it has an additional 4 bits usage for page offsets. But I didn't
audit intensively, so some silly limits may be lurking in dark corners.

-- wli