子スレッドが親スレッドのcgroupに自動的に入るのを防ぐ方法はありますか?

子スレッドが親スレッドのcgroupに自動的に入るのを防ぐ方法はありますか?

私は私が作成したLinux cgroupにアプリケーションスレッドのいくつかを明示的に書いています。cpuたとえば、今はv1について話していますが、v2の方法を知っていればいいでしょう。

ただし、子スレッド(pthread_create()親スレッドの呼び出しで作成したり、cgroupに明示的に書き込んだり、親スレッドの後に再構築したスレッド)も、直接作成せずにcgroupに表示されることがわかります。

これはアプリケーションに悪影響を及ぼす可能性があります。いくつかのスレッドが予期せずcgroupに到達します。常にこの警告に注意し、スレッドプールなどの事項に注意する必要があります。

この問題に対する解決策はありますか?たとえば、サブスレッドが親cgroupに自動的に入らないように無効にする方法はありますか?助けてくれてありがとう。

ベストアンサー1

マニュアルページからclone(2)このフラグに関する情報を見つけることができますCLONE_INTO_CGROUP

   CLONE_INTO_CGROUP (since Linux 5.7)
          By default, a child process is placed in the same version
          2 cgroup as its parent.  The CLONE_INTO_CGROUP flag allows
          the child process to be created in a different version 2
          cgroup.  (Note that CLONE_INTO_CGROUP has effect only for
          version 2 cgroups.)

          In order to place the child process in a different cgroup,
          the caller specifies CLONE_INTO_CGROUP in cl_args.flags
          and passes a file descriptor that refers to a version 2
          cgroup in the cl_args.cgroup field.  (This file descriptor
          can be obtained by opening a cgroup v2 directory using
          either the O_RDONLY or the O_PATH flag.)  Note that all of
          the usual restrictions (described in cgroups(7)) on
          placing a process into a version 2 cgroup apply.

マニュアルページの下に詳細情報があります。

ただし、これは定義されたセットを使用するpthread_createラッパーです。cloneバナー変更できない事項:

  const int clone_flags = (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SYSVSEM
               | CLONE_SIGHAND | CLONE_THREAD
               | CLONE_SETTLS | CLONE_PARENT_SETTID
               | CLONE_CHILD_CLEARTID
               | 0);

cloneしたがって、目標を達成する唯一の方法は代わりに使用するようですpthread_create。個人的に試したことはありませんが、最善の方法のようです。

おすすめ記事