• Aucun résultat trouvé

Process-to-Page Mapping

When a process executes, various dynamic structures are used to locate the memory segments, translate them from virtual to physical addresses, and manipulate them to achieve the results desired. Figure 7-5 shows how these structures point from a process to its segment page mappings.

When a process executes, the kernel maintains a proc structure, a data structure for each active process. The proc structure points to a virtual address space, which forms the header of a doubly linked list of several

per-process regions, each corresponding to some element of the process (such as code, data, bss, shared memory). In turn, each per-process region points to a region, which points to page mappings of the code in physical memory.

Subsequent sections of this chapter describe the virtual address space and its related structures.

Process-oriented

System-oriented

per-process region (pregion)

region

page mapping

Figure 7-5. Simplification of an Active Process Executing in Main Memory.

7 -12 Memory Management

Pages

Pages are the smallest contiguous block of physical memory that can be allocated for storing data and processes. Pages are also the smallest unit of memory protection. As of the current release, the page size of all HP- UX systems is 4 KB.

A free page is a page of physical memory not mapped to a virtual address; that is, not currently being used by any process. A used page is mapped to a virtual address. The system keeps track of all free and used pages in physical memory.

Every physical page in the system is represented by an entry in the kernel's pfdat array data structure. A pfdat entry keeps information for the

hardware-independent code on page conditions such as a page's validity, the state of the page, and whether the page has been modified. Implementation of the actual page mapping is hardware dependent.

You can lock critical pages of processes in memory to prevent their being paged out by using the system call plock(2) as described in the HP- UX Reference; see

"Lockable Memory", earlier in this chapter.

Virtual Address Space

Virtual memory uses a structure for mapping processes termed the virtual address space, described in the kernel header structure

/usr/include/sys/vas .h. The virtual address space contains information and

pointers to the memory that the process can reference. 7 One virtual address space exists per process and serves several purposes:

• It provides the overall description of each process.

• It contains pointers to another element in the memory-management subsystem-per-process regions, or pregions.

• It keeps track of pregions most recently involved in page faults (explained in

"How the Kernel Executes Processes using Demand Paging").

• It contains pointers to page tables that enable the CPU to access physical addresses of data. (Series 300/400 only).

On HP- UX systems, the entire virtual-memory system can handle addresses of 32 bits, allowing processes a maximum virtual address space of 4 Gigabytes.

Memory Management 7-13

7

The Series 300/400 has a linear address space without base and offset. All memory is conceptually contiguous. Each process (including the kernel) shares the entire 232 (4 GB) address range.

On the Series 700/800, space registers hold either 16 bits (for 48-bit addressing) or 32 bits (for 64-bit addressing) and are used to point to the virtual space to be accessed. The specific location within that space is specified by a 32-bit quantity called the byte offset.

The present Series 700/800 48-bit addressing implementation can be thought of as having 216 32-bit spaces.

Configuring Virtual Address Space

Operating-system parameters limit the size of the code, data, stack, and shared-memory segments for each individual process. These parameters have predefined defaults, but you can reconfigure them in the kernel using the procedures outlined in the System Administration Tasks manual. The following list shows configurabl~ system parameters for code, data, stack, and shared

Limits the number of shared-memory identifiers.

Per-Process Regions (pregions)

The virtual address space structure points to per-process regions, or pregions.

Pregions are logical segments that point to specific segments of a process, including code (text, or process instructions), data, u_area and kernel stack, user stack, shared-memory segments, and shared-library code and data segments.

Pregions hold page protections and the number of pages mapped to each segment.

Each segment also corresponds to the segments of virtual address space illustrated in Figure 7-6, Figure 7-7, and Figure 7-8.

7-14 Memory Management

The text segment (or code segment) holds a process's executable object code and may be shared by multiple processes. The maximum size of the text (or code) segment can be changed by the configurable operating-system parameter maxtsiz.

The data segment contains a process's initialized and uninitialized data structures (bss). It can grow as needed by a program's run-time logic (using sbrk(2), malloc(3C), or malloc(3X), as described in the HP-UX Reference).

The total allotment for initialized data, uninitialized data and dynamically allocated memory can be changed by the configurable operating-system parameter maxds iz.

The u_area contains information about process characteristics. The kernel stack segment, which is in the u_area segment, contains a process's run-time stack during kernel mode. Both u_area and kernel stack segment are fixed in size.

The user stack segment contains a process's run-time stack during user mode.

The user stack expands during process execution; its default maximum size can be changed using the configurable operating-system parameter maxssiz.

Shared memory segments are typically used when multiple processes must share data (for example, in a windowing system, where all window processes must be able to update common data structures). They can be created using the shmop(2) system call (see specifications in the HP-UX Reference).

Each shared library segment typically has three pregions-code, initialized data, and bss.

110 mappings are the ranges of addresses the operating system uses to deal with I/O devices.

When a process executes, the memory management subsystem traverses the pregions to find pointers to another data structure, called a region, which points to the address of the desired page of code or data.

Per-Process Region Layouts

Per-process regions (pregions) represent the virtual address space in memory.

The layouts of the Series 300/400 and 700/800 virtual address space differ in specifics. This section shows the mappings of both Series 300/400 and Series 700/800.

Memory Management 7-15

7

7

Placement of Segments in Address Space (Series 300/400)

The segments of virtual address space for a process reside in virtual memory as shown in Figure 7-6. In the Series 300/400 memory design, the percentage and boundaries of memory address are not critical.

As a process is executed, the stack segments grow in the direction shown by the arrows in Figure 7-6. Segments are arranged to allow for ample memory allocation, to prevent overlap that would cause error (such as ENOMEM) and kill the process.

7-16 Memory Management

(high address) ,..-_ _ _ _ _ _ _ _ -".

oxFFFFFFFF kernel stack

---

u area

===

us; stack

]== }

maxssiz

---I/O mappings shared memory memory-mapped files

shared libraries

f---Figure 7-6. Series 300/400 User Process Virtual Address Space

Memory Management 7 -17

7

7

Placement of Segments in Address Space (Series 700/800)

In the Series 700/800, the virtual address space is divided into one-GB quadrants and addressed by units of 32 bits. Each quadrant has several segments associated with it, as shown in Figure 7-8 and explained on the next page.

The basic segments (quadrants) of the Series 700/800 can be described as follows:

• First one-GB quadrant always contains the process's code and sometimes some of the data.

Text is addressed from OxOOOOOOOO to Ox3FFFFFFF.

• Second quadrant contains data (static data, stack, and heap).

Data is addressed from Ox40000000 to Ox7FFFFFFF.

• Third quadrant, which is addressed from Ox80000000 to OxBFFFFFFF, is used somewhat differently on Series 700 and Series 800:

D On the Series 700, the third contains shared memory, shared mapped files, and shared library code.

D On the Series 800, the third quadrant contains memory-mapped segments (such as shared-library code).

• Fourth quadrant, which is addressed from OxCOOOOOOO to OxFFFFFFFF, contains shared-memory segments. On the Series 700, fourth quadrant also contains shared memory-mapped files and shared library code. On PA-RISC architecture (both Series 700 and 800), addresses from OxFOOOOOOO to OxFFFFFFFF are used for I/O space.

On the Series 700, an EXEC_MAGIC user executable (a. out) format allows data to start immediately after the code area in the first quadrant, instead of at the beginning of the second quadrant, and grow to the beginning of the user stack. Executables created with this format can handle more than 1 GB of data; refer to ld(l) in the HP-UX Reference Manual for information.

7 -18 Memory Management

(high address)

shared memory 4th quadrant shared memory-mapped

Series 700 User Process Virtual Address Space with EXEC_ MAGIC implemented.

Memory Management 7 -19

7

7

(high address)

OxFFFFFFFF OxEFFFFFFF

OxC0002000

OxBFFFFFFF

OxBOOOOOOO

maxssiZ{

maxdsiz{

Ox40000000

maxtsiz {

OxOOOOOOOO·

(low address)

I/O mappings

10---shared memory

r---

gateway page

shared library code shared memory-mapped

files

:== r-- __

~9J:!l~ user stack

]==

stack _ _ _ u area

I---}-1-__

ma"o~.Jheap)_ _

1---

initialized data bss

---code (text)

4th quadrant

3rd quadrant

2nd quadrant

1 st quadrant

Figure 7 -S. Series SOD User Process Virtual Address Space

7 -20 Memory Management

Regions

Regions are data structures unique to the file or chunk of memory being accessed. Regions represent ranges of addresses and inform the process about where the data exists in physical memory.

Each process segment's per-process region maps directly to a segment of memory in a region. Regions are associated with the system rather than a process.

In turn, the region points to two kernel lists, which keep track of pages of data.

A region might be private or shared. A private region (such as a process's data segment, u_area, or stack) has only one pregion pointing to it. A shared region (such as shared memory, code, graphics) can have more than one pregion point to it, because more than one process might be accessing the same segment of memory.

Virtual Nodes (vnodes)

A region usually references a virtual node (vnode), an interface for reading and writing pages of data between memory and disk. Vnodes are supersets of inodes that the MMU stores to keep track of swapped or paged memory while it is out on disk. Vnodes are categorized by file type-hfs, nfs, dux, cdfs, and swap-and are defined in the header file, vnode. h. Kernel routines read the stored file type when:

• Bringing requested and additional pages in from disk.

• Writing pages out to disk.

• Giving page information to the kernel for later computation.

• Duplicating page information for use by multiple processes.

Memory Management 7-21

7