Not Enough Memory? Extend Memory with Swap - part 3

Testing swap

Now , Let's test that we extend our memory:

free command - Find available memory
 main@work:~# sudo free -m
               total        used        free      shared  buff/cache   available
 Mem:            488         150           6           9         332         300
 Swap:           749           0         749

Now, there is ~300MB free available memory and ~750MB of swap memory. Thus, we can allocate easily ~1000MB.

Test memory allocation
 root@lamp:~# ./ 750
 success =>  750MB was allocated
 root@lamp:~# ./ 1000
 success => 1000MB was allocated


This method can be used to run programs which require more memory than the installed in the machine. However, there is a performance penalty as the system has to read some of the memory from and write it to the slower disk device.