"Cannot allocate memory" when upgrading

Swap does not “take” RAM. Swap adds fake RAM from disk. When apps are out of memory, rather than failing due to being unable to allocate memory, they can use disk as a very slow alternative to memory.

It is the difference between failing completely with out of memory and slowing down for a little bit.

https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-swap-what-is.html