Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Expand
titleContents

Table of Contents
indent15px
stylenone

To change maximum processes per user

  1. open /etc/security/limits.conf as root user
  2. Write the following lines at the bottom of the page.

    Code Block
    <Username>	hard	nproc		unlimited
    <Username>	soft	nproc		unlimited
    Note

    Replace <Username> with original user name.

  3. Restart the machine.

To change maximum file handles per user

  1. open /etc/security/limits.conf as root user
  2. Write the following lines at the bottom of the page.

    Code Block
    <Username>	hard	nofile		unlimited
    <Username>	soft	nofile		unlimited 
    Note

    Replace <Username> with original user name.

  3. Restart the machine.

Checking the Swap Size

# free -k

The command free is used to know how much swap space is currently used by the system. It displays the memory details in KB.

Following is a sample output resulting from free -k command:

Code Block
titleOutput Sample
		      total	   used      free	shared	buffers	  cached
Mem:		3082356	2043700   1038656	  	 0	  50976	 1646268
-/+ buffers/cache: 	 346456   2735900
Swap:		4192956       0	  4192956 

# swapon -s

Swapon command with option -s displays the current swap size in KB and the file name.

Following is a sample output resulting from swapon -s command:

Code Block
titleOutput Sample
	 Filename			    Type           Size   		  Used 		   Priority
    /dev/sda2    	  partition    	   4192956 				0    		    -1 

# cat /proc/swaps

This command is same as the swapon -s command, which gives the same output:

Code Block
titleOutput Sample
	 Filename			    Type           Size   		  Used 		   Priority
    /dev/sda2    	  partition    	   4192956 				0    		    -1 

Increasing the swap size

Additional Swap Space can be created using a:

  1. Hard Drive
  2. File

Both the methods are explained in the below sections.

Using a Hard Drive Partition

If you have an additional hard disk (or space available in an existing disk), create a partition using fdisk command.

Assume that the partition created is: /dev/sdc1 and perform the following actions:

  1. Setup this newly created partition as swap area using the mkswap command:

    # mkswap /dev/sdc1
     

  2. Enable the swap partition for usage using swapon command:

    # swapon /dev/sdc1
     

  3. Add the following line to the /etc/fstab file to make the swap space partition available even after the reboot:
    # cat /etc/fstab

    Code Block
    /dev/sdc1			swap			swap			defaults			0 0
  4. Verify whether the newly created swap area is available for your requirement using swapon and free commands:

    # swapon -s 

    Code Block
    titleSample Output for # swapon -s command
    Filename		     Type 	 	   Size 		 Used	      Priority
    /dev/sda2		partition 		4192956 			0 				-1
    /dev/sdc1		partition 		1048568 			0 				-2
    Note

    In the output of swapon -s command, the Type column will say "partition" if the swap space is created from a disk partition.

    # free -k

    Code Block
    titleSample Output for # free -k command
    		      total	     used    free	shared	buffers   cached
    Mem:		3082356	  3022364   59992	  	 0	  55056	 2645472
    -/+ buffers/cache: 	 323836   2758520
    Swap:		5241524       0	  5241524 

Using a File

If you do not have any additional disks, create a file somewhere on your file system and use that file for swap space.

  1. Create a swap file with the name "myswapfile" under /root  directory with a size of 1024MB (1GB) using the following dd command:
    # dd if=/dev/zero of=/root/myswapfile bs=1M count=1024

    Code Block
    1024+0 records in
    1024+0 records out
  2. Check the user permissions set in the file using the following command:
    # ls -l /root/myswapfile

    Code Block
    -rw-r--r--		 1 root			root			1073741824	 Aug 14 23:47 /root/myswapfile
  3. Create Root Permission, that is, change the permission of the swap file so that only root can access it.
    # chmod 600 /root/myswapfile
     
  4. Make this file as a swap file using mkswap command:
    # mkswap /root/myswapfile

    Code Block
    titlemkswap command output
    Setting up swapspace version 1, size = 1073737 kB
  5. Enable the newly created swapfile.
    # swapon /root/myswapfile
     
  6. To make this swap file available as a swap area even after the reboot, add the following line to the /etc/fstab file using command:
    # cat /etc/fstab

    Code Block
    /dev/sdc1			swap			swap			defaults			0 0
  7. Verify whether the newly created swap area is available for your requirement using swapon and free commands:

    # swapon -s 

    Code Block
    titleSample Output for # swapon -s command
    Filename		     Type 	 	   Size 		 Used	      Priority
    /dev/sda2		partition 		4192956 			0 				-1
    /dev/sdc1		partition 		1048568 			0 				-2
    Note

    In the output of swapon -s command, the Type column will say "file" if the swap space is created from a swap file. 

    # free -k

    Code Block
    titleSample Output for # free -k command
    		      total	     used    free	shared	buffers   cached
    Mem:		3082356	  3022364   59992	  	 0	  55056	 2645472
    -/+ buffers/cache: 	 323836   2758520
    Swap:		5241524       0	  5241524 
Tip

If you don't want to reboot to verify whether the system takes all the swap space mentioned in the /etc/fstab, you can do the following, which will disable and enable all the swap partition mentioned in the /etc/fsta:

swapoff -a

swapon -a

Adaptavist ThemeBuilder EngineAtlassian Confluence