maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   How to set swappiness? (https://talk.maemo.org/showthread.php?t=48966)

shadowjk 2010-09-07 20:10

Re: How to set swappiness?
 
Well it's write mixed with reads, which on all sd/mmc/usbflash I've seen translates into a big read/modify/write cycle right after write-read commands come from host..

At one point I plotted all writes done by kswapd, and found that it's indeed mostly sequential until it reaches the end of the swap area, after which it becomes increasingly random.. swapoff/swapon fixes that, and I now have a script that checks iostat for amount of writes and does swapoff/swapon/swapoff via a temporary swapfile when writes exceed swap size..

msa 2010-09-09 19:56

Re: How to set swappiness?
 
i created a file named swapmop in etc/event.d/

content:
Quote:

# swappiness auf 30

start on started rcS-late

script
echo 30 > /proc/sys/vm/swappiness
end script
then i rebooted.
when doing cat /proc/sys/vm/swappiness, it still sais "100"

what am i doing wrong? :O

slender 2010-09-09 20:12

Re: How to set swappiness?
 
Quote:

Originally Posted by shadowjk (Post 809968)
...and I now have a script that checks iostat for amount of writes and does swapoff/swapon/swapoff via a temporary swapfile when writes exceed swap size..

Would it be possible to share that script with us? :)

sake 2010-09-09 20:41

Re: How to set swappiness?
 
Quote:

Originally Posted by msa (Post 811948)
i created a file named swapmop in etc/event.d/

content:


then i rebooted.
when doing cat /proc/sys/vm/swappiness, it still sais "100"

what am i doing wrong? :O

try to add:
Code:

#!/bin/sh
at the very beginning of your script.
also try
Code:

chmod a+x /etc/event.d/swapmop
as root

msa 2010-09-09 21:09

Re: How to set swappiness?
 
Quote:

Originally Posted by sake (Post 812002)
try to add:
Code:

#!/bin/sh
at the very beginning of your script.
also try
Code:

chmod a+x /etc/event.d/swapmop
as root

the #!/bin/sh helped! thanks!
though right now i'm not seeing any differences at all...

/edit:
ha, there is a difference: my RAM-usage is constantly at around 180 mb. not sure if thats good...?!

egoshin 2010-09-10 20:49

Re: How to set swappiness?
 
#!/bin/sh should not have difference. But don't forget a space between 30 and >

Actually, it is better to use this script in /etc/event.d/myscript

Code:

description "tuning system"
author My Name

console output

start on started rcS-late

script
        echo "30" > /proc/sys/vm/swappiness
end script


Sorry for possible misguide...

DrWilken 2010-09-10 21:01

Re: How to set swappiness?
 
Quote:

Originally Posted by msa (Post 812031)
ha, there is a difference: my RAM-usage is constantly at around 180 mb. not sure if thats good...?!

Using the memory available isn't a BAD thing... ;) Running out of memory is though... :) That's where swap is useful.

High swappiness makes the system swap out (RAM->SWAP) aggressively (idle processes memory blocks are moved to disk).

Low swappiness swaps out when memory is running full instead.

http://kerneltrap.org/node/3000

Experiment with it and find out what setting fits Your usage pattern... ;)

I wouldn't recommend setting the value too low (30 seems fine here so far).

msa 2010-09-10 22:13

Re: How to set swappiness?
 
Quote:

Originally Posted by egoshin (Post 813005)
#!/bin/sh should not have difference. But don't forget a space between 30 and >

Actually, it is better to use this script in /etc/event.d/myscript

Sorry for possible misguide...

thanks!

i tried to use your script, but it did not work. i ended up modifying it until i had the first script i used to make it work.

i had to remove the following part:
Code:

description "tuning system"
author My Name

console output

and still add the #!/bin/sh to make it work. i tried different combinations also, but non worked.

DrWilken 2010-09-10 22:24

Re: How to set swappiness?
 
This worked for me (/etc/event.d/tuning):
Code:

description "System Tuning"
author "Christian Wilken"

console output

start on started rcS-late

script
        echo "30" > /proc/sys/vm/swappiness
        echo "1" > /proc/sys/vm/oom_kill_allocating_task
end script

No chmod'ing or anything else needed (look at all the other files in /etc/event.d)... ;)

matthew maude 2010-09-10 22:55

Re: How to set swappiness?
 
its easier to use vi editor for this, run

sudo gainroot

vi /etc/init.d/rcS

scroll down to 263/281

press the letter i - don't press enter after

it looks like this
echo 100 > /proc/sys/vm/swappiness

use the arrows to move the cursor and change the value to 30 or whatever you want - keep it above 30 tho

then press the onscreen 'esc' button

then type this

:wq

then hit enter

DrWilken 2010-09-11 06:38

Re: How to set swappiness?
 
Quote:

Originally Posted by matthew maude (Post 813085)
its easier to use vi editor for this, run

sudo gainroot

vi /etc/init.d/rcS

scroll down to 263/281

press the letter i - don't press enter after

it looks like this
echo 100 > /proc/sys/vm/swappiness

use the arrows to move the cursor and change the value to 30 or whatever you want - keep it above 30 tho

then press the onscreen 'esc' button

then type this

:wq

then hit enter

Or move the curser till it's over the 1 in 100 and press rw (replace word), enter 30, then esc, and then :wq ;)

There's a reason for creating a new event.d script though (I also edited rcS at first).

matthew maude 2010-09-11 08:29

Re: How to set swappiness?
 
Quote:

Originally Posted by DrWilken (Post 813244)
Or move the curser till it's over the 1 in 100 and press r (replace), enter 30, then esc, and then :wq ;)

There's a reason for creating a new event.d script though (I also edited rcS at first).

ah, didn't know that
i'm so new to linux that i only found out about vi a few days ago whilst trying to add aliases to root/.profile
and i only found out cos i overwrote the damn file and lost the ability to run any apt command or do a reboot
learning something new every day tho :D

DrWilken 2010-09-11 08:43

Re: How to set swappiness?
 
Google for Vi Cheat Sheet... ;)

Oh, and have a nice journey... :cool:

kaze.daniel 2010-09-13 23:15

Re: How to set swappiness?
 
what about that:

HTML Code:

# my rcS.e fix

start on started rcS-late

script
      echo 30 > /proc/sys/vm/swappiness
      echo 0 > /proc/sys/vm/page-cluster
      echo 1 > /proc/sys/vm/laptop_mode
      echo 1 > /proc/sys/vm/oom_kill_allocating_task
      echo 0 > /proc/sys/vm/dirty_expire_centisecs
      echo 0 > /proc/sys/vm/dirty_writeback_centisecs
      echo 60 > /proc/sys/vm/dirty_background_ratio
      echo 95 > /proc/sys/vm/dirty_ratio
      echo 0 > /proc/sys/net/ipv4/tcp_timestamps
      echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_save
end script


egoshin 2010-09-14 01:15

Re: How to set swappiness?
 
Quote:

Originally Posted by kaze.daniel (Post 815333)
what about that:

HTML Code:

# my rcS.e fix

start on started rcS-late

script
      echo 30 > /proc/sys/vm/swappiness
      echo 0 > /proc/sys/vm/page-cluster
      echo 1 > /proc/sys/vm/laptop_mode
      echo 1 > /proc/sys/vm/oom_kill_allocating_task
      echo 0 > /proc/sys/vm/dirty_expire_centisecs
      echo 0 > /proc/sys/vm/dirty_writeback_centisecs
      echo 60 > /proc/sys/vm/dirty_background_ratio
      echo 95 > /proc/sys/vm/dirty_ratio
      echo 0 > /proc/sys/net/ipv4/tcp_timestamps
      echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_save
end script


Just add first 4 lines to be in sync with coding standards:

Code:

description "it is my own N900 tuning"
author "YourName"

console output

instead of ugly line started from # (sorry for that). And please - enclose any numeric value before '>' sign into double-quotes like

echo "95" > /proc/sys/vm/dirty_ratio

It could not expose you to very common bug - the sequence like '95>' without space has a special meaning in shell.

Note: I didn't evaluate the effect of that "echo" commands.

allnameswereout 2010-09-14 01:51

Re: How to set swappiness?
 
For an explanation of these settings and values see http://www.knownokia.ca/2010/08/n900...-and-more.html

FWIW, I'm gonna try them out next days.

smackpotato 2010-09-14 01:53

Re: How to set swappiness?
 
I have a long time ago made a script that sets swappiness to 100 it is on the garage it is called "seatbelt" install the script will set swappines at startup.
whether this is a good thing to do i do not know. It worked great on the 770

SavageD 2010-09-14 02:37

Re: How to set swappiness?
 
To save users the time of searching, It's here ...

Using the seat belts read me file, I'm guessing we have to do this?

As root.
Copy the script to /etc/init.d
Change script mode to executable
Create this symbolic link using this command:

ln -s /etc/init.d/<Script Name> /etc/rc2.d/S80seatbelt"

Reboot

And

To reverse changes, remove the link and script...

So basically all we need to do is create a sym link to a script for it to run on start up?

allnameswereout 2010-09-14 03:07

Re: How to set swappiness?
 
Quote:

Originally Posted by SavageD (Post 815382)
To save users the time of searching, It's here ...

Using the seat belts read me file, I'm guessing we have to do this?

As root.
Copy the script to /etc/init.d
Change script mode to executable
Create this symbolic link using this command:

ln -s /etc/init.d/<Script Name> /etc/rc2.d/S80seatbelt"

Reboot

And

To reverse changes, remove the link and script...

So basically all we need to do is create a sym link to a script for it to run on start up?

Ehm...

Quote:

# swappiness can be set from 1 to 100
echo 100 > /proc/sys/vm/swappiness
echo 2 > /proc/sys/vm/overcommit_memory
echo 40 > /proc/sys/vm/overcommit_ratio
:confused:

No need for fugly sysvinit junk.

On Maemo 5 just put in /etc/event.d/tuning

Code:

description "N900 tuning"
author "VA"

console output

start on started rcS-late

script
      echo "30" > /proc/sys/vm/swappiness
      echo "0" > /proc/sys/vm/page-cluster
      echo "1" > /proc/sys/vm/laptop_mode
      echo "1" > /proc/sys/vm/oom_kill_allocating_task
      echo "0" > /proc/sys/vm/dirty_expire_centisecs
      echo "0" > /proc/sys/vm/dirty_writeback_centisecs
      echo "60" > /proc/sys/vm/dirty_background_ratio
      echo "95" > /proc/sys/vm/dirty_ratio
      echo "0" > /proc/sys/net/ipv4/tcp_timestamps
      echo "1" > /proc/sys/net/ipv4/tcp_no_metrics_save
end script

For explanation of each of these settings see URL in my previous post.

iareraccoon 2010-09-14 04:18

Re: How to set swappiness?
 
Quote:

Originally Posted by kaze.daniel (Post 815333)
what about that:

HTML Code:

# my rcS.e fix

start on started rcS-late

script
      echo 30 > /proc/sys/vm/swappiness
      echo 0 > /proc/sys/vm/page-cluster
      echo 1 > /proc/sys/vm/laptop_mode
      echo 1 > /proc/sys/vm/oom_kill_allocating_task
      echo 0 > /proc/sys/vm/dirty_expire_centisecs
      echo 0 > /proc/sys/vm/dirty_writeback_centisecs
      echo 60 > /proc/sys/vm/dirty_background_ratio
      echo 95 > /proc/sys/vm/dirty_ratio
      echo 0 > /proc/sys/net/ipv4/tcp_timestamps
      echo 1 > /proc/sys/net/ipv4/tcp_no_metrics_save
end script


I've switched to this script from the 15 swappiness I had previously and I noticed a significant speed boost! Thanks!

debernardis 2010-09-14 05:24

Re: How to set swappiness?
 
The tuning lines described by kaze.daniel and allnameswereout seem to work wonders on my n900. Music doesn't stutter at all like when I edited only swappiness and page-cluster. The GUI is superfluid like liquid helium. Life's good :) Thanks guys!

elbttrd 2010-09-14 21:54

Re: How to set swappiness?
 
Quote:

Originally Posted by slender (Post 802678)
I have also tested swappiness 30 and page-cluster 0. I'm pretty sure that responsivness has been better. I would be highly interested on possible side-effects on these changes.

are you still using these settings? any bad side-effects? thanks!

slender 2010-09-14 22:41

Re: How to set swappiness?
 
nope, but unfortunately i have had couple of shutdowns. These were done by purpose. So no long uptime (3 days or more) tests.

I have also applied other tweaks (made tuning file to /etc/event.d/ dir) and still no ill side effects. IMO the biggest difference came with just swappiness 30. I should try to make heavy banging with multimedia/browser + sleep + test how it wakes up when call comes.

still i would like to get more information about purpose of swapon and swapoff commands. Why, when, how?

debernardis 2010-09-15 09:19

Re: How to set swappiness?
 
I liked kaze.daniel and allnameswereout's hack so much that made a debian package for everybody to test it without the need for messing with root terminal.

See here.

allnameswereout 2010-09-15 11:33

Re: How to set swappiness?
 
Neat but please note nobody has tested any of the settings. Speaking for myself, I am able to experience an improvement (more snappier) with swappiness = 30. The settings have to be carefully tested and benchmarked in order to declare them both usable and safe. One could argue "if it doesn't hurt, it doesn't matter" but I don't recommend to the general public changing too many settings you don't know effect about. That said, if anyone can explain how to benchmark the effects I'd love to share the benchmarks from my machines.

zlatko 2010-09-15 11:51

Re: How to set swappiness?
 
I am running swappiness at 30 for about a week. Haven't noticed any improvements neither in speed or battery life. Haven't noticed any deterioration either though.
So the effects can not be felt in everyday use(for my phone and usage pattern).

PS. @allnameswereout - I am using stock kernel without any modifications.

jnack95 2010-09-15 12:12

Re: How to set swappiness?
 
Quote:

Originally Posted by zlatko (Post 816770)
I am running swappiness at 30 for about a week. Haven't noticed any improvements neither in speed or battery life. Haven't noticed any deterioration either though.
So the effects can not be felt in everyday use(for my phone and usage pattern).

Same here....

allnameswereout 2010-09-15 12:37

Re: How to set swappiness?
 
Here is a compilation of observations made by N900 users shared in this thread when using swappiness = 30.

Battery-life improved & responsiveness improved & no regressions
pycage
hackfanatic

Responsiveness improved
slender note: and page-cluster 0
JaseP
iareraccoon note: using knownokia.ca's settings compared to merely swapiness = 15

No improvements & no regressions
memoryguy
zlatko
jnack95

Note that nobody has specified which kernel they're using. I'm not sure whether this is relevant.

You're encouraged to verify my compilation, improve details on your (future) reports, and use above compilation as basis in next analysis of this tweak whether in this thread or on wiki.

debernardis 2010-09-15 12:53

Re: How to set swappiness?
 
I found no particular effect from swappiness changing alone, but the complete set of new values you quoted from kaze.daniel worked wonders on my nit. I haven't had a jerkiness in the user interface since I changed them.

allnameswereout 2010-09-15 13:29

Re: How to set swappiness?
 
Quote:

Originally Posted by debernardis (Post 816825)
I found no particular effect from swappiness changing alone, but the complete set of new values you quoted from kaze.daniel worked wonders on my nit. I haven't had a jerkiness in the user interface since I changed them.

Have you noticed a decrease of screen tearing?

debernardis 2010-09-15 13:47

Re: How to set swappiness?
 
Quote:

Originally Posted by allnameswereout (Post 816855)
Have you noticed a decrease of screen tearing?

With these new values? Yes, absolutely.

It's difficult to substantiate with benchmarks but the main effect is on the gui snappiness, swiftness, lack of tearing, in a word fluidity. I didn't imagine that those problems depended on memory allocation in ram vs flash memory.

MasterZap 2010-09-15 17:30

Re: How to set swappiness?
 
Quote:

Originally Posted by allnameswereout (Post 815391)
Ehm...

:confused:

No need for fugly sysvinit junk.

On Maemo 5 just put in /etc/event.d/tuning

Code:

description "N900 tuning"
author "VA"

console output

start on started rcS-late

script
      echo "30" > /proc/sys/vm/swappiness
      echo "0" > /proc/sys/vm/page-cluster
      echo "1" > /proc/sys/vm/laptop_mode
      echo "1" > /proc/sys/vm/oom_kill_allocating_task
      echo "0" > /proc/sys/vm/dirty_expire_centisecs
      echo "0" > /proc/sys/vm/dirty_writeback_centisecs
      echo "60" > /proc/sys/vm/dirty_background_ratio
      echo "95" > /proc/sys/vm/dirty_ratio
      echo "0" > /proc/sys/net/ipv4/tcp_timestamps
      echo "1" > /proc/sys/net/ipv4/tcp_no_metrics_save
end script

For explanation of each of these settings see URL in my previous post.

Holy crap.

On my device, this is a *significant* change. I used to get all these hangs and "hello, is anybody home?" and "Hey, I *CLICKED* here already" frustrated interaction with the device. With these changes, they all went away (so far - *knock on wood*).

I must say it was an enlightening read about the swap stuff in that linux thread. Clearly, in my opinon, swappiness=100 is *always* utter madness on *any* system.

The example mentioned in that thread is when un-tar'ing a multi-megabyte file, the filecache utilizing all "free" space as disk-cache, hence swapping out all apps, hence making the machine dead slow. Well, that's crazy, an un-tar basicaly serially reads/writes ONCE, and needs NO CACHEING AT ALL for efficiency!!!

Thank you deepest for the person inventing these settings. For now, I label them golden. The only thing that could un-golden these settings would be crash issues (none so far) or battery drainage (not enough data yet to judge, but it is very unlikely, if anything avoiding swapping should take LESS battery than excessive swapping would!)

Again, thanks

/Z

daperl 2010-09-15 18:05

Re: How to set swappiness?
 
Not to be too dramatic, but if you're not noticing an improvement from swappiness = 30, you might want to audit what you have running and/or installed. With almost 5 days of uptime, and with no other changes to usage patterns, my n900 consistently feels like a different device. And I log many hours a day with it.

Hopefully in the next few weeks I'll try some of the other optimizations, but this one seems like a no-brainer.

Also, about 2 months ago I made the following recommended changes in:

/home/user/.config/tracker/tracker.cfg

Code:

...
LowMemoryMode=true
...
Throttle=15
...

This too had a positive effect on performance, but don't forget to restart the tracker.

egoshin 2010-09-15 18:19

Re: How to set swappiness?
 
Just warning - N900 has not enough RAM for all applications which it runs, typical sizes are:

gstreamer - 100MB,
pulseaudio - 60-70MB
modest - 45-80MB
browser - 60-120MB or more
etc

And it also has a slow flash for swap.

So, with very non-aggressive swapiness it is easy to hit a situation then you have no free memory and incoming call may wait until kernel swaps out some apps. It may take up to 5-10 secs just to swap out... but kernel may need to swap in/load a phone application... ===> missed call.

I believe it is a reason why Nokia set swapiness to 100.

daperl 2010-09-15 18:34

Re: How to set swappiness?
 
Well, we're on the bleeding edge here, maybe it's time for a dynamic strategy that involves mlock type mechanisms.

travik 2010-09-15 18:39

Re: How to set swappiness?
 
I've been running with swappiness set at 30 for about a week now and have noticed a tremendous improvement in speed and battery life. I'm trying now with allnameswereout's further tuning to see how it improves.

egoshin's point makes sense; i hardly ever get calls so haven't noticed any such problem, but would be interested in hearing about others' experience.

elbttrd 2010-09-15 21:01

Re: How to set swappiness?
 
im currently using 30 swappiness and 0 page cluster.

heres an experiment i did: opened about 15 or more odd applications, including the media player, phone, conversations, pictures, microb etc. then i tried calling my phone from a landline a couple of times and it did what it was expected to do. no lags in receiving calls what so ever. there was tearing tho when i was scrolling the screen and i can feel that the system was working really hard..

ill try to observe a few more days if theres anything unusual happening but a couple of days ago when i only tried the 30 swappiness setting, the conversations application became laggy when its coming from sleep. ill check if this will happen again with my page cluster set to 0.

IINexusII 2010-09-15 21:08

Re: How to set swappiness?
 
Quote:

Originally Posted by elbttrd (Post 817277)
im currently using 30 swappiness and 0 page cluster.

heres an experiment i did: opened about 15 or more odd applications, including the media player, phone, conversations, pictures, microb etc. then i tried calling my phone from a landline a couple of times and it did what it was expected to do. no lags in receiving calls what so ever. there was tearing tho when i was scrolling the screen and i can feel that the system was working really hard..

ill try to observe a few more days if theres anything unusual happening but a couple of days ago when i only tried the 30 swappiness setting, the conversations application became laggy when its coming from sleep. ill check if this will happen again with my page cluster set to 0.


i did the exact same thing!!! lol

using the tuning script from knownokias page. it did seem to lag ALOT though wen i updated filebox thru application manager, and it took about 16seconds for the phone to receive the call :S will test again

edit: it seems so. apt-worker lags up the phone once i install something. its prob not getting enough swap for setting up the apps, only way is to kill it from xterm

mbo 2010-09-16 06:43

Re: How to set swappiness?
 
made the same experience with apt-worker some days ago. swappiness was set to 30 without further modified settings.

jorjino 2010-09-16 06:49

Re: How to set swappiness?
 
Shall I remove faster kinetic scrolling - (desktop_kinetic_2.2.138-1+0m5_armel.deb)
before installation of this add-on?
Sorry if my question looks noob...

Thanks.
Regards


All times are GMT. The time now is 09:58.

vBulletin® Version 3.8.8