Info

struct rlimit {

unsigned long rlim_cur; unsigned long rlim_max;

The definition is purposely kept very general so that it can accept many different resource types.

□ rlim_cur is the current resource limit for the process. It is also referred to as the soft limit.

□ rlim_max is the maximum allowed value for the limit. It is therefore also referred to as the hard limit.

The setrlimit system call is used to increase or decrease the current limit. However, the value specified in rlim_max may not be exceeded. getrlimits is used to check the current limit.

The limitable resources are identified by reference to their position in the rlim array, which is why the kernel defines pre-processor constants to associate resource and position. Table 2-1 lists the possible constants and their meanings. Textbooks on system programming provide detailed explanations on best use of the various limits in practice, and the manual page setrlimit(2) contains more detailed descriptions of all limits.

The numeric values differ between architectures because Linux tries to establish binary compatibility with the specific native Unix systems.

Because the limits relate to very different parts of the kernel, the kernel must check that the limits are observed in the corresponding subsystems. This is why we encounter rlimit time and time again in later chapters of this book.

If a resource type may be used without limits (the default setting for almost all resources), rlim_infinity is used as the value for rlim_max. Exceptions are, among others:

□ The number of open files (rlimit_nofile, limited to 1,024 by default).

□ The maximum number of processes per user (rlimit_nproc), defined as max_threads/2. max_threads is a global variable whose value specifies how many threads may be generated so that an eighth of available RAM is used only for management of thread information, given a minimum possible memory usage of 20 threads.

The boot-time limits for the init task are defined in INIT_RLIMITS in include/asm-generic-resource.h.

Notice that kernel 2.6.25, which was still under development when this book was written, will contain one file per process in the proc filesystem, which allows for inspecting the current rlimit values:

[email protected]> cat /proc/self/limits

Limit Soft Limit Hard Limit Units

Max

cpu time

unlimited

unlimited

ms

Max

file size

unlimited

unlimited

bytes

Max

data size

unlimited

unlimited

bytes

Max

stack size

8388608

unlimited

bytes

Max

core file size

0

unlimited

bytes

Max

resident set

unlimited

unlimited

bytes

Max

processes

unlimited

unlimited

processes

Max

open files

1024

1024

files

Max

locked memory

unlimited

unlimited

bytes

Max

address space

unlimited

unlimited

bytes

Max

file locks

unlimited

unlimited

locks

Max

pending signals

unlimited

unlimited

signals

Max

msgqueue size

unlimited

unlimited

bytes

Max

nice priority

0

0

Max

realtime priority

0

0

Max

realtime timeout

unlimited

unlimited

us

Table 2-1: Process-Specific Resource Limits.

Constant

Meaning

RLIMIT_CPU

Maximum CPU time in milliseconds.

RLIMIT_FSIZE

Maximum file size allowed.

RLIMIT_DATA

Maximum size of the data segment.

RLIMIT_STACK

Maximum size of the (user mode) stack.

RLIMIT_CORE

Maximum size for core dump files.

RLIMIT_RSS

Maximum size of the resident size set-, in other words, the maximum number of page frames that a process uses. Not used at the moment.

RLIMIT_NPROC

Maximum number of processes that the user associated with the real UID of a process may own.

RLIMIT_NOFILE

Maximum number of open files.

RLIMIT_MEMLOCK

Maximum number of non-swappable pages.

RLIMIT_AS

Maximum size of virtual address space that may be occupied by a process.

RLIMIT_LOCKS

Maximum number of file locks.

RLIMIT_SIGPENDING

Maximum number of pending signals.

RLIMIT_MSGQUEUE

Maximum number of message queues.

RLIMIT_NICE

Maximum nice level for non-real-time processes.

RLIMIT_RTPRIO

Maximum real-time priority.

Most of the code to generate the information is already present in kernel 2.6.24, but the final connection with /proc will only be made in the following kernel release.

Continue reading here: Process Types

Was this article helpful?

0 0