MEMCNTL(2) | System Calls | MEMCNTL(2) |
memcntl
— memory
management control
#include
<sys/types.h>
#include <sys/mman.h>
int
memcntl
(void *addr,
size_t len, int cmd,
void *arg, int attr,
int mask);
The
memcntl
()
function allows the calling process to apply a variety of control operations
over the address space identified by the mappings established for the
address range [ addr, addr +
len ).
The addr argument must be a multiple of the pagesize as returned by sysconf(3C). The scope of the control operations can be further defined with additional selection criteria (in the form of attributes) according to the bit pattern contained in attr.
The following attributes specify page mapping selection criteria:
MEMCNTL_SHARED
MEMCNTL_PRIVATE
The following attributes specify page protection selection criteria. The selection criteria are constructed by a bitwise OR operation on the attribute bits and must match exactly.
PROT_READ
PROT_WRITE
PROT_EXEC
The following criteria may also be specified:
The PROC_TEXT
attribute specifies all
privately mapped segments with read and execute permission, and the
PROC_DATA
attribute specifies all privately mapped
segments with write permission.
Selection criteria can be used to describe various abstract memory objects within the address space on which to operate. If an operation shall not be constrained by the selection criteria, attr must have the value 0.
The operation to be performed is identified by the argument
cmd. The symbolic names for the operations are defined
in <sys/mman.h>
as
follows:
MC_LOCK
MAP_PRIVATE
page in the address range is changed,
the lock will be transferred to the private page.
The arg argument is not used, but must
be NULL
to ensure compatibility with potential
future enhancements.
MC_LOCKAS
NULL
and 0 respectively, to
ensure compatibility with potential future enhancements. The
arg argument is a bit pattern built from the flags:
MCL_CURRENT
MCL_FUTURE
The value of arg determines whether the
pages to be locked are those currently mapped by the address space,
those that will be mapped in the future, or both. If
MCL_FUTURE
is specified, then all mappings
subsequently added to the address space will be locked, provided
sufficient memory is available.
MC_SYNC
MAP_SHARED
mapping is the file the page is mapped
to; the backing storage for a modified MAP_PRIVATE
mapping is its swap area. The arg argument is a bit
pattern built from the flags used to control the behavior of the
operation:
MS_ASYNC
MS_SYNC
is also specified).MS_SYNC
MS_INVALIDATE
MC_UNLOCK
NULL
to ensure compatibility with potential future
enhancements.MC_UNLOCKAS
NULL
, 0, and NULL
,
respectively, to ensure compatibility with potential future
enhancements.MC_HAT_ADVISE
uint_t mha_cmd; uint_t mha_flags; size_t mha_pagesize;
The accepted values for mha_cmd are:
MHA_MAPSIZE_VA MHA_MAPSIZE_STACK MHA_MAPSIZE_BSSBRK
The mha_flags member is reserved for future use and must always be set to 0. The mha_pagesize member must be a valid size as obtained from getpagesizes(3C) or the constant value 0 to allow the system to choose an appropriate hardware address translation mapping size.
MHA_MAPSIZE_VA
sets the preferred
hardware address translation mapping size of the region of memory from
addr to addr +
len. Both addr and
len must be aligned to an
mha_pagesize boundary. The entire virtual address
region from addr to addr +
len must not have any holes. Permissions within
each mha_pagesize-aligned portion of the region
must be consistent. When a size of 0 is specified, the system selects an
appropriate size based on the size and alignment of the memory region,
type of processor, and other considerations.
MHA_MAPSIZE_STACK
sets the preferred
hardware address translation mapping size of the process main thread
stack segment. The addr and
len arguments must be NULL
and 0, respectively.
MHA_MAPSIZE_BSSBRK
sets the preferred
hardware address translation mapping size of the process heap. The
addr and len arguments must
be NULL
and 0, respectively. See the NOTES
section of the ppgsz(1) manual page
for additional information on process heap alignment.
The attr argument must be 0 for all
MC_HAT_ADVISE
operations.
The mask argument must be 0; it is reserved for future use.
Locks established with the lock operations are not
inherited by a child process after
fork(2). The
memcntl
()
function fails if it attempts to lock more memory than a system-specific
limit.
Due to the potential impact on system resources, the operations
MC_LOCKAS
, MC_LOCK
,
MC_UNLOCKAS
, and MC_UNLOCK
are restricted to privileged processes.
The
memcntl
()
function subsumes the operations of
plock(3C).
MC_HAT_ADVISE
is intended to improve
performance of applications that use large amounts of memory on processors
that support multiple hardware address translation mapping sizes; however,
it should be used with care. Not all processors support all sizes with equal
efficiency. Use of larger sizes may also introduce extra overhead that could
reduce performance or available memory. Using large sizes for one
application may reduce available resources for other applications and result
in slower system wide performance.
Upon successful completion, memcntl
()
returns 0. Otherwise, it returns
-1 and sets
errno to indicate an error.
The memcntl
() function will fail if:
EAGAIN
MC_LOCK
or
MC_LOCKAS
was specified, some or all mappings in
the address range [addr, addr
+ len) are locked for I/O when
MC_HAT_ADVISE
was specified, or the system has
insufficient resources when MC_HAT_ADVISE
was
specified.
The cmd is
MC_LOCK
or MC_LOCKAS
and
locking the memory identified by this operation would exceed a limit or
resource control on locked memory.
EBUSY
MC_SYNC with
the
MS_INVALIDATE
option was
specified.EINVAL
MC_LOCKAS
or
MC_UNLOCKAS
is specified; the
arg argument is not valid for the function
specified; mha_pagesize or
mha_cmd is invalid; or
MC_HAT_ADVISE
is specified and not all pages in
the specified region have the same access permissions within the given
size boundaries.ENOMEM
EPERM
PRIV_PROC_LOCK_MEMORY
} privilege is not
asserted in the effective set of the calling process and
MC_LOCK
, MC_LOCKAS
,
MC_UNLOCK
, or MC_UNLOCKAS
was specified.ppgsz(1), fork(2), mmap(2), mprotect(2), getpagesizes(3C), mlock(3C), mlockall(3C), msync(3C), plock(3C), sysconf(3C), attributes(7), privileges(7)
March 13, 2022 | OmniOS |