一、協議注冊:proto_register
的核心使命
在Linux網絡協議棧中,proto_register
是協議初始化的基石,主要完成三項關鍵任務:
-
Slab緩存創建(內存管理核心)
prot->slab = kmem_cache_create_usercopy(prot->name, prot->obj_size, ...); if (prot->twsk_prot) prot->twsk_prot->twsk_slab = kmem_cache_create(...);
-
為主協議對象(如
struct sock
)創建高效內存池 -
為TIME_WAIT狀態對象(
struct tcp_timewait_sock
)單獨創建緩存 -
使用
SLAB_HWCACHE_ALIGN
優化CPU緩存對齊
-
-
全局協議注冊
mutex_lock(&proto_list_mutex); list_add(&prot->node, &proto_list); // 加入全局協議鏈表 assign_proto_idx(prot