memadvise(2) — CX/UX
NAME
memadvise − region memory binding control
SYNOPSIS
#include <sys/resource.h>
int memadvise (cmd, which, who, flags)
int cmd, which, who, ∗flags;
DESCRIPTION
memadvise is used to perform two functions:
1. Control the binding of a process’s regions to or from local memory.
2. Control the cache modes of a process’s regions.
Binding to/from Local Memory Local memory is an architectural feature consisting of a pool of memory physically located on each CPU board. A local memory access by the corresponding CPU does not require access to the system bus, thus reducing bus contention in multiprocessor configurations. Note that the local memory pool to which a region is bound is always that of the CPU on which the process is currently executing.
Four (4) regions of the process’s address space may be individually or collectively loaded into a CPU’s local memory. They are:
Text Contains the executable instructions of the process. By default, the text region can be shared by multiple processes. Non-sharable text regions may be created when the program is linked by using the -N option to ld (1).
Data Contains the initialized and uninitialized (bss) data of the program. Data regions are not shared by multiple processes.
Stack Contains the user-mode stack of the process. Stack regions are not shared by multiple processes.
PCB Contains the process control block, kernel-mode stack and u-area of the process. These are not shared by multiple processes.
The binding of shared memory regions to local memory is controlled by shmget(2).
memadvise controls whether or not the text, data, stack, or PCB regions are to be bound into a CPU’s local memory, and what action should be taken if the specified regions will not "fit".
The binding of a region to local memory may be either "hard" or "soft". If a binding for a particular region is "hard", then the process will be aborted if pages cannot be allocated within local memory when needed. A "soft" binding allows pages to be allocated within global memory when pages are not available for allocation within local memory.
cmd is one of:
MA_SETLMEM Set the region flags of all the specified processes to flags.
MA_GETLMEM Return the logical sum of the current region flags of all the specified processes.
flags values are constructed by or-ing flags from the following list:
MA_TEXT_LOCAL If set, load the text region of the process into local memory.
MA_TEXT_HARD If set, the process is to be aborted if the text region will not fit into local memory. If reset, any pages that will not fit in local memory will be loaded into global memory.
MA_DATA_LOCAL If set, load the data region of the process into local memory.
MA_DATA_HARD If set, the process is to be aborted if the data region will not fit into local memory. If reset, any pages that will not fit in local memory will be loaded into global memory.
MA_STACK_LOCAL If set, load the user-mode stack region of the process into local memory.
MA_STACK_HARD If set, the process is to be aborted if the stack region will not fit into local memory. If reset, any pages that will not fit in local memory will be loaded into global memory.
MA_PCB_LOCAL If set, load the process control block (pcb), kernel-mode stack and process u-area for the process into local memory.
MA_PCB_HARD If set, the process is to be aborted if the pcb, kernel stack, or u-area will not fit into local memory. If reset, any pages that will not fit in local memory will be loaded into global memory.
The MA_x_HARD bit may be set only if the corresponding region’s (or pcb’s) MA_x_LOCAL bit is set.
Controlling Cache Modes Some architectures support both writethrough and copyback cache modes. In copyback mode, the number of writes to memory is reduced. This decreases memory bus traffic and reduces the latency of write transactions. In writethrough mode, all write transactions result in an actual write to memory.
While copyback mode yields higher performance, it suffers from cache coherency problems resulting from I/O dma transfers. To overcome these problems, the kernel may need to perform expensive cache operations which may impact interrupt and context switch latency.
This service allows some control over the cache modes used for the data and stack regions. By default, copyback mode will be used. However, if I/O is performed directly into these regions (via raw or direct I/O) then it is recommended that writethrough mode be used.
cmd is one of:
MA_SETCACHE Set the region cache flags of all the specified processes to flags.
MA_GETCACHE Return the logical sum of the current region cache flags of all the specified processes.
flags values are constructed by or-ing flags from the following list:
MA_DATA_CB If set, the data region will use copyback mode. If this bit is not set, then writethrough mode will be used.
MA_STACK_CB If set, the stack region will use copyback mode. If this bit is not set, then writethrough mode will be used.
MA_COPYBACK This is equivalent to MA_DATA_CB and MA_STACK_CB. Both the data and stack regions will use copyback mode.
MA_WRITETHROUGH No bits are set. Both the data and stack regions will use writethrough mode.
Parameters and Errors The following commands provide control over a process’s, process group’s, or user’s use of local memory. Which is one of
PRIO_PROCESSprocess id
PRIO_PGRPprocess group id
PRIO_USERuser id
and who is interpreted relative to which: a process identifier for PRIO_PROCESS, a process group identifier for PRIO_PGRP, and a user ID for PRIO_USER. A value of 0 for who refers to the calling process’s identifier, group identifier, or user ID.
memadvise will fail if any of the following are true:
[EINVAL] Which or cmd were not one of the values documented above.
[EINVAL] An invalid flags bit was set.
[EINVAL] A MA_x_HARD bit was set without the corresponding MA_x_LOCAL bit set.
[ESRCH] No process(es) were located using the which and who values specified.
[EACCESS] A process was located, but neither its effective nor real user ID matched the effective user ID of the caller.
[EACCESS] The caller tried to add or remove a local memory binding and its effective user ID is not the super-user.
[EFAULT] The address specified for flags is invalid.
RETURN VALUE
Upon successful completion, 0 is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
SEE ALSO
run(1), rerun(1).
fork(2), getpriority(2), getquantum(2), shmbind(2).
memory(7), cache(7).
CX/UX Programmer’s Reference Manual