kmem, mem(4) | memory files |
mem, kmem(4) | memory files |
MEM(4) | MidnightBSD Kernel Interfaces Manual | MEM(4) |
mem
, kmem
—
memory files
device mem
The special file /dev/mem is an interface to the physical memory of the computer. Byte offsets in this file are interpreted as physical memory addresses. Reading and writing this file is equivalent to reading and writing memory itself. Only offsets within the bounds of /dev/mem are allowed.
Kernel virtual memory is accessed through the interface /dev/kmem in the same manner as /dev/mem. Only kernel virtual addresses that are currently mapped to memory are allowed.
On ISA the I/O memory space begins at physical address 0x000a0000
and runs to 0x00100000. The per-process data size for the current process is
UPAGES
long, and ends at virtual address
0xf0000000.
The MEM_EXTRACT_PADDR
ioctl can be used to
look up the physical address and NUMA domain of a given virtual address in
the calling process' address space. The request is described by
struct mem_extract { uint64_t me_vaddr; /* input */ uint64_t me_paddr; /* output */ int me_domain; /* output */ int me_state; /* output */ };
The ioctl returns an error if the address is not valid. The
information returned by MEM_EXTRACT_PADDR
may be out
of date by the time that the ioctl call returns. Specifically, concurrent
system calls, page faults, or system page reclamation activity may have
unmapped the virtual page or replaced the backing physical page before the
ioctl call returns. Wired pages, e.g., those locked by
mlock(2), will not be
reclaimed by the system.
The me_state field provides information about the state of the virtual page:
ME_STATE_INVALID
ME_STATE_VALID
ME_STATE_MAPPED
Several architectures allow attributes to be
associated with ranges of physical memory. These attributes can be
manipulated via
ioctl
()
calls performed on /dev/mem. Declarations and
data types are to be found in
<sys/memrange.h>
.
The specific attributes, and number of programmable ranges may vary between architectures. The full set of supported attributes is:
MDF_UNCACHEABLE
MDF_WRITECOMBINE
MDF_WRITETHROUGH
MDF_WRITEBACK
MDF_WRITEPROTECT
Memory ranges are described by
struct mem_range_desc { uint64_t mr_base; /* physical base address */ uint64_t mr_len; /* physical length of region */ int mr_flags; /* attributes of region */ char mr_owner[8]; };
In addition to the region attributes listed above, the following flags may also be set in the mr_flags field:
Operations are performed using
struct mem_range_op { struct mem_range_desc *mo_desc; int mo_arg[2]; };
The MEMRANGE_GET
ioctl is used to
retrieve current memory range attributes. If
mo_arg[0] is set to 0, it will be updated with the
total number of memory range descriptors. If greater than 0, the array
at mo_desc will be filled with a corresponding
number of descriptor structures, or the maximum, whichever is less.
The MEMRANGE_SET
ioctl is used to add,
alter and remove memory range attributes. A range with the
MDF_FIXACTIVE
flag may not be removed; a range
with the MDF_BUSY
flag may not be removed or
updated.
mo_arg[0] should be set to
MEMRANGE_SET_UPDATE
to update an existing or
establish a new range, or to MEMRANGE_SET_REMOVE
to remove a range.
EOPNOTSUPP
]ENXIO
]EINVAL
]EBUSY
]ENOSPC
]ENOENT
]EPERM
]The mem
and kmem
files appeared in Version 6 AT&T UNIX.
The ioctl interface for memory range attributes was added in
FreeBSD 3.2.
Busy range attributes are not yet managed correctly.
This device is required for all users of kvm(3) to operate.
August 25, 2020 | midnightbsd-3.1 |