Class MMAN
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Enum values:static final long
Return value ofmmap(long, long, int, int, int, long)
in case of an error.static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
static final int
static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
The flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.static final int
The flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.static final int
The flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.static final int
Enum values:static final int
Enum values:static final int
Enum values:static final int
Theprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).static final int
Theprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).static final int
Theprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).static final int
Theprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).static final int
Theprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).static final int
Theprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file). -
Method Summary
Modifier and TypeMethodDescriptionstatic long
mmap
(long addr, long length, int prot, int flags, int fd, long offset) Creates a new mapping in the virtual address space of the calling process.static int
munmap
(ByteBuffer addr) Deletes the mappings for the specified address range, and causes further references to addresses within the range to generate invalid memory references.static int
nmunmap
(long addr, long length) Unsafe version of:munmap(java.nio.ByteBuffer)
-
Field Details
-
MAP_FAILED
public static final long MAP_FAILEDReturn value ofmmap(long, long, int, int, int, long)
in case of an error.- See Also:
-
PROT_EXEC
public static final int PROT_EXECTheprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).It is either
PROT_NONE
or the bitwise OR of one or more of the following flags.Enum values:
PROT_EXEC
- Pages may be executed.PROT_READ
- Pages may be read.PROT_WRITE
- Pages may be written.PROT_NONE
- Pages may not be accessed.PROT_GROWSDOWN
- Extend change to start ofgrowsdown
vma (mprotect
only).PROT_GROWSUP
- Extend change to start ofgrowsup
vma (mprotect
only).
- See Also:
-
PROT_READ
public static final int PROT_READTheprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).It is either
PROT_NONE
or the bitwise OR of one or more of the following flags.Enum values:
PROT_EXEC
- Pages may be executed.PROT_READ
- Pages may be read.PROT_WRITE
- Pages may be written.PROT_NONE
- Pages may not be accessed.PROT_GROWSDOWN
- Extend change to start ofgrowsdown
vma (mprotect
only).PROT_GROWSUP
- Extend change to start ofgrowsup
vma (mprotect
only).
- See Also:
-
PROT_WRITE
public static final int PROT_WRITETheprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).It is either
PROT_NONE
or the bitwise OR of one or more of the following flags.Enum values:
PROT_EXEC
- Pages may be executed.PROT_READ
- Pages may be read.PROT_WRITE
- Pages may be written.PROT_NONE
- Pages may not be accessed.PROT_GROWSDOWN
- Extend change to start ofgrowsdown
vma (mprotect
only).PROT_GROWSUP
- Extend change to start ofgrowsup
vma (mprotect
only).
- See Also:
-
PROT_NONE
public static final int PROT_NONETheprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).It is either
PROT_NONE
or the bitwise OR of one or more of the following flags.Enum values:
PROT_EXEC
- Pages may be executed.PROT_READ
- Pages may be read.PROT_WRITE
- Pages may be written.PROT_NONE
- Pages may not be accessed.PROT_GROWSDOWN
- Extend change to start ofgrowsdown
vma (mprotect
only).PROT_GROWSUP
- Extend change to start ofgrowsup
vma (mprotect
only).
- See Also:
-
PROT_GROWSDOWN
public static final int PROT_GROWSDOWNTheprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).It is either
PROT_NONE
or the bitwise OR of one or more of the following flags.Enum values:
PROT_EXEC
- Pages may be executed.PROT_READ
- Pages may be read.PROT_WRITE
- Pages may be written.PROT_NONE
- Pages may not be accessed.PROT_GROWSDOWN
- Extend change to start ofgrowsdown
vma (mprotect
only).PROT_GROWSUP
- Extend change to start ofgrowsup
vma (mprotect
only).
- See Also:
-
PROT_GROWSUP
public static final int PROT_GROWSUPTheprot
argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).It is either
PROT_NONE
or the bitwise OR of one or more of the following flags.Enum values:
PROT_EXEC
- Pages may be executed.PROT_READ
- Pages may be read.PROT_WRITE
- Pages may be written.PROT_NONE
- Pages may not be accessed.PROT_GROWSDOWN
- Extend change to start ofgrowsdown
vma (mprotect
only).PROT_GROWSUP
- Extend change to start ofgrowsup
vma (mprotect
only).
- See Also:
-
MAP_SHARED
public static final int MAP_SHAREDThe flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.This behavior is determined by including exactly one of the following values in
flags
.Enum values:
MAP_SHARED
- Share this mapping.Updates to the mapping are visible to other processes mapping the same region, and (in the case of file-backed mappings) are carried through to the underlying file. (To precisely control when updates are carried through to the underlying file requires the use of
msync(2)
.)MAP_SHARED_VALIDATE
- This flag provides the same behavior asMAP_SHARED
except thatMAP_SHARED
mappings ignore unknown flags inflags
.By contrast, when creating a mapping using
MAP_SHARED_VALIDATE
, the kernel verifies all passed flags are known and fails the mapping with the errorEOPNOTSUPP
for unknown flags. This mapping type is also required to be able to use some mapping flags (e.g.,MAP_SYNC
).MAP_PRIVATE
- Create a private copy-on-write mapping.Updates to the mapping are not visible to other processes mapping the same file, and are not carried through to the underlying file. It is unspecified whether changes made to the file after the
mmap(long, long, int, int, int, long)
call are visible in the mapped region.
- See Also:
-
MAP_SHARED_VALIDATE
public static final int MAP_SHARED_VALIDATEThe flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.This behavior is determined by including exactly one of the following values in
flags
.Enum values:
MAP_SHARED
- Share this mapping.Updates to the mapping are visible to other processes mapping the same region, and (in the case of file-backed mappings) are carried through to the underlying file. (To precisely control when updates are carried through to the underlying file requires the use of
msync(2)
.)MAP_SHARED_VALIDATE
- This flag provides the same behavior asMAP_SHARED
except thatMAP_SHARED
mappings ignore unknown flags inflags
.By contrast, when creating a mapping using
MAP_SHARED_VALIDATE
, the kernel verifies all passed flags are known and fails the mapping with the errorEOPNOTSUPP
for unknown flags. This mapping type is also required to be able to use some mapping flags (e.g.,MAP_SYNC
).MAP_PRIVATE
- Create a private copy-on-write mapping.Updates to the mapping are not visible to other processes mapping the same file, and are not carried through to the underlying file. It is unspecified whether changes made to the file after the
mmap(long, long, int, int, int, long)
call are visible in the mapped region.
- See Also:
-
MAP_PRIVATE
public static final int MAP_PRIVATEThe flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.This behavior is determined by including exactly one of the following values in
flags
.Enum values:
MAP_SHARED
- Share this mapping.Updates to the mapping are visible to other processes mapping the same region, and (in the case of file-backed mappings) are carried through to the underlying file. (To precisely control when updates are carried through to the underlying file requires the use of
msync(2)
.)MAP_SHARED_VALIDATE
- This flag provides the same behavior asMAP_SHARED
except thatMAP_SHARED
mappings ignore unknown flags inflags
.By contrast, when creating a mapping using
MAP_SHARED_VALIDATE
, the kernel verifies all passed flags are known and fails the mapping with the errorEOPNOTSUPP
for unknown flags. This mapping type is also required to be able to use some mapping flags (e.g.,MAP_SYNC
).MAP_PRIVATE
- Create a private copy-on-write mapping.Updates to the mapping are not visible to other processes mapping the same file, and are not carried through to the underlying file. It is unspecified whether changes made to the file after the
mmap(long, long, int, int, int, long)
call are visible in the mapped region.
- See Also:
-
MAP_HUGE_SHIFT
public static final int MAP_HUGE_SHIFT- See Also:
-
MAP_HUGE_MASK
public static final int MAP_HUGE_MASK- See Also:
-
MAP_32BIT
public static final int MAP_32BITEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_ANONYMOUS
public static final int MAP_ANONYMOUSEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_ANON
public static final int MAP_ANONEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_DENYWRITE
public static final int MAP_DENYWRITEEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_EXECUTABLE
public static final int MAP_EXECUTABLEEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_FILE
public static final int MAP_FILEEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_FIXED
public static final int MAP_FIXEDEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_FIXED_NOREPLACE
public static final int MAP_FIXED_NOREPLACEEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_GROWSDOWN
public static final int MAP_GROWSDOWNEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_HUGETLB
public static final int MAP_HUGETLBEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_HUGE_2MB
public static final int MAP_HUGE_2MBEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_HUGE_1GB
public static final int MAP_HUGE_1GBEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_LOCKED
public static final int MAP_LOCKEDEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_NONBLOCK
public static final int MAP_NONBLOCKEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_NORESERVE
public static final int MAP_NORESERVEEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_POPULATE
public static final int MAP_POPULATEEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_STACK
public static final int MAP_STACKEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_SYNC
public static final int MAP_SYNCEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
MAP_UNINITIALIZED
public static final int MAP_UNINITIALIZEDEnum values:
MAP_32BIT
- Put the mapping into the first 2 Gigabytes of the process address space.This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The
MAP_32BIT
flag is ignored whenMAP_FIXED
is set.MAP_ANONYMOUS
- The mapping is not backed by any file; its contents are initialized to zero.The
fd
argument is ignored; however, some implementations requirefd
to be -1 ifMAP_ANONYMOUS
(orMAP_ANON
) is specified, and portable applications should ensure this. Theoffset
argument should be zero. The use ofMAP_ANONYMOUS
in conjunction withMAP_SHARED
is supported on Linux only since kernel 2.4.MAP_ANON
- Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.MAP_DENYWRITE
- This flag is ignored.(Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with
ETXTBSY
. But this was a source of denial-of-service attacks.)MAP_EXECUTABLE
- This flag is ignored.MAP_FILE
- Compatibility flag. Ignored.MAP_FIXED
- Don't interpretaddr
as a hint: place the mapping at exactly that address.addr
must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified byaddr
andlength
overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used,mmap(long, long, int, int, int, long)
will fail.Software that aspires to be portable should use the
MAP_FIXED
flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!MAP_FIXED_NOREPLACE
- This flag provides behavior that is similar toMAP_FIXED
with respect to theaddr
enforcement, but differs in thatMAP_FIXED_NOREPLACE
never clobbers a preexisting mapped range.If the requested range would collide with an existing mapping, then this call fails with the error
EEXIST
. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.Note that older kernels which do not recognize the
MAP_FIXED_NOREPLACE
flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED
" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.(since Linux 4.17)
MAP_GROWSDOWN
- This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a
SIGSEGV
signal.MAP_HUGETLB
- Allocate the mapping using "huge" pages.See the Linux kernel source file
Documentation/admin-guide/mm/hugetlbpage.rst
for further information, as well as NOTES, below.(since Linux 2.6.32)
MAP_HUGE_2MB
- Used in conjunction withMAP_HUGETLB
to select alternativehugetlb
page sizes (respectively, 2 MB and 1 GB) on systems that support multiplehugetlb
page sizes.More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset
MAP_HUGE_SHIFT
. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via theHugepagesize
field exposed by/proc/meminfo
.) Thus, the above two constants are defined as:#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
The range of huge page sizes that are supported by the system can be discovered by listing the subdirectories in
/sys/kernel/mm/hugepages
.(since Linux 3.8)
MAP_HUGE_1GB
- SeeMAP_HUGE_2MB
.MAP_LOCKED
-MAP_NONBLOCK
-MAP_NORESERVE
-MAP_POPULATE
-MAP_STACK
-MAP_SYNC
-MAP_UNINITIALIZED
-
- See Also:
-
-
Method Details
-
mmap
public static long mmap(long addr, long length, int prot, int flags, int fd, long offset) Creates a new mapping in the virtual address space of the calling process.The starting address for the new mapping is specified in
addr
. Thelength
argument specifies the length of the mapping (which must be greater than 0).If
addr
isNULL
, then the kernel chooses the (page-aligned) address at which to create the mapping; this is the most portable method of creating a new mapping. Ifaddr
is notNULL
, then the kernel takes it as a hint about where to place the mapping; on Linux, the kernel will pick a nearby page boundary (but always above or equal to the value specified by/proc/sys/vm/mmap_min_addr
) and attempt to create the mapping there. If another mapping already exists there, the kernel picks a new address that may or may not depend on the hint. The address of the new mapping is returned as the result of the call.The contents of a file mapping (as opposed to an anonymous mapping; see
MAP_ANONYMOUS
below), are initialized usinglength
bytes starting at offsetoffset
in the file (or other object) referred to by the file descriptorfd
.offset
must be a multiple of the page size as returned bysysconf(_SC_PAGE_SIZE)
.After the
mmap()
call has returned, the file descriptor,fd
, can be closed immediately without invalidating the mapping.- Parameters:
prot
- describes the desired memory protection of the mapping (and must not conflict with the open mode of the file). One or more of:PROT_EXEC
PROT_READ
PROT_WRITE
PROT_NONE
PROT_GROWSDOWN
PROT_GROWSUP
flags
- one or more of:- Returns:
- on success, returns a pointer to the mapped area. On error, the value
MAP_FAILED
is returned, anderrno
is set to indicate the error.
-
nmunmap
public static int nmunmap(long addr, long length) Unsafe version of:munmap(java.nio.ByteBuffer)
-
munmap
Deletes the mappings for the specified address range, and causes further references to addresses within the range to generate invalid memory references.The region is also automatically unmapped when the process is terminated. On the other hand, closing the file descriptor does not unmap the region.
The address
addr
must be a multiple of the page size (butlength
need not be). All pages containing a part of the indicated range are unmapped, and subsequent references to these pages will generateSIGSEGV
. It is not an error if the indicated range does not contain any mapped pages.- Returns:
- on success, returns 0. On failure, it returns -1, and
errno
is set to indicate the error (probably toEINVAL
).
-