Go to main content

man pages section 2: System Calls

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

mremap(2)

Name

mremap - re-map pages of memory

Synopsis

#include <sys/mman.h>

void *mremap(void *addr, size_t len, size_t newlen, int flags, ...
    /* void *newaddr */);

Description

The mremap() function re-maps a portion of a process's address space previously mapped using mmap().

pa = mremap(addr, len, newlen, flags, newaddr);

Using mremap(), a virtual memory segment can be expanded, shrunk, or moved to a new location in the address space of a process.

The mremap() function is supported only for mapped files and anonymous memory.

The flags argument provides information about how to handle the call. The value of the flags is the bitwise inclusive OR of one or more of the other flags in the following table, defined in the header sys/mman.h:

MREMAP_MAYMOVE

The kernel may move the existing mapping if there is not space to expand the mapping at its current location.

MREMAP_FIXED

Re-map addr starting at newaddr. If MREMAP_FIXED is not specified, the value of newaddr is ignored and need not be passed. Use of this flag requires that the MREMAP_MAYMOVE flag is also specified.

Return Values

Upon successful completion, the mremap() function returns the address at which the mapping was placed (pa); otherwise, it returns a value of MAP_FAILED and sets errno to indicate the error. The symbol MAP_FAILED is defined in the header <sys/mman.h>. No successful return from mremap() will return the value MAP_FAILED.

Errors

The mremap() function will fail if:

EAGAIN

The mapping could not be locked in memory.

There was insufficient room to reserve swap space for the mapping.

The flag is MAP_ADI and the memory identified by this operation would exceed a limit or resource control on ADI memory or the total amount of system memory is temporarily insufficient to allocate ADI metadata.

EEXIST

A mapping already exists that conflicts with the requested operation.

EFBIG

The mremap() system call returns EFBIG when it tries to map a section of a file at an offset equal or larger than 0x7fffffff from a NFSv2 filesystem.

EINVAL

The arguments addr (and newaddr if MREMAP_FIXED was specified) are not multiples of the page size as returned by sysconf().

The arguments len or newlen are not multiples of the page size as returned by sysconf().

The flags argument is invalid (flags other than MREMAP_MAYMOVE or MREMAP_FIXED were specified).

MREMAP_FIXED was specified without MREMAP_MAYMOVE.

The argument len or newlen has a value equal to 0.

The memory region specified by addr and len is not a mapped file or anonymous memory.

ENOMEM

There is insufficient room in the address space to effect the mapping.

The mapping could not be locked in memory, if required by mlockall(3C), because it would require more space than the system is able to supply.

The operation would exceed RLIMIT_VMEM (see getrlimit(2)).

EOVERFLOW

The file is a regular file and the mapping would exceed the maximum offset established by the existing mapping to the file.

Usage

Use of mremap() may reduce the amount of memory available to other memory allocation functions.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Async-Signal-Safe

See Also

getrlimit(2), memcntl(2), mmap(2), mprotect(2), munmap(2), mlockall(3C), sysconf(3C), adi(7), attributes(7), resource-controls(7)

History

The mremap() function was added in the Solaris 11.4.45 release.