Skip to content

Managing /var/tmp

April 27, 2011

If you run a multi-user system one of the many things that you will want to do is prevent any one user from being able to consume all the resources on the system. Solaris has plenty of features for managing CPU resources and even memory resources.

One of the perennial problems is how to control the use of temporary file systems such as /tmp and /var/tmp. If you set quotas on the file systems then you have to then have a job that will clear the file system at boot time however that results in a non deterministic boot time as file systems that contain many files can take many minutes or even hours to empty.

However there is a way to have fixed boot time and user quotas when using ZFS.

The principle is simple.

Have an empty file systems that has quotas configured on it. Then
have an SMF service that destroys the existing filesystem for
/var/tmp and then snapshots and clones the empty filesystem with a
mount point of /var/tmp.

You can easily see the relationship of the file systems with zfs

$ zfs list -o name,origin,creation,mountpoint -rt all rpool/tmp_template rpool/tmp
NAME                         ORIGIN                       CREATION               MOUNTPOINT
rpool/tmp                    rpool/tmp_template@snapshot  Wed Apr 27  7:00 2011  /var/tmp
rpool/tmp_template           -                            Tue Apr 26 14:09 2011  none
rpool/tmp_template@snapshot  -                            Wed Apr 27  7:00 2011  -

To achieve this you first need to create a new SMF service.

Mine is called svc:/system/filesystem/create_var_tmp and that has to depend on the service svc:/system/filesystem/minimal and be depended on by svc:/system/filesystem/local so that the new file system is set up before filesystem/local runs.

$ svcs -l  svc:/system/filesystem/create_var_tmp:default
fmri         svc:/system/filesystem/create_var_tmp:default
name         Create /var/tmp
enabled      true
state        online
next_state   none
state_time   Wed Apr 27 10:16:56 2011
logfile      /var/svc/log/system-filesystem-create_var_tmp:default.log
restarter    svc:/system/svc/restarter:default
dependency   require_all/none svc:/system/filesystem/minimal (online)
$ svcs -D  svc:/system/filesystem/create_var_tmp:default
STATE          STIME    FMRI
online         10:16:56 svc:/system/filesystem/local:default

With this in place the reboot time is consistent but you do have to edit the users quota on both file systems.


From → General

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: