Pull Request has been successfully merged by openeuler-ci-bot.
(Thank you for xhmlja's contribution.)变更摘要
本 PR 针对 Linux 4.19 内核(如 openEuler 20.03 LTS)上 NBD 设备连接数过多导致的启动性能问题做优化。由于每次为 NBD 设备附加 socket 都会冻结该设备的块队列,而各设备的 nbd netlink 命令又在内核全局锁下串行化,4.19 内核的每次冻结还需等待 RCU 宽限期,使得并发启动沙箱被额外连接阻塞。改动新增 hostkernel 包用于识别宿主内核版本,并在 DirectPathMount.Open 中通过 connectionsPerDevice 将 4.19 内核的每设备连接数收敛为 1,其他内核仍沿用特性开关 NBDConnectionsPerDevice 的取值。
主要改动
- 新增内核版本检测包: 新增
packages/shared/pkg/hostkernel/hostkernel.go,通过unix.Uname读取内核 release 字符串,并用sync.OnceValue缓存结果,提供IsLinux419();内部isLinux419Release以精确匹配4.19或前缀4.19.判定版本。 - 新增每设备连接数决策函数:
path_direct.go中新增connectionsPerDevice(flagValue int, linux419 bool) int,当内核为 4.19 且特性开关值大于 1 时返回 1,否则原样返回开关值。 - 接入沙箱 NBD 挂载流程:
DirectPathMount.Open改为先用d.featureFlags.IntFlag(ctx, featureflags.NBDConnectionsPerDevice)读取配置,再结合hostkernel.IsLinux419()经connectionsPerDevice计算实际 socket 数,据此创建socksServer与dispatchers。 - 依赖调整:
packages/shared/go.mod中golang.org/x/sys由 indirect 依赖提升为直接依赖,以支持unix.Uname。 - 新增单元测试: 新增
connections_test.go与hostkernel_test.go,分别覆盖不同内核/开关组合下的连接数返回值,以及4.19、4.19.90-...等 release 字符串的判定边界(如4.190、14.19.1、空串返回false)。


Welcome To openEuler Community
Hey @xhmlja , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
Contact Guide
If you have any questions, please contact the SIG: sig-CloudNative ,
and any of the maintainers: @duguhaotian, @gaodaweiky, @jimmieme, @lu-wei-army, @weibaohui, @wonleing, @yangzhao_kl, @zhaoyifan28, @zmr_2020 ,
and any of the committers: @feijianqiang, @zhourenjianz .


门禁正在运行, 您可以通过以下链接查看实时门禁检查结果.
若您对门禁结果含义不清晰或者遇到问题不知如何解决,可参考门禁指导手册
门禁入口及编码规范检查: multiarch/openeuler/trigger/KASandbox/525


/lgtm


当前PR是否有AI参与:
[x] 否
[ ] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :
参考:openEuler社区《生成式AI工具使用与开源贡献政策》
PR功能描述 / 为什么需要这个合入**:
该PR关联的issue
(格式为fixes #<issue号>, 或者resolves #<issue号>): fixes #
希望检视人员了解: