2019年5月25日 星期六

prefetch

在 Linux Kernel,為了減少 cache miss 來增進效能,可將預期會用到的資料用 prefetch() 事先讀取,但有些只是想像效能會較好,沒有實證反而可能有反效果。

例如 <linux/list.h> 的 list_for_each() macro:
    #define list_for_each(pos, head) \
 for (pos = (head)->next; prefetch(pos->next), pos != (head); \
            pos = pos->next)
經過實證反而效能較差 (短 list、null prefetch),硬體自己做的不會較差。

其它:
  • reordering structures that commonly accessed together fields are found in the same cache line
  • linked-list => cache-unfriendly
  • singly-linked hlist hash table list 
  • likely()
參考:
The problem with prefetch

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...