HP OpenVMS Systems Documentation

Content starts here

OpenVMS Programming Concepts Manual

Previous Contents Index

12.3.6 Process Swapping

The operating system balances the needs of all the processes currently executing, providing each with the system resources it requires on an as-needed basis. The memory management routines balance the memory requirements of the process. Thus, the sum of the working sets for all processes currently in physical memory is called the balance set.

When a process whose working set is in memory becomes inactive---for example, to wait for an I/O request or to hibernate---the entire working set or part of it may be removed from memory to provide space for another process's working set to be brought in for execution. This removal from memory is called swapping.

The working set may be removed in two ways:

  • Partially---Also called swapper trimming. Pages are removed from the working set of the target process so that the number of pages in the working set is fewer, but the working set is not swapped.
  • Entirely---Called swapping. All pages are swapped out of memory.

When a process is swapped out of the balance set, all the pages (both modified and unmodified) of its working set are swapped, including any pages that had been locked in the working set.

A privileged process may lock itself in the balance set. While pages can still be paged in and out of the working set, the process remains in memory even when it is inactive. To lock itself in the balance set, the process issues the Set Process Swap Mode (SYS$SETSWM) system service, as follows:


This call to SYS$SETSWM disables process swap mode. You can also disable swap mode by setting the appropriate bit in the STSFLG argument to the Create Process (SYS$CREPRC) system service; however, you need the PSWAPM privilege to alter process swap mode.

A process can also lock particular pages in memory with the Lock Pages in Memory (SYS$LCKPAG) system service. These pages are forced into the process's working set if they are not already there. When pages are locked in memory with this service, the pages remain in memory even when the remainder of the process's working set is swapped out of the balance set. These remaining pages stay in memory until they are unlocked with SYS$ULKPAG. The SYS$LCKPAG system service can be useful in special circumstances, for example, for routines that perform I/O operations to devices without using the operating system's I/O system.

You need the PSWAPM privilege to issue the SYS$LCKPAG or SYS$ULKPAG system service.

12.3.7 Sections

A section is a disk file or a portion of a disk file containing data or instructions that can be brought into memory and made available to a process for manipulation and execution. A section can also be one or more consecutive page frames in physical memory or I/O space; such sections, which require you to specify page frame number (PFN) mapping, are discussed in Chapter 13, Section

Sections are either private or global (shared).

  • Private sections are accessible only by the process that creates them. A process can define a disk data file as a section, map it into its virtual address space, and manipulate it.
  • Global sections can be shared by more than one process. One copy of the global section resides in physical memory, and each process sharing it refers to the same copy, except for copy-on-reference sections. For a copy-on-reference section, each process refers to the same global section, but each process gets its own copy of each page upon reference. A global section can contain shareable code or data that can be read, or read and written, by more than one process. Global sections are either temporary or permanent and can be defined for use within a group or on a systemwide basis. Global sections can be mapped to a disk file or created as a global page-file section, or they can be a PFN mapped section.

When modified pages in writable disk file sections are paged out of memory during image execution, they are written back into the section file rather than into the paging file, as is the normal case with files. (However, copy-on-reference sections are not written back into the section file.)

The use of disk file sections involves these two distinct operations:

  1. The creation of a section defines a disk file as a section and informs the system what portions of the file contain the section.
  2. The mapping of a section makes it available to a process and establishes the correspondence between virtual blocks in the file and specific addresses in the virtual address space of a process.

The Create and Map Section (SYS$CRMPSC) system service creates and maps a private section or a global section. Because a private section is used only by a single process, creation and mapping are simultaneous operations. In the case of a global section, one process can create a permanent global section and not map to it; other processes can map to it. A process can also create and map a global section in one operation.

The following sections describe the creation, mapping, and use of disk file sections. In each case, operations and requirements that are common to both private sections and global sections are described first, followed by additional notes and requirements for the use of global sections. Section discusses global page-file sections. Creating Sections

To create a disk file section, you must follow these steps:

  1. Open or create the disk file containing the section.
  2. Define which virtual blocks in the file comprise the section.
  3. Define the characteristics of the section. Opening the Disk File

Before you can use a file as a section, you must open it using OpenVMS RMS. The following example shows the OpenVMS RMS file access block ($FAB) and $OPEN macros used to open the file and the channel specification to the SYS$CRMPSC system service necessary for reading an existing file:

SECFAB: $FAB    FNM=<SECTION.TST>, ; File access block
                RTV= -1
        $OPEN   FAB=SECFAB
        $CRMPSC_S -

The file options parameter (FOP) indicates that the file is to be opened for user I/O; this option is required so that OpenVMS RMS assigns the channel using the access mode of the caller. OpenVMS RMS returns the channel number on which the file is accessed; this channel number is specified as input to the SYS$CRMPSC system service (chan argument). The same channel number can be used for multiple create and map section operations.

The option RTV= -1 tells the file system to keep all of the pointers to be mapped in memory at all times. If this option is omitted, the SYS$CRMPSC service requests the file system to expand the pointer areas if necessary. Storage for these pointers is charged to the BYTLM quota, which means that opening a badly fragmented file can fail with an EXBYTLM failure status. Too many fragmented sections may cause the byte limit to be exceeded.

The file may be a new file that is to be created while it is in use as a section. In this case, use the $CREATE macro to open the file. If you are creating a new file, the file access block (FAB) for the file must specify an allocation quantity (ALQ parameter).

You can also use SYS$CREATE to open an existing file; if the file does not exist, it is created. The following example shows the required fields in the FAB for the conditional creation of a file:

                ALQ=4, -
                FOP=<UFO,CIF,CBT>, -

When the $CREATE macro is invoked, it creates the file GLOBAL.TST if the file does not currently exist. The CBT (contiguous best try) option requests that, if possible, the file be contiguous. Although section files are not required to be contiguous, better performance can result if they are. Defining the Section Extents

After the file is opened successfully, the SYS$CRMPSC system service can create a section from the entire file or from only certain portions of it. The following arguments to SYS$CRMPSC define the extents of the file that comprise the section:
  • pagcnt (page count). On Alpha systems, this argument is optional. It indicates the size of the space that will be mapped. The pagcnt argument is in units of page frames (PFNs) for a PFN-mapped section and in units of pagelets (512-byte blocks) for disk-backed sections, including page file sections.
    If pagcnt is not supplied, then the section size defaults either to the file size for a section being created and not mapped or to the minimum of the file size and the size specified by inadr for a section being created and mapped simultaneously. You can map only what you have access to. Once a starting point is established, you can map pagcnt more space as long as you do not exceed the total size of the item you are mapping, such as the remaining blocks of a file or the remaining space in a global section.
  • vbn (virtual block number). This argument is optional. It defines the number of the virtual block in the file that is the beginning of the section. If you do not specify this argument, the value 1 is passed (the first virtual block in the file is the beginning of the section). If you have specified physical page frame number (PFN) mapping, the vbn argument specifies the starting PFN. Defining the Section Characteristics

The flags argument to the SYS$CRMPSC system service defines the following section characteristics:

  • Whether it is a private section or a global section. The default is to create a private section.
  • How the pages of the section are to be treated when they are copied into physical memory or when a process refers to them. The pages in a section can be either or both of the following:
    • Read/write or read-only
    • Created as demand-zero pages or as copy-on-reference pages, depending on how the processes are going to use the section and whether the file contains any data (see Section
  • Whether the section is to be mapped to a disk file or to specific physical page frames (see Section

Table 12-3 shows the flag bits that must be set for specific characteristics on Alpha systems.

Table 12-3 Flag Bits to Set for Specific Section Characteristics on Alpha Systems
  Section to Be Created
Correct Flag
Private Global PFN
SEC$M_GBL 0 1 0 1
SEC$M_CRF Optional Optional 0 0
SEC$M_DZRO Optional Optional 0 0
SEC$M_WRT Optional Optional Optional Optional
SEC$M_PERM Not used Optional Not used 1
SEC$M_SYSGBL Not used Optional Not used Optional
SEC$M_PFNMAP 0 0 1 1
SEC$M_EXPREG Optional Optional Optional Optional
SEC$M_PAGFIL 0 Optional 0 0

When you specify section characteristics, the following restrictions apply:

  • Global sections cannot be both demand-zero and copy-on-reference.
  • Demand-zero sections must be writable. Defining Global Section Characteristics

If the section is a global section, you must assign a character string name (gsdnam argument) to it so that other processes can identify it when they map it. The format of this character string name is explained in Section

The flags argument specifies the following types of global section:

  • Group temporary (the default)
  • Group permanent
  • System temporary
  • System permanent

Group global sections can be shared only by processes executing with the same group number. The name of a group global section is implicitly qualified by the group number of the process that created it. When other processes map it, their group numbers must match.

A temporary global section is automatically deleted when no processes are mapped to it, but a permanent global section remains in existence even when no processes are mapped to it. A permanent global section must be explicitly marked for deletion with the Delete Global Section (SYS$DGBLSC) system service.

You need the user privileges PRMGBL and SYSGBL to create permanent group global sections or system global sections (temporary or permanent), respectively.

A system global section is available to all processes in the system.

Optionally, a process creating a global section can specify a protection mask (prot argument) to restrict all access or a type of access (read, write, execute, delete) to other processes. Global Section Name

The gsdnam argument specifies a descriptor that points to a character string.

Translation of the gsdnam argument proceeds in the following manner:

  1. The current name string is prefixed with GBL$ and the result is subject to logical name translation.
  2. If the result is a logical name, step 1 is repeated until translation does not succeed or until the number of translations performed exceeds the number specified by the system parameter LNM$C_MAXDEPTH.
  3. The GBL$ prefix is stripped from the current name string that could not be translated. This current string is the global section name.

For example, assume that you have made the following logical name assignment:


Your program contains the following statements:

#include <descrip.h>
    status = sys$crmpsc(&gsdnam, ...);

The following logical name translation takes place:

  1. GBL$ is prefixed to GSDATA.
  2. GBL$GSDATA is translated to GSDATA_001. (Further translation is not successful. When logical name translation fails, the string is passed to the service.)

There are three exceptions to the logical name translation method discussed in this section:

  • If the name string starts with an underscore (_), the operating system strips the underscore and considers the resultant string to be the actual name (that is, further translation is not performed).
  • If the name string is the result of a logical name translation, then the name string is checked to see if it has the terminal attribute. If the name string is marked with the terminal attribute, the operating system considers the resultant string to be the actual name (that is, further translation is not performed).
  • If the global section has a name in the format name_nnn, the operating system first strips the underscore and the digits (nnn), then translates the resultant name according to the sequence discussed in this section, and finally reappends the underscore and digits. The system uses this method in conjunction with known images and shared files installed by the system manager. Mapping Sections

When you call the SYS$CRMPSC system service to create or map a section, or both, you must provide the service with a range of virtual addresses (inadr argument) into which the section is to be mapped.

On Alpha systems, the inadr argument specifies the size and location of the section by its start and end addresses. SYS$CRMPSC interprets the inadr argument in the following ways:

  • If both addresses specified in the inadr argument are the same and the SEC$M_EXPREG bit is set in the flags argument, SYS$CRMPSC allocates the memory in whichever program region the addresses fall but does not use the specified location.
  • If both addresses are different, SYS$CRMPSC maps the section into memory using the boundaries specified.

On Alpha systems, if you know specifically which pages the section should be mapped into, you provide these addresses in a 2-longword array. For example, to map a private section of 10 pages into virtual pages 10 through 19 of the program region, specify the input address array as follows:

    unsigned int maprange[1]; /* Assume page size = 8 KB */

    maprange[0] = 0x14000;    /* Address (hex) of page 10 */
    maprange[1] = 0x27FFF;    /* Address (hex) of page 19 */

On Alpha systems, the inadr argument range must have a lower address on an even page boundary and a higher address exactly one less than a page boundary. You do this to avoid programming errors that might arise because of incorrect programming assumptions about page sizes. For example, the range can be expressed as the following on an 8 KB page system:

0 ----> 1FFF
2000 ----> 7FFF
inadr[0] = first byte in range
inadr[1] = last byte in range

If the range is not expressed in terms of page-inclusive boundaries, then an SS$_INVARG condition value is returned.

You do not need to know the explicit addresses to provide an input address range. If you want the section mapped into the first available virtual address range in the program region (P0) or control region (P1), you can specify the SEC$M_EXPREG flag bit in the flags argument. In this case, the addresses specified by the inadr argument control whether the service finds the first available space in the P0 or P1. The value specified or defaulted for the pagcnt argument determines the amount of space mapped.

On Alpha systems, the relpag argument specifies the location in the section file at which you want mapping to begin.

On Alpha systems, the SYS$CRMPSC and SYS$MGBLSC system services map a minimum of one CPU-specific page. If the section file does not fill a single page, the remainder of the page is filled with zeros after faulting the page into memory. The extra space on the page should not be used by your application because only the data that fits into the section file will be written back to the disk.

The following example shows part of a program used to map a section at the current end of the program region:

    unsigned int status, inadr[1], retadr[1], flags;

    This range used merely to indicate P0 space since SEC$M_EXPREG
       is specified
    inadr[0]= 0x200; /* Any program (P0) region address */
    inadr[1]= 0x200; /* Any P0 address (can be same) */

/* Address range returned in retadr */

    flags = SEC$M_EXPREG;
    status = sys$crmpsc(&inadr, &retadr, flags, ...);

The addresses specified do not have to be currently in the virtual address space of the process. The SYS$CRMPSC system service creates the required virtual address space during the mapping of the section. If you specify the retadr argument, the service returns the range of addresses actually mapped.

On Alpha systems, the starting retadr address should match inadr, plus relpag if specified. The ending (higher) address will be limited by the lower of:

  • The value of the pagcnt argument
  • The actual remaining block count in the file starting with specified starting vbn, or relpag
  • The bound dictated by the inadr argument

After a section is mapped successfully, the image can refer to the pages using one of the following:

  • A base register or pointer and predefined symbolic offset names
  • Labels defining offsets of an absolute program section or structure

The following example shows part of a program used to create and map a process section on Alpha systems:

                FOP=UFO, -
                FAC=PUT, -
        .LONG   ^X14000                  ; First 8 KB page
        .LONG   ^X27FFF                  ; Last page
        .BLKL   1                       ; First page mapped
        .BLKL   1                       ; Last page mapped
        $OPEN   FAB=SECFAB              ; Open section file
        BLBS    R0,10$
        BSBW    ERROR

10$:    $CRMPSC_S -
                INADR=MAPRANGE,-        ; Input address array
                RETADR=RETRANGE,-       ; Output array
                PAGCNT=#4,-             ; Map four pagelets
                FLAGS=#SEC$M_WRT,-      ; Read/write section
                CHAN=SECFAB+FAB$L_STV   ; Channel number
        BLBS    R0,20$
        BSBW    ERROR
20$:    MOVL    RETRANGE,R6             ; Point to start of section

Notes on Example

  1. The OPEN macro opens the section file defined in the file access block SECFAB. (The FOP parameter to the $FAB macro must specify the UFO option.)
  2. The SYS$CRMPSC system service uses the addresses specified at MAPRANGE to specify an input range of addresses into which the section will be mapped. The pagcnt argument requests that only 4 pagelets of the file be mapped.
  3. The flags argument requests that the pages in the section have read/write access. The symbolic flag definitions for this argument are defined in the $SECDEF macro. Note that the file access field (FAC parameter) in the FAB also indicates that the file is to be opened for writing.
  4. When SYS$CRMPSC completes, the addresses of the 4 pagelets that were mapped are returned in the output address array at RETRANGE. The address of the beginning of the section is placed in register 6, which serves as a pointer to the section.

Previous Next Contents Index