Linuxの匿名プロセスとは何ですか?

Linuxの匿名プロセスとは何ですか?

task_structのmmフィールドとactive_mmフィールドの違いを理解しようとしています。リヌス・トバルズが20年前に送ったメール「匿名プロセス」という概念が引用された。


 - we have "real address spaces" and "anonymous address spaces". The
   difference is that an anonymous address space doesn't care about the
   user-level page tables at all, so when we do a context switch into an
   anonymous address space we just leave the previous address space
   active.

   [...]

 - "tsk->mm" points to the "real address space". For an **anonymous process**,
   tsk->mm will be NULL, for the logical reason that an **anonymous process**
   really doesn't _have_ a real address space at all.

 - however, we obviously need to keep track of which address space we
   "stole" for such an anonymous user. For that, we have "tsk->active_mm",
   which shows what the currently active address space is.

   The rule is that for a process with a real address space (ie tsk->mm is
   non-NULL) the active_mm obviously always has to be the same as the real
   one.

   For a **anonymous process**, tsk->mm == NULL, and tsk->active_mm is the
   "borrowed" mm while the **anonymous process** is running. When the
   **anonymous process** gets scheduled away, the borrowed address space is
   returned and cleared.

ベストアンサー1

この部分はある程度説明します。Eメールあなたはそれを省略しました。

「匿名アドレス空間」の明白な用途は、ユーザマッピングを必要としない全てのスレッドである。すべてのカーネルスレッドはデフォルトでこのカテゴリに属していますが、「実際の」スレッドでも一時的にユーザーには実行されないと言えます。スペースが重要であるため、スケジューラは仮想マシンの状態を切り替えるのに時間を無駄にしないように努めることができます。現時点では、以前のスタイルのbdflush syncのみがこれを実行できます。

カーネルスレッドはカーネルメモリにのみアクセスするので、ユーザ空間メモリの内容には興味がない。 「匿名プロセス」はこれを最適化したものです。

スケジューラがカーネルスレッド操作に切り替えると、比較的時間がかかるメモリマッピング設定をスキップし、前のプロセスのアドレス空間のみを維持できます。アドレス空間のカーネル部分はすべてのプロセスに対して同じ方法でマッピングされるため、これらの操作にどのマッピングが使用されるかは違いはありません。

この最適化は、タスクがカーネル空間コードを実行している間(たとえば、システムコールがsync完了するのを待っている間)、ユーザー空間タスクに一時的に適用することもできます。実際のアドレス空間は、ユーザー空間に戻る前に復元するだけです。パスワード。電子メールで述べたように、少なくともそれ以降はこれはもう行われていないようです。bdflushカーネルスレッドに置き換えられましたpdflush

おすすめ記事