linux核心中的__read_mostly變數

來源:互聯網
上載者:User


linux核心中的__read_mostly變數 核心版本:2.6.14在閱讀socket源碼的時候,有如下一句(net/socket.c):[plain] static struct vfsmount *sock_mnt __read_mostly;  感覺__read_mostly很奇怪,就深入分析了一下。__read_mostly原語將定義為存放在.data.read_mostly段中。  www.2cto.com  [plain] #if defined(CONFIG_X86) || defined(CONFIG_SPARC64)  #define __read_mostly __attribute__((__section__(".data.read_mostly")))  #else  #define __read_mostly  #endif  由此可見,我們可以將經常需要被讀取的資料定義為 __read_mostly類型,這樣Linux核心被載入時,該資料將自動被存放到Cache中,以提高整個系統的執行效率。另一方面,如果所在的平台沒有Cache,或者雖然有Cache,但並不提供存放資料的介面(也就是並不允許人工放置資料在Cache中),這樣定義為 __read_mostly類型的資料將不能存放在Linux核心中,甚至也不能夠被載入到系統記憶體去執行,將造成Linux 核心啟動失敗。 解決的方法有兩種:修改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中這個宏沒有意義。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.