Monday, April 15, 2013

Solaris 10 Resource Management

Solaris 10 resource mangement is a major step forward over what was available in Solaris 8 and 9. In Solaris 10, we can manage resources at a zone, project or task level. This page focuses mainly on project-level resource management. Additional information is available in Sun's System Administration Guide: Solaris Containers-Resource Management and Solaris Zones on the Sun Documentation Web Site.

Projects

Projects are collections of tasks, which are collections of processes. A new task is started in a project when a new session is opened by a login, cron, newtask, setproject or su command. Each process belongs to only one task, and each task belongs to only one project.

The default project for a user is determined as per the getdefaultproj() man page.

When there is more than one policy in place for a particular object, the smallest container's control is enforced first.

Projects are maintained via the /etc/project file. Changes to /etc/project become available for new tasks in a project. (prctl and rctladm are used to perform runtime changes.)

The fields in an /etc/project entry are:

  • projname: Name of the project.
  • projid: Unique numerical project identifier less than UID_MAX (2147483647).
  • comment: Project description.
  • user-list: Comma-separated list of users.
  • group-list: Comma-separated list of groups.
  • attributes: Semicolon-separated list of name-value pairs, such as resource controls, in a name[=value] format.

After a default Solaris 10 installation, /etc/project contains the following:

system:0::::(default project for system processes and daemons)
user.root:1::::(processes owned by the root user)
noproject:2::::(IP Quality of Service)
default:3::::(default assigned to every otherwise unassigned user)
group.staff:10::::(default used for unassigned users in the "staff" group)

Parameters are set by adding them to the last field of the project entry:
projectname:101::::project.max-lwps=(privileged,200,deny)

Management Commands

Commands for managing project attributes include the following:

  • projects: Displays project memberships for users, lists projects from the project database, prings information on given projects.
  • newtask: Executes the shell or command in a new task in the current project.
  • projadd: Adds a new entry to the /etc/project entry.
  • projmod: Modifies information for a project in /etc/project.
  • projdel: Deletes a project from /etc/project.
  • rctladm: Displays/modifies global state of active resource controls, sets logging or actions.
  • prctl: Displays/modifies local resource controls.
  • ipcs: Identifies which IPC objects are being used in a project.
  • rcapadm: Manages rcapd memory-capping daemon.
  • prstat -J: Displays resource consumption on a per-project basis
  • priocntl -i project-name: Sets/displays scheduling parameters of the project.
  • poolbind -i project-name: Assigns a project to a resource pool.

Usage examples are provided at the end of this page.

Privilege Levels

Each resource control threshhold needs to be associated with one of the following privilege levels:

  • basic: Can be modified by owner of calling process.
  • privileged: Only modifiable by superuser
  • system: Fixed for the duration of the operating system instance

IPC Resource Controls

The Solaris 10 IPC resource management framework fixes some serious problems in the older SVR4-based system. Some parameters were converted to be set dynamically, some defaults were increased, some parameters were retired, and the names of the surviving parameters were changed to be more human-readable.

In older Solaris versions, the resource limits were system-wide (causing potential conflicts) and reboots were required for even minor changes.

The Solaris 10 system permits project-based resource controls and allows controls to be monitored and changed via prctl.

Additional information about IPC resource management can be found on the IPC Issues page.

For the purposes of IPC resource management, the following are the important parameters:

  • project.max-shm-ids: Maximum shared memory IDs for a project. Replaces shmmni
  • project.max-sem-ids: Maximum semaphore IDs for a project. Replaces semmni
  • project.max-msg-ids: Maximum message queue IDs for a project. Replaces msgmni
  • project.max-shm-memory: Total amount of shared memory allowed for a project. Replaces shmmax
  • process.max-sem-nsems: Maximum number of semaphores allowed per semaphore set. Replaces semmsl
  • process.max-sem-ops: Maximum number of semaphore operations allowed per semop. Replaces semopm
  • process.max-msg-messages: Maximum number of messages on a message queue. Replaces msgtql
  • process.max-msg-qbytes: Maximum number of bytes of messages on a message queue. Replaces msgmnb

An Oracle-specific example is provided below.

Other Resource Controls

The new Solaris 10 resource controls include compatibility interfaces to the old rlimit-style resource controls. Existing applications using the old interfaces can continue to run unchanged.

Additional Resource Controls:

  • [zone|project].cpu-shares: Maximum CPU shares allowed (under Fair Share Scheduler)
  • [task|process].max-cpu-time: Maximum CPU time available to processes in this task.
  • project.max-contracts: Maximum number of contracts allowed
  • project.max-crypto-memory: Total kernel memory usable by libpkcsll for hardware crypto accelleration.
  • project.max-device-locked-memory: Total locked memory allowed.
  • process.max-address-space: Maximum address space.
  • process.max-core-size: Maximum core dump size.
  • process.max-data-size: Maximum heap size.
  • process.max-file-descriptor: Maximum file descriptor index.
  • process.max-file-size: Maximum file offset allowed for writes.
  • process.max-stack-size: Maximum stack memory segment available.
  • [zone|project|task].max-lwps: Maximum lwps available to this project.
  • process.max-port-events: Maximum events per port.
  • project.max-port-ids: Maximum allowable event ports.
  • project.max-tasks: Maximum allowable tasks.
  • rcap.max-rss: Maximum physical memory consumption by processes in project.
A full list of resources is available on the resource_controls man page.

Resources beginning with the rcap string are associated with the rcapd resource-capping daemon.

rcapd

rcapd caps memory useage within a project. In each zone, rcapd can be enabled via
rcapadm -E
This command will start rcapd and set it up in SMF so that it will be restarted automatically.

We can use projmod to set the memory cap for a project:
projmod -s -K rcap.max-rss=sizeMB project-name
Alternatively, we can set the rcap.max-rss control directly in /etc/project.

rcapd does not account for shared memory in an intuitive way. To be safe, we need to allow enough room for shared memory to be included under the cap. We should not depend solely on rcapd to manage process memory.

Logging

Global logging can be enabled by setting syslog=level with rctladm, where level is one of the usual syslog levels: debug, info, notice, warning, err, crit, alert or emerge.

Actions

It is possible to use rctladm to specify one of the following actions on a process that violates the control:

  • none: No action taken. (Useful for monitoring.)
  • deny: Denies request.
  • signal=: Enable a signal. See the rctladm man page for a list of allowed signals.

Command Examples

The projadd man page provides an example of how to add a project:

The following command creates the project salesaudit and sets the resource controls specified as arguments to the -K option.

projadd -p 111 -G sales,finance -c "Auditing Project" -K "rcap.max-rss=10GB" -K "process.max-file-size=(priv,50MB,deny)" -K "task.max-lwps=(priv,100,deny)" salesaudit

This command would produce the following entry in /etc/project:
salesaudit:111:Auditing Project::sales,finance:process.max-file-size=(priv,52428800,deny); rcap.max-rss=10737418240;task.max-lwps=(priv,100,deny)

To start up a task under this project, run the following:
newtask -p salesaudit command

A running process can be associated with a new task:
newtask -v -p project-name -c PID

To verify the project governing the current shell, we would run:
id -p

To view resource constraints for a process, we would run something like the following:
prctl -n resource-name -i process PID

To view resource constraints for the current shell, we could run:
prctl $$

To temporarily set resource constraints on a particular project, we could run something like:
prctl -n resource-name -t privilege-level -v value -e action -i project project-name

To activate logging on a global resource control facility, run something like:
rctladm -e syslog=level resource-name

To list all existing projects, run:
projects -l

To see how a project's IPC objects are allocated against existing limits, run something like:
ipcs -J

To display a process's project id, use a command of the form:
ps -o projid -p PID

To match project or task ids for pgrep, pkill or prstat commands, use the -T or -J options:
pgrep -J project-IDs
pkill -T task-IDs
prstat -J

Oracle Setup Example

Oracle 9i recommends several minimum semaphore and shared memory settings. Since Solaris 10 has increased the defaults on several settings above previous levels, and since several other ones have become obsolete, only the shmmax parameter should need to be set.

In particular, the new defaults for some key parameters are:

  • semmni: 128 (100 recommended)
  • semmsl: 512 (256 recommended)
  • shmmni: 128 (100 recommended)

The following are obsolete:

The projmod command can be used to set the shmmax to the desired level (default is 1/4 physical memory):
projmod -sK "project.max-shm-memory=(privileged,gigabytes-sharedGB,deny)" project-name

It makes sense to set up projects (and project limits) for each environment on the server. To ensure that each instance actually starts up in the proper project, the startup scripts will need to include a
newtask -p project-name
line.

A full example of this type is found in Chapter 4 of The Sun BluePrints Guide to Solaris Containers.

Default Project

The default project for a user is determined as per the getdefaultproj() man page:

The getdefaultproj() function first looks up the project key word in the user_attr database used to define user attributes in restricted Solaris environments. If the database is available and the keyword is present, the function looks up the named project, returning NULL if it cannot be found or if the user is not a member of the named project. If absent, the function looks for a match in the project database for the special project user.username. If no match is found, or if the user is excluded from project user.username, the function looks at the default group entry of the passwd database for the user, and looks for a match in the project database for the special name group.groupname, where groupname is the default group associated with the password entry corresponding to the given username. If no match is found, or if the user is excluded from project group.groupname, the function returns NULL. A special project entry called 'default' can be looked up and used as a last resort, unless the user is excluded from project 'default'. On successful lookup, this function returns a pointer to the valid project structure. By convention, the user must have a default project defined on a system to be able to log on to that system.

Additional Reading

Additional information is available in Sun's System Administration Guide: Solaris Containers-Resource Management and Solaris Zones and The Sun BluePrints Guide to Solaris Containers on the Sun Documentation Web Site.

Sunday, April 14, 2013

Resource Pool Management

The purpose of resource pools is to segregate different workloads to eliminate their contention for certain types of resources. Resource pools allow persistent configuration for workload processor set and scheduler assignments.

Pools can operate on the following types of elements:

  • system: The system as a whole
  • pool: Define resource pools
  • pset: Processor sets.
  • cpu: Single processor.

Each project can have a project.pool attribute set in /etc/project in order to assign a resource pool. This would be set by a command of the following form:
projmod -a -K project.pool=poolname project-name

Dynamic resource pools are implemented via the poold daemon. poold can only execute in the global zone.

The default static pools configuration file is /etc/pooladm.conf. If this file exists, its configuration is applied at boot time.

The poolcfg command operates on a configuration file, though poolcfg -d may be used to modify the current kernel state. pooladm is used to activate the pool configuration contained in a file or to display information about the configuration currently in the kernel.

To enable a configuration, run:
pooladm -e To instantiate the configuration in a file, run:
pooladm -c filename
To dump the active configuration to a file, run:
pooladm -s filename
To disable pools, run
pooladm -d
To display the pool configuration in a "nice" format, run:
poolcfg -c info

poolstat can be used to display information on resource pools. If executed from a non-global zone, however, it will only display information for the pool assigned to that zone.

Multiple non-global zones can be associated with a particular resource pool. When this is done, processes from within one of these zones cannot be assigned to a different resource pool via poolbind, even when the attempt is made from the global zone.

poold Properties

The following are the property names for poold:

  • system.poold.log-level: Logging level
  • system.poold.log-location: Log location
  • system.poold.monitor-interval: Sampling interval
  • system.poold.history-file: Decision history
  • pset.max: Maximum CPUs for a pset.
  • pset.min: Minimum CPUs for a pset.
  • cpu.pinned: (true/false) Whether the CPU is pinned.
  • system.poold.objectives: System objectives.
  • pset.poold.objectives: Pset objectives.
  • pool.importance: User-assigned importance of a pool.
  • pool.scheduler: Defines scheduler to be used by a pool.

These are assigned with poolcfg. For example, to assign a pool to a scheduler, run:
poolcfg -c 'modify pool pool-name (string pool.scheduler="scheduler-initials ")'

poold Configuration: Constraints and Objectives

Minimum and maximum numbers of processors available to a processor set can be set with the pset.min and pset.max properties. The cpu.pinned property indicates that a particular CPU should not be moved out of its processor set.

The libpool man page contains detailed information on property constraints.

Configuration objectives define the behavior of poold. The available objectives are:

  • wt-load: The weighted-load objective provides pooled resources based on the weight of the active objects. It is a system-wide objective.
  • locality: locality is defined on a pset. It defines how much weight is given to the closeness of available resources. It can be assigned values of tight (maximize locality), loose (minimize locality) or none (not taken into account-default).
  • utilization: This is defined to be greater than (>), less than (<) or about (~) some percentage of utilization for a pset. The > and < operators can be used to set a range, but ~ must be used alone if at all.

The objectives are also set with poolcfg:
poolcfg -c 'modify system system-name (string system.poold.objectives="objective "),

If wt-load is set, note that the psets need to have "locality none" set as an objective.

Processor Sets

Each processor can belong to only one processor set at a time. The default processor set is created when poold is enabled. It cannot be destroyed.

To create a processor set with a range of possible numbers of CPUs, run:
poolcfg -c 'create pset pset-name (uint pset.min = min-cpus; unit pset.max = max-cpus)'
To create a pool, run:
poolcfg -c 'create pool pool-name'
To associate a pool and a pset, run:
poolcfg -c 'associate pool pool-name (pset pset-name)'
To apply the changes, run:
pooladm -c

To transfer processors between processor sets, run:
poolcfg -dc 'transfer number-procs from pset pset-source to pset-target'

Additional Reading

Additional information is available in Sun's System Administration Guide: Solaris Containers-Resource Management and Solaris Zones.

Saturday, April 13, 2013

Book Review: Root Cause Analysis by Duke Okes

Okes has done a remarkable job creating a book that is readable, concise and useful. There are several well-known books which will smother you with statistics and studies. Okes' book is a common sense introduction to root cause analysis that is general enough to be widely applicable, but specific enough to help most front-line people sharpen their troubleshooting process.

The examples are well-chosen and pointed, and the graphs and charts are explicit and well-explained.

If you need to troubleshoot or perform root cause analyses, this is an excellent book to keep on your bookshelf.

Book Review: Oracle Solaris 11 System Administration: The Complete Reference

Authors of books in the "Complete Reference" series have always had a tough row to hoe. They attempt to condense an entire set of product documentation to a single, referenceable volume. And all that has to be done in the time frame allowed by software release schedules.

Kudos to the authors of this particular volume for having pulled together a lucid, reasonably detailed summary of the most important parts of Solaris. Despite the name, no one book can actually be a complete reference for something as complex as Solaris, but this book is a pretty good addition to any Solaris admin's bookshelf.

One of the difficulties of writing a book by committee is maintaining the same audience and consistent focus across chapters and topics. In this case, there are some chapters where the level of detail does not match what is present in other chapters. And in some cases, there is a distinct audience mis-match.

I came across one howler in Chapter 10: "differences between shells are subtle, indistinguishable to most regular Solaris 11 users." The author of that chapter goes on to explain that for that reason, the chapter will focus on bash. Fair enough on the selection of the most common shell for detailed discussion. But you have to wonder how useful a chapter is going to be if the assumed audience is too clueless to see the difference in how sh and csh (for example) execute even simple actions like setting an environment variable.

It would be nearly impossible for a book of this type to earn 5 stars. But this volume gets a solid 4 in my book.

Process Accounting

Process accounting can be turned on by referencing the /etc/init.d/acct file, either in a command line with start/stop, or by linking to the appropriate rc file:

ln -s /etc/init.d/acct /etc/rc2.d/S22acct

ln -s /etc/init.d/acct /etc/rc0.d/K22acct

The /etc/acct/holidays file may also need to be edited, if different monitoring is desired during holidays.

The root and adm crontabs can also be edited to run dodisk, ckpacct, monacct, and runacct.

Process accounting logs can be examined directly using acctcom.

Friday, April 12, 2013

Kernel Memory

Kernel memory size can be tracked using the sar -k command. The total of the "alloc" fields is the kernel memory size. If it appears to be growing without bound, you may have a memory leak. It should be noted that not all buckets are tracked by sar -k, so the reported memory size is not as accurate as that reported by crash.

On occasion there are problems related to memory leaks in the kernel or one of the associated modules. In these cases, kmastat can provide useful information pinpointing the source of the leak.

To check on kernel memory allocations on a running system, run a crash session as follows:

# crash
dumpfile = /dev/mem, namelist = /dev/ksyms, outfile = stdout
> kmastat

The first number on the "Total" line represents the total amount of memory allocated by the kernel. If this is a significant fraction of available system memory and growing, there is a problem.

The output from the kmastat command also contains information on a number of "buckets" or categories for memory allocation.

Additional information can be obtained via the kmausers command, but this requires that we load kadb prior to booting. To do this, reach the ok> prompt, then:

ok> boot kadb -d
kadb: (hit the "return" key)
kadb[0]: kmem_flags/W 01
kadb[0]: :c

Loading kadb this way means that kadb will only be effective for this current boot session.

Once the system is up, we can either force a core dump via STOP-A/ ok> sync, or we can examine the live system. In either case, inside the crash session we would type:

>kmausers bucket_name

The result will show memory allocations inside that bucket. The names of functions inside each allocation will be a tip-off to what is actually grabbing the memory allocation.

A script can be run from cron to capture this information. The format of this script would be something like:

#!/bin/sh
date >> log_file
echo "kmastat" | /usr/sbin/crash -w log_file
sleep 20
echo "kmausers kmem_alloc_2048" | /usr/sbin/crash -w log_file

Slab Allocator

Solaris 2.4+ uses a kernel memory allocator known as a slab allocator.

A kernel memory allocator performs the following functions:

  • Allocate memory
  • Initialize objects/structures
  • Use objects/structures
  • Deconstruct objects/structures
  • Free memory

The structures in the memory objects include sub-objects such as linked list headers, mutexes, reference counts and condition variables. In the case of Solaris, the deconstruction step includes setting objects to their initial settings, which can save time when the memory objects have to be re-initialized.

A translation lookaside buffer (TLB) is an associative cache of recent address translations. When the MMU (memory management unit) cannot find a translation in the TLB, it lookus it up in the address maps and loads the address into the TLB. Entries in the TLB are replaced on a least recently used basis.

The slab allocator is organized as a collection of object caches. Each of these caches contains only one type of object (proc structures, vnodes, etc). The kernel is responsible for restoring each object to its initial state when it is released. When a cache requires additional space, the allocator gives a slab of memory from the page-level allocator and creates objects from it. The slab contains enough memory for several object instances. A small part of the slab is used by the cache to manage memory in the slab; the rest is divided into buffers that are the size of the object. The allocator then initializes these buffers with the appropriate constructor.

When the page-level allocator needs to recover memory, unused slabs are reaped by deconstructing the objects on slabs whose objects are all free, then removing the slab from the cache in question.

The structure for each slab includes unused space at the beginning of the slab (coloring area), the set of objects, more unused space (the amount left over after the maximum number of objects has been created), and a slab data area. Each object also includes a four byte area for a free list pointer. The slab data area includes a count of in-use objects, pointers for a doubly-linked list of slabs in the same cache, and a pointer to the first free area in the slab. The coloring areas are different sizes for each slab in a cache (where possible). This allows a balanced distribution of traffic on the hardware caches and memory busses by varying the offsets for the different slabs.

Large object slabs are slightly different in that management data is stored in a separate pool of memory, since large slabs are usually multiples of a page in size. A hash table is also maintained to provide lookups between the management area and the slabs.

Thursday, April 11, 2013

Lock Contention

Four types of locking are available on Solaris:
  • Mutexes
  • Semaphores (counters) (not the same as IPC semaphores)
  • Condition variables (generalized semaphores)
  • Multiple-reader, single-writer locks

The following types of locking problems can occur:

  • Lock contention (due to excessively coarse granularity or inappropriate lock type)
  • Deadlock (each process is waiting for a lock held by another process)
  • Lost locks
  • Race conditions
  • Incomplete or buggy lock implementation

Mutex Locks

A "mutex lock" is a "mutual exclusion lock." It is created by the LDSTUB (load-store-unsigned-byte) instruction, which is an atomic (indivisible) operation that reads a byte from memory and writes 0xFF into that location. (When the lock is cleared, 0x00 is written back to the memory location.)

If the value that was read from memory is already 0xFF, another processor has already set the lock. At that point, the processor can "spin" by sitting in a loop and testing to see if the lock has cleared (i.e., been written back to 0x00). This sort of "spin lock" is usually used when the wait time for the lock is expected to be short. (If the wait is expected to be longer, the process should sleep so that the CPU can be used by another process. This is known as a "block.")

Adaptive Locks

Solaris 2.x provides a type of locking known as adaptive locks. When one thread attempts to acquire one of these that is held by another thread, it checks to see if the second thread is active on a processor. If it is, the first thread spins. If the second thread is blocked, the first thread blocks as well.

Read/Write Locks

This type of lock allows multiple concurrent reads, but prevents other accesses of the resource when writes are taking place.

Lock Contention Indicators

One indicator of a possible lock contention problem is when vmstat reports that the system is not idle, but that cpu/sy dominates cpu/us. (Note: this observation is only true if the system is not running an NFS server or other major service that runs from inside the kernel.)

One way to pin down a lock contention problem is by tracing the problem process with truss.

Another way to attempt to track down the problem is with mpstat. The smtx measurement shows the number of times a CPU failed to obtain a mutex immediately. The master CPU (the one taking the clock interrupt--usually CPU 0) will tend to have a high reading. Depending upon CPU speed, a reading of more than 500 may be an indication of a system in trouble. If the smtx is greater than 500 on a single CPU and sys dominates usr (ie, system time is larger than user time, and system time is greater than 20%), it is likely that mutex contention is occurring.

Similarly, mpstat/srw value reports on the number of times that a CPU failed to obtain a read/write lock immediately.

For Solaris 2.6 and above, the lockstat command can help to pin down the culprit. The kernel takes a performance hit while lockstat is running, so you probably only want to use this command while you are actually looking at the output.

With lockstat, look for large counts (indv), especially with long locking times (nsec).

In any case, extreme mutex contention problems should be reported to Sun. Changes have been implemented in current versions of the SunOS 5.x kernel that dramatically increase the scalability of the operating system over multiple processors. Unless additional issues are brought to the vendor's attention, they cannot be expected to correct them in future releases.

Wednesday, April 10, 2013

Service Management Facility

The Service Management Facility was introduced in Solaris 9 as an alternative way to manage services. In Solaris 10, SMF has been made the default way to manage most services. The SMF framework has significant advantages over the legacy SVR4 mechanisms, primarily in terms of service monitoring and integration with the Fault Management Facility.

Basic Commands

The basic commands for managing services under SMF (Service Management Facility) control are svcs, svccfg and svcadm. The man pages for these commands are a good source of detailed information.

inetadm can be used to monitor services under inetd control.

Many commands require referencing the service identifier, also known as an FMRI.

svcs

  • svcs -a: Lists all services currently installed, including their state.
  • svcs -d FMRI: Lists dependencies for FMRI.
  • svcs -D FMRI: Lists dependents for FMRI.
  • svcs -l FMRI: Provides a long listing of information about FMRI; includes dependency information
  • svcs -p FMRI: Shows relationships between services and processes.
  • svcs -t: This change is temporary (does not persist past a boot).
  • svcs -x: Explains why a service is not available.
  • svcs -xv: Verbose debugging information.

svcadm

  • svcadm clear FMRI: Clear faults for FMRI.
  • svcadm disable FMRI: Disable FMRI.
  • svcadm enable FMRI: Enable FMRI.
  • svcadm refresh FMRI: Force FMRI to read config file.
  • svcadm restart FMRI: Restart FMRI.

To make configuration changes to a non-inetd service, edit the configuration file, then enter the svcadm restart command.

svccfg

  • svccfg: Enter interactive mode.
  • svccfg -s FMRI setenv ENV_VARIABLE value: Set an environment variable for FMRI. Follow by svcadm refresh and restart commands.

inetadm

  • inetadm -l FMRI: Displays properties for FMRI.
  • inetadm -m FMRI property_name=value: Set a property for FMRI.

In particular, the "exec" value for an inetd-controlled service is the command line executed for that service by SMF. It may be desirable, for example, to change this value to add logging or other command-line flags.

To convert an inetd.conf file to SMF format, run the command:
inetconv -i /etc/inet/inetd.conf

Service Identifiers

Services are identified by their FMRI. (This stands for Fault Managed Resource Identifier.) An example is:
svc:/system/system-log:default
Some commands do not require the full FMRI if there is no ambiguity.

Legacy init scripts have FMRIs starting with lrc. For example:
lrc:/etc/rcS_d/S35cacheos_sh

Converted inetd services have a syntax like one of the following, depending on whether or not they are rpc services:
svc:network/service-name/protocol svc:network/rpc-service-name/rpc_protocol

SMF Service Starts

The svc.startd daemon is the master process starter and restarter for SMF. It tracks service state and manages dependencies.

Services that are managed through init scripts can be added to SMF via the inetconv command. Such additions are only monitored for status, but other SMF facilities may not work.

Maintenance

If a service is in the maintenance state, first make sure that all associated processes have died:
svcs -p FMRI
Next, (for all processes displayed by the above):
pkill -9 PID
Consult the appropriate logs in /var/svc/log to check any errors; perform any needed maintenance.
Restore the service:
svcadm clear FMRI

Scripts

The scripts that implement the startups and shutdowns are located in their usual place in /etc/init.d for the lrc services, or in /lib/svc/method for most of the other services.

Other locations may be specified for a particular service. To track down the script locations for a particular service, do something like the following:

# svccfg -s smtp
svc:/network/smtp> list
:properties
sendmail
svc:/network/smtp> select sendmail
svc:/network/smtp:sendmail> list
:properties
svc:/network/smtp:sendmail> listprop *exec
start/exec astring "/lib/svc/method/smtp-sendmail start"
stop/exec astring "/lib/svc/method/smtp-sendmail stop %{restarter/contract}" refresh/exec astring "/lib/svc/method/smtp-sendmail refresh"

Boot Messages

Boot messages are much less verbose than previously. To get verbose output, boot with the
boot -v
or
boot -m verbose
commands.

svcadm can be used to change the run levels. The FMRIs associated with the different run levels are:

  • S: milestone/single-user:default
  • 2: milestone/multi-user:default
  • 3: milestone/multi-user-server:default
Run levels can be displayed with
who -r

SMF Profiles

SMF profiles are XML files in /var/svc/profile which list sets of service instances which are enabled and disabled.

Different SMF profiles can be used. They are stored in /var/svc/profile. To use a different one, perform the following procedure:
svccfg apply /var/svc/profile/desired_profile.xml

The local profile /var/svc/profile/site.xml allows local customizations. This profile is applied after the standard profiles.

To make a copy of the current profile for editing, run:
svccfg extract> profile-file.xml

Service Configuration Repository

Stores persistent configuration information and SMF runtime data for services.

Each service's manifest is in an XML-formatted text file located in /var/svc/manifest. The information from the manifests is imported into the repository through svccfg import or during a reboot.

This is covered in the svccfg, svcprodp, service_bundle and svc.configd man pages.

If the repository is corrupted, it can be restored from an automatic backup using the /lib/svc/bin/restore_repository command. The svcadm refresh; svc adm restart command will make a snapshot active. Automatic snapshots are taken for initial (import of the manifest), running (when service methods are executed) and start (last successful start).

Revert to a Snapshot

The procedure to revert to a snapshot is the following:
Run svccfg in interactive mode:
svccfg
In the svc:> prompt, select the desired service with a full FMRI:
select FMRI
List the available snapshots:
listsnap
Revert to the desired snapshot:
revert desired_snapshot_label
Quit out of the svccfg interactive mode:
quit
Update the service configuration repository information:
svcadm refresh FMRI
svcadm restart FMRI

Boot Troubleshooting

To step through the SMF portion of the boot process, start with:
boot -m milestone=none
Then step through the milestones for the different boot levels:
svcadm milestone svc:/milestone/single-user:default
svcadm milestone svc:/milestone/multi-user:default
svcadm milestone svc:/milestone/multi-user-server:default

Several things should be examined if a service fails to start:

  • Is the service in maintenance mode? (svcs -l FMRI)
  • If so, why? Check the log file specified in the svcs -l FMRI | grep logfile output, and run svcs -xv FMRI
  • If the problem has been resolved, clear the fault with svcadm clear FMRI
  • Check for service dependencies with svcs -d FMRI The output from svcs -l distinguishes between optional and mandatory dependencies.
  • Check the startup properties with svcprop -p start FMRI The startup for the process can be trussed to get some visibility into where it is failing by inserting a truss into the start or exec statement for the service. To do this, just add truss -f -a -o /path/service-truss.out to the beginning of the start or exec statement with an svccfg -s statement.

Solaris Fault Management

The Solaris Fault Management Facility is designed to be integrated into the Service Management Facility to provide a self-healing capability to Solaris 10 systems.

The fmd daemon is responsible for monitoring several aspects of system health.

The fmadm config command shows the current configuration for fmd.

The Fault Manager logs can be viewed with fmdump -v and fmdump -e -v.

fmadm faulty will list any devices flagged as faulty.

fmstat shows statistics gathered by fmd.

Fault Management

With Solaris 10, Sun has implemented a daemon, fmd, to track and react to fault management. In addition to sending traditional syslog messages, the system sends binary telemetry events to fmd for correlation and analysis. Solaris 10 implements default fault management operations for several pieces of hardware in Sparc systems, including CPU, memory, and I/O bus events. Similar capabilities are being implemented for x64 systems.

Once the problem is defined, failing components may be offlined automatically without a system crash, or other corrective action may be taken by fmd. If a service dies as a result of the fault, the Service Management Facility (SMF) will attempt to restart it and any dependent processes.

The Fault Management Facility reports error messages in a well-defined and explicit format. Each error code is uniquely specified by a Universal Unique Identifier (UUID) related to a document on the Sun web site.

Resources are uniquely identified by a Fault Managed Resource Identifier (FMRI). Each Field Replaceable Unit (FRU) has its own FMRI. FMRIs are associated with one of the following conditions:

  • ok: Present and available for use.
  • unknown: Not present or not usable, perhaps because it has been offlined or unconfigured.
  • degraded: Present and usable, but one or more problems have been identified.
  • faulted: Present but not usable; unrecoverable problems have been diagnosed and the resource has been disabled to prevent damage to the system.

The fmdump -V -u eventid command can be used to pull information on the type and location of the event. (The eventid is included in the text of the error message provided to syslog.) The -e option can be used to pull error log information rather than fault log information.

Statistical information on the performance of fmd can be viewed via the fmstat command. In particular, fmstat -m modulename provides information for a given module.

The fmadm command provides administrative support for the Fault Management Facility. It allows us to load and upload modules and view and update the resource cache. The most useful capabilities of fmadm are provided through the following subcommands:

  • config: Display the configuration of component modules.
  • faulty: Display faulted resources. With the -a option, list cached resource information. With the -i option, list persistent cache identifier information, instead of most recent state and UUID.
  • load /path/module: Load the module.
  • unload module: Unload module; the module name is the same as reported by fmadm config.
  • rotate logfile: Schedule rotation for the specified log file. Used with the logadm configuration file.

Tuesday, April 09, 2013

Solaris Important Header Files

Some of these header files contain important information that can be used when analyzing a core dump or setting parameter values.

Location
Description
/usr/include/sys Most system header files.
/usr/include/vm Header files describing virtual memory structures.
/usr/include/sys/fs Header files describing file system structures and types.
/usr/platform/`arch -k`/include/sys Architecture dependent structures.
/usr/platform/`arch -k`/include/vm Architecture-dependent virtual memory structures.
/usr/include/[net, nfs, rpc, protocols, inet, netinet] Define networking data structures.

Monday, April 08, 2013

Solaris System Configuration Files

For details about the files and commands summarized here, consult the appropriate man pages or Solaris Documentation
File
Description
/etc/bootparams Contains information regarding network boot clients.
/etc/cron.d/cron.allow
/etc/cron.d/cron.deny
Allow access to crontab for users listed in this file. If the file does not exist, access is permitted for users not in the /etc/cron.d/cron.deny file.
/etc/defaultdomain NIS domain set by /etc/init.d/inetinit
/etc/default/cron Sets cron logging with the CRONLOG variable.
/etc/default/login Controls root logins via specification of the CONSOLE variable, as well as variables for login logging thresholds and password requirements.
/etc/default/su Determines logging activity for su attempts via the SULOG and SYSLOG variables, sets some initial environment variables for su sessions.
/etc/dfs/dfstab Determines which directories will be NFS-shared at boot time. Each line is a share command.
/etc/dfs/sharetab Contains a table of resources that have been shared via share.
/etc/group Provides groupname translation information.
/etc/hostname.interface Assigns a hostname to interface; assigns an IP address by cross- referencing /etc/inet/hosts.
/etc/hosts.allow
/etc/hosts.deny
Determine which hosts will be allowed access to TCP wrapper mediated services.
/etc/hosts.equiv Determines which set of hosts will not need to provide passwords when using the "r" remote access commands (eg rlogin, rsh, rexec)
/etc/inet/hosts
/etc/hosts
Associates hostnames and IP addresses.
/etc/inet/inetd.conf
/etc/inetd.conf
Identifies the services that are started by inetd as well as the manner in which they are started. inetd.conf may even specify that TCP wrappers be used to protect a service.
/etc/inittab inittab is used by init to determine scripts to for different run levels as well as a default run level.
/etc/logindevperm Contains information to change permissions for devices upon console logins.
/etc/magic Database of magic numbers that identify file types for file.
/etc/mail/aliases
/etc/aliases
Contains mail aliases recognized by sendmail.
/etc/mail/sendmail.cf
/etc/sendmail.cf
Mail configuration file for sendmail.
/etc/minor_perm Specifies permissions for device files; used by drvconfig
/etc/mnttab Contains information about currently mounted resources.
/etc/name_to_major List of currently configured major device numbers; used by drvconfig.
/etc/netconfig Network configuration database read during network initialization.
/etc/netgroup Defines groups of hosts and/or users.
/etc/netmasks Determines default netmask settings.
/etc/nsswitch.conf Determines order in which different information sources are accessed when performing lookups.
/etc/path_to_inst Contents of physical device tree using physical device names and instance numbers.
/etc/protocols Known protocols.
/etc/remote Attributes for tip sessions.
/etc/rmtab Currently mounted filesystems.
/etc/rpc Available RPC programs.
/etc/services Well-known networking services and associated port numbers.
/etc/syslog.conf Configures syslogd logging.
/etc/system Can be used to force kernel module loading or set kernel tuneable parameters.
/etc/vfstab Information for mounting local and remote filesystems.
/var/adm/messages Main log file used by syslogd.
/var/adm/sulog Default log for recording use of su command.
/var/adm/utmpx User and accounting information.
/var/adm/wtmpx User login and accounting information.
/var/local/etc/ftpaccess
/var/local/etc/ftpconversions
/var/local/etc/ftpusers
wu-ftpd configuration files to set ftp access rights, conversion/compression types, and a list of userids to exclude from ftp operations.
/var/lp/log Print services activity log.
/var/sadm/install/contents Database of installed software packages.
/var/saf/_log Logs activity of SAF (Service Access Facility).

Book Review: Solaris Internals

This book should be in the library of any serious Solaris administrator. It is not a book for beginners, but it is well-organized and well-explained. The authors went to a great deal of trouble to clean up the parts of the original edition that were not as easily understood, and their effort shows.

The examples are clear and well-explained, and the information is indexed and cross-referenced in a way that makes it easy to follow threads across chapters.

The authors of this book have been extraordinarily generous with their time and energy. Jim Mauro was very encouraging and helpful in explaining topics which found their way onto my web site and into my book. The entire community owes these gentlemen a debt of gratitude for their professionalism and their generosity.

Sunday, April 07, 2013

Sun System Bus Sizing

This is an older posting I made to the original Solaris Troubleshooting site. The information is a little dated in terms of available hardware options, but the concepts and philosophy are the same.

The system bus has a fixed bandwidth. Too many devices on the bus can create more traffic than the bus can handle, which results in contention and packet loss.

prtdiag -v reports on many system bus configuration issues. It is possible to see if the bus is overloaded by adding up the reported capacities of the devices on a bus and seeing if they exceed the capacity of the bus.

Where possible, similar cards can be placed on the same board so that the interrupts are directed to the same CPU (and associated caches).

This is a table of typical system bus capacities:

Bus Speed Width Burst
Bandwidth
Sustained
Bandwidth
MBus 33MHz 64 bit 264 MB/s 86 MB/s
MBus 36MHz 64 bit 288 MB/s 94 MB/s
MBus 40MHz 64 bit 320 MB/s 105 MB/s
MBus 50MHz 64 bit 400 MB/s 130 MB/s
XDBus 40MHz 64 bit 320 MB/s 250 MB/s
XDBus 50MHz 64 bit 400 MB/s 312 MB/s
UPA 72MHz 128 bit 1.15 GB/s 1 GB/s
UPA 83.5MHz 128 bit 1.3 GB/s 1.2 GB/s
UPA 100MHz 128 bit 1.5 GB/s 1.44 GB/s
Gigaplane 83.5MHz 256 bit 2.6 GB/s 2.5 GB/s
GigaplaneXB 100MHz 1024 bit 12.8 GB/s 12.8 GB/s

Peripheral Buses

The two peripheral buses on Sun systems are Sbus and PCI bus. Sbus runs at 20-25MHz and comes in 32 or 64 bit sizes. Peak Sbus bandwidth is 200 MB/s. The venerable Sbus has been retired in favor of the newer PCI bus as PCI bus performance has improved.

PCI buses runs at 33 or 66MHz and may be 32 or 64 bit. The peak PCI bus bandwidth is 528 MB/s for 64-bit buses at 66MHz.

(For desktop PC hardware, 33MHz PCI buses are still common. 33 MHz buses have peak bandwidths of 264 MB/s for 64-bit and 132 MB/s for 32-bit.)

Newer PCI-x buses run at 133MHz and allow up to 1066 MB/s. PCI-x 2.0 defines clock rates of 266MHz and 533MHz, with peak bandwidths of 2.1 GB/s and 4.2 GB/s, respectively.

Low profile PCI buses are becoming more common, since their smaller form factor fits well with the increasing miniaturization of the system. Low profile PCI comes in MD1 and MD2 flavors, with the primary difference being the shorter length of the MD1 cards. Currently, they do not support 64-bit PCI extensions.

Mini PCI cards are also produced for use in portable and sealed case computers. They are small in size, do not support 64-bit extensions and have a different connector layout, but still otherwise follow the PCI standard.

SCSI Bus

SCSI buses can operate at one of these speeds:
  • 4 MB/s (asynchronous)
  • 5 MB/s (synchronous)
  • 10 MB/s (fast)
  • 20 MB/s (ultra, fast/wide or fast-20)
  • 40 MB/s (ultra/wide or narrow ultra-2)
  • 80MB/s (wide ultra-2)
  • 160 MB/s (ultra-3 or ultra-160)
  • 320 MB/s (ultra-320)
SCSI buses and devices negotiate speed between the controller and the devices on the chain. prtconf can report information that can be used to determine the speed of a particular device.

The scsi_options parameter can be set in the /etc/system file to limit bus speed or set other characteristics. Check device documentation to determine if these settings need to be specified.

SCSI chains may be made of single-ended (SE) or differential connections. Differential connections come in low voltage (LVD) and high voltage (HVD) variants. SE, LVD, and HVD should not be mixed, as this may damage the equipment.

Differential connections permit longer chains, but the hardware is usually more expensive. Single-ended chains must be less than 6m in length; LVD chains must be less than 12m in length; HVD chains must be less than 20m for synchronous connections or 25m for asynchronous connections. (Remember that chain length includes the length of the connectors and cabling in the devices, not just the external cable.)

Starting with Ultra 2, only differential connections are available. Only LVD is available for Ultra160 or Ultra320.

The SCSI target numbers represent attachment points on the SCSI chain. Each target number may include as many as 8 devices (luns or logical unit numbers). Embedded SCSI devices only include one lun.

Higher target numbers receive better service. On a narrow bus, the target priorities run 7 -> 0. On a wide bus, they run 7 -> 0, then 15 -> 8. The host adapter is usually 7. This can cause problems where busy disks and tape devices share a SCSI bus, since tape devices are usually assigned target 6.

Saturday, April 06, 2013

Book Review: The Practice of System and Network Administration

System Administration as a Profession

"The Practice of System and Network Administration" is different from most of the other technical books on a professional SA's bookshelf. This book is about how to become a professional system administrator.

The profession is about more than knowning obscure options to different commands. To become a professional, a system administrator needs to change mindset from a straight-ahead techie to a member of the team who has specialized expertise.

System administration has not always been recognized as a profession. System administrators themselves are partly to blame for that. We have tended to focus strictly on technology and not on how to structure our work to benefit both ourselves and the organizations we work for. Limoncelli, Hogan and Chalup have put togeter a great standard reference for people who are ready to transition to being professional system administrators.

Solaris Kernel Tuning

sysdef -i reports on several system resource limits. Other parameters can be checked on a running system using adb -k :

adb -k /dev/ksyms /dev/mem
parameter-name/D
^D
(to exit)

More information on kernel tuning is available in Sun's online documentation.

maxusers

maxusers is the most frequently tuned kernel parameter. Its original use (as an overall limit to the number of concurrent users on a system) is much less important than its role as a basis for calculating other kernel parameters.

The default value is set to either the number of MB of physical memory or MAX_DEFAULT_MAXUSERS, whichever is lower.

For Solaris 2.5.1-7, MAX_DEFAULT_MAXUSERS is 1024. For Solaris 8-10, MAX_DEFAULT_MAXUSERS is 2048.

maxusers can be set explicitly in the /etc/system file, but is limited to 2x MAX_DEFAULT_MAXUSERS.

Several key kernel parameters are set when maxusers is set unless explicitly overridden in the /etc/system file. Some of these formulas differ between different versions of Solaris:

  • max_nprocs: Number of processes = 10 + (16 x maxusers)
  • ufs_ninode: Inode cache size = (17xmaxusers)+90 (Solaris 2.5.1) or 4x(maxusers + max_nprocs)+320 (Solaris 2.6-8). See the Disk I/O page for more information.
  • ncsize: Name lookup cache size = (17xmaxusers)+90 (Solaris 2.5.1) or 4x(maxusers + max_nprocs)+320 (Solaris 2.6-8). See the Disk I/O page for more information.
  • ndquot: Quota table size = (maxusers x 10) + max_nprocs
  • maxuprc: User process limit = max_nprocs - 5

ptys

Solaris 8+ dynamically sizes the number of ptys available to a system, so you are less likely to run into pty starvation than was the case under Solaris 2.5.1-7. There are still hard system limits that are set based upon hardware configuration, and it may be necessary to increase the number of ptys manually as in Solaris 2.5.1-7.

If the system is suffering from pty starvation, the number of ptys available can be increased by increasing pt_cnt above the default of 48. Solaris 2.5.1 and 2.6 systems should not have pt_cnt set higher than 3844 due to limitations with the telnet and rlogin daemons. Solaris 7 does not have this restriction, but there may be other system issues that prevent setting pt_cnt arbitrarily high. Once pt_cnt is increased, a reconfiguration boot (boot -r) is required to build the ptys.

If pt_cnt is increased, some sources recommend that other variables be set at the same time. Other sources (such as the Solaris2 FAQ) suggest that this advice is spurious and results in a needless consumption of resources. See the notes below before making any of these changes; setting the values too high may result in wasted memory. In any case, one form of these recommendations is:

  • npty: Set to pt_cnt (see the note below)
  • nautopush: Set to twice the value of pt_cnt
  • sadcnt: Set to same value as pt_cnt

npty limits the number of BSD ptys. These are not usually used by applications, but may need to be increased on a system running a special service. In addition to setting npty in the /etc/system file, the /etc/iu.ap file will need to be edited to substitute the value npty-1 in the third field of the ptsl line. After both changes are made, a boot -r is required for the changes to take effect. Note that Solaris does not support any more than 176 BSD ptys in any case.

sadcnt sets the number of STREAMS addressable devices and nautopush sets the number of STREAMS autopush entries. nautopush should be set to twice sadcnt. Whether or not these values need to be increased as above depends on the types of activity on the system.

RAM Tuneables

See the Memory/Swapping page for a discussion of parameters related to RAM and paging.

Disk I/O Tuneables

See the Disk I/O page for a full discussion of disk I/O-related tuneables.

IPC Tuneables

Check the IPC Tuning page for InterProcess Communication-related resource parameters.

File Descriptors

See the File Descriptors page for more discussion regarding tuning issues.

File descriptors are retired when the file is closed or the process terminates. Opens always choose the lowest-numbered file descriptor available. Available file descriptors are allocated as follows:

  • rlim_fd_cur: If you are running old code, it is dangerous to set this value higher than 256 due to limitations with the stdio library. If programs require more file descriptors, they should use setrlimit directly.
  • rlim_fd_max: If you are running old code, it is dangerous to set this value higher than 1024 due to limitations with select(). If programs require more file descriptors, they should use setrlimit directly.

(The cautionary notes on both of these items become less important as applications are re-written to use poll() rather than select(), or are developed as native 64-bit applications. Any changes should be tested in a non-production environment before deployment. The Solaris2 FAQ includes a discussion of this issue.)

Misc Tuneables

  • dump_cnt: Size of dumps.
  • rstchown: Posix/restricted chown enabled (default=1)
  • ngroups_max: Maximum number of supplementary groups per user (default=32).

Friday, April 05, 2013

IPC Issues

Most of the InterProcess Communication parameters are reported by sysdef -i . Other parameters can be checked on a running system using adb -k :
adb -k /dev/ksyms /dev/mem
parameter-name/D
^D
(to exit)

In Solaris 10, control of the shared memory, semaphore and message queue parameters have been shifted to project-based resource controls. (See the project, prctl and getrctl man pages for detailed information.)

Many of the maximum parameter values discussed below represent 32-bit limits on integer size for Solaris 2.6 and 2.5.1. In Solaris 7+, these limits have been lifted somewhat. In theory, the maximums for Solaris 7+ would be in the 16 EB (exabytes) range rather than 2 GB (for Solaris 2.6 and 2.5.1). In practice, implementation details limit the range to something like 16 TB (terabytes). Due to the memory used by the kernel to set up space for the structures governed by these parameters, it is important to think about the useage of the resource before tuning it. In most cases, the 32-bit limits provide more than adequate head room for growth.

Shared memory, semaphores and message queues are only enabled if the appropriate kernel modules are loaded. These are automatically loaded if certain IPC functions are called, but they can also be forced to load via /etc/system forceload commands or root modload commands.

Each of these three facilities runs on top of the /kernel/misc/ipc module. Shared memory connects to the ipc module via /kernel/sys/shmsys, semaphores connect via /kernel/sys/semsys and message queues connect via /kernel/sys/msgsys.

For Solaris 2.5.1-9, the module names will need to be included when setting these parameters in the /etc/system file. For example:
set shmsys:parameter=value

Solaris 10 sets the parameters for these facilities via the project interface.

Other IPC mechanisms exist (such as named pipes), but they are not tuneable in the sense of this discussion.

Each IPC resource has at least these attributes: key (identifies this instance of the resource), creator (UID/GID of the creating process), owner (UID/GID of the resource owner), and permissions (similar to filesystem read/write/execute owner/group/other permissions).

Each object is created by calling the appropriate *get function ( shmget / semget / msgget ) with the desired key. If no objects of that type with that key exist, it is created and a resource ID is passed back to the caller.

Once created, the IPC objects can be controlled with the appropriate *ctl function ( shmctl / semctl / msgctl ).

The ipcs command presents information on IPC services that are currently loaded. It presents a "facility not in system" message if a given module has not been loaded yet.

Shared Memory

Shared memory provides the fastest way for processes to pass large amounts of data to one another. As the name implies, shared memory refers to physical pages of memory that are shared by more than one process.

Of particular interest is the "Intimate Shared Memory" facility, where the translation tables are shared as well as the memory. This enhances the effectiveness of the TLB (Translation Lookaside Buffer), which is a CPU-based cache of translation table information. Since the same information is used for several processes, available buffer space can be used much more efficiently. In addition, ISM-designated memory cannot be paged out, which can be used to keep frequently-used data and binaries in memory.

Database applications are the heaviest users of shared memory. Vendor recommendations should be consulted when tuning the shared memory parameters.

Solaris 10 only uses the shmmax and shmmni parameters. (Other parameters are set dynamically within the Solaris 10 IPC model.)

  • shmmax (max-shm-memory in Solaris 10+): This is the maximum size of a shared memory segment (ie the largest value that can be used by shmget). Its theoretical maximum value is 4294967295 (4GB), but practical considerations usually limit it to less than this. There is no reason not to tune this value as high as possible, since no kernel resources are allocated based on this parameter. Solaris 10 sets shmmax to 1/4 physical memory by default, vs 512k for previous versions.
  • shmmin: This is the smallest possible shared memory segment size. The default is 1 byte; this parameter should probably not be tuned.
  • shmmni (max-shm-ids in Solaris 10+): Maximum number of shared memory identifiers at any given time. This parameter is used by kernel memory allocation to determine how much size to put aside for shmid_ds structures. Each of these is 112 bytes and requires an additional 8 bytes for a mutex lock; if it is set too high, memory useage can be a problem. The maximum setting for this variable in Solaris 2.5.1 and 2.6 is 2147483648 (2GB), and the default is 100. For Solaris 10, the default is 128 and the maximum is MAXINT.
  • shmseg: Maximum number of segments per process. It is usually set to shmmni, but it should always be less than 65535. Sun documentations suggests a maximum for this parameter of 32767 and a default of 8 for Solaris 2.5.1 and 2.6.

Semaphores

Semaphores are a shareable resource that take on a non-negative integer value. They are manipulted by the P (wait) and V (signal) functions, which decrement and increment the semaphore, respectively. When a process needs a resource, a "wait" is issued and the semaphore is decremented. When the semaphore contains a value of zero, the resources are not available and the calling process spins or blocks (as appropriate) until resources are available. When a process releases a resource controlled by a semaphore, it increments the semaphore and the waiting processes are notified.

Solaris 10 only uses the semmni, semmsl and semopm parameters. (Other parameters are dynamic within the Solaris 10 IPC model.)

  • semmap: This sets the number of entries in the semaphore map. This should never be greater than semmni. If the number of semaphores per semaphore set used by the application is "n" then set
    semmap = ((semmni + n - 1)/n)+1
    or more. Alternatively, we can set semmap to semmni x semmsl. An undersized semmap leads to "WARNING: rmfree map overflow" errors. The default setting is 10; the maximum for Solaris 2.6 is 2GB. The default for Solaris 9 was 25; Solaris 10 increased the default to 512. The limit is SHRT_MAX.
  • semmni (max-sem-ids in Solaris 10+): Maximum number of systemwide semaphore sets. Each control structure consumes 84 bytes. For Solaris 2.5.1-9, the default setting is 10; for Solaris 10, the default setting is 128. The maximum is 65535
  • semmns: Maximum number of semaphores in the system. Each structure uses 16 bytes. This parameter should be set to semmni x semmsl. The default is 60; the maximum is 2GB.
  • semmnu: Maximum number of undo structures in the system. This should be set to semmni so that each control structure has an undo structure. The default is 30, the maximum is 2 GB.
  • semmsl (max-sem-nsems in Solaris 10+): Maximum number of semaphores per semaphore set. The default is 25, the maximum is 65535.
  • semopm (max-sem-ops in Solaris 10+): Maximum number of semaphore operations that can be performed in each semop call. The default in Solaris 2.5.1-9 is 10, the maximum is 2 GB. Solaris 10 increased the default to 512.
  • semume: Maximum number of undo structures per process. This should be set to semopm times the number of processes that will be using semaphores at any one time. The default is 10; the maximum is 2 GB.
  • semusz: Number of bytes required for semume undo structures. This should not be tuned; it is set to semume x (1 + sizeof(undo)). The default is 96; the maximum is 2 GB.
  • semvmx: Maximum value of a semaphore. This should never exceed 32767 (default value) unless SEM_UNDO is never used. The default is 32767; the maximum is 65535.
  • semaem: Maximum adjust-on-exit value. This should almost always be left alone. The default is 16384; the maximum is 32767.

Message Queues

Unix uses message queues for asynchronous message passing between processes. Each message has a type field, which can be used for priority messaging or directing a message to a chosen recipient.

Message queues are implemented as FIFO (first-in first-out) mechanisms. They consist of a header pointing to a linked list.

Solaris 2.5.1 and before used very coarse-grained mutex locking for message queues, which resulted in uneccessary contention as compared to 2.6 and later versions.

Solaris 10 only uses the msgmni, msgmnb and msgtql parameters. (Other parameters are dynamic within the Solaris 10 IPC model.)

  • msgmap: Number of entries in the msg map. The default is 100, the maximum is 2 GB.
  • msgmax: Maximum size of a message. The default is 2048; the maximum is 2 GB. Shared memory should be considered for moving large messages between processes; it is much more efficient for large data transfers.
  • msgmnb (max-msg-qbytes in Solaris 10+): Maximum number of bytes for the message queue. Te default is 4096; the maximum is 2 GB. The default in Solaris 10 was increased to 65536 and the maximum increased to ULONG_MAX.
  • msgmni (max-msg-ids in Solaris 10+): Number of unique message queue identifiers. The default is 50; the maximum is 2 GB. The default in Solaris 10 has been increased to 128. This should be set to 10% above the sum of the recommendations for applications on the system. Kernel resources are allocated based upon this parameter, so it should not be sized arbitrarily large.
  • msgssz: Message segment size. The default is 8; the maximum is 2 GB.
  • msgtql (max-msg-messages in Solaris 10+): Number of message headers. The default is 40; the maximum is 2 GB. Solaris 10 increased the default to 8192 and the maximum to UINT_MAX
  • msgseg: Number of message segments. The default is 1024; the maximum is 32 KB.

Solaris 10+ IPC Resource Management

The Solaris 10 IPC resource management framework was designed to overcome several shortcomings of the older SVR4-based system. Several parameters were converted to be dynamically resized, the defaults were increased, the names were changed to be more human-readable, the resource limits were system-wide (permitting potential conflicts) and reboots were required for even minor changes.

The Solaris 10 system allows changes to be associated with a project and monitored via prctl.

Additional information about Solaris 10+ resource management can be found on the Resource Management web page or in Sun's System Administration Guide: Solaris Containers-Resource Management and Solaris Zones on the Sun Documentation Web Site.

For the purposes of IPC resource management, the following are the important parameters:

  • project.max-shm-ids: Maximum shared memory IDs for a project. Replaces shmmni
  • project.max-sem-ids: Maximum semaphore IDs for a project. Replaces semmni
  • project.max-msg-ids: Maximum message queue IDs for a project. Replaces msgmni
  • project.max-shm-memory: Total amount of shared memory allowed for a project. Replaces shmmax
  • process.max-sem-nsems: Maximum number of semaphores allowed per semaphore set. Replaces semmsl
  • process.max-sem-ops: Maximum number of semaphore operations allowed per semop. Replaces semopm
  • process.max-msg-qbytes: Maximum number of bytes of messages on a message queue. Replaces msgmnb
  • process.max-msg-messages: Maximum number of messages on a message queue. Replaces msgtql