jeyzu pushed a commit to branch master.

commit 00af0e77e327d8ca8e1d78caaf0cfdd1251c0fd2
Author: Jérémy Zurcher <[email protected]>
Date:   Thu May 16 11:46:20 2013 +0200

    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.
---
 src/lib/eo/eo_ptr_indirection.c | 16 +++++++++++-----
 1 file 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 @@
 # define BITS_TABLE_ID            5
 # define BITS_ENTRY_ID           12
 # define BITS_GENERATION_COUNTER 10
+# define DROPPED_TABLES           0
+# define DROPPED_ENTRIES          3
 typedef int16_t Table_Index;
 typedef uint16_t Generation_Counter;
 #else
@@ -76,6 +78,8 @@ typedef uint16_t Generation_Counter;
 # define BITS_TABLE_ID           11
 # define BITS_ENTRY_ID           12
 # define BITS_GENERATION_COUNTER 30
+# define DROPPED_TABLES           2
+# define DROPPED_ENTRIES          2
 typedef int16_t Table_Index;
 typedef uint32_t Generation_Counter;
 #endif
@@ -86,16 +90,17 @@ typedef uint32_t Generation_Counter;
 #define SHIFT_TABLE_ID        (BITS_ENTRY_ID + BITS_GENERATION_COUNTER)
 #define SHIFT_ENTRY_ID        (BITS_GENERATION_COUNTER)
 
-/* Maximum ranges */
+/* Maximum ranges - a few tables and entries are dropped to minimize the amount
+ * of wasted bytes, see _eo_id_mem_alloc */
 #define MAX_MID_TABLE_ID      (1 << BITS_MID_TABLE_ID)
-#define MAX_TABLE_ID          (1 << BITS_TABLE_ID)
-#define MAX_ENTRY_ID          (1 << BITS_ENTRY_ID)
+#define MAX_TABLE_ID          ((1 << BITS_TABLE_ID) - DROPPED_TABLES )
+#define MAX_ENTRY_ID          ((1 << BITS_ENTRY_ID) - DROPPED_ENTRIES)
 #define MAX_GENERATIONS       (1 << BITS_GENERATION_COUNTER)
 
 /* Masks */
 #define MASK_MID_TABLE_ID     (MAX_MID_TABLE_ID - 1)
-#define MASK_TABLE_ID         (MAX_TABLE_ID - 1)
-#define MASK_ENTRY_ID         (MAX_ENTRY_ID - 1)
+#define MASK_TABLE_ID         ((1 << BITS_TABLE_ID) - 1)
+#define MASK_ENTRY_ID         ((1 << BITS_ENTRY_ID) - 1)
 #define MASK_GENERATIONS      (MAX_GENERATIONS - 1)
 
 #define MEM_HEADER_SIZE       16
@@ -127,6 +132,7 @@ _eo_id_mem_alloc(size_t size)
    hdr = ptr;
    hdr->size = newsize;
    hdr->magic = MEM_MAGIC;
+   /* DBG("asked:%lu allocated:%lu wasted:%lu bytes", size, newsize, (newsize 
- size)); */
    return (void *)(((unsigned char *)ptr) + MEM_HEADER_SIZE);
 #else
    return malloc(size);

-- 

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d

Reply via email to