1. 程式人生 > >深入理解SPDK 之二: 消息和無鎖隊列

深入理解SPDK 之二: 消息和無鎖隊列

access 綁定 線程 less 消息傳遞 predicate 數據 傳統 準備工作

並發理論

期望: 隨著硬件的線性增加,性能也線性增加;

  • 傳統 鎖 的優點:

    1. 無鎖 到有鎖 擴展的方便;
    2. 鎖直接加在共享數據的前面;
  • 缺點:
    隨著系統內線程的增加,數據和臨界段的競爭越來越激烈,而且多個線程可能處於不同物理core,頻繁競爭導致劇烈的L1 cache 失效。

  • SPDK的做法:各管各媽;你看我娃

** 各管各媽

SPDK takes a different approach altogether. Instead of placing shared data in a global location that all threads access after acquiring a lock, SPDK will often assign that data to a single thread.

** 你看我娃
When other threads want to access the data, they pass a message to the owning thread to perform the operation on their behalf.

消息傳遞架構

  • libspdk_thread.a: SPDK‘s thread abstraction, located in;
  • spdk_thread: 線程執行的抽象
  • spdk_poller: 執行的線程內被周期執行的函數的抽象
  • spdk_allocate_thread() :分配spdk 線程
    參數是三個函數指針: 給其他線程提供的為即將創建的線程傳遞參數的函數指針;給其他線程提供的啟動當前線程poller的函數接口; 停止當前線程poller的函數接口

    spdk_io_device: 之前的含義是 支持無鎖多隊列IO請求的設備,後來泛指is any pointer, whose uniqueness is predicated only on its memory address

    spdk_io_channel: 之前的含義是指 給特別為上面IO設備分配的線程;現在是指和某個spdk_io_device綁定的per-thread的上下文context.

spdk 事件框架

現在直接調用 spdk_app_start() 為你打理所有下面的準備工作:

  • spawning one thread per core,
  • pinning each thread to a unique core,
  • allocating lockless rings between the threads for message passing

深入理解SPDK 之二: 消息和無鎖隊列