git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve cake allocator's memory utilisation (#43)
[lunaix-os.git]
/
lunaix-os
/
includes
/
lunaix
/
mm
/
cake.h
diff --git
a/lunaix-os/includes/lunaix/mm/cake.h
b/lunaix-os/includes/lunaix/mm/cake.h
index 81321f87b898c7ce1b6bd05b50f35d342dc5d8ff..d880531399d1d06d42cad3a59c6f463e3e14afc3 100644
(file)
--- a/
lunaix-os/includes/lunaix/mm/cake.h
+++ b/
lunaix-os/includes/lunaix/mm/cake.h
@@
-2,10
+2,12
@@
#define __LUNAIX_CAKE_H
#include <lunaix/ds/llist.h>
#define __LUNAIX_CAKE_H
#include <lunaix/ds/llist.h>
+#include <lunaix/spike.h>
#define PILE_NAME_MAXLEN 20
#define PILE_NAME_MAXLEN 20
-#define PILE_CACHELINE 1
+#define PILE_ALIGN_CACHE 0b0001
+#define PILE_FL_EXTERN 0b0010
struct cake_pile;
struct cake_pile;
@@
-17,28
+19,45
@@
struct cake_pile
struct llist_header full;
struct llist_header partial;
struct llist_header free;
struct llist_header full;
struct llist_header partial;
struct llist_header free;
- unsigned int offset;
- unsigned int piece_size;
- unsigned int cakes_count;
- unsigned int alloced_pieces;
- unsigned int pieces_per_cake;
- unsigned int pg_per_cake;
- char pile_name[PILE_NAME_MAXLEN];
+ u32_t offset;
+ u32_t piece_size;
+ u32_t cakes_count;
+ u32_t alloced_pieces;
+ u32_t pieces_per_cake;
+ u32_t pg_per_cake;
+ u32_t options;
+ char pile_name[PILE_NAME_MAXLEN+1];
pile_cb ctor;
};
pile_cb ctor;
};
-typedef unsigned
int piece_index
_t;
+typedef unsigned
short piece
_t;
-#define EO_FREE_PIECE (-1)
+#define EO_FREE_PIECE ((piece_t)-1)
+
+#define CAKE_FL_SIZE 128
+#define CAKE_FL_MAXLEN \
+ ((unsigned int)((CAKE_FL_SIZE - sizeof(ptr_t)) / sizeof(piece_t)))
+struct cake_fl
+{
+ piece_t indices[CAKE_FL_MAXLEN];
+ struct cake_fl* next;
+} align(CAKE_FL_SIZE);
struct cake_s
{
struct llist_header cakes;
struct cake_s
{
struct llist_header cakes;
+ struct cake_pile* owner;
void* first_piece;
unsigned int used_pieces;
unsigned int next_free;
void* first_piece;
unsigned int used_pieces;
unsigned int next_free;
- piece_index_t free_list[0];
+ union {
+ struct cake_fl* fl;
+ struct {
+ void* rsvd;
+ piece_t free_list[0];
+ };
+ };
};
/**
};
/**
@@
-82,9
+101,21
@@
cake_init();
void
cake_export();
void
cake_export();
+void
+cake_reclaim_freed();
+
/********** some handy constructor ***********/
void
cake_ctor_zeroing(struct cake_pile* pile, void* piece);
/********** some handy constructor ***********/
void
cake_ctor_zeroing(struct cake_pile* pile, void* piece);
+#define DEADCAKE_MARK 0xdeadcafeUL
+
+static inline void
+cake_ensure_valid(void* area) {
+ if (unlikely(*(unsigned int*)area == DEADCAKE_MARK)) {
+ fail("access to freed cake piece");
+ }
+}
+
#endif /* __LUNAIX_VALLOC_H */
#endif /* __LUNAIX_VALLOC_H */