IRIX Increase And Maintain Swap
The IRIX system allows programs occupying more space than the system limit to run, since each program is only partially loaded into memory at any given time. One of the effects of this policy is that the IRIX system has to preallocate swap space based on likely future usage, and sometimes this prediction is incorrect. When the swap space is actually needed, the IRIX system allocates the most convenient available space, not the specific space allocated. So the physical allocation is separate from the accounting allocation.
If your system preallocates all your swap space, but the space has not yet been used, it may appear that your system is running out of swap space when it is not. It is possible that your system has simply preallocated the rights to future swap space to existing processes, and no new processes can allocate space due to the strict swap space accounting in the IRIX system.
Strict swap space accounting is always in effect, but the ability to add both physical and virtual swap space through ordinary system files allows the administrator to add swap space or to effectively turn off strict swap space accounting, without having to either repartition the disk or reconfigure and reboot the system. Monitoring Paging and Swap Space
Use sar -p, sar -w, sar -q, swap -s, and swap -l to monitor paging and swap space use. If you find that you are running out of swap space, two solutions are available: you can add more memory, or you can add more swap space. Adding swap space does not improve the performance of large programs, but it permits them to run successfully.
Under sar(1), swapping of whole processes is reported with the -w flag. Performance problems associated with swapping come from the excess or slow I/O involved in paging.
Adding Virtual Swap Space
If processes are being denied stack growth or new processes due to a stated lack of swap space, and you believe that there is adequate physical space, add the following entry to your /etc/fstab file:
/usr/swap swap swap pri=4,vlength=204800 0 0
Then give the command:
mkfile -v 0b /usr/swap
The file (/usr/swap) will be zero-length, so you have added only virtual swap space and no real swap area. Your kernel should then allow more processes to execute. However, when an attempt is made to access more than the system limit, the IRIX system swaps the largest running program out of memory. Listing Swap Space with the swap -l Command
To determine how much swap space is already configured in your workstation, use the swap(1M) command:
If you are running applications that require the system to swap out programs frequently, you may also want to fine-tune the swap area of the disk used by the operating system. For more information on this process, see “Paging and Swapping” in Chapter 10. Checking Swap Activity with the swap -s Command
The swap -s command is a very useful tool for determining if you need to add swap space of some sort. The output of the swap -s command looks something like:
total: 0 allocated + 64248 reserved = 64248 blocks used, 17400 blocks available
The fields displayed are as follows (see the swap(1M) man page for more details): Allocated
The number of 512- bytes blocks allocated to private pages (for example, pages that contain data that is in use) Reserved
The number of 512- byte blocks currently allocated but not yet marked as private pages (the space has been claimed, but is not yet being used) Blocks used
The number of 512- byte blocks either allocated or reserved (the total number of allocated and reserved blocks) Blocks available
The number of 512- byte blocks available for future reservation and allocation (the total swap shown by the swap -l command less the number of blocks used)
Given the following sample swap -s output:
total: 0 allocated + 34200 reserved = 34200 blocks used, 47448 blocks available
You see that 0 swap blocks are in use, 34200 have been reserved but not used, which leaves 47448 blocks available for reservation. So, at this point, the system is not swapping, but the programs running on the system have requested approximately 17 MB of swap space, just in case they need to grow. Note: 10000 blocks is equal to approximately 5 MB.
Many applications reserve what is known as virtual swap space. That is, they request more memory than they will ever need. The actual size of the application is the amount of physical system resources that the application is using. The virtual size of the application is the amount of system resources it is using plus the amount of extra resources requested but not in use. This is the case in the above example; space has been reserved, but is not in use. Negative Swap Space
Look at another example of swap -s output:
total: 41920 allocated + 58736 reserved = 100656 blocks used, -19400 blocks available
It may seem worrisome that the swap space available is a negative number. What this means, though, is that some of the allocated/in use pages are located in main memory (RAM). The swap -s output does not take main memory into account. The data that is shown in the negative is actually data that is contained in system memory.
It appears that approximately 20 MB of physical swap space is in use, as shown by the amount of allocated space. Therefore, the system is not out of physical swap space. If there was no more physical swap space, the number of allocated blocks would be very close to the number of blocks reported by the swap -l command. Approximately 30 additional megabytes of swap space has been requested, shown by the requested field, giving a total of 50 MB requested and/or in use. This appears to leave an overrun of 10 MB.
Another way to think of that negative number is that it is the amount of physical swap space minus the number of blocks used (allocated + requested). So, as long as that negative number has an absolute value less than approximately the amount of physical memory (obtained from the hinv command) that you have, you have not overrun your system.
The following example shows swap -s output of a system that has most likely come to its swapping limit:
total: 76920 allocated + 23736 reserved = 100656 blocks used, -19400 blocks available
Notice that the total numbers are the same, but the number of allocated blocks is much higher. If the swap -l in this example were to report 81000 blocks of physical swap space on the system, it is easy to see that there are only 4000 physical blocks that are not in use. Turning On Virtual Swapping
If swap -s reports a negative number, increase virtual swap when your system is not near its physical limits. This allows your system to allocate space to those applications that grab more space than they actually need. To do this, you can turn on virtual swapping by entering the following commands:
su chkconfig vswap on /etc/init.d/swap start
This allocates more swap space, or space that can be reserved but not allocated. See the /etc/init.d/swap file and the swap(1M) man page for more information.
If virtual swapping is already on (use chkconfig to find out) or if the number of allocated blocks is approaching the number of blocks reported by the swap -l command, the only way to remedy the situation is to add more physical memory or swap space. See the swap(1M) man page for more information regarding adding swap space (whether through another disk partition or a swap file). Increasing Swap Space on a One-Disk System
Suppose you do not have the luxury of a multidisk system. This section explains how to increase the size of the swap partition on a single disk. You can increase your available swap space by repartitioning your disk, as described earlier in this chapter, or you can add space with the swap command as discussed here.
The swap command allows you to designate a portion of any disk partition as additional swap space. You can add swap space at any time and delete the new swap space when you no longer need it. There are several options available with this command, and the command is described completely in the swap(1M) man page, but the most convenient method to use is to specify a normal system file as additional swap space.
To specify a file as additional swap space, you first create an empty file of appropriate size with the mkfile(1M) command. For example, if you want to add 10 MB of swap space to your system, and you want that space to be taken from the /usr filesystem, use the following mkfile command:
mkfile -v 10m /var/tmp/moreswap
In this command, the -v option directs mkfile to be verbose in its output to you, which means that you see the following message as a confirmation that the file has been created:
/var/tmp/moreswap 10485760 bytes
If you do not specify the -v option, mkfile does its work silently. The second field in the mkfile command is the size of the file. In this case, 10m specifies a file that is 10 MB in size. You can use b, k, or m as a suffix to the size argument to indicate that the size number is in bytes, kilobytes, or megabytes, respectively. For example, the following commands all produce files of 10 MB:
mkfile -v 10485760b /var/tmp/moreswap mkfile -v 10240k /var/tmp/moreswap mkfile -v 10m /var/tmp/moreswap
Once your file is created, you can use the swap command to add it as swap space on the system. When you make your file, be certain that the file resides in the filesystem from which you want to take the space. The /var/tmp directory is a good place to use as it typically has more available space than the root filesystem (/). Note, however, that you can also use filesystems mounted remotely via NFS. Complete information on using remote mounted filesystems for swap space is available in the swap(1M) man page.
To begin using your new file as swap space, give the following command:
/sbin/swap -a /var/tmp/moreswap
The -a option indicates that the named file is to be added as swap space immediately. To check your new swap space, use the command:
This command lists all current swap spaces and their status.
To make your new swap file permanent (automatically added at boot time), add the following line to your /etc/fstab file:
/var/tmp/moreswap swap swap pri=3 0 0
Note that if you create a swap file in the /tmp directory of your root filesystem, the file is removed when the system is booted. The /var/tmp directory of the /var filesystem is not cleaned at boot time, and is therefore a better choice for the location of swap files. If you want to create your swap files in the root filesystem, first create a /swap directory, and then create your swap files within that directory. Increasing Swap Space on a Multidisk System
Adding more swap space to a multidisk system can be done just as if you were adding space on a single-disk system. You can always use the mkfile and swap commands to add a swap file to your system. However, if you want to add dedicated swap space in a new disk partition, follow the steps in Procedure 6-2:
Procedure 6-2. Adding Dedicated Swap Space
1. To double the default amount of swap space, you can use another disk drive as follows: Partition/slice 0 Temporary space (mount as /tmp) 1 Swap space 6 usr2
Note that the operating system continually writes onto the partition that is used as swap space, completely destroying any data that might exist there. Be sure that the swap partition does not overlap any user filesystem partitions. Verify the size of the swap partition in blocks.
Once you choose a partition, create the /etc/init.d/addswap file to add this partition permanently as a swap partition. Place a line of the following form in the file:
2. swap -a /dev/dsk/devicename 0 length The argument devicename is the device name where the swap partition is located (such as ips0d1s1), and length is in blocks. 3. Use the chmod command to enable execute permission on the file. The command is: chmod +x addswap 4. Create a symbolic link to the new file with the command: ln -s /etc/init.d/addswap /etc/rc2.d/S59addswap
The /etc/rc2.d directory controls the system activities that take place when the system boots into multiuser mode (run level 2). The S at the beginning of the symbolic link file that you created indicates that the commands in the file should be started when the system initiates this run level. Symbolic link files that begin with the letter K indicate that the commands described in the file should be killed. The number following the S or K at the beginning of the link filename indicates the sequence in which the commands are executed.
You can also modify the file /etc/fstab to document (in the form of a comment) that the chosen partition is being used as a swap partition.
Share your opinion