[問題] 為何 process list 使用質數乘法 hash?
在 Understanding the Linux kernel 3rd, 章節 3.2.3.1 讀到
為了有效率的從 PID 找出 process descriptor,因而使用 hash table
將 32 bit 的 PID 排進 2048 個entry 的表格。
hash function 是:
index = PID * 0x9e370001 >> 21
書中解釋 0x9e370001 是選擇接近 2^32 黃金分割的質數 --> 魔術常數
我對於 hash 及 linux kernel都只有初淺知識,所以不太了解:
為何不簡單的取 PID 的 LSB 11 bits當 index?
能指點其中原因嗎?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.73.49.155
※ 編輯: zstar 來自: 203.73.49.155 (01/22 13:09)
推
01/22 22:55, , 1F
01/22 22:55, 1F
→
01/24 11:16, , 2F
01/24 11:16, 2F
→
01/24 11:20, , 3F
01/24 11:20, 3F
LinuxDev 近期熱門文章
PTT數位生活區 即時熱門文章