close
This essay has been submitted by a student. This is not an example of the work written by professional essay writers.

Swap Space

downloadDownload printPrint

Pssst… we can write an original essay just for you.

Any subject. Any type of essay.

We’ll even meet a 3-hour deadline.

Get your price

121 writers online

blank-ico
Download PDF

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?

  • SWAP partition work as an overflow to your RAM
  • While your memory is filled up totally
  • Grow the amount of usable memory without in truth getting more RAM
  • A SWAP partition can also support to move some items from your memory
  • Can move infrequently needed items away from your high-speed memory

Disadvantage of SWAP

Takes up space on your hard drive as SWAP partition do not change the size dynamically. Does to necessary to improve performance.

All about Linux SWAP space

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:

Filename Type

Size Used Priority

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:

  • Simple but inefficient
  • Navigating the directory structure and the disk location data structure need time and potentially additional disk accesses.
  • External fragmentation can greatly increase swapping times by forcing various search during reading or writing of a process image

Improvement

  • Caching block location information in main memory
  • Contiguous allotment for the swap file, but the cost of traversing FS data structure still stay
  • In different partition: raw partition
  • Create a swap space during disk partitioning
  • A different swap space storage manager is used to allocate as de-allocate blocks.
  • Use algorithms optimize for speed, instead of storage planning
  • Internal fragment maybe increase

Linux supports both approaches

The example of SWAP space Management:

  • Solaris 1
  • 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

  • Solaris 2
  • Allocates SWAP space only when a page is displaced of physical memory

  • Not when the virtual memory page is first created.
  • Data Structure for Swapping on Linux Systems

    Swap file

    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:

    1. For a desktop system, use a swap space of double system memory, as it will let you run a big number of applications (many of which may well be futile and easily swapped), making more RAM ready to use for the active applications.
    2. For a server, have a little amount of swap available (say half of the physical memory) so that you have some flexibleness for swapping when needed, but monitor the amount of swap space used and upgrade your RAM if required.
    3. For older desktop machines (with say only 128MB), use as much swap space as you can spare part, even up to 1GB.

    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.

infoRemember: This is just a sample from a fellow student.

Your time is important. Let us write you an essay from scratch

100% plagiarism-free

Sources and citations are provided

Find Free Essays

We provide you with original essay samples, perfect formatting and styling

Cite this Essay

To export a reference to this article please select a referencing style below:

Swap Space. (2018, October 23). GradesFixer. Retrieved July 25, 2021, from https://gradesfixer.com/free-essay-examples/swap-space/
“Swap Space.” GradesFixer, 23 Oct. 2018, gradesfixer.com/free-essay-examples/swap-space/
Swap Space. [online]. Available at: <https://gradesfixer.com/free-essay-examples/swap-space/> [Accessed 25 Jul. 2021].
Swap Space [Internet]. GradesFixer. 2018 Oct 23 [cited 2021 Jul 25]. Available from: https://gradesfixer.com/free-essay-examples/swap-space/
copy to clipboard
close

Sorry, copying is not allowed on our website. If you’d like this or any other sample, we’ll happily email it to you.

    By clicking “Send”, you agree to our Terms of service and Privacy statement. We will occasionally send you account related emails.

    close

    Attention! This essay is not unique. You can get a 100% Plagiarism-FREE one in 30 sec

    Receive a 100% plagiarism-free essay on your email just for $4.99
    get unique paper
    *Public papers are open and may contain not unique content
    download public sample
    close

    Sorry, we could not paraphrase this essay. Our professional writers can rewrite it and get you a unique paper.

    close

    Thanks!

    Your essay sample has been sent.

    Want us to write one just for you? We can custom edit this essay into an original, 100% plagiarism free essay.

    thanks-icon Order now
    boy

    Hi there!

    Are you interested in getting a customized paper?

    Check it out!
    Having trouble finding the perfect essay? We’ve got you covered. Hire a writer
    exit-popup-close

    Haven't found the right essay?

    Get an expert to write you the one you need!

    exit-popup-print

    Professional writers and researchers

    exit-popup-quotes

    Sources and citation are provided

    exit-popup-clock

    3 hour delivery

    exit-popup-persone