LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-25-2015, 01:42 PM   #1
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
System ignoring swap.


I haven't really used a swap partition/file in some time, since I have 32GB of RAM. The other day, I had a program go nuts and consume all of my RAM in seconds. I've set up another swap partition to at least slow down a program if it decides to eat all of my RAM again.

After I set up the swap partition, I've noticed the system seems to be ignoring it. I've tried with a swap partition, and a swap file. Everything seems fine, but the system won't use it.

Code:
# dmesg | tail -1
[150458.058154] Adding 67108860k swap on /dev/sdb2.  Priority:100 extents:1 across:67108860k FS
Code:
# free -m
             total       used       free     shared    buffers     cached
Mem:         32186       9232      22954        236         23       4374
-/+ buffers/cache:       4834      27352
Swap:        65535          0      65535
Code:
# cat /proc/sys/vm/swappiness
100
 
Old 06-25-2015, 01:52 PM   #2
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,493

Rep: Reputation: Disabled
It's not using it because it doesn't need to.
Your system is using 4834M with 27352M still free, (the difference is just cached data).

Last edited by fatmac; 06-25-2015 at 01:55 PM.
 
Old 06-25-2015, 01:57 PM   #3
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
With swappiness at 100, and running something that consumes memory, I would think it would use at least a little bit of swap.

The problem happened when I ran the command convert on a 1.6GB gif.

Code:
ls -lh new4.gif
-rw-r--r-- 1 replica replica 1.6G Jun 25 13:55 new4.gif

convert new4.gif -delay 1000 new5.gif
This consumes my RAM quickly, and the computer will stop responding before swap is used.

Code:
# free -m
             total       used       free     shared    buffers     cached
Mem:         32186      26855       5331        302         96      10529
-/+ buffers/cache:      16228      15958
Swap:        65535          0      65535

Last edited by replica9000; 06-25-2015 at 01:59 PM.
 
Old 06-25-2015, 04:40 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
"This consumes my RAM quickly, and the computer will stop responding before swap is used" How do you know that the issue is this if it stops?

Some programs will usually still use swap even if there is enough ram.


Guess you could create some more swap on a usb flash drive and use it as priority to see if the hard drive access is killing this deal. Swapoff the hard drive swap before you test.
 
Old 06-25-2015, 05:12 PM   #5
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
Code:
# swapon -s
Filename                                Type            Size    Used    Priority
/mnt/usb/SWAP                           file            2047992 0       -1


# free -m
             total       used       free     shared    buffers     cached
Mem:         32186      30824       1362      12714        131      25028
-/+ buffers/cache:       5664      26521
Swap:         1999          0       1999
Edit: Looks like it does work. Even with swappiness at 100, I still had to push the RAM to less than 1GB before swap kicked in.

Code:
# free -m
             total       used       free     shared    buffers     cached
Mem:         32186      31940        246      26086          6      26676
-/+ buffers/cache:       5257      26929
Swap:        65535       2721      62814

Last edited by replica9000; 06-25-2015 at 05:22 PM.
 
Old 06-25-2015, 05:30 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Also, pop a ulimit on that program. (See man bash.)

Don't allow it to run amok, especially if you suspect that the behavior is being caused by a bug of some kind. Once the limit is reached, attempts to allocate more memory will start to be denied.
 
Old 06-25-2015, 05:50 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by replica9000 View Post
Edit: Looks like it does work. Even with swappiness at 100, I still had to push the RAM to less than 1GB before swap kicked in.
Well sure, why would it use it before then?

RAM is used for basically two things:
1) Memory for running programs
2) Disk cache for commonly-accessed files

swappiness controls how aggressively the system will dump #1 to swap to clear up room for more of #2. However, if you haven't cached enough of your disk to even fill up your available RAM (1+2 < RAM), then why would it put anything on swap? You need to use enough disk cache to fill up your RAM with #2 before the system will even consider dumping #1 to swap, it won't do it before then because there would be no point.
 
Old 06-25-2015, 06:06 PM   #8
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by sundialsvcs View Post
Also, pop a ulimit on that program. (See man bash.)

Don't allow it to run amok, especially if you suspect that the behavior is being caused by a bug of some kind. Once the limit is reached, attempts to allocate more memory will start to be denied.
Thanks. I'll look into it. Last time something like this happened to me, I had made the mistake of having unlimited scrollback in Konsole, and had a looped script error out. I wasn't expecting convert (imagemagick) to go nuts creating a gif.


Quote:
Originally Posted by suicidaleggroll View Post
Well sure, why would it use it before then?

RAM is used for basically two things:
1) Memory for running programs
2) Disk cache for commonly-accessed files

swappiness controls how aggressively the system will dump #1 to swap to clear up room for more of #2. However, if you haven't cached enough of your disk to even fill up your available RAM (1+2 < RAM), then why would it put anything on swap? You need to use enough disk cache to fill up your RAM with #2 before the system will even consider dumping #1 to swap, it won't do it before then because there would be no point.
I was under the impression that a swappiness value of 100 would prefer swap pretty quickly, even if swap was not needed. I was surprised that my system still froze before swap was used. In the past, when a program went nuts and X had stopped responding, I was able to login via ssh, and kill the offending app.
 
Old 06-25-2015, 07:01 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by replica9000 View Post
I was under the impression that a swappiness value of 100 would prefer swap pretty quickly, even if swap was not needed.
Needed for what. It won't stick a program into swap if nothing can make use of that RAM, it wouldn't make sense. What would be the point? If the RAM isn't needed for anything else, including disk cache, then there's no reason for the system to start throwing programs into swap. Now once your disk cache fills up the remainder of your RAM and the system has to make a decision between throwing away older disk cache versus throwing a running program into swap to make room for new disk cache, THAT'S when swappiness comes into play. A low value will keep your programs in RAM and throw away old disk cache to make room for new. A high value will throw unused programs into swap to make the room.

swappiness has nothing to do with an out of control program gobbling up all of your RAM.

Quote:
Originally Posted by replica9000 View Post
I was surprised that my system still froze before swap was used. In the past, when a program went nuts and X had stopped responding, I was able to login via ssh, and kill the offending app.
That is odd. Maybe it wasn't actually frozen? Maybe it was just busy trying to offload programs to swap as fast as possible to prevent an OOM condition? Sometimes a system can appear to "hang" for minutes while this is happening, but if you give it time usually it'll finally get enough data into swap that you can start to get a response out of it, and you can kill the offending process.
 
Old 06-28-2015, 02:02 PM   #10
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
I think what threw me off, was that in the past, a small amount of swap was used (<100mib) even with all of the free RAM available. This time around, after a few days, swap usage was still at 0. I was starting to think that my storage setup was to blame. Seems to work fine.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Running out of storage; system ignoring home partition rabirk Slackware 15 06-10-2013 09:36 AM
raid1 system swap the_zone Slackware 3 10-09-2012 02:41 PM
Is swap a file system? FSoftware Lover Linux - General 18 02-17-2007 06:16 PM
swap file system gaganvyas Linux - General 2 07-18-2005 07:15 AM
system is not using swap partition android1654 Linux - General 2 11-23-2004 11:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:42 PM.

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