Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,169 +0,0 @@
1
-/*
2
- * shared memory, multi-process safe, pool based, mostly lockless version of 
3
- *  f_malloc
4
- *
5
- * This file is part of Kamailio, a free SIP server.
6
- *
7
- * Copyright (C) 2007 iptelorg GmbH
8
- *
9
- * Permission to use, copy, modify, and distribute this software for any
10
- * purpose with or without fee is hereby granted, provided that the above
11
- * copyright notice and this permission notice appear in all copies.
12
- *
13
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
- */
21
-
22
-#if !defined(ll_malloc_h)  
23
-#define ll_malloc_h
24
-
25
-
26
-#include "meminfo.h"
27
-
28
-#include "../lock_ops.h"
29
-#include "../atomic_ops.h"
30
-#include "../compiler_opt.h"
31
-/* defs*/
32
-
33
-
34
-#ifdef GEN_LOCK_T_UNLIMITED
35
-#define SFM_LOCK_PER_BUCKET
36
-#else
37
-#define SFM_ONE_LOCK
38
-#endif
39
-
40
-#ifdef DBG_SF_MALLOC
41
-#if defined(__CPU_sparc64) || defined(__CPU_sparc)
42
-/* tricky, on sun in 32 bits mode long long must be 64 bits aligned
43
- * but long can be 32 bits aligned => malloc should return long long
44
- * aligned memory */
45
-	#define SF_ROUNDTO	sizeof(long long)
46
-#else
47
-	#define SF_ROUNDTO	sizeof(void*) /* size we round to, must be = 2^n, and
48
-                      sizeof(sfm_frag) must be multiple of SF_ROUNDTO !*/
49
-#endif
50
-#else /* DBG_SF_MALLOC */
51
-	#define SF_ROUNDTO 8UL
52
-#endif
53
-#define SF_MIN_FRAG_SIZE	SF_ROUNDTO
54
-
55
-#define SFM_POOLS_NO 4U /* the more the better, but higher initial
56
-                            mem. consumption */
57
-
58
-#define SF_MALLOC_OPTIMIZE_FACTOR 14UL /*used below */
59
-#define SF_MALLOC_OPTIMIZE  (1UL<<SF_MALLOC_OPTIMIZE_FACTOR)
60
-								/* size to optimize for,
61
-									(most allocs <= this size),
62
-									must be 2^k */
63
-
64
-#define SF_HASH_POOL_SIZE	(SF_MALLOC_OPTIMIZE/SF_ROUNDTO + 1)
65
-#define SF_POOL_MAX_SIZE	SF_MALLOC_OPTIMIZE
66
-
67
-#define SF_HASH_SIZE (SF_MALLOC_OPTIMIZE/SF_ROUNDTO + \
68
-		(sizeof(long)*8-SF_MALLOC_OPTIMIZE_FACTOR)+1)
69
-
70
-/* hash structure:
71
- * 0 .... SF_MALLOC_OPTIMIZE/SF_ROUNDTO  - small buckets, size increases with
72
- *                            SF_ROUNDTO from bucket to bucket
73
- * +1 .... end -  size = 2^k, big buckets */
74
-
75
-struct sfm_frag{
76
-	union{
77
-		struct sfm_frag* nxt_free;
78
-		long reserved;
79
-	}u;
80
-	unsigned long size;
81
-	unsigned long id; /* TODO better optimize the size */
82
-	/* pad to SF_ROUNDTO multiple */
83
-	char _pad[((3*sizeof(long)+SF_ROUNDTO-1)&~(SF_ROUNDTO-1))-3*sizeof(long)];
84
-#ifdef DBG_SF_MALLOC
85
-	const char* file;
86
-	const char* func;
87
-	unsigned long line;
88
-	unsigned long check;
89
-#endif
90
-};
91
-
92
-struct sfm_frag_lnk{
93
-	struct sfm_frag* first;
94
-#ifdef SFM_LOCK_PER_BUCKET
95
-	gen_lock_t lock;
96
-#endif
97
-	unsigned long no;
98
-};
99
-
100
-struct sfm_pool_head{
101
-	struct sfm_frag* first;
102
-#ifdef SFM_LOCK_PER_BUCKET
103
-	gen_lock_t lock;
104
-#endif
105
-	unsigned long no;
106
-	unsigned long misses;
107
-};
108
-
109
-struct sfm_pool{
110
-#ifdef SFM_ONE_LOCK
111
-	gen_lock_t lock;
112
-#endif
113
-	unsigned long missed;
114
-	unsigned long hits; /* debugging only TODO: remove */
115
-	unsigned long bitmap;
116
-	struct sfm_pool_head pool_hash[SF_HASH_POOL_SIZE];
117
-};
118
-
119
-struct sfm_block{
120
-#ifdef SFM_ONE_LOCK
121
-	gen_lock_t lock;
122
-#endif
123
-	atomic_t crt_id; /* current pool */
124
-	int type; /* type of pool */
125
-	unsigned long size; /* total size */
126
-	/* stats are kept now per bucket */
127
-	struct sfm_frag* first_frag;
128
-	struct sfm_frag* last_frag;
129
-	unsigned long bitmap; /* only up to SF_MALLOC_OPTIMIZE */
130
-	struct sfm_frag_lnk free_hash[SF_HASH_SIZE];
131
-	struct sfm_pool pool[SFM_POOLS_NO];
132
-	int is_init;
133
-	gen_lock_t get_and_split;
134
-	char _pad[256];
135
-};
136
-
137
-
138
-
139
-struct sfm_block* sfm_malloc_init(char* address, unsigned long size, int type);
140
-void sfm_malloc_destroy(struct sfm_block* qm);
141
-int sfm_pool_reset();
142
-
143
-#ifdef DBG_SF_MALLOC
144
-void* sfm_malloc(struct sfm_block*, unsigned long size,
145
-					const char* file, const char* func, unsigned int line);
146
-#else
147
-void* sfm_malloc(struct sfm_block*, unsigned long size);
148
-#endif
149
-
150
-#ifdef DBG_SF_MALLOC
151
-void  sfm_free(struct sfm_block*, void* p, const char* file, const char* func, 
152
-				unsigned int line);
153
-#else
154
-void  sfm_free(struct sfm_block*, void* p);
155
-#endif
156
-
157
-#ifdef DBG_SF_MALLOC
158
-void*  sfm_realloc(struct sfm_block*, void* p, unsigned long size, 
159
-					const char* file, const char* func, unsigned int line);
160
-#else
161
-void*  sfm_realloc(struct sfm_block*, void* p, unsigned long size);
162
-#endif
163
-
164
-void  sfm_status(struct sfm_block*);
165
-void  sfm_info(struct sfm_block*, struct mem_info*);
166
-
167
-unsigned long sfm_available(struct sfm_block*);
168
-
169
-#endif
Browse code

mem Remove SVN ID, remove history

Olle E. Johansson authored on 25/02/2015 08:12:38
Showing 1 changed files
... ...
@@ -1,8 +1,9 @@
1
-/* $Id$
2
- *
1
+/*
3 2
  * shared memory, multi-process safe, pool based, mostly lockless version of 
4 3
  *  f_malloc
5 4
  *
5
+ * This file is part of Kamailio, a free SIP server.
6
+ *
6 7
  * Copyright (C) 2007 iptelorg GmbH
7 8
  *
8 9
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -17,17 +18,6 @@
17 18
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 19
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 20
  */
20
-/*
21
- * History:
22
- * --------
23
- *  2003-05-21  on sparc64 roundto 8 even in debugging mode (so malloc'ed
24
- *               long longs will be 64 bit aligned) (andrei)
25
- *  2004-07-19  support for 64 bit (2^64 mem. block) and more info
26
- *               for the future de-fragmentation support (andrei)
27
- *  2004-11-10  support for > 4Gb mem., switched to long (andrei)
28
- *  2007-06-11  forked from the sf_malloc code (andrei)
29
- */
30
-
31 21
 
32 22
 #if !defined(ll_malloc_h)  
33 23
 #define ll_malloc_h
Browse code

core/mem: ll_malloc initialization updated to be able to set pool type

Daniel-Constantin Mierla authored on 03/05/2014 18:05:12
Showing 1 changed files
... ...
@@ -131,6 +131,7 @@ struct sfm_block{
131 131
 	gen_lock_t lock;
132 132
 #endif
133 133
 	atomic_t crt_id; /* current pool */
134
+	int type; /* type of pool */
134 135
 	unsigned long size; /* total size */
135 136
 	/* stats are kept now per bucket */
136 137
 	struct sfm_frag* first_frag;
... ...
@@ -145,7 +146,7 @@ struct sfm_block{
145 146
 
146 147
 
147 148
 
148
-struct sfm_block* sfm_malloc_init(char* address, unsigned long size);
149
+struct sfm_block* sfm_malloc_init(char* address, unsigned long size, int type);
149 150
 void sfm_malloc_destroy(struct sfm_block* qm);
150 151
 int sfm_pool_reset();
151 152
 
Browse code

- added sf_malloc: a multi-process safe (internal locking), multi-pool f_malloc version. Should perform better on lots of CPU once properly tunned (experimental for now) - added ll_malloc: same as above but most operation are lockless (except for "big" fragment handling). For now needs tunning and it still keeps too many debugging statistics. (experimental for now)

Andrei Pelinescu-Onciul authored on 12/06/2007 18:07:12
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,178 @@
1
+/* $Id$
2
+ *
3
+ * shared memory, multi-process safe, pool based, mostly lockless version of 
4
+ *  f_malloc
5
+ *
6
+ * Copyright (C) 2007 iptelorg GmbH
7
+ *
8
+ * Permission to use, copy, modify, and distribute this software for any
9
+ * purpose with or without fee is hereby granted, provided that the above
10
+ * copyright notice and this permission notice appear in all copies.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ */
20
+/*
21
+ * History:
22
+ * --------
23
+ *  2003-05-21  on sparc64 roundto 8 even in debugging mode (so malloc'ed
24
+ *               long longs will be 64 bit aligned) (andrei)
25
+ *  2004-07-19  support for 64 bit (2^64 mem. block) and more info
26
+ *               for the future de-fragmentation support (andrei)
27
+ *  2004-11-10  support for > 4Gb mem., switched to long (andrei)
28
+ *  2007-06-11  forked from the sf_malloc code (andrei)
29
+ */
30
+
31
+
32
+#if !defined(ll_malloc_h)  
33
+#define ll_malloc_h
34
+
35
+
36
+#include "meminfo.h"
37
+
38
+#include "../lock_ops.h"
39
+#include "../atomic_ops.h"
40
+#include "../compiler_opt.h"
41
+/* defs*/
42
+
43
+
44
+#ifdef GEN_LOCK_T_UNLIMITED
45
+#define SFM_LOCK_PER_BUCKET
46
+#else
47
+#define SFM_ONE_LOCK
48
+#endif
49
+
50
+#ifdef DBG_SF_MALLOC
51
+#if defined(__CPU_sparc64) || defined(__CPU_sparc)
52
+/* tricky, on sun in 32 bits mode long long must be 64 bits aligned
53
+ * but long can be 32 bits aligned => malloc should return long long
54
+ * aligned memory */
55
+	#define SF_ROUNDTO	sizeof(long long)
56
+#else
57
+	#define SF_ROUNDTO	sizeof(void*) /* size we round to, must be = 2^n, and
58
+                      sizeof(sfm_frag) must be multiple of SF_ROUNDTO !*/
59
+#endif
60
+#else /* DBG_SF_MALLOC */
61
+	#define SF_ROUNDTO 8UL
62
+#endif
63
+#define SF_MIN_FRAG_SIZE	SF_ROUNDTO
64
+
65
+#define SFM_POOLS_NO 4U /* the more the better, but higher initial
66
+                            mem. consumption */
67
+
68
+#define SF_MALLOC_OPTIMIZE_FACTOR 14UL /*used below */
69
+#define SF_MALLOC_OPTIMIZE  (1UL<<SF_MALLOC_OPTIMIZE_FACTOR)
70
+								/* size to optimize for,
71
+									(most allocs <= this size),
72
+									must be 2^k */
73
+
74
+#define SF_HASH_POOL_SIZE	(SF_MALLOC_OPTIMIZE/SF_ROUNDTO + 1)
75
+#define SF_POOL_MAX_SIZE	SF_MALLOC_OPTIMIZE
76
+
77
+#define SF_HASH_SIZE (SF_MALLOC_OPTIMIZE/SF_ROUNDTO + \
78
+		(sizeof(long)*8-SF_MALLOC_OPTIMIZE_FACTOR)+1)
79
+
80
+/* hash structure:
81
+ * 0 .... SF_MALLOC_OPTIMIZE/SF_ROUNDTO  - small buckets, size increases with
82
+ *                            SF_ROUNDTO from bucket to bucket
83
+ * +1 .... end -  size = 2^k, big buckets */
84
+
85
+struct sfm_frag{
86
+	union{
87
+		struct sfm_frag* nxt_free;
88
+		long reserved;
89
+	}u;
90
+	unsigned long size;
91
+	unsigned long id; /* TODO better optimize the size */
92
+	/* pad to SF_ROUNDTO multiple */
93
+	char _pad[((3*sizeof(long)+SF_ROUNDTO-1)&~(SF_ROUNDTO-1))-3*sizeof(long)];
94
+#ifdef DBG_SF_MALLOC
95
+	const char* file;
96
+	const char* func;
97
+	unsigned long line;
98
+	unsigned long check;
99
+#endif
100
+};
101
+
102
+struct sfm_frag_lnk{
103
+	struct sfm_frag* first;
104
+#ifdef SFM_LOCK_PER_BUCKET
105
+	gen_lock_t lock;
106
+#endif
107
+	unsigned long no;
108
+};
109
+
110
+struct sfm_pool_head{
111
+	struct sfm_frag* first;
112
+#ifdef SFM_LOCK_PER_BUCKET
113
+	gen_lock_t lock;
114
+#endif
115
+	unsigned long no;
116
+	unsigned long misses;
117
+};
118
+
119
+struct sfm_pool{
120
+#ifdef SFM_ONE_LOCK
121
+	gen_lock_t lock;
122
+#endif
123
+	unsigned long missed;
124
+	unsigned long hits; /* debugging only TODO: remove */
125
+	unsigned long bitmap;
126
+	struct sfm_pool_head pool_hash[SF_HASH_POOL_SIZE];
127
+};
128
+
129
+struct sfm_block{
130
+#ifdef SFM_ONE_LOCK
131
+	gen_lock_t lock;
132
+#endif
133
+	atomic_t crt_id; /* current pool */
134
+	unsigned long size; /* total size */
135
+	/* stats are kept now per bucket */
136
+	struct sfm_frag* first_frag;
137
+	struct sfm_frag* last_frag;
138
+	unsigned long bitmap; /* only up to SF_MALLOC_OPTIMIZE */
139
+	struct sfm_frag_lnk free_hash[SF_HASH_SIZE];
140
+	struct sfm_pool pool[SFM_POOLS_NO];
141
+	int is_init;
142
+	gen_lock_t get_and_split;
143
+	char _pad[256];
144
+};
145
+
146
+
147
+
148
+struct sfm_block* sfm_malloc_init(char* address, unsigned long size);
149
+void sfm_malloc_destroy(struct sfm_block* qm);
150
+int sfm_pool_reset();
151
+
152
+#ifdef DBG_SF_MALLOC
153
+void* sfm_malloc(struct sfm_block*, unsigned long size,
154
+					const char* file, const char* func, unsigned int line);
155
+#else
156
+void* sfm_malloc(struct sfm_block*, unsigned long size);
157
+#endif
158
+
159
+#ifdef DBG_SF_MALLOC
160
+void  sfm_free(struct sfm_block*, void* p, const char* file, const char* func, 
161
+				unsigned int line);
162
+#else
163
+void  sfm_free(struct sfm_block*, void* p);
164
+#endif
165
+
166
+#ifdef DBG_SF_MALLOC
167
+void*  sfm_realloc(struct sfm_block*, void* p, unsigned long size, 
168
+					const char* file, const char* func, unsigned int line);
169
+#else
170
+void*  sfm_realloc(struct sfm_block*, void* p, unsigned long size);
171
+#endif
172
+
173
+void  sfm_status(struct sfm_block*);
174
+void  sfm_info(struct sfm_block*, struct mem_info*);
175
+
176
+unsigned long sfm_available(struct sfm_block*);
177
+
178
+#endif