Skip to content

Commit 89618de

Browse files
madmajestronikic
authored andcommitted
Change behavior of smart configuration setting
The smart configuration setting can now be used to increase the chance of full cache wipes during periods of high memory pressure. The idea is to use smart values > 1 to avoid performance problems when the expunge() hook is executed too often. The previous behavior was changed because it could unpredictably cause the insertion of new cache entries to fail, making the smart setting nearly useless.
1 parent 0649eb1 commit 89618de

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

apc_cache.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,9 @@ PHP_APCU_API void apc_cache_default_expunge(apc_cache_t* cache, size_t size)
753753
/* gc */
754754
apc_cache_wlocked_gc(cache);
755755

756-
/* check that expunge is necessary */
757-
if (cache->smart > 0L && apc_sma_get_avail_mem(cache->sma) >= (size_t) (cache->smart * size)) {
758-
apc_cache_wunlock(cache);
759-
return;
760-
}
756+
/* smart > 1 increases the probability of a full cache wipe,
757+
* so expunge() is called less often when memory is low. */
758+
size = (cache->smart > 0L) ? (size_t) (cache->smart * size) : size;
761759

762760
/* look for junk */
763761
for (i = 0; i < cache->nslots; i++) {

apc_cache.h

+4-12
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,12 @@ PHP_APCU_API void apc_cache_serializer(apc_cache_t* cache, const char* name);
251251

252252
/* {{{ apc_cache_default_expunge
253253
* Where smart is not set:
254-
* Where no ttl is set on cache:
255-
* 1) Perform cleanup of stale entries
256-
* 2) Expunge if available memory is less than sma->size/2
257-
* Where ttl is set on cache:
258-
* 1) Perform cleanup of stale entries
259-
* 2) If available memory if less than the size requested, run full expunge
254+
* 1) Perform cleanup of stale entries
255+
* 2) If available memory is less than the size requested, run full expunge
260256
*
261257
* Where smart is set:
262-
* Where no ttl is set on cache:
263-
* 1) Perform cleanup of stale entries
264-
* 2) Expunge is available memory is less than size * smart
265-
* Where ttl is set on cache:
266-
* 1) Perform cleanup of stale entries
267-
* 2) If available memory if less than the size requested, run full expunge
258+
* 1) Perform cleanup of stale entries
259+
* 2) If available memory is less than the size requested * smart, run full expunge
268260
*
269261
* The TTL of an entry takes precedence over the TTL of a cache
270262
*/

0 commit comments

Comments
 (0)