Processor Affinity
Introduction
在 multiple processor 環境中,我們傾向於讓一個 thread 綁定在一個 processor 上面而不是頻繁遷移
Reason
當 thread 在某個 processor 上執行時,會把需要用到的數據存到 processor 的 cache 上面。如果將 thread 換到另一個 processor 上跑,舊的 cache 就廢掉了
→ 這會造成大量的 cache miss
Tradeoff: Processor Affinity and Load Balancing
系統為了平衡各個 core 的工作量,可能會把 thread 從一個 processor 遷到另一個,這會讓 thread 失去之前建立的 cache 增加 cache miss
→ 需要再 performance 和 load balancing 間權衡
Affinity Mode
1. Soft Affinity
OS 盡量讓 thread 待在原 processor 上跑(無保證)
2. Hard Affinity
Process 明確指定自己只能在某些 processor 上運行(強制執行)