[英]Is there a size limit for kernel module in linux?
我在加載 kernel 模塊時遇到問題,有一個大數據結構,大小約為 memory 的 2Gb - 我是否預先分配表(以便在我執行size -A module.ko
或嘗試vmalloc()
時顯示 in.bss vmalloc()
它在加載時,模塊加載失敗insmod: error inserting 'module.ko': -1 Cannot allocate memory
。
我嘗試在用戶模式 linux 上調試問題,但我得到了一堆段錯誤(可以在 gdb 中繼續,但最終overflow in relocation type 10 val <value in the ball park of 6G>
和'module' likely not compiled with -mcmodel=kernel
中出現控制台消息溢出'module' likely not compiled with -mcmodel=kernel
。我認為使用Kbuild
時-mcmodel
應該是正確的,對吧?
所以問題是:
-mcmodel=large
並期望它工作嗎?I've tried this on debian squeeze, 64-bit, 2.6.32-5-amd64 (host) with 8Gb of memory and 2.6.32 in uml with 4G memory, so this should not be an ordinary out of memory problem.
如果存在這樣的限制,則可以在限制范圍內工作的額外功勞:)
至於您的第一個問題 - 模塊本身的限制是 64 兆字節。 模塊加載器將拒絕加載超過此大小的模塊。 從kernel/module.c :
if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
return ERR_PTR(-ENOMEM);
這對於 2.6.32 和較新的內核(最高 3.3)都是如此。
編輯:在 kernel 3.4 版中,刪除了 64 Mb 限制。 現在實際限制只取決於 memory vmalloc()
可以分配多少。
Remember that kernel-space memory is different from user-space memory -- on 32-bit Linux, the kernel has only 1Gb address space. 64 位 Linux 上的 kernel 有一個日志更多空間地址空間,但kernel 文檔表明只有 1536MB 可用於模塊。
如果我將表定義為static
- 模塊加載確實會失敗 - 這可能是因為Andrew Aylett的答案中提到的 1.5G 限制
但是,如果我進行動態vmalloc()
調用,我能夠在具有 8Gb 的 memory 的主機上獲得高達 7680Mb 的數據(直到 kernel 殺死了一些關鍵進程並且我的 X 掛起)。
所以回答我的問題:
static
的數據 額外的功勞:只需執行vmalloc()
這僅適用於2.6.10之后的 linux 內核 - 在此之前, vmalloc()
限制為 64 Mb。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.