krish – 起死回生 [Wake up from death & return to life.]

November 24, 2011

Linux swapping even if RAM is available..

Filed under: GNU/Linux — krish @ 3:27 pm
Tags: , , , , ,

I noticed this after a very long time, on my laptop today…thought I’d just blog up what to do about it :)

krish@shenron:~$ free
total used free shared buffers cached
Mem: 5717368 1556752 4160616 0 32116 295768
-/+ buffers/cache: 1228868 4488500
Swap: 4296696 156708 4139988

So, that’s pretty much more than 2/3 rds of RAM available, but the swap is being used already.

This setting is controlled by ‘vm.swappiness’
krish@shenron:~$ sysctl -A | grep "vm.swappiness"
vm.swappiness = 60

or you could find the value in
krish@shenron:~$ cat /proc/sys/vm/swappiness
60

The default value is 60.
A value of 0 means “never use swap till RAM is available“ .
A value of 100 would mean “swap as soon as possible”.

Using 0 is bit hard on the machine :D , let’s use a value of 10
krish@shenron:~$ sudo sysctl -w vm.swappiness=10
[sudo] password for krish:
vm.swappiness = 10
.
krish@shenron:~$ sudo sysctl -A | grep "vm.swappiness"
vm.swappiness = 10

This value is not persistent on reboot unless you write it to /etc/sysctl.conf ;)

November 12, 2009

Swapping two variables without using third variable – old trick

Filed under: Programming — krish @ 6:21 pm
Tags: , ,

Pretty old trick, used today in my php code :


// Swap the months if from-month selected is later than to-month
//if($frommon > $tomon){
// $tempmon = $frommon;
// $frommon = $tomon;
// $tomon = $tempmon;
//}
// Smarter way using X-OR
if($frommon > $tomon){
$frommon = $frommon ^ $tomon ^ ( $tomon = $frommon );
}

September 17, 2009

Increase swap space on Linux

Filed under: GNU/Linux — krish @ 8:32 pm
Tags:

a) Login as the root user

b) Type following command to create 1G swap file (1024 * 1GB =
1048576 block size):
# dd if=/dev/zero of=/swap1 bs=1024 count=1048576

c) Set up the Linux swap:
# mkswap /swap1

d) Activate /swap1 swap space immediately:
# swapon -a /swap1

e) To check the current swaps in use type:
# swapon -s

f) To ensure /swap1 being used after Linux system reboot, add entry to
/etc/fstab file. Open this file using text editor such as vi:
# vi /etc/fstab

Append following line:
/swap1 swap swap defaults 0 0

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: