Linux

這些名為磁碟的執行緒是什麼0,d我是_0,d一世sķ0, disk1等?

  • May 20, 2022

我正在使用 Ubuntu 20.04 LTS。核心版本為 5.4.0-42。

這是一個範常式序:

// mre.c
// Compile with: cc -o mre mre.c -lSDL2
#include <stdio.h>
#include <SDL2/SDL.h>
int main(void)
{
   SDL_Init(SDL_INIT_VIDEO); // Doesn't work without SDL_INIT_VIDEO
   getchar();
}

當我在打開執行緒名稱的情況下查看正在執行的程序./mrehtop,我看到它有以下四個執行緒:

  • mre:disk$3
  • mre:disk$2
  • mre:disk$1
  • mre:disk$0

以下是一些/usr/libexec/ibus-x11具有相似名稱的執行緒:

  • ibus-x1:disk$3
  • ibus-x1:disk$2
  • ibus-x1:disk$1
  • ibus-x1:disk$0

許多程序沒有它們(也許它們沒有使用某個圖形界面?)

這樣的執行緒總是四個(我的電腦有四個核心)並按降序排列。/usr/lib/xorg/Xorg有八個這樣的執行緒,每個數字 0-3 兩個。它們是乾什麼用的?

這些執行緒用於檯面磁碟記憶體

  util_queue_init(&cache->cache_queue, "disk$", 32, 4,
                  UTIL_QUEUE_INIT_RESIZE_IF_FULL |
                  UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY |
                  UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY);

https://sources.debian.org/src/mesa/22.0.3-1/src/util/disk_cache.c/?hl=174#L174

然後在裡面util_queue_init()

  /* Form the thread name from process_name and name, limited to 13
   * characters. Characters 14-15 are reserved for the thread number.
   * Character 16 should be 0. Final form: "process:name12"
   *
   * If name is too long, it's truncated. If any space is left, the process
   * name fills it.
   */

https://sources.debian.org/src/mesa/22.0.3-1/src/util/u_queue.c/?hl=405#L414-L420

因此,所有以某種方式呼叫該檯面程式碼的 GUI 程序都會創建那些額外的執行緒,例如在我的 f33 桌面系統上:

   pid     tid            comm cls
  1942    1989  gnome-s:disk$0 BAT 
  1942    1990  gnome-s:disk$1 BAT 
  1942    1991  gnome-s:disk$2 BAT 
  1942    1992  gnome-s:disk$3 BAT 
  2041    2237  Xwaylan:disk$0 BAT 
  2041    2238  Xwaylan:disk$1 BAT 
  2041    2239  Xwaylan:disk$2 BAT 
  2041    2240  Xwaylan:disk$3 BAT 
  2041    2259  Xwaylan:disk$0 BAT 
  2041    2260  Xwaylan:disk$1 BAT 
  2041    2261  Xwaylan:disk$2 BAT 
  2041    2262  Xwaylan:disk$3 BAT 
  2292    2325  gsd-xse:disk$0 BAT 
  2292    2326  gsd-xse:disk$1 BAT 
  2292    2327  gsd-xse:disk$2 BAT 
  2292    2328  gsd-xse:disk$3 BAT 
  2307    2344  ibus-x1:disk$0 BAT 
  2307    2345  ibus-x1:disk$1 BAT 
  2307    2346  ibus-x1:disk$2 BAT 
  2307    2347  ibus-x1:disk$3 BAT 
  2464    2578  firefox:disk$0 BAT 
  2464    2579  firefox:disk$1 BAT 
  2464    2580  firefox:disk$2 BAT 
  2464    2581  firefox:disk$3 BAT 
  2756    2785  firefox:disk$0 BAT 
  2756    2786  firefox:disk$1 BAT 
  2756    2787  firefox:disk$2 BAT 
  2756    2788  firefox:disk$3 BAT 
  2806    2841  firefox:disk$0 BAT 
  2806    2842  firefox:disk$1 BAT 
  2806    2843  firefox:disk$2 BAT 
  2806    2844  firefox:disk$3 BAT 
  2919    3078  firefox:disk$0 BAT 
  2919    3079  firefox:disk$1 BAT 
  2919    3080  firefox:disk$2 BAT 
  2919    3081  firefox:disk$3 BAT 
  3346    3367  firefox:disk$0 BAT 
  3346    3368  firefox:disk$1 BAT 
  3346    3369  firefox:disk$2 BAT 
  3346    3370  firefox:disk$3 BAT 
  3408    3426  firefox:disk$0 BAT 
  3408    3427  firefox:disk$1 BAT 
  3408    3428  firefox:disk$2 BAT 
  3408    3429  firefox:disk$3 BAT 
  5794    5825  firefox:disk$0 BAT 
  5794    5826  firefox:disk$1 BAT 
  5794    5827  firefox:disk$2 BAT 
  5794    5828  firefox:disk$3 BAT 
  6345    6364  firefox:disk$0 BAT 
  6345    6365  firefox:disk$1 BAT 
  6345    6366  firefox:disk$2 BAT 
  6345    6367  firefox:disk$3 BAT 
  9502    9525  firefox:disk$0 BAT 
  9502    9526  firefox:disk$1 BAT 
  9502    9527  firefox:disk$2 BAT 
  9502    9528  firefox:disk$3 BAT 
 22548   22565  firefox:disk$0 BAT 
 22548   22566  firefox:disk$1 BAT 
 22548   22567  firefox:disk$2 BAT 
 22548   22568  firefox:disk$3 BAT 
 33788   33807      vlc:disk$0 BAT 
 33788   33808      vlc:disk$1 BAT 
 33788   33809      vlc:disk$2 BAT 
 33788   33810      vlc:disk$3 BAT 
 48178   74574  kwallet:disk$0 BAT 
 48178   74575  kwallet:disk$1 BAT 
 48178   74576  kwallet:disk$2 BAT 
 48178   74577  kwallet:disk$3 BAT 
 60824   60830  chromiu:disk$0 BAT 
 60824   60831  chromiu:disk$1 BAT 
 60824   60832  chromiu:disk$2 BAT 
 60824   60833  chromiu:disk$3 BAT 
 69502   69519  firefox:disk$0 BAT 
 69502   69520  firefox:disk$1 BAT 
 69502   69521  firefox:disk$2 BAT 
 69502   69522  firefox:disk$3 BAT

引用自:https://unix.stackexchange.com/questions/605898