"Glinc memory management," notes DAY1

x86_64 fixed mapping address stack and mmap

  Randomize_va_space only need to set a global variable value of 0, this variable defaults to 1. Users can disable this feature by setting the / proc / sys / kernel / randomize_va_space, you may use the following command:

sudo sysctl -w kernel.randomize_va_space=0

Delayed allocate memory

  Only when it actually visit was to establish a physical address mapping of this address, which is one of the basic idea of ​​Linux memory management. Linux kernel memory when the user application, but it is assigned to a linear region (ie virtual memory), and not the actual allocation of physical memory; only when the user uses this memory, the kernel will be assigned to a specific physical page user, this time to take up valuable physical memory. Kernel physical page is released by releasing the linear region, to find its corresponding physical page, the process will release its entirety.

Kernel data structures mm_struct
  • start_code: starting address of the code segment
  • End address process code segment: end_code
  • start_stack: process stack segment start address
  • start_brk: Dynamic memory allocation process start address (the start address of the heap)
  • brk: Dynamic memory allocation is the current end address (last address of the current stack)
Heap operations related functions

#include <unistd.h>

  • System call int brk (void * addr);
  • C library function void * sbrk (intptr_t increment);
Mapping function related to the operation area Mmap

#include <sys/mman.h>

  • void the mmap (void addr, size_t length, int Prot, the flags int, int FD, of off_t offset);
      the mmap () function maps a file into memory or other objects. File is mapped to multiple pages, if the size of the file size and not all the pages, the last page space is not used will be cleared.
  • munmap int (void * addr, size_t length);
      munmap performs the reverse operation to delete a specific address region of the subject map.

Guess you like

Origin www.cnblogs.com/luoleqi/p/11964408.html