the linux swap space

Upload: dhanasekaran-anbalagan

Post on 05-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 The Linux Swap Space

    1/2

    The Linux Swap Space

    The Linux swap space is an efficient way to utilise all available memory. It is an area of the hard

    drive deliberately set aside for the use of the system to be used in conjunction with Random Access

    Memory (RAM).

    How Linux Uses Swap Space

    Swap space is there because in days of yore RAM was a very expensive commodity, but software,

    including the kernel always seem to need more memory than was installed on a system. Thus, a bitof the hard was allocated for use as a sort of very slow RAM.

    The amount of the hard disk was, traditionally, twice the amount of installed RAM, so if the system

    had 8mb of RAM then 16mb of the hard drive was allocated for swap space.

    It is still good practise to allocate a certain proportion of the hard drive to swap space, though the

    amount allocated does not have to be twice the amount of installed RAM. This does not hold true

    for systems with less than 1 gigabyte of RAM, in these cases it is still a good idea to allocate double

    the amount of RAM.

    However, with RAM, as with many things computer hardware related, how much you needs will

    depend on what the system is intended for. A mail server in a small office won't really need muchmore than 512mb of RAM, a print server might need up 1gb, a gamer will need at least 3gb or 4gb

    of RAM, but for just surfing the web, writing the occasional letter or homework assignment,

    downloading email and watching the occasional youtube video, you could get away with 256mb of

    RAM, 512mb might be better though.

    If you are intending to use your system fro development, the more RAM the better. If you are a

    casual user, why whittle? Linux, like all other operating systems, has a limit to how much RAM it

    can access or use. For 32-bit Linux installations, this is about 4 gigabytes. For 64 bit Linux

    installations, this is about 16 exabytes. One exabyte is equal to, about, one billion gigabytes...

    To see how this works just do this simple calculation:

    for 32 bit:

    2^32 that's 2 to the power of 32

    http://www.ovenproof-linux.com/2010/09/linux-swap-space-is-efficient-way-to.htmlhttp://www.ovenproof-linux.com/2010/09/linux-swap-space-is-efficient-way-to.html
  • 8/2/2019 The Linux Swap Space

    2/2

    for 64 bit:

    2^64 that's 2 to the power of 64.

    To see how much swap you have you can do one of two commands:

    $ swapon -s

    Filename Type Size Used Priority/dev/sda5 partition 730916 126596 -1

    or

    $ free -m

    total used free shared buffers cached

    Mem: 1435 995 439 0 17 189

    -/+ buffers/cache: 788 646

    Swap: 713 123 590

    This shows in megabytes

    $ freetotal used free shared buffers cached

    Mem: 1469884 857068 612816 0 18992 339320

    -/+ buffers/cache: 498756 971128

    Swap: 730916 115324 615592This shows in kilobytes

    You can also do:$ top

    Tasks: 141 total,1 running, 140 sleeping, 0 stopped, 0 zombie

    Cpu(s): 12.3%us, 13.6%sy, 5.4%ni, 67.3%id, 0.8%wa, 0.3%hi, 0.2%si,

    0.0%stMem: 1469884k total, 1022800k used, 447084k free, 18556k

    buffers

    Swap: 730916k total, 125992k used, 604924k free, 195892k

    cached

    $ cat /proc/meminfo | grep Swap

    SwapCached: 13696 kB

    SwapTotal: 730916 kB

    SwapFree: 615704 kB

    As you can see you get lots of ways to see how much swap space you have and how much of it

    being used.

    If you are installing Linux, it is probably a good idea to put the swap space on a separate partition to

    the /root file system. This keeps the swap partition safer from data overflows and all sorts of other

    nasties; safer than having the swap partition mounted in the same partition as the /root file system.

    We will look at how to increase, or even decrease, the amount of swap space in a later posting.