summaryrefslogtreecommitdiff
path: root/src/lib/eo/eo_ptr_indirection.c
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-05-16 11:46:20 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2013-05-16 13:17:11 +0200
commit00af0e77e327d8ca8e1d78caaf0cfdd1251c0fd2 (patch)
treef3427d32684200707ca57b63621f929b2c8b674d /src/lib/eo/eo_ptr_indirection.c
parenta9e69d519cd5240320e278cdc4efa8b1723a5fa1 (diff)
eo ptr ind: minimize amount of wasted memory
- because of mmap PAGE_SIZE alignement and added magic header, almost a memory page is wasted per table and mid table allocation. - reducing the number of tables per mid table and the number of entries per table solves this.
Diffstat (limited to 'src/lib/eo/eo_ptr_indirection.c')
-rw-r--r--src/lib/eo/eo_ptr_indirection.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lib/eo/eo_ptr_indirection.c b/src/lib/eo/eo_ptr_indirection.c
index 47c5295..b355370 100644
--- a/src/lib/eo/eo_ptr_indirection.c
+++ b/src/lib/eo/eo_ptr_indirection.c
@@ -68,6 +68,8 @@
68# define BITS_TABLE_ID 5 68# define BITS_TABLE_ID 5
69# define BITS_ENTRY_ID 12 69# define BITS_ENTRY_ID 12
70# define BITS_GENERATION_COUNTER 10 70# define BITS_GENERATION_COUNTER 10
71# define DROPPED_TABLES 0
72# define DROPPED_ENTRIES 3
71typedef int16_t Table_Index; 73typedef int16_t Table_Index;
72typedef uint16_t Generation_Counter; 74typedef uint16_t Generation_Counter;
73#else 75#else
@@ -76,6 +78,8 @@ typedef uint16_t Generation_Counter;
76# define BITS_TABLE_ID 11 78# define BITS_TABLE_ID 11
77# define BITS_ENTRY_ID 12 79# define BITS_ENTRY_ID 12
78# define BITS_GENERATION_COUNTER 30 80# define BITS_GENERATION_COUNTER 30
81# define DROPPED_TABLES 2
82# define DROPPED_ENTRIES 2
79typedef int16_t Table_Index; 83typedef int16_t Table_Index;
80typedef uint32_t Generation_Counter; 84typedef uint32_t Generation_Counter;
81#endif 85#endif
@@ -86,16 +90,17 @@ typedef uint32_t Generation_Counter;
86#define SHIFT_TABLE_ID (BITS_ENTRY_ID + BITS_GENERATION_COUNTER) 90#define SHIFT_TABLE_ID (BITS_ENTRY_ID + BITS_GENERATION_COUNTER)
87#define SHIFT_ENTRY_ID (BITS_GENERATION_COUNTER) 91#define SHIFT_ENTRY_ID (BITS_GENERATION_COUNTER)
88 92
89/* Maximum ranges */ 93/* Maximum ranges - a few tables and entries are dropped to minimize the amount
94 * of wasted bytes, see _eo_id_mem_alloc */
90#define MAX_MID_TABLE_ID (1 << BITS_MID_TABLE_ID) 95#define MAX_MID_TABLE_ID (1 << BITS_MID_TABLE_ID)
91#define MAX_TABLE_ID (1 << BITS_TABLE_ID) 96#define MAX_TABLE_ID ((1 << BITS_TABLE_ID) - DROPPED_TABLES )
92#define MAX_ENTRY_ID (1 << BITS_ENTRY_ID) 97#define MAX_ENTRY_ID ((1 << BITS_ENTRY_ID) - DROPPED_ENTRIES)
93#define MAX_GENERATIONS (1 << BITS_GENERATION_COUNTER) 98#define MAX_GENERATIONS (1 << BITS_GENERATION_COUNTER)
94 99
95/* Masks */ 100/* Masks */
96#define MASK_MID_TABLE_ID (MAX_MID_TABLE_ID - 1) 101#define MASK_MID_TABLE_ID (MAX_MID_TABLE_ID - 1)
97#define MASK_TABLE_ID (MAX_TABLE_ID - 1) 102#define MASK_TABLE_ID ((1 << BITS_TABLE_ID) - 1)
98#define MASK_ENTRY_ID (MAX_ENTRY_ID - 1) 103#define MASK_ENTRY_ID ((1 << BITS_ENTRY_ID) - 1)
99#define MASK_GENERATIONS (MAX_GENERATIONS - 1) 104#define MASK_GENERATIONS (MAX_GENERATIONS - 1)
100 105
101#define MEM_HEADER_SIZE 16 106#define MEM_HEADER_SIZE 16
@@ -127,6 +132,7 @@ _eo_id_mem_alloc(size_t size)
127 hdr = ptr; 132 hdr = ptr;
128 hdr->size = newsize; 133 hdr->size = newsize;
129 hdr->magic = MEM_MAGIC; 134 hdr->magic = MEM_MAGIC;
135 /* DBG("asked:%lu allocated:%lu wasted:%lu bytes", size, newsize, (newsize - size)); */
130 return (void *)(((unsigned char *)ptr) + MEM_HEADER_SIZE); 136 return (void *)(((unsigned char *)ptr) + MEM_HEADER_SIZE);
131#else 137#else
132 return malloc(size); 138 return malloc(size);