31 #include <sys/resource.h> 33 #include <sys/types.h> 40 size_t __page_size = 0;
43 static unsigned char *init_address = (
unsigned char *)(10LL << 39);
45 void *get_base_pointer(
GID_t gid)
48 return init_address + PER_LP_PREALLOCATED_MEMORY * gid.
to_int;
51 void *get_segment_memory(
struct segment *seg,
size_t size)
53 unsigned char *new_brk, *ret = NULL;
57 (
unsigned char *)(((
unsigned long long)seg->brk + size + (64 - 1)) &
61 if (
likely(new_brk >= seg->base + PER_LP_PREALLOCATED_MEMORY)) {
69 void free_segment_memory(
void *ptr)
80 seg = rsalloc(
sizeof(
struct segment));
85 the_address = init_address + PER_LP_PREALLOCATED_MEMORY * gid.
to_int;
88 mmap(the_address, PER_LP_PREALLOCATED_MEMORY,
89 PROT_READ | PROT_WRITE,
90 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0);
91 if (
unlikely(seg->base == MAP_FAILED)) {
93 rootsim_error(
true,
"Unable to mmap LPs memory\n");
104 void segment_init(
void)
107 size_t max_address_space = PER_LP_PREALLOCATED_MEMORY *
n_prc_tot * 2;
110 limit.rlim_cur = max_address_space;
111 limit.rlim_max = max_address_space;
113 if (setrlimit(RLIMIT_AS, &limit) != 0) {
114 perror(
"Unable to set the maximum address space");
116 "Unable to pre-allocate per-LP memory. Aborting...\n");
140 void initialize_memory_map(
struct lp_struct *lp)
144 lp->
mm->segment = NULL;
145 lp->
mm->buddy = NULL;
150 void finalize_memory_map(
struct lp_struct *lp)
152 malloc_state_wipe(&lp->
mm->m_state);
#define likely(exp)
Optimize the branch as likely taken.
#define SLAB_MSG_SIZE
Slab allocator max message size.
unsigned int to_int
The GID numerical value.
struct memory_map * mm
Memory map of the LP.
Memory Manager main header.
malloc_state * malloc_state_init(void)
Event & Cross State Synchornization.
unsigned int n_prc_tot
Total number of logical processes running in the simulation.
#define unlikely(exp)
Optimize the branch as likely not taken.