By clicking “Check Writers’ Offers”, you agree to our terms of service and privacy policy. We’ll occasionally send you promo and account related email
No need to pay just yet!
About this sample
About this sample
Words: 1724 |
Pages: 4|
9 min read
Published: Oct 23, 2018
Words: 1724|Pages: 4|9 min read
Published: Oct 23, 2018
Linux is a free, open-source operating system it has been under active development since 1991, so most Linux installations suggest that you include a SWAP partition. This may appear odd to Windows users, who are used to having their entire operating system on a single partition. the SWAP partition acts as an overflow to your (RAM) memory. If your memory is full completely, any additional applications will be run off of the SWAP partition instate of memory. Swapping is needful for two important reasons. First, when the system needs more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately. Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache. Why we use SWAP?
Takes up space on your hard drive as SWAP partition do not change the size dynamically. Does to necessary to improve performance.
Linux has two forms of swap space: the swap partition and the swap file. The swap partition is an independent part of the hard disk used only for swapping; no other files can occupy there. The swap file is a special file in the filesystem that occupies between your system and data files. To see what swap space you have, use the command swapon -s. The output will look something like this:
Each line lists a different swap space being used by the system. Now, the 'Type' field indicates that this swap space is a partition rather than a file, and from 'Filename' we see that it is on the disk sda5. The 'Size' is listed in kilobytes, and the 'Used' field tells you how many kilobytes of swap space has been used but in this example there is none. 'Priority' tells Linux which swap space to use first. One great thing about the Linux swapping subsystem is that if you mount two or more swap spaces (preferably on two different devices) with the same priority, Linux will interleave its swapping activity between them, which can significantly increase swapping performance. To add a more swap partition to your system, first, you need to provide it. Step one is to ensure that the partition is marked as a swap partition and step two is to make the swap filesystem. To check that the partition is marked for swap, run as root:
Fdisk -l /dev/ hdb replace /dev/hdb with the device of the hard disk on your system with the swap partition on it. You should see output that looks like this: Device Boot Start End Blocks Id System/dev/hdb1 2328 2434 859446 82 Linux swap / Solaris
If the partition isn't noticeable as swap you will need to change it by running fdisk and using the 't' menu option. pay attention when working with partitions -- you don't want to delete important partitions by fault or change the id of your system partition to swap by the fault. All data on a swap partition will be destroyed, so double-check every change you make. Also note that Solaris uses the same ID as Linux swap space for its partitions, so pay attention not to kill your Solaris partitions by mistake.
At that moment a partition is marked as swap, you need to prepare it using the mkswap (make swap) command as root: mkswap /dev/hdb1 If you see no errors, your swap space is ready to use. To start it instantly, type: swapon /dev/hdb1
You can prove that it is being used by running swapon -s. To mount the swap space automatically at boot time, you must add an entry to the /etc/fstab file, which hold a list of filesystems and swap spaces that need to be mounted at boot up. The format of each line is: Since swap space is a particular type of filesystem, many of these parameters aren't suitable. For swap space, add: /dev/hdb1 none swap sw 0 0, where /dev/hdb1 is the swap partition. It doesn't have a specific mount point, from now none. It is of type swap with options of sw, and the last two parameters aren't used so they are entered as 0.
To check that your swap space is being automatically mounted without having to boot a computer again, you can run the swapoff -a command (that turns off all swap spaces) and then swapon -a (that mounts all swap spaces listed in the /etc/fstab file) and then check it with swapon -s.
Swap space location. Swap space can be carved out of the normal file system, or in a different disk partition.
A big file inside the file system:
Linux supports both approaches The example of SWAP space Management:
Text segment pages are brought in from the file system and are thrown away if selected for paged out.
More efficient to reread from FS than write it to the SWAP space.
Swap space: only used as a backing store for pages of unnamed memory
Allocates SWAP space only when a page is displaced of physical memory
As well as the swap partition, Linux also supports a swap file that you can create, prepare, and mount in a fashion similar to that of a swap partition. The advantage of swap files is that you don't need to find an empty partition or repartition a disk to add extra swap space.
To create a swap file, use the dd command to create an empty file. To create a 1GB file, type: dd if=/dev/zero of=/swapfile bs=1024 count=1048576
/swapfile is the name of the swap file, and the count of 1048576 is the size in kilobytes.
Prepare the swap file using mkswap just as you would a partition, but for this time use the name of the swap file: mkswap /swapfile
And closely, mount it using the swapon command: swapon /swapfile. The /etc/fstab entry for a swap file would look like this: /swapfile none swap sw 0 0 How huge should my swap space be?
It could be to run a Linux system without a swap space, and the system will run well if you have a big amount of memory -- but if you run out of physical memory then the system will break down, as it has nothing else it can do, so it is advisable to have a swap space, particularly since disk space is comparatively cheap. The necessary question is how much? Older versions of Unix-type operating systems (such as Sun OS and Ultrix) require a swap space of two to three times that of physical memory. Recent execution (such as Linux) don't require that much, but they can use it if you arrange it. A rule of thumb is as follows:
The Linux 2.6 kernel append a new kernel parameter called swappiness to let administrators tweak the way Linux swaps. It is a number from 0 to 100. Basically, greater values lead to more pages being swapped and lessen values lead to more applications being kept in memory, even if they are idle. Kernel upholder Andrew Morton has said that he runs his desktop machines with a swappiness of 100, stating that "My point is that decreasing the tendency of the kernel to swap stuff out is wrong. You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful."
One downside to Morton's idea is that if memory is swapped out too quickly then application response time drops, because when the application's window is clicked the system has to swap the application back into memory, which will make it feel slow. The nonpayment value for swappiness is 60. You can alter it temporarily (until you next reboot) by typing as root: echo 50 > /proc/sys/vm/swappiness If you want to change it permanently then you need to change the vm.swappiness parameter in the /etc/sysctl.conf file.
Managing swap space is a necessary prospect of system administration. With good planning and suitable use, swapping can provide many benefits. Don't be afraid to experiment, and always monitor your system to guarantee you are getting the results you need.
Browse our vast selection of original essay samples, each expertly formatted and styled