nxt_malloc.h (521:93dc4a28dd37) nxt_malloc.h (2084:7d479274f334)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#ifndef _NXT_UNIX_MALLOC_H_INCLUDED_
8#define _NXT_UNIX_MALLOC_H_INCLUDED_

--- 10 unchanged lines hidden (view full) ---

19
20
21#if (NXT_DEBUG)
22
23NXT_EXPORT void nxt_free(void *p);
24
25#else
26
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#ifndef _NXT_UNIX_MALLOC_H_INCLUDED_
8#define _NXT_UNIX_MALLOC_H_INCLUDED_

--- 10 unchanged lines hidden (view full) ---

19
20
21#if (NXT_DEBUG)
22
23NXT_EXPORT void nxt_free(void *p);
24
25#else
26
27#define \
28nxt_free(p) \
27#define nxt_free(p) \
29 free(p)
30
31#endif
32
33
34#if (NXT_HAVE_MALLOC_USABLE_SIZE)
35
36/*

--- 12 unchanged lines hidden (view full) ---

49 * are usually 4 or 8 spare bytes respectively. However, if allocation
50 * is larger than about 128K, spare size may be up to one page: glibc aligns
51 * sum of allocation and bookkeeping size to a page. So if requirement
52 * of the large allocation size is not strict it is better to allocate
53 * with small cutback and then to adjust size with malloc_usable_size().
54 * Glibc malloc_usable_size() is fast operation.
55 */
56
28 free(p)
29
30#endif
31
32
33#if (NXT_HAVE_MALLOC_USABLE_SIZE)
34
35/*

--- 12 unchanged lines hidden (view full) ---

48 * are usually 4 or 8 spare bytes respectively. However, if allocation
49 * is larger than about 128K, spare size may be up to one page: glibc aligns
50 * sum of allocation and bookkeeping size to a page. So if requirement
51 * of the large allocation size is not strict it is better to allocate
52 * with small cutback and then to adjust size with malloc_usable_size().
53 * Glibc malloc_usable_size() is fast operation.
54 */
55
57#define \
58nxt_malloc_usable_size(p, size) \
56#define nxt_malloc_usable_size(p, size) \
59 size = malloc_usable_size(p)
60
57 size = malloc_usable_size(p)
58
61#define \
62nxt_malloc_cutback(cutback, size) \
59#define nxt_malloc_cutback(cutback, size) \
63 size = ((cutback) && size > 127 * 1024) ? size - 32 : size
64
65#elif (NXT_FREEBSD)
66
67/*
68 * FreeBSD prior to 7.0 (phkmalloc) aligns sizes to
69 * 16 - 2048 a power of two
70 * 2049 - ... aligned to 4K

--- 5 unchanged lines hidden (view full) ---

76 * 2049 - 1M aligned to 4K
77 * 1M- ... aligned to 1M
78 * See table in src/lib/libc/stdlib/malloc.c
79 *
80 * FreeBSD 7.0 malloc_usable_size() is fast for allocations, which
81 * are lesser than 1M. Larger allocations require mutex acquiring.
82 */
83
60 size = ((cutback) && size > 127 * 1024) ? size - 32 : size
61
62#elif (NXT_FREEBSD)
63
64/*
65 * FreeBSD prior to 7.0 (phkmalloc) aligns sizes to
66 * 16 - 2048 a power of two
67 * 2049 - ... aligned to 4K

--- 5 unchanged lines hidden (view full) ---

73 * 2049 - 1M aligned to 4K
74 * 1M- ... aligned to 1M
75 * See table in src/lib/libc/stdlib/malloc.c
76 *
77 * FreeBSD 7.0 malloc_usable_size() is fast for allocations, which
78 * are lesser than 1M. Larger allocations require mutex acquiring.
79 */
80
84#define \
85nxt_malloc_usable_size(p, size) \
81#define nxt_malloc_usable_size(p, size) \
86 size = malloc_usable_size(p)
87
82 size = malloc_usable_size(p)
83
88#define \
89nxt_malloc_cutback(cutback, size)
84#define nxt_malloc_cutback(cutback, size)
90
91#endif
92
93#elif (NXT_HAVE_MALLOC_GOOD_SIZE)
94
95/*
96 * MacOSX aligns sizes to
97 * 16 - 496 aligned to 16, 32-bit
98 * 16 - 992 aligned to 16, 64-bit
99 * 497/993 - 15K aligned to 512, if lesser than 1G RAM
100 * 497/993 - 127K aligned to 512, otherwise
101 * 15K/127K- ... aligned to 4K
102 *
103 * malloc_good_size() is faster than malloc_size()
104 */
105
85
86#endif
87
88#elif (NXT_HAVE_MALLOC_GOOD_SIZE)
89
90/*
91 * MacOSX aligns sizes to
92 * 16 - 496 aligned to 16, 32-bit
93 * 16 - 992 aligned to 16, 64-bit
94 * 497/993 - 15K aligned to 512, if lesser than 1G RAM
95 * 497/993 - 127K aligned to 512, otherwise
96 * 15K/127K- ... aligned to 4K
97 *
98 * malloc_good_size() is faster than malloc_size()
99 */
100
106#define \
107nxt_malloc_usable_size(p, size) \
101#define nxt_malloc_usable_size(p, size) \
108 size = malloc_good_size(size)
109
102 size = malloc_good_size(size)
103
110#define \
111nxt_malloc_cutback(cutback, size)
104#define nxt_malloc_cutback(cutback, size)
112
113#else
114
105
106#else
107
115#define \
116nxt_malloc_usable_size(p, size)
108#define nxt_malloc_usable_size(p, size)
117
109
118#define \
119nxt_malloc_cutback(cutback, size)
110#define nxt_malloc_cutback(cutback, size)
120
121#endif
122
123
124#if (NXT_HAVE_POSIX_MEMALIGN || NXT_HAVE_MEMALIGN)
125#define NXT_MAX_MEMALIGN_SHIFT 32
126
127#elif (NXT_FREEBSD)
128#define NXT_MAX_MEMALIGN_SHIFT 12
129
130#else
131#define NXT_MAX_MEMALIGN_SHIFT 3
132#endif
133
134
135#endif /* _NXT_UNIX_MALLOC_H_INCLUDED_ */
111
112#endif
113
114
115#if (NXT_HAVE_POSIX_MEMALIGN || NXT_HAVE_MEMALIGN)
116#define NXT_MAX_MEMALIGN_SHIFT 32
117
118#elif (NXT_FREEBSD)
119#define NXT_MAX_MEMALIGN_SHIFT 12
120
121#else
122#define NXT_MAX_MEMALIGN_SHIFT 3
123#endif
124
125
126#endif /* _NXT_UNIX_MALLOC_H_INCLUDED_ */