linux内核中的__read_mostly变量
在阅读socket源码的时候,有如下一句(net/socket.c):
本文引用地址:https://www.eepw.com.cn/article/201611/319987.htm[plain]view plaincopyprint?
- staticstructvfsmount*sock_mnt__read_mostly;
感觉__read_mostly很奇怪,就深入分析了一下。
__read_mostly原语将定义为存放在.data.read_mostly段中。
[plain]view plaincopyprint?
- #ifdefined(CONFIG_X86)||defined(CONFIG_SPARC64)
- #define__read_mostly__attribute__((__section__(".data.read_mostly")))
- #else
- #define__read_mostly
- #endif
解决的方法有两种:
- 修改include/asm/cache.h中的__ready_mostly定义为:#define __read_mostly
- 修改arch/xxx/kernel/vmlinux.S,将.data.read_mostly段的位置到实际内存空间中去,例如放置在 .data段之后等等。
此外,内核源码通过CONFIG_X86)和(CONFIG_SPARC64)来判断该怎样定义__read_mostly,因此在arm中这个宏没有意义。
评论