LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 05-03-2010, 04:13 AM   #1
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Rep: Reputation: 16
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,
 
Old 05-03-2010, 04:51 AM   #2
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
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.
 
Old 05-03-2010, 05:06 AM   #3
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
But my applications are killed. I saw many times that the virtualbox for example is killed.
 
Old 05-03-2010, 07:01 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by mahmoodn View Post
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 View Post
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.

Last edited by johnsfine; 05-03-2010 at 07:04 AM.
 
Old 05-03-2010, 08:07 AM   #5
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
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.

Last edited by mahmoodn; 05-03-2010 at 08:10 AM.
 
Old 05-03-2010, 08:35 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
First find out if the swap space is already enabled. Please post the output of free -m as deadeyes suggested.
 
Old 05-04-2010, 02:34 AM   #7
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
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
 
Old 05-04-2010, 04:09 AM   #8
ronlau9
Senior Member
 
Registered: Dec 2007
Location: In front of my LINUX OR MAC BOX
Distribution: Mandriva 2009 X86_64 suse 11.3 X86_64 Centos X86_64 Debian X86_64 Linux MInt 86_64 OS X
Posts: 2,369

Rep: Reputation: Disabled
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

Last edited by ronlau9; 05-04-2010 at 04:13 AM.
 
Old 05-04-2010, 04:33 AM   #9
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
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

Last edited by mahmoodn; 05-04-2010 at 04:35 AM.
 
Old 05-04-2010, 05:23 AM   #10
ronlau9
Senior Member
 
Registered: Dec 2007
Location: In front of my LINUX OR MAC BOX
Distribution: Mandriva 2009 X86_64 suse 11.3 X86_64 Centos X86_64 Debian X86_64 Linux MInt 86_64 OS X
Posts: 2,369

Rep: Reputation: Disabled
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.
 
Old 05-04-2010, 06:50 AM   #11
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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).

Last edited by johnsfine; 05-04-2010 at 06:55 AM.
 
Old 05-04-2010, 07:17 AM   #12
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
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
 
Old 05-04-2010, 07:17 AM   #13
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
Quote:
Originally Posted by johnsfine View Post
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.

Last edited by deadeyes; 05-04-2010 at 07:19 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ubuntu Restricted Extras - Lets Ubuntu Play Everything [Ubuntu for Beginners Sc LXer Syndicated Linux News 0 04-20-2010 12:10 AM
Use Windows pagefile.sys (swap) as Linux swap? bluesword1969 Linux - General 3 02-19-2010 02:35 PM
XP won't change pagefile space?? (aka another reason not to use MS...) jmite General 12 11-17-2008 10:39 PM
LXer: Printing with Ubuntu: Insights for a quick and easy Ubuntu printer installation LXer Syndicated Linux News 0 06-03-2006 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 01:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration