Skip to content

Commit 29b109c

Browse files
committedMar 26, 2025
wip
1 parent 360293d commit 29b109c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
 

‎apc_cache.c

+12
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,18 @@ PHP_APCU_API void apc_cache_entry(apc_cache_t *cache, zend_string *key, zend_fca
12811281
}
12821282
/*}}}*/
12831283

1284+
PHP_APCU_API void apc_cache_entry_relocate(apc_cache_t* cache, apc_cache_entry_t *entry_old, apc_cache_entry_t *entry_new)
1285+
{
1286+
// ptrdiff_t offset = entry_new - entry_old;
1287+
1288+
if (entry_new->next)
1289+
entry_new->next->pprev = &entry_new->next;
1290+
1291+
*entry_new->pprev = entry_new;
1292+
1293+
// Todo: when first element, slot-ptr has to be changed
1294+
}
1295+
12841296
/*
12851297
* Local variables:
12861298
* tab-width: 4

‎apc_sma.c

+31
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,37 @@ PHP_APCU_API zend_bool apc_sma_get_avail_size(apc_sma_t* sma, size_t size) {
658658
return 0;
659659
}
660660

661+
PHP_APCU_API zend_bool apc_sma_defrag(apc_sma_t* sma, size_t size) {
662+
int32_t i;
663+
size_t realsize = ALIGNWORD(size + ALIGNWORD(sizeof(struct block_t)));
664+
665+
for (i = 0; i < sma->num; i++) {
666+
sma_header_t *shmaddr = SMA_HDR(sma, i);
667+
668+
/* If total size of available memory is too small, we can skip the contiguous-block check */
669+
if (shmaddr->avail < realsize) {
670+
continue;
671+
}
672+
673+
SMA_LOCK(sma, i);
674+
block_t *cur = BLOCKAT(ALIGNWORD(sizeof(sma_header_t)));
675+
676+
/* Look for a contiguous block of memory */
677+
while (cur->fnext) {
678+
cur = BLOCKAT(cur->fnext);
679+
680+
if (cur->size >= realsize) {
681+
SMA_UNLOCK(sma, i);
682+
return 1;
683+
}
684+
}
685+
686+
SMA_UNLOCK(sma, i);
687+
}
688+
689+
return 0;
690+
}
691+
661692
PHP_APCU_API void apc_sma_check_integrity(apc_sma_t* sma)
662693
{
663694
/* dummy */

0 commit comments

Comments
 (0)