LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   using pagefile in ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/using-pagefile-in-ubuntu-805608/)

mahmoodn 05-03-2010 04:13 AM

using pagefile in ubuntu
 
When the memory usage reaches 95% and above I noticed that the disk activity and load graphs go up and some of my applications are killed by the system. In windows, if someone define a pagefile then the OS will try to use it at the expense of very slow response. Why ubuntu does not use SWAP in such a way?

Thanks for any reply,

deadeyes 05-03-2010 04:51 AM

Ubuntu does use swap.
The reason why disk activity is going up is due to swap space being space alocated on disk(which is the same principle as pagefile in windows).
As disks are slow this give you indeed a large performance hit.

You can see the swap usage if you execute:
Code:

free -m
Normally linux would not kill processes. In the end your swapfile and memory is full and you just get a crash.
So there are 2 fixes here:
1. more memory
2. fix the application if it has a mem leak.

mahmoodn 05-03-2010 05:06 AM

But my applications are killed. I saw many times that the virtualbox for example is killed.

johnsfine 05-03-2010 07:01 AM

Quote:

Originally Posted by mahmoodn (Post 3955424)
Why ubuntu does not use SWAP in such a way?

If you had allocated and enabled enough swap space, Ubuntu would use it.

Typically that is done by creating a swap partition when you install Ubuntu. But it can be done later adding a swap partition and/or a swap file.

Quote:

Originally Posted by deadeyes (Post 3955445)
Ubuntu does use swap.
The reason why disk activity is going up is due to swap space being space alocated on disk(which is the same principle as pagefile in windows).

I'm pretty sure that Ubuntu (unlike Windows) does not default to allocating swap (pagefile) space when needed. The user needs to allocate enough in advance.

Lack of memory may be causing disk usage due to paging anonymous pages to and from the swap space. But also due to paging non anonymous pages from other files. If there is no swap space or too little swap space, the anonymous pages are forced to stay in ram, resulting in more disk activity to swap the non anonymous pages.

Quote:

Normally linux would not kill processes.
Actually it does kill processes when out of memory.

Depending on the mix of memory use by the various processes, adding swap space would stop it from killing processes but probably not stop it from slowing down with excess disk activity when a lot is running. But maybe adding swap space would fix that as well.

mahmoodn 05-03-2010 08:07 AM

With 2GB RAM, here is the "fdisk -l" output:
Quote:

Device Boot Start End Blocks Id System
/dev/sda1 * 1 6629 53247411 7 HPFS/NTFS
/dev/sda2 6630 48155 333557595 83 Linux
/dev/sda4 48156 60801 101578995 5 Extended
/dev/sda5 48644 60801 97659135 83 Linux
/dev/sda6 48157 48642 3903763+ 82 Linux swap
I still wonder how can I tell ububtu to use the swap.

johnsfine 05-03-2010 08:35 AM

First find out if the swap space is already enabled. Please post the output of free -m as deadeyes suggested.

mahmoodn 05-04-2010 02:34 AM

Code:

mahmood@localhost:~$ free -m
            total      used      free    shared    buffers    cached
Mem:          2012        720      1291          0        84        339
-/+ buffers/cache:        296      1715
Swap:            0          0          0


ronlau9 05-04-2010 04:09 AM

Sda6 seems to be you're swap file
Sda6 do have a UUID
In you're fstab file you should find sda6 under his UUID
To find the UUID sudo su ls -l /dev/disk/by-uuid
If you have discover the UUID sudo su nano /etc/fstab and add it to you're fstab file
Instead of nano you can use kwrite or pico ore any other real linux text editor

mahmoodn 05-04-2010 04:33 AM

Code:

mahmood@localhost:~$ sudo ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 2010-05-04 16:28 2e1d191f-1bc8-4d80-8195-84adf80ffdd3 -> ../../sda5
lrwxrwxrwx 1 root root 10 2010-05-04 16:28 4677020f-399f-449e-bcb9-6fcc35a37c20 -> ../../sda2
lrwxrwxrwx 1 root root 10 2010-05-04 16:28 619F8313282BFCFF -> ../../sda1
lrwxrwxrwx 1 root root 10 2010-05-04 16:28 cd30cc3a-c3d0-4412-8f85-5dbec4d70c4c -> ../../sda6

Code:

mahmood@localhost:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'vol_id --uuid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>  <type>  <options>      <dump>  <pass>
proc            /proc          proc    defaults        0      0
# / was on /dev/sda5 during installation
UUID=2e1d191f-1bc8-4d80-8195-84adf80ffdd3 /              ext4    relatime,errors=remount-ro 0      1
# swap was on /dev/sda6 during installation
UUID=60345e61-670e-43de-8087-805603f74c85 none            swap    sw              0      0

/dev/scd0      /media/cdrom0  udf,iso9660 user,noauto,exec,utf8 0      0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0      0
#/home/mahmood/sources/splash.iso /media/splash iso9660 ro,loop,auto 0 0
/dev/sda2 /home/mahmood ext4 nodev,nosuid 0 2

As you can see, the UUID in the ls -l command for SWAP is different from that in the fstab file. Should I only paste that UUID to the fstab file and restart? Are other options " swap sw 0 0" fine?

currently the "free -m" command shows:
Code:

mahmood@localhost:~$ free -m
            total      used      free    shared    buffers    cached
Mem:          2012      1957        54          0          6        87
-/+ buffers/cache:      1864        147
Swap:            0          0          0


ronlau9 05-04-2010 05:23 AM

The UUID you get from the command ls ls -l is the correct one
YOu should change the UUID in the FSTAB file accordingly
Every time you delete and create a partition the UUID can change.

johnsfine 05-04-2010 06:50 AM

fdisk shows there is a swap partition. free shows the swap partition isn't enabled.

It appears ronlau9 knows this topic a bit better than I do, but I'll ad a few details.

I think changes for swap in fstab will take effect the next time you reboot. You might want to add the swap without rebooting or add it in a way that gives you better feedback if something else is wrong. (You would still need to fix fstab so the swap would be enabled on subsequent reboots).

I think the command to enable the swap before reboot is
sudo /sbin/swapon -U uuid
(replacing uuid with the same value you also edit into fstab).

Alternately, after editing fstab
sudo /sbin/swapon -a
That will use the info you put in fstab.

I'm not sure, but it may be necessary to prepare the swap partition with mkswap before doing the swapon or the reboot. So if swapon fails, try using
sudo /sbin/mkswap /dev/sda6
But first double check that sda6 is really the partition you have reserved for swap (in case something has changed since the fdisk output from post #5).

mahmoodn 05-04-2010 07:17 AM

Thanks,
I also used
Code:

sudo mount -a
to apply the changesin fstab file without rebooting. Now the free -m shows that the SWAP is working:
Code:

mahmood@localhost:~$ free -m
            total      used      free    shared    buffers    cached
Mem:          2012      1960        52          0          4        376
-/+ buffers/cache:      1579        432
Swap:        3812        123      3688


deadeyes 05-04-2010 07:17 AM

Quote:

Originally Posted by johnsfine (Post 3955558)
Actually it does kill processes when out of memory.

Indeed... you can see that on the screen :) however then it is too late already.

Your output of free -m seems fine.
Your swap is active and should be more then enough.
As I said before, probably this is just getting a little more time before your system crashes anyway.
As disk is used as memory, access will be slower, more swapping will be needed and this is a spiral effect.


All times are GMT -5. The time now is 09:06 AM.