Swap space

From Edgar BV Wiki
Revision as of 08:54, 11 April 2018 by Red (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Working with swap space:

Creating swap space

In order to get a partition to be swapspace you have to fdisk it as swapspace (type 82), then make it into swap space using

mkswap -L label /dev/sdc1

Once you have done this you enter it into /etc/fstab as

/dev/sdc1 none swap sw 0 0

and then activate it by

swapon -L label

or

swapon -a


Removing swapspace

If it's on a logical volume, first

swapoff -a

or swapoff -L label

then with

swapon -s

you can check which devices are being used for swap.

uncomment it from the /etc/fstab. Should lvm / LVM lvremove give you shit about it being busy you can try dmtools. Unmount the device first, check lsof and fuser as well.

dmsetup uses the /dev/mapper names, not /dev/pvname/lvname.

dmsetup info -c

shows all the devices and if there are files open on it.

dmsetup info -c edgarghost-swap_1

shows the specific device (-c optional)

dmsetup remove --force edgarghost-swap_1

should reset the open file count to 0 (even if it gives a failure) then you can

dmsetup remove edgarghost-swap_1

again.

If none of this works, you can see what's in

/etc/initramfs-tools/conf.d/resume

change the device and then do

update-initramfs -u

and then reboot.

testing swapspace by using it

vi memeater.c

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char** argv) {
    int max = -1;
    int mb = 0;
    char* buffer;

    if(argc > 1)
        max = atoi(argv[1]);

    while((buffer=malloc(1024*1024)) != NULL && mb != max) {
        memset(buffer, 0, 1024*1024);
        mb++;
        printf("Allocated %d MB\n", mb);
        sleep(1);
    }      
return 0;
}

gcc memeater.c -o memeater

memeater