pmmp / ext-pmmpthread

Fork of https://github.com/krakjoe/pthreads with a revamped API and PHP 8.1+ support
Other
81 stars 17 forks source link

Using OPcache JIT will cause memory leak #61

Closed larryTheCoder closed 2 years ago

larryTheCoder commented 3 years ago

Environment

Introduction

The memory leak problem occurs when JIT is enabled for PocketMine-MP server especially for the PopulationTasks in one of the AsyncWorker. Unfortunately I am unable to reproduce this memory leak outside PopulationTask and this leak is producible without any plugins used in the server. The leak seems to start when the chunk is being generated(?)

This could either be PocketMine-MP issue but I do not think that this is the case since it is working just fine without JIT enabled.

Reproducing Code

It can be reproduced using my debug branch of PocketMine-MP 4.0 software. The only changes is that, there will be memory_get_usage() in certain parts where I believe the memory leaks begin.

opcache.jit will be set to 1205

Expected Output

This is what would happen if JIT is not enabled. No abnormal memory usage, everything is fine. non-jit.txt

Memory usage in bytes

Memory usage: 23054712 23146400 23146400 23146400  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23146400 23146400 23146400  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23146400 23146400 23146400  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23149224 23149224 23149224  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23137784 23137784 23137784  31457280 31457280 31457280 31457280
Memory usage: 23054712 23138208 23138208 23138208  31457280 31457280 31457280 31457280
Memory usage: 23054712 23146400 23146400 23146400  31457280 31457280 31457280 31457280
...

Actual Output

This is when JIT is enabled, the memory usage gradually increased until the worker ran out of memory and died. jit.txt

Memory usage in bytes

Memory usage: 29945536 30041320 30041320 30041320  39845888 39845888 39845888 39845888
Memory usage: 29957824 30061800 30061800 30061800  39845888 39845888 39845888 39845888
Memory usage: 29966016 30069144 30069144 30069144  39845888 39845888 39845888 39845888
Memory usage: 29974208 30071264 30071264 30071264  39845888 39845888 39845888 39845888
Memory usage: 29986496 30090472 30090472 30090472  39845888 39845888 39845888 39845888
Memory usage: 29998784 30094992 30095840 30095840  39845888 39845888 39845888 39845888
Memory usage: 30011072 30110952 30110952 30110952  39845888 39845888 39845888 39845888
Memory usage: 30019264 30115472 30115896 30115896  39845888 39845888 39845888 39845888
Memory usage: 30031552 30135528 30135528 30135528  39845888 39845888 39845888 39845888
Memory usage: 30039744 30132280 30132704 30132704  39845888 39845888 39845888 39845888
Memory usage: 30047936 30152760 30152760 30152760  39845888 39845888 39845888 39845888
Memory usage: 30060224 30157280 30157280 30157280  39845888 39845888 39845888 39845888
Memory usage: 30072512 30172392 30172392 30172392  39845888 39845888 39845888 39845888
...
dktapps commented 3 years ago

I think this is a fault of the JIT itself. I've also seen problems like this using PHPStan.

dktapps commented 2 years ago

Hi, I don't intend to investigate this since the JIT has continued to be unreliable.