php / php/php-src

Disable SHM reattachment

オープン
#20,470 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Feature Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

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:

  1. 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.
  2. 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).
  3. 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

See https://github.com/php/php-src/pull/17838.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ext/opcache/shared_alloc_win32.c から始め、リンクされている pull request #17838 と #7865 を読んでください。SHM の再アタッチが IIS、Nginx、Apache、および提案されている ISAPI SAPI にどのような影響を与えるかを確認し、その後、必要なデプロイメントの変更を定義してください。完了の条件は、サポートされているスレッド構成を壊すことなく再アタッチを無効にする、合意済みの設計と実装ができていることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
backend, operating-systems
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。