Skip to content

Commit c441c9e

Browse files
committed
trying rshutdown graph compaction
1 parent 5c243f5 commit c441c9e

5 files changed

Lines changed: 473 additions & 29 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
OPcache explicit volatile cache relocates unreferenced shared graph blocks during compaction
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.static_cache.volatile_size_mb=8
9+
--FILE--
10+
<?php
11+
12+
function build_relocatable_graph(): array
13+
{
14+
$rows = [];
15+
for ($i = 0; $i < 3500; $i++) {
16+
$rows[] = [
17+
$i,
18+
str_repeat(chr(65 + ($i % 26)), 48),
19+
[$i * 2, $i * 3],
20+
];
21+
}
22+
23+
return [
24+
'rows' => $rows,
25+
'meta' => ['kind' => 'relocatable'],
26+
];
27+
}
28+
29+
OPcache\volatile_clear();
30+
31+
var_dump(OPcache\volatile_store('shared_graph_relocation_first', str_repeat('A', 1500000)));
32+
var_dump(OPcache\volatile_store('shared_graph_relocation_graph', build_relocatable_graph()));
33+
var_dump(OPcache\volatile_store('shared_graph_relocation_third', str_repeat('C', 1500000)));
34+
35+
OPcache\volatile_delete('shared_graph_relocation_first');
36+
37+
var_dump(OPcache\volatile_store('shared_graph_relocation_merged', str_repeat('M', 3200000)));
38+
39+
$graph = OPcache\volatile_fetch('shared_graph_relocation_graph');
40+
var_dump($graph['rows'][123][1]);
41+
var_dump($graph['rows'][123][2][1]);
42+
var_dump($graph['meta']['kind']);
43+
var_dump(strlen(OPcache\volatile_fetch('shared_graph_relocation_merged')));
44+
var_dump(strlen(OPcache\volatile_fetch('shared_graph_relocation_third')));
45+
46+
?>
47+
--EXPECT--
48+
bool(true)
49+
bool(true)
50+
bool(true)
51+
bool(true)
52+
string(48) "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
53+
int(369)
54+
string(11) "relocatable"
55+
int(3200000)
56+
int(1500000)

ext/opcache/zend_static_cache.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,11 +1290,17 @@ static zend_result zend_opcache_static_cache_rinit(void)
12901290

12911291
zend_result zend_opcache_static_cache_rshutdown(void)
12921292
{
1293+
bool shared_graph_refs_released;
1294+
12931295
zend_opcache_static_cache_clear_lookup_caches();
12941296
zend_opcache_static_cache_request_shutdown();
12951297
zend_opcache_static_cache_release_request_entry_locks();
12961298
zend_opcache_static_cache_release_request_local_slots();
1297-
zend_opcache_static_cache_release_request_shared_graph_refs();
1299+
1300+
shared_graph_refs_released = zend_opcache_static_cache_release_request_shared_graph_refs();
1301+
if (shared_graph_refs_released) {
1302+
zend_opcache_static_cache_compact_after_request_shutdown();
1303+
}
12981304

12991305
EG(static_cache_class_access_active) = false;
13001306
EG(tracked_mutation_hooks_active) = false;

ext/opcache/zend_static_cache_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ bool zend_opcache_static_cache_header_init_locked(void);
421421
void zend_opcache_static_cache_free_locked(uint32_t payload_offset);
422422
uint32_t zend_opcache_static_cache_alloc_locked(size_t size, const void *source);
423423
bool zend_opcache_static_cache_compact_to_fit_locked(size_t size);
424+
bool zend_opcache_static_cache_compact_available_locked(void);
425+
void zend_opcache_static_cache_compact_after_request_shutdown(void);
424426
bool zend_opcache_static_cache_startup_storage_before_request(void);
425427
void zend_opcache_static_cache_shutdown_storage(void);
426428
void zend_opcache_static_cache_ensure_ready(void);
@@ -461,13 +463,15 @@ bool zend_opcache_static_cache_shared_graph_copy_fits_buffer(
461463
size_t target_buffer_len);
462464
bool zend_opcache_static_cache_fetch_shared_graph(const unsigned char *buffer, size_t buffer_len, zval *destination);
463465
bool zend_opcache_static_cache_shared_graph_can_overwrite_payload_locked(uint32_t payload_offset);
466+
bool zend_opcache_static_cache_shared_graph_can_move_payload_locked(uint32_t payload_offset);
467+
bool zend_opcache_static_cache_shared_graph_rebase_moved_payload_locked(uint32_t payload_offset, ptrdiff_t delta);
464468
bool zend_opcache_static_cache_shared_graph_acquire_locked(uint32_t payload_offset);
465469
bool zend_opcache_static_cache_shared_graph_retire_payload_locked(uint32_t payload_offset);
466470
bool zend_opcache_static_cache_shared_graph_release_ref_locked(uint32_t payload_offset);
467471
bool zend_opcache_static_cache_has_request_shared_graph_ref(uint32_t payload_offset);
468472
void zend_opcache_static_cache_register_shared_graph_ref(uint32_t payload_offset);
469473
void zend_opcache_static_cache_defer_retired_shared_graph_free(uint32_t payload_offset);
470-
void zend_opcache_static_cache_release_request_shared_graph_refs(void);
474+
bool zend_opcache_static_cache_release_request_shared_graph_refs(void);
471475
bool zend_opcache_static_cache_clear_locked(void);
472476
bool zend_opcache_static_cache_prepare_value(
473477
zend_opcache_static_cache_prepared_value *prepared,

0 commit comments

Comments
 (0)