31 #include <sys/resource.h> 33 #include <sys/types.h> 40 extern void *__real_malloc(
size_t size);
42 size_t __page_size = 0;
45 static unsigned char *init_address = (
unsigned char *)(10LL << 39);
47 void *get_base_pointer(
GID_t gid)
50 return init_address + PER_LP_PREALLOCATED_MEMORY * gid.
to_int;
53 void *get_segment_memory(
struct segment *seg,
size_t size)
55 unsigned char *new_brk, *ret = NULL;
59 (
unsigned char *)(((
unsigned long long)seg->brk + size + (64 - 1)) &
63 if (
likely(new_brk >= seg->base + PER_LP_PREALLOCATED_MEMORY)) {
71 void free_segment_memory(
void *ptr)
82 seg = rsalloc(
sizeof(
struct segment));
87 the_address = init_address + PER_LP_PREALLOCATED_MEMORY * gid.
to_int;
90 mmap(the_address, PER_LP_PREALLOCATED_MEMORY,
91 PROT_READ | PROT_WRITE,
92 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0);
93 if (
unlikely(seg->base == MAP_FAILED)) {
95 rootsim_error(
true,
"Unable to mmap LPs memory\n");
106 void segment_init(
void)
109 size_t max_address_space = PER_LP_PREALLOCATED_MEMORY *
n_prc_tot * 2;
112 limit.rlim_cur = max_address_space;
113 limit.rlim_max = max_address_space;
115 if (setrlimit(RLIMIT_AS, &limit) != 0) {
116 perror(
"Unable to set the maximum address space");
118 "Unable to pre-allocate per-LP memory. Aborting...\n");
142 void initialize_memory_map(
struct lp_struct *lp)
146 lp->
mm->segment = get_segment(lp->
gid);
147 lp->
mm->buddy =
buddy_new(PER_LP_PREALLOCATED_MEMORY);
152 void finalize_memory_map(
struct lp_struct *lp)
154 malloc_state_wipe(lp->
mm);
155 buddy_destroy(lp->
mm->buddy);
#define likely(exp)
Optimize the branch as likely taken.
#define SLAB_MSG_SIZE
Slab allocator max message size.
Dynamic Memory Logger and Restorer (DyMeLoR)
unsigned int to_int
The GID numerical value.
struct memory_map * mm
Memory map of the LP.
GID_t gid
Global ID of the LP.
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.
struct buddy * buddy_new(size_t requested_size)