Chapter 6. Configuring Disk and Swap Space

This chapter provides you with background information on disk usage and the tools and options available to you to manage it. For a variety of reasons, users often accumulate files without realizing how much disk space they are using. This is not so much a problem for workstation users, but can be a big problem for servers, where multiple users must share system resources. The IRIX system provides a number of utilities to help you manage disk usage.

You also may need to allocate disk space for the system to use as swap space. Swap space is disk space allocated to be used as medium-term memory for the operating system kernel. Lack of swap space limits the number and size of applications that may run at once on your system, and can interfere with system performance.

For specifics on setting and maintaining disk quotas, see IRIX Admin: Disks and Filesystems .

Disk Usage Commands

The commands in this section help you determine the current status of disk usage on your system.

du (Disk Usage) Command

The du  command shows specific disk usage by file or directory anywhere on the system. The size of the files and directories can be shown in 512-byte blocks, or in 1K blocks if you use the -k flag. For more complete information, consult the du(1) man page.

df (Free Disk Blocks) Command

The df command shows the free space remaining on each filesystem on your workstation. Free space is shown for all filesystems, whether they are local or NFS-mounted. The amount of free space is displayed in 512-byte blocks, or in 1 KB blocks if you use the -k option. For more complete information, consult the df(1) man page.

quot (Disk Usage by User) Command

The quot command displays the number of kilobytes of disk usage for each user in a specified filesystem. You can use the output of this command to mail your users, notifying them of their disk usage. For complete information, see the quot(1M) man page.

diskusg (Disk Accounting) Command

Part of the system accounting package is the diskusg command. Like quot, this utility reports the disk usage of each user on your system. The difference is that diskusg is typically used as part of the system accounting package with dodisk rather than as a standalone command. For complete information on using diskusg, see the diskusg(1) man page.

Managing Disk Space

This section describes several commands you can use to help you in managing disk space. In particular, various techniques are discussed which allow you to maximize available disk space.

File Compression and Archiving

One way to minimize disk usage is to encourage your users to archive or compress their files. Compression works best for files that are rarely used but that should not be discarded. Users can achieve some disk savings by using the compress utility. Compressing a file allows you to leave it on the system, but can reduce the size of the file by as much as 50%. Compressed files have the suffix .Z and should not be renamed. Compression and archiving can be used together for maximum disk space savings.

If the files in question are used infrequently, consider archiving them to tape, floppy, or other archive media. This maintains protection if you need the files later, but regaining them is slightly more difficult than if they are compressed.

Disk Space Management with the quotas Subsystem

The quotas subsystem allows you to deal with severe disk usage problems. Using this subsystem, you can place a maximum disk usage quota on each user on your system. For complete information about this subsystem, see the quotas(4) man page.

In general, it is your job as the site administrator to set disk use policies, establishing and enforcing quotas if necessary. You should publish clear guidelines for disk use, and notify users who regularly exceed their quotas. It is also a good idea to impose quotas on the use of temporary directories, such as /tmp and on all anonymous guest accounts, such as guest and uucp. If your root filesystem reaches 100% capacity, your system may shut down and inconvenience your users.

Be as flexible as possible with disk quotas. Often, legitimate work forces users to temporarily exceed disk quotas. This is not a problem as long as it is not chronic.

Do not, under any circumstances, remove user files arbitrarily and without proper warning.

A typical scenario is when all the users on the system know they should try to limit disk use in their home accounts to about 20 MB (about 40,000 512-byte blocks). User norton consistently uses more than twice this limit. To alleviate the problem of too much disk space, follow the steps in Procedure 6-1:

Procedure 6-1. Enforcing Disk Quota Guidelines

  1. Meet with the user and find out why he or she is using this much disk space. There may be legitimate reasons that require you to reconsider the disk use policy and perhaps increase the amount of available disk space.

    If the user is merely saving an inordinate number of outdated files, suggest that he or she back up the files onto tape and remove them from the system. For example, many users save e-mail messages in enormous mailboxes for long after the messages are useful. Saving the files to tape keeps them handy, while saving disk space.

  2. If you cannot meet with the person, or cannot discuss the matter in person, try sending e-mail.

    If you use a script that automatically checks disk use (with diskusg) and sends mail to users who exceed their quotas, note that people get used to these messages after some time and start to ignore them. Send the particular user a personal message, stating that you need to discuss the situation.

  3. Sometimes a user is not aware that data is available elsewhere on the system, or on other accessible workstations at the site. A user may have personal copies of site-specific tools and data files. Work with the user to reduce this kind of redundancy.

  4. Make sure the user is still active on the system. Sometimes people leave an organization, and the site administrators are not immediately informed.

    Also, the user may not need the account on a particular workstation any longer and may not have cleaned up the files in that account. To see if this is the case, check the last time the user logged in to the system with the finger(1) command:

    finger norton
    

    Among other information, finger displays the date and time the user last logged in to the system. This information is read from /etc/wtmp, if it exists.

  5. If in an extreme case you must remove a user's files, back them up to tape before removing them. Do not take this step lightly. Removing user files unnecessarily can disrupt work and engender ill will from your coworkers. Make sure you give the user plenty of advance notice that you are going to copy the files to tape and remove them from the system.

    As an added precaution, you may want to make two copies of the tape and send one copy to the user whose files you remove. Make sure you verify that the tapes are readable before you remove the files from the system.

Disk Space Management with NFS

If your system is running the optional Network File System (NFS) software, you can use this product to reduce disk consumption on your workstations by exporting commonly used directories. When a system exports a directory, it makes that directory available to all systems running the NFS software. For example, if you have 10 workstations on your network and each workstation is storing 5 MB of online man pages and release notes, you can eliminate 45 MB of wasted disk space by designating one workstation to be the man page server and exporting the /usr/man and /usr/catman directories. All other workstations can remove those files and mount them remotely from the server. Since NFS mounts take up no disk space on the client workstation, that disk space is available for other uses.

Another option is to mount free disk space from another system. This option works best when there is an uneven load across several systems. For example, if one workstation is using only 25% of its available space and other workstations are above 90%, it may be useful to mount a filesystem to even out the load.

Used wisely, your network can save a tremendous amount of disk space through this strategy. Be aware, though, that the drawback to this strategy is that if your server must be rebooted or serviced, no one can access the files and programs that are mounted from that server while it is offline.

Disk Space Management with Disk Partitions

An extreme method of enforcing disk use quotas is to create a disk partition and filesystem for each user account and to mount the filesystem on an empty directory as the user's home directory. Then, when users run out of disk space, they will not be able to create or enlarge any files. They can, however, still write their files to /tmp and /var/tmp, unless those directories are also full. When users attempt to write or create a file that takes them over their limit, they receive an error message indicating that no disk space is left on the device.

This method of disk control is not generally recommended. It requires a great deal of preparation and maintenance on the part of the administrator, and is not easily modified once in place. Additionally, fragmenting your disk into many small partitions reduces the total amount of available disk space and produces a performance overhead on your system. In this case, the disk controller must write a user's files within only one small partition, instead of in the next convenient place on the disk.

Consider this method of disk space control only if your system is so overloaded and your users so obstinate that all other measures have failed. If your /usr partition is chronically 100% full, the system is halting operations daily due to lack of disk space, and there is no way to increase your disk space, then you may want to consider this method.

Wasted Disk Space

Sometimes there is a great deal of wasted disk space on a system. When you are low on space, check to make sure that large files have not accumulated in the temporary directories or in the administrative directories.

The /var/adm directory structure is notorious for accumulating large log files and other large files that are useful for debugging problems that use up a tremendous amount of space. The /var/adm/crash directory may be storing several images of the IRIX kernel (from past system failures) and copies of the entire core memory (vmcore). These files can take up large amounts of space (many megabytes) and should be archived on tape and removed from your system.

If you have system auditing enabled, be aware that this facility generates very large audit trail record files, and these need to be archived to tape on a regular (perhaps daily) basis.

Also, check any UUCP or ftp directories you may have available, and generally look for core files, and any other large and unnecessary files that may exist on your system.

Swap Space

T he IRIX operating system uses a portion of the disk as swap space for temporarily saving part or all of a user's program when there is not enough physical memory to contain all of the running programs. If you run many very large programs, you might run out of swap space. For a complete discussion of the dynamics of paging and swapping, see “Paging and Swapping” in Chapter 10.

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:

swap -l

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:

swap -l

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.

  2. 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:

    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.