François Trahay
A process needs to be present in main memory to run
Central memory divided into two parts
Memory management concerns the process space
Memory capacities are increasing, but so are the requirements → Need for multiple memory levels
Principle of inclusion to limit updates between different levels
The memory pages of a process can be
→ each process has a contiguous memory space to store its data
The paging mecanism
k
bits:
p
bitsd = (k - p)
bitsThe correspondence between logical address and address physical is done with a page table that contains
x86_64
or RISC-V
, a page table =
4-levels tree
satp
register (cr3
on x86
architectures)n[0..3]
) + 1
offset, then translated using:.text
,
.data
, etc.)open
mmap
) with the appropriate permissions/proc/<pid>/maps
$ cat /proc/self/maps
5572f3023000-5572f3025000 r--p 00000000 08:01 21495815 /bin/cat
5572f3025000-5572f302a000 r-xp 00002000 08:01 21495815 /bin/cat
5572f302e000-5572f302f000 rw-p 0000a000 08:01 21495815 /bin/cat
5572f4266000-5572f4287000 rw-p 00000000 00:00 0 [heap]
7f33305b4000-7f3330899000 r--p 00000000 08:01 22283564 /usr/lib/locale/locale-archive
7f3330899000-7f33308bb000 r--p 00000000 08:01 29885233 /lib/x86_64-linux-gnu/libc-2.28.so
7f33308bb000-7f3330a03000 r-xp 00022000 08:01 29885233 /lib/x86_64-linux-gnu/libc-2.28.so
[...]
7f3330ab9000-7f3330aba000 rw-p 00000000 00:00 0
7ffe4190f000-7ffe41930000 rw-p 00000000 00:00 0 [stack]
7ffe419ca000-7ffe419cd000 r--p 00000000 00:00 0 [vvar]
7ffe419cd000-7ffe419cf000 r-xp 00000000 00:00 0 [vdso]
void* malloc(size_t size)
size bytes
void* realloc(void* ptr, size_t size)
malloc
void* calloc(size_t nmemb, size_t size)
malloc
, but memory is initialized to 0void *aligned_alloc( size_t alignment, size_t size )
malloc
. The returned address is a multiple of
alignment
void free(void* ptr)
Memory alignment depends on the type of data
char
(1-byte), short
(2-bytes),
int
(4-bytes), …A data structure may be larger than its content
A data structure can be packed with
__attribute__((packed))
void *sbrk(intptr_t increment)
increment
bytesvoid *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
flags
contains MAP_ANON
, does not map
any file, but allocates an area filled with 0s→ Non-Uniform Memory Access → On which memory bank to allocate data?
void *numa_alloc_interleaved(size_t size)
mbind
long mbind(void *addr, unsigned long len, int mode, const unsigned long *nodemask, unsigned long maxnode, unsigned flags)