@@ -152,15 +152,15 @@ static inline block_t *find_block(sma_header_t *header, size_t realsize) {
152
152
}
153
153
154
154
/* {{{ sma_allocate: tries to allocate at least size bytes in a segment */
155
- static APC_HOTSPOT size_t sma_allocate (sma_header_t * header , size_t size , size_t fragment , size_t * allocated )
155
+ static APC_HOTSPOT size_t sma_allocate (sma_header_t * header , size_t size , size_t min_block_size , size_t * allocated )
156
156
{
157
157
void * shmaddr ; /* header of shared memory segment */
158
158
block_t * prv ; /* block prior to working block */
159
159
block_t * cur ; /* working block in list */
160
160
size_t realsize ; /* actual size of block needed, including header */
161
- size_t block_size = ALIGNWORD (sizeof (struct block_t ));
161
+ size_t block_header_size = ALIGNWORD (sizeof (struct block_t ));
162
162
163
- realsize = ALIGNWORD (size + block_size );
163
+ realsize = ALIGNWORD (size + block_header_size );
164
164
165
165
/*
166
166
* First, insure that the segment contains at least realsize free bytes,
@@ -178,9 +178,9 @@ static APC_HOTSPOT size_t sma_allocate(sma_header_t *header, size_t size, size_t
178
178
return SIZE_MAX ;
179
179
}
180
180
181
- if (cur -> size == realsize || ( cur -> size > realsize && cur -> size < (realsize + ( MINBLOCKSIZE + fragment )) )) {
181
+ if (cur -> size >= realsize && cur -> size < (realsize + min_block_size )) {
182
182
/* cur is big enough for realsize, but too small to split - unlink it */
183
- * (allocated ) = cur -> size - block_size ;
183
+ * (allocated ) = cur -> size - block_header_size ;
184
184
prv = BLOCKAT (cur -> fprev );
185
185
prv -> fnext = cur -> fnext ;
186
186
BLOCKAT (cur -> fnext )-> fprev = OFFSET (prv );
@@ -192,7 +192,7 @@ static APC_HOTSPOT size_t sma_allocate(sma_header_t *header, size_t size, size_t
192
192
193
193
oldsize = cur -> size ;
194
194
cur -> size = realsize ;
195
- * (allocated ) = cur -> size - block_size ;
195
+ * (allocated ) = cur -> size - block_header_size ;
196
196
nxt = NEXT_SBLOCK (cur );
197
197
nxt -> prev_size = 0 ; /* block is alloc'd */
198
198
nxt -> size = oldsize - realsize ; /* and fix the size */
@@ -221,7 +221,7 @@ static APC_HOTSPOT size_t sma_allocate(sma_header_t *header, size_t size, size_t
221
221
fprintf (stderr , "allocate(realsize=%d,size=%d,id=%d)\n" , (int )(size ), (int )(cur -> size ), cur -> id );
222
222
#endif
223
223
224
- return OFFSET (cur ) + block_size ;
224
+ return OFFSET (cur ) + block_header_size ;
225
225
}
226
226
/* }}} */
227
227
@@ -288,7 +288,7 @@ static APC_HOTSPOT size_t sma_deallocate(void* shmaddr, size_t offset)
288
288
/* }}} */
289
289
290
290
/* {{{ APC SMA API */
291
- PHP_APCU_API void apc_sma_init (apc_sma_t * sma , void * * data , apc_sma_expunge_f expunge , int32_t num , size_t size , char * mask ) {
291
+ PHP_APCU_API void apc_sma_init (apc_sma_t * sma , void * * data , apc_sma_expunge_f expunge , int32_t num , size_t size , size_t min_alloc_size , char * mask ) {
292
292
int32_t i ;
293
293
294
294
if (sma -> initialized ) {
@@ -298,6 +298,7 @@ PHP_APCU_API void apc_sma_init(apc_sma_t* sma, void** data, apc_sma_expunge_f ex
298
298
sma -> initialized = 1 ;
299
299
sma -> expunge = expunge ;
300
300
sma -> data = data ;
301
+ sma -> min_block_size = min_alloc_size > 0 ? ALIGNWORD (min_alloc_size + ALIGNWORD (sizeof (struct block_t ))) : MINBLOCKSIZE ;
301
302
302
303
#ifdef APC_MMAP
303
304
/*
@@ -399,7 +400,6 @@ PHP_APCU_API void apc_sma_detach(apc_sma_t* sma) {
399
400
}
400
401
401
402
PHP_APCU_API void * apc_sma_malloc_ex (apc_sma_t * sma , size_t n , size_t * allocated ) {
402
- size_t fragment = MINBLOCKSIZE ;
403
403
size_t off ;
404
404
int32_t i ;
405
405
zend_bool nuked = 0 ;
@@ -412,7 +412,7 @@ PHP_APCU_API void *apc_sma_malloc_ex(apc_sma_t *sma, size_t n, size_t *allocated
412
412
return NULL ;
413
413
}
414
414
415
- off = sma_allocate (SMA_HDR (sma , last ), n , fragment , allocated );
415
+ off = sma_allocate (SMA_HDR (sma , last ), n , sma -> min_block_size , allocated );
416
416
417
417
if (off != SIZE_MAX ) {
418
418
void * p = (void * )(SMA_ADDR (sma , last ) + off );
@@ -434,7 +434,7 @@ PHP_APCU_API void *apc_sma_malloc_ex(apc_sma_t *sma, size_t n, size_t *allocated
434
434
return NULL ;
435
435
}
436
436
437
- off = sma_allocate (SMA_HDR (sma , i ), n , fragment , allocated );
437
+ off = sma_allocate (SMA_HDR (sma , i ), n , sma -> min_block_size , allocated );
438
438
if (off != SIZE_MAX ) {
439
439
void * p = (void * )(SMA_ADDR (sma , i ) + off );
440
440
sma -> last = i ;
0 commit comments