HP OpenVMS Systems Documentation

OpenVMS Programming Concepts Manual

Page-file sections are used to store temporary data in private or
global (shared) sections of memory. In releases prior to OpenVMS Alpha
Version 7.3, the maximum amount of data that could be backed up to page
files was 32 GB per process (4 process page files, each 8 GB) and 504
GB per system (63 page files, each 8 GB).

With OpenVMS Alpha Version 7.3, the previous limits for page-file
sections were extended significantly to take advantage of larger
physical memory. Now images that use 64-bit addressing can map and
access an amount of dynamic virtual memory that is larger than the
amount of physical memory available on the system.

With this design, if a process requires additional page-file space,
page files can be allocated dynamically. Space is no longer reserved in
a distinct page file, and pages are no longer bound to an initially
assigned page file. Instead, if modified pages must be written back,
they are written to the best available page file.

Each page or swap file can hold approximately 16 million pages (128
GB), and up to 254 page or swap files can be installed. Files larger
than 128 GB are installed as multiple files.

Note the following DCL command display changes and system parameter
changes as a result of the larger page-file section design:

The SHOW MEMORY/FILES display reflects the nonreservable design.
For example:

Number of swap files. Begins with an index
value of 1 and increases in count.

Number of page files. Begins with an index
value of 254 and decreases in count.

Total committed page file usage. As in
previous releases, more pages can reside in page-file sections
systemwide than would fit into installed page files.

The SHOW MEMORY/FILES/FULL display no longer contains separate
usage information for page and swap files. Because page-file
information is no longer reserved, the system does not need to maintain
the number of processes interested in a distinct page or swap file. For
example:

To facilitate memory protection and mapping, the virtual addresss space
on VAX systems is subdivided into segments of 512-byte sizes called
pages. (On Alpha systems, memory page sizes are much
larger and vary from system to system. See Chapter 12 for
information about Alpha page sizes.) Versions of system services and
run-time library routines that accept page-count values as arguments
interpret these arguments in 512-byte quantities. Services and routines
automatically round the specified addresses to page boundaries.

The initial size of a process's virtual address space depends on the
size of the image being executed. The virtual address space of an
executing program consists of the following three regions:

Process program region (P0) The process program region is also
referred to as P0 space. P0 space contains the instructions and data
for the current image. Your program can dynamically allocate
storage in the process program region by calling run-time library (RTL)
dynamic memory allocation routines or system services.

Process control region (P1) The process control region is also
referred to as P1 space. P1 space contains system control information
and the user-mode process stack. The user mode stack expands as
necessary toward the lower-addressed end of P1 space.

Common system region (S0) The common system region is also
referred to as S0 space. S0 space contains the operating system. Your
program cannot allocate or free memory within the common system region
from the user access mode. This common system region (S0) of system
virtual address space can have appended to it additional virtual
address space, known as a reserved region, or S1 space, that creates a
single region of system space. As a result, the system virtual address
space increases from 1 GB to 2 GB.

The memory management routines map and control the relationship between
physical memory and the virtual address space of a process. These
activities are, for the most part, transparent to you and your
programs. In some cases, however, you can make a program more efficient
by explicitly controlling its virtual memory usage.

The maximum size to which a process can increase its address space is
controlled by the system parameter VIRTUALPAGECNT.

Using memory management system services, a process can add a specified
number of pages to the end of either the program region or the control
region. Adding pages to the program region provides the process with
additional space for image execution, for example, for the dynamic
creation of tables or data areas. Adding pages to the control region
increases the size of the user stack. As new pages are referenced, the
stack is automatically expanded, as shown in Figure 13-2. (By using
the STACK= option in a linker options file, you can also expand the
user stack when you link the image.)

Figure 13-2 illustrates the layout of a process's virtual memory. The
initial size of a process's virtual address space depends on the size
of the image being executed.

Extended physical addressing increases the size of a physical address
from 30 bits to 32 bits. This increases the capacity for physical
memory from 512 MB to 3.5 GB as shown in Figure 13-3. The 512 MB is
still reserved for I/O and adapter space.

Figure 13-3 Physical Address Space for VAX Systems with
XPA

Extended virtual addressing (XVA) increases the size of the virtual
page number field in the format of a system space address from 21 bits
to 22 bits. The region of system virtual address space, known as the
reserved region or S1 space, is appended to the existing region of
system virtual address space known as S0 space, thereby creating a
single region of system space. As a result, the system virtual address
space increases from 1 GB to 2 GB as shown in Figure 13-4.

As shown in Figure 13-3, extended addressing increases the maximum
physical address space supported by VAX systems from 1 GB to 4 GB. This
is accomplished by expanding the page frame number (PFN) field in a
page table entry (PTE) from 21 bits to 23 bits, and implementing
changes in the memory management arrays that are indexed by PFN. Both
the process page table entry and system page table entry are changed.

Sophisticated software systems must often create and manage complex
data structures. In these systems, the size and number of elements are
not always known in advance. You can tailor the memory allocation for
these elements by using dynamic memory allocation. By
managing the memory allocation, you can avoid allocating fixed tables
that may be too large or too small for your program. Managing memory
directly can improve program efficiency. By allowing you to allocate
specific amounts of memory, the operating system provides a hierarchy
of routines and services for memory management. Memory allocation and
deallocation routines allow you to allocate and free storage within the
virtual address space available to your process.

There are three levels of memory allocation routines:

Memory management system services
The memory management system services comprise the lowest level of
memory allocation routines. These services include, but are not limited
to, the following:

For most cases in which a system service is used for memory
allocation, the Expand Region (SYS$EXPREG) system service is used to
create pages of virtual memory. Because system services provide
more control over allocation procedures than RTL routines, you must
manage the allocation precisely. System services provide extensive
control over address space allocation by allowing you to do the
following types of tasks:

Add or delete virtual address space to the process program region
(P0) or process control region (P1)

Add or delete virtual address space at a specific range of addresses

Increase or decrease the number of pages in a program's working set

Lock or delete pages of a program's working set in memory

Lock the entire program's working set in memory (by disabling
process swapping)

Define disk files containing data or shareable images and map the
files into the virtual address space of a process

RTL page management routines RTL routines are available for
creating, deleting, and accessing information about virtual address
space. You can either allocate a specified number of contiguous pages
or create a zone of virtual address space. A zone is a
logical unit of the memory pool or subheap that you can control as an
independent area. It can be any size required by your program. Refer to
Chapter 14 for more information about zones. The RTL page
management routines LIB$GET_VM_PAGE and LIB$FREE_VM_PAGE provide a
convenient mechanism for allocating and freeing pages of memory.
These routines maintain a processwide pool of free pages. If
unallocated pages are not available when LIB$GET_VM_PAGE is called, it
calls SYS$EXPREG to create the required pages in the program region (P0
space).

RTL heap management routines The RTL heap management routines
LIB$GET_VM and LIB$FREE_VM provide a mechanism for allocating and
freeing blocks of memory of arbitrary size.
The following are heap management routines based on the concept of
zones:

If an unallocated block is not available to satisfy a call to
LIB$GET_VM, LIB$GET_VM calls LIB$GET_VM_PAGE to allocate additional
pages.

Modular application programs can call routines at any or all levels of
the hierarchy, depending on the kinds of services the application
program needs. You must observe the following basic rule when using
multiple levels of the hierarchy:

Memory that is allocated by an allocation routine at one level of the
hierarchy must be freed by calling a deallocation routine at the same
level of the hierarchy. For example, if you allocated a page of memory
by calling LIB$GET_VM_PAGE, you can free it only by calling
LIB$FREE_VM_PAGE.

The system services allow you to add address space anywhere within the
process's program region (P0) or control region (P1). To add address
space at the end of P0 or P1, use the Expand Program/Control Region
(SYS$EXPREG) system service. SYS$EXPREG optionally returns the range of
virtual addresses for the new pages. To add address space in other
portions of P0 or P1, use SYS$CRETVA.

The value 0 is passed in the region argument to
specify that the pages are to be added to the program region. To add
the same number of pages to the control region, you would specify
REGION=#1.

Note that the region argument to SYS$EXPREG is
optional; if it is not specified, the pages are added to or deleted
from the program region by default.

The SYS$EXPREG service can add pages only to the end of a particular
region. When you need to add pages to the middle of these regions, you
can use the Create Virtual Address Space (SYS$CRETVA) system service.
Likewise, when you need to delete pages created by either SYS$EXPREG or
SYS$CRETVA, you can use the Delete Virtual Address Space (SYS$DELTVA)
system service. For example, if you have used the SYS$EXPREG service
twice to add pages to the program region and want to delete the first
range of pages but not the second, you could use the SYS$DELTVA system
service, as shown in the following example:

In this example, the first call to SYS$EXPREG adds 4 pages to the
program region; the virtual addresses of the created pages are returned
in the 2-longword array at retadr1. The second call adds 3 pages and
returns the addresses at retadr2. The call to SYS$DELTVA deletes the
first 4 pages that were added.

Caution

Be aware that using SYS$CRETVA presents some risk because it can delete
pages that already exist if those pages are not owned by a more
privileged access mode. Further, if those pages are deleted, no
notification is sent. Therefore, unless you have complete control over
an entire system, use SYS$EXPREG or the RTL routines to allocate
address space.

When the SYS$EXPREG system service adds pages to a region, it adds them
in the normal direction of growth for the region. The return address
array, if requested, indicates the order in which the pages were added.
For example:

If the program region is expanded, the starting virtual address is
smaller than the ending virtual address.

If the control region is expanded, the starting virtual address is
larger than the ending virtual address.

The addresses returned indicate the first byte in the first page that
was added or deleted and the last byte in the last page that was added
or deleted.

When input address arrays are specified for the Create and Delete
Virtual Address Space (SYS$CRETVA and SYS$DELTVA, respectively) system
services, these services add or delete pages beginning with the address
specified in the first longword and ending with the address specified
in the second longword.

Note

The operating system always adjusts the starting and ending virtual
addresses up or down to fit page boundaries.

The order in which the pages are added or deleted does not have to be
in the normal direction of growth for the region. Moreover, because
these services add or delete only whole pages, they ignore the
low-order 9 bits of the specified virtual address (the low-order 9 bits
contain the byte offset within the page). The virtual addresses
returned indicate the byte offsets.

Table 13-1 shows some sample virtual addresses in hexadecimal that
may be specified as input to SYS$CRETVA or SYS$DELTVA and shows the
return address arrays if all pages are successfully added or deleted.

Note that if the input virtual addresses are the same, as in the fourth
and fifth items in Table 13-1, a single page is added or deleted.
The return address array indicates that the page was added or deleted
in the normal direction of growth for the region.