I can trace this recommendation that swap should be twice the size of the physical memory as far back as 1989, see SunOS 4 installation manual, page 37, but I wonder if there was ever any technical reason for this rule? The only technical reference I can find is the following phrase from FreeBSD man 7 tuning:
The kernel's VM paging algorithms are tuned to perform best when there isat least 2x swap verses main memory. Configuring too little swap can leadto inefficiencies in the VM page scanning code as well as create issueslater on if you add more memory to your machine.
But this man page was introduced only in 2001 by Matt Dillon. On the other hand, the FreeBSD installer required a swap size 2x RAM since 1993. I wonder if this originated in the 4.3BSD virtual memory implementation. I have checked The Design and Implementation of the 4.4BSD Operating System, but there is not much about swap space. But McKusick's 1986 paper A New Virtual Memory Implementation for Berkeley UNIX contains the following sentence:
The expected mode of operation for which the system was tuned was to have the sum of active virtual memory be one and a half to two times the physical memory on the machine.
Update: The question isn't about why we need to limit the swap size. The question is why the specific number 2x was selected. Why not 1.5x? Why not 3x? So far, my understanding was that with BSD reserving swap space for each anonymous allocation, 1x felt too low, and 2x is just the next whole number, but that note about VM paging algorithms being tuned for 2x gives an alternative reason.






