Skip to content

Single process memory model for opcache in ZTS #20774

@dktapps

Description

@dktapps

Description

In ZTS, all requests run inside the same process, so there's no need for coordination between different processes.
This means that a non-SHM memory model could be used, and a lock file could be replaced by a regular mutex.

This would be beneficial for applications that run exclusively in ZTS and create userland threads, such as PocketMine-MP. PocketMine already uses ZTS and opcache CLI in most places, but it's currently unable to assume opcode caching is always available due to some platforms restricting access to certain lockfile features and SHM, such as Android.
PocketMine has a lot of users who insist on running servers on their mobile devices for some reason, so they'd stand to benefit :)

Since classes and op_arrays in general are non-thread-safe by default, threading extensions benefit a ton from Opcache since Opcache makes op_arrays and many other structures thread-safe by design, so they don't need to be copied. However, because Opcache uses features that are restricted on some platforms - features which are not necessary when running in ZTS mode and creating user threads - the likes of ext-pmmpthread still have to copy-paste large amounts of code from zend_persist.c to provide this functionality if Opcache is not available. If Opcache had a non-SHM memory model that didn't require lockfiles, mmap or any other fancy stuff, this would allow my threading extension to assume Opcache will always be available and caching code, which would potentially allow me to delete an insane amount of code and massively reduce the maintenance burden of the extension.

I don't know if there might be some advantages for ZTS in general (perhaps lower overhead?) but this doesn't seem like a hard change in any case as far as I can understand, so I thought I'd float the suggestion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions