Disable SHM reattachment
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.2k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
Description
I'm opening this issue to restart the discussion started by @cmb69 in https://github.com/php/php-src/pull/17838 and https://github.com/php/php-src/pull/7865.
SHM reattachment leads to a number of problems, and likely fails often in practice, so I would like to disable it.
The reason we have SHM reattachment is that Windows doesn't support fork(), so multi-process SAPIs spawn independent processes. Therefore each process needs to reattach the Opcache SHM of previous processes.
This comes with a number of problems:
- The SHM must be attached at the same address in all processes. If the address is not free in one process, reattachment can not happen.
- When ASLR is enabled, some addresses referenced by SHM are invalid (such as opcode handler addresses stored in op arrays). Therefore, reattachment fails when ASLR is enabled (source).
- The memory layout of each process can differ regardless of ASLR, for example when DLLs were loaded in a different order. Therefore, SHM can not usually reference addresses out of SHM. This leads to various Windows-specific workarounds and special cases in the code base. For example, the inheritance cache is disabled for sub-classes of internal classes.
Additionally, this makes preloading incompatible with Windows, which blocks https://github.com/php/php-src/pull/18204.
In cases 1 and 2, the process fails with a fatal error, or fallsback to file_cache_only mode (when enabled), which is slower. So processes can randomly fail or be slower.
Case 2 implies that reattachment fails most of the times, now that ASLR is enabled by default.
Because of these, I believe that it would be beneficial to disable reattachment entirely.
Here is the impact on existing ways to deploy PHP, and what changes are required before we can disable reattachment:
IIS + FastCGI
In this configuration IIS itself manages PHP processes. Unfortunately this enforces a process-based model, and reattachment is required so that concurrent requests share the same cache.
I suggest that we recommend other configurations for performance-sensitive deployments. Disabling reattachment wouldn't impact development setups, so we can continue to support this configuration without reattachment.
Nginx + FastCGI
In this configuration, php-cgi manages child processes itself. Therefore we can switch this SAPI to threads in ZTS builds so that reattachment is not necessary anymore. This would likely make the SAPI more resource-efficient on Windows as well.
Apache + mod_php
Uses mpm_winnt, which spawns a single process and multiple threads.
Therefore, reattachment should not be necessary.
See https://github.com/php/php-src/pull/7865.
Additionally, @cmb69 started the implementation of an isapi-based SAPI:
IIS + isapi
Threaded, doesn't need reattachment
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza con ext/opcache/shared_alloc_win32.c y lee los pull requests vinculados #17838 y #7865. Revisa cómo afecta la reanudación de la conexión a SHM a IIS, Nginx, Apache y la SAPI ISAPI propuesta, y define los cambios de despliegue necesarios. Se considera terminado cuando exista un diseño acordado y una implementación que desactive la reanudación de la conexión sin romper las configuraciones con hilos compatibles.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, php
- Área
- backend, operating-systems
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100