Categories
Device

How to create a swap file on linux

Old News 😉

Paging – Wikipedia, the free encyclopedia

In some older virtual memory operating systems, space in swap backing store is reserved when programs allocate memory for runtime data. OS vendors typically issue guidelines about how much swap space should be allocated. 1.5 times the installed RAM is a typical number. With a large amount of RAM, the disk space needed for the backing store can be very large. Newer versions of these operating systems attempt to solve this problem: for example, some HP-UX kernels offer a tunable swapmem_on that controls whether RAM can be used for memory reservations. In systems with sufficient RAM, this significantly reduces the needed space allocation for the backing store.

Confusion over size of swap partition – MEPISlovers Forums

G’day all.
Will repartition HDD when I replace 6.5 with 7.0 to create a separate home partition. The handbook for 7.0 recommends the size of the swap partition to be double that of your RAM, but no larger than 1Gb.
I have a recent laptop with 2Gb of RAM. My swap partition is currently set to 4Gb which was based on my reading at that time. Subsequently found the most common recommendations of swap size to be half of RAM, equal to RAM and twice size of RAM. One recommendation even stated that the swap partition is probably not necessary in these days of large RAM.

Would someone be kind enough to point me in the direction of an appropriate size for a swap partition? Many thanks in advance.
Cheers,
Miles

Linux Partition HOWTO Partitioning requirements/ How large should my swap space be?

Conventional wisdom creates swap space equal to the amount of RAM .

But keep in mind that this is just a rule of thumb. It is easily possible to create scenarios where programs have extremely large or extremely small working sets. For example, a simulation program with a large data set that is accessed in a very random fashion would have almost no noticeable locality of reference in its data segment, so its working set would be quite large.

On the other hand, a graphics program with many simultaneously opened JPEGs, all but one iconified, would have a very large data segment. But image transformations are all done on one single image, most of the memory occupied by the program is not accessed. The same is true for an editor with many editor windows where only one window is being modified at a time. These programs have – if they are designed properly – a very high locality of reference and large parts of them can be kept swapped out without too severe performance impact. A user who never never quits programs once launched would want a lot of swap space for the same reason.

Servers typically are configured with more swap space than their desktop counterparts. Even though a given amount of swap is sufficient for its operations, the server might come under transient heavy loads which cause it to page out at a high rate. Some administrators prefer this to the server crashing altogether. In these cases, swap might be several times the size of ram.

Currently, the maximum size of a swap partition is architecture-dependent. For i386, m68k, ARM and PowerPC, it is “officially” 2Gb. It is 128Gb on alpha, 1Gb on sparc, and 3Tb on sparc64. An opteron on the 2.6 kernel can write to a 16 Tb swap partition. For linux kernels 2.1 and earlier, the limit is 128Mb. The partition may be larger than 128 MB , but excess space is never used. If you want more than 128 MB of swap for a 2.1 and earlier kernel, you have to create multiple swap partitions (8 max). After 2.4, 32 swap areas are “officially” possible. See setting up swap for details.

The short answer is anywhere is fine. However, if you are interested in extracting as much speed as possible, there are two basic strategies (other than buying more RAM ):

  1. Split the swap space across multiple drives, or at least on the drive you write to least.
  2. Put each swap partition on the outer tracks.

Here are the considerations:

  • Choice of drive
    If you have a disk with many heads and one with less heads and both are identical in other parameters, the disk with many heads will be faster. Reading data from different heads is fast, since it is purely electronic. Reading data from different tracks is slow, since it involves physically moving the head.

    It follows then that writing swap on a separate drive will be faster than moving the head back and forth on a single drive.

    Placement:
    Older disks have the same number of sectors on all tracks. With these disks it will be fastest to put your swap in the middle of the disks, assuming that your disk head will move from a random track towards the swap area.

    Newer disks use ZBR (zone bit recording). They have more sectors on the outer tracks. With a constant number of rpms, this yields a far greater performance on the outer tracks than on the inner ones. Put your swap on the fast tracks. (In general, low-numbered cylinders are associated low partition numbers. However, see Kristian’s more recent comments on this issue. -Tony)

  • Usage:
    Of course your disk head will not move randomly. If you have swap space in the middle of a disk between a constantly busy home partition and an almost unused archive partition, you would be better of if your swap were near the home partition for even shorter head movements. You would be even better off, if you had your swap on another otherwise unused disk, though.
  • Striping:
    Speed can be increased by writing to multiple swap areas simultaneously. Swap spaces with the same priority will be written to like a RAID. See setting up swap for details.

Summary: Put your swap on a fast disk with many heads that is not busy doing other things. If you have multiple disks: Split swap and scatter it over all your disks or even different controllers.

max swap size: With kernel 2.4, the limit is 64 swap spaces at a maximum of 64Gb each, although this is not reflected in the man page for mkswap . With the 64 bit opteron on the 2.6 kernel, 128 swap areas are permitted, each a whopping 16 Tb! (thanks to Peter Chubb for the calculation)

Written by Allen White on June 25, 2014 . Posted in Linux

Again this is a realy quick and simple guide that I thought id type up as I taught myself Linux. Here we will create a folder and then delete it. We will also learn how to delete a folder and all its contents in Linux also.

Create a Directory in Linux

To do this we can use the mkdir command. We create a folder called test here.

We use the ls command to see that we have created the test directory.

How to create a swap file on linux
Now if we wanted to set permissions on the test directory we could use this guide.

Remove a Directory in Linux

If we wanted to delete this directory we can use the rmdir command, bare in mind this command can only be used with empty folders. As seen below we list the directory with the ls command, we delete it then to make sure its gone run ls again.

How to create a swap file on linux

Delete a Folder, Sub Folders and all Contents in Linux

Lets say though we had a folder than had multiple files and sub folders in it that we wanted to get delete. Here I have created a test folder with test1,test2 and test3 folders and also a test file as seen here.

To delete these folders we must drop back to the root folder in which the top level test folder is, do this with the cd .. (change directory) command.

We then use the rm -ir command to delete the top level folder and all its files and sub folders. You will be promoted to descend and deleted the files and folders, select yes to do so.

How to create a swap file on linux

If you also want to learn Linux then consider a VPS, check out this link 25% OFF VPS Hosting .