Virtual memory (swap) in linux

How much memory does your machine have:

free -om

What about the split-- how much of it is in swap rather than in regular memory? Obtain the memory exhauster program, memory3.c, per your instructor. Then compile it:

gcc memory3.c -o memory3

Run the memory exhauster and see where it stops:

./memory3

Write down both how much memory was available to the machine at the time, and where the program stopped.

The place that houses your swap space is very likely a disk partition. Identify it and note its name:

fdisk -l

Supposing that it's /dev/hda2 (might be different on your box), turn it off:

swapoff /dev/hda2

Recheck available memory and note disappearance of swap:

free -om

Run the memory exhauster, note where it stops, and compare with where it stopped:

./memory3

Write down both how much memory was available to the machine at the time, and where the program stopped.

A file could also house swap space. Make one whose size is about the same as that of the now-disabled swap partition. For example, if it's a 256MB partition make a 256MB file:

dd if=/dev/zero of=~/myswapfile bs=1048576 count=256

Adjust the "count" parameter to the desired number of megabytes. The file will be full of zeros. Start using it for virtual memory swapping:

swapon ~/myswapfile

You'll get an error message, because it needs a little bit of internal formatting and currently it's nothing but zeros. Check that:

od -Ad -tx1z ~/myswapfile

Now format the file internally as swap space:

mkswap ~/myswapfile

Check the formatting again, it'll be slightly different and readied for the swapping role:

od -Ad -tx1z ~/myswapfile

Turn it on:

swapon ~/myswapfile

Check available memory:

free -om

and exhaust it:

./memory3

Note how far it gets. Write down both how much memory was available to the machine at the time, and where the program stopped.

Now, in addition to the swap file turn the swap partition back on too:

swapon /dev/hda2

Check available memory:

free -om

and its split between sources:

swapon -s

and exhaust it:

./memory3

How far did it get? Write down both how much memory was available to the machine at the time, and where the program stopped.



What were the approximate memory consumption limits at which the program was terminated, and what was their relationship to the amount of swap available at the time?

Posted bySiebel Expert at 11:47 PM 0 comments