并发理论
期望: 随着硬件的线性增加,性能也线性增加;
-
传统 锁 的优点:
- 无锁 到有锁 扩展的方便;
- 锁直接加在共享数据的前面;
-
缺点:
随着系统内线程的增加,数据和临界段的竞争越来越激烈,而且多个线程可能处于不同物理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