已合并
runtime: add ClearSpan experiment to clear spans on first allocation #61
runtime: add ClearSpan experiment to clear spans on first allocation #61
已合并
cyf_123123创建于 5月13日
cyf_123123
cyf_123123
5月13日

runtime: add ClearSpan experiment to clear spans on first allocation

This change introduces the ClearSpan GOEXPERIMENT, which clears an
entire span when the first object is allocated from a span that still
requires zeroing.

The ClearSpan path moves zeroing work from each individual small
allocation to the first allocation from the span. Once the span is
cleared, needzero is reset so later allocations from the same span can
avoid repeated per-object clearing. Tiny allocation zeroing is also
adjusted to avoid redundant clearing when the span has already been
zeroed.

Tests are added to validate that ClearSpan resets needzero and clears
the backing memory only when the experiment is enabled.

likedislike
Pull Request已成功合入, 合并人@openeuler-ci-bot
(感谢 cyf_123123 的贡献)
cyf_123123cyf_123123
5月13日 创建了 pull request,commit d2f899cd
openeuler-ci-botopeneuler-ci-bot成员
5月13日 将genedna,jing-rui设为审查人
openeuler-ci-botopeneuler-ci-bot成员
5月13日 添加了label:sig/sig-golang
openeuler-ci-bot
openeuler-ci-bot成员
5月13日 评论:

Welcome To openEuler Community

Hey @qq_44302067 , 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.

Contact Guide

If you have any questions, please contact the SIG: sig-golang ,
and any of the maintainers: @genedna, @jing-rui ,
and any of the committers: @fuowang, @wd-gitcode .

likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月13日 添加了label:openeuler-cla/yes
openeuler-ci-botopeneuler-ci-bot成员
5月13日 添加了label:ci_processing
openeuler-ci-bot
openeuler-ci-bot成员
5月13日 评论:

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

likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月13日 删除了label:ci_processing
openeuler-ci-bot
openeuler-ci-bot成员
5月13日 评论:
Check Name Build Result Build Details
check_sca ✅SUCCESS #50
check_code ✅SUCCESS
check_package_license ⚠WARNING
check_anti_poisoning ✅SUCCESS
x86_64 check_build ✅SUCCESS #45
aarch64 check_build ✅SUCCESS #50
likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月13日 添加了label:ci_successful
openeuler-ci-bot
openeuler-ci-bot成员
5月13日 评论:
likedislike
wd-gitcode成员
5月14日 评论:

请先解决代码冲突

likedislike
wd-gitcode成员
5月14日 评论:

/ai help

likedislike
atomgit-bot
atomgit-bot
5月14日 评论:

AtomGit AI 助手使用指南

在 PR 评论中使用命令即可触发。支持在普通评论和代码行评论中使用。

功能 命令 说明
代码审查 /ai review 检查代码质量、潜在问题、安全风险
PR 摘要 /ai summary 生成 PR 变更内容的结构化摘要
代码解释 /ai explain 解释代码变更的逻辑和意图
自由提问 @atomgit-bot <问题> 询问关于本 PR 的任何问题
帮助 /ai help 显示此帮助信息

免责声明

AI 助手可能存在误判,请结合自身判断。可以对评论点 👍 或 👎 帮助我们改进。

likedislike
不准确?
wd-gitcode成员
5月14日 评论:

/ai review

likedislike
atomgit-bot
atomgit-bot
5月14日 评论:

代码审查

本次 PR 引入 ClearSpan 实验特性,在 span 首次分配时批量清零整个 span 内存以减少逐对象清零开销。核心逻辑正确,与 sweep 路径的 needzero 重置机制配合良好。测试代码存在使用全局 emptymspan 的不当做法和未使用的导出变量。

类型 数量
🔴 阻塞 0 处
🟡 建议 1 处

✅ 批准

likedislike
不准确?
atomgit-bot
atomgit-bot5月14日进行代码检视2
src/runtime/export_runtime_test.go
@@ -0,0 +16,4 @@
16+ 
17+ clearSpanFunc(c.alloc[spc])
18+ needzero = c.alloc[spc].needzero
19+ return
atomgit-bot
atomgit-bot5月14日评论:

🟡 Medium Priority

TryClearSpanFunc 通过 allocmcache() 获取 mcache,其 alloc[spc] 指向全局 emptymspan(见 mcache.go:95 初始化逻辑)。测试直接修改 emptymspan.needzero 并对其调用 clearSpanFunc,这会触发 memclrNoHeapPointers(unsafe.Pointer(0), 0)。虽然各平台 memclrNoHeapPointers 实现对 size=0 均安全返回,但修改全局 emptymspan 破坏了测试隔离性,并行测试下可能触发 race detector 报警,且 emptymspan.needzero 被永久修改可能影响后续依赖该值的逻辑。

同一段代码其他问题

  • 导出的变量 Class_to_size / Size_to_class8 / Size_to_class128 未被使用:这三个变量在该文件及整个 diff 范围内均未被任何测试引用,属于无用的导出,增加维护负担并可被误认为有外部依赖。
likedislike
不准确?
cyf_123123
cyf_123123
5月18日 评论:

已修改:测试已改为使用独立的测试 mspan 和本地 byte buffer,不再通过 allocmcache() 修改全局 emptymspan;同时删除了未使用的导出变量,并补充校验实际内存是否被 clearSpanFunc 清零。

cyf_123123cyf_123123
5月18日 virtual merging failed, update merge request[project_id: 8744692, iid: 61, target_commit_sha: 81d0fff494e4835f8404a6477158e22c30f87cd3], message: Conflict detected
此处折叠了11条事件消息 查看更多
openeuler-ci-botopeneuler-ci-bot成员
5月18日 删除了label:ci_successful
openeuler-ci-bot
openeuler-ci-bot成员
5月18日 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci_successful.

likedislike
openeuler-ci-bot
openeuler-ci-bot成员
5月18日 评论:

CLA Signature Pass

qq_44302067, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月18日 添加了label:ci_processing
openeuler-ci-bot
openeuler-ci-bot成员
5月18日 评论:

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

likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月18日 删除了label:ci_processing
openeuler-ci-bot
openeuler-ci-bot成员
5月18日 评论:
Check Name Build Result Build Details
check_sca ✅SUCCESS #69
check_code ✅SUCCESS
check_package_license ⚠WARNING
check_anti_poisoning ✅SUCCESS
x86_64 check_build ✅SUCCESS #64
aarch64 check_build ✅SUCCESS #69
likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月18日 添加了label:ci_successful
openeuler-ci-bot
openeuler-ci-bot成员
5月18日 评论:
likedislike
wd-gitcode成员
5月18日 评论:

/lgtm
/approve

likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月18日 添加了label:approvedlgtm
openeuler-ci-bot
openeuler-ci-bot成员
5月18日 评论:

Review Code Feedback

  • The label lgtm, approved was added to this pull request. It means that wd-gitcode reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
openeuler-ci-botopeneuler-ci-bot成员
5月18日 合入了pull request,合并节点 SHA:e47e10fff21cbbc212eb7f173695fdcc7aab5f0e