首页 > 解决方案 > 如何在 Linux 内核中更改 PAGESIZE

问题描述

我想PAGE_SIZE4096实验中改变。所以我改变了PAGE_SHIFTin的值/arch/x86/include/asm/page_types.h。但我无法编译它。

In file included from include/linux/linkage.h:4:0,
from include/linux/kernel.h:6,
from include/linux/cache.h:4,
from include/linux/time.h:4,
from arch/x86/kernel/vsyscall_64.c:23:
arch/x86/kernel/vsyscall_64.c: function ‘map_vsyscall’ 内:
include/linux/compiler.h:437:20: eroor: call to ‘compiletime_assert_390’ declared with attribute error: BUILD_BUG_ON failed: (unsigned long)__fix_to_virt(VVAR_PAGE) != (unsigned long)VVAR_ADDRESS
prefix ## suffix(); \
^
include/linux/compiler.h:442:2: note: in expansion of macro ‘__compiletime_assert’
__compiletime_assert(condition, msg, prefix, suffix)
^
include/linux/compiler.h:454:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE)
^
include/linux/bug.h:53:37: note: in expansion of macro ‘compiletime_assert’
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/bug.h:77:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^
arch/x86/kernel/vsyscall_64.c:389:2: note: in expansion of macro ‘BUILD_BUG_ON ’
BUILD_BUG_ON((unsigned long)__fix_to_virt(VVAR_PAGE) !=
^
make[2]: * [arch/x86/kernel/vsyscall_64.o] eroor 1
make[1]: * [arch/x86/kernel] error 2
make: *** [arch/x86] error 2

可能是由于 VVAR_PAGE,但我不知道如何更改它。我应该怎么办?

标签: linux-kernelkernelpaging

解决方案


您不能直接修改PAGE_SIZEby 设置PAGE_SHIFT,因为它是在编译时生成的。

假设您的处理器是 x86,您可以使用CONFIG_PAGE_SIZE_XXX诸如CONFIG_PAGE_SIZE_8KB. 请注意,使用大页面会不必要地占用大量空间,因为即使是 1 字节文件也会占用磁盘上的一整页。此外,更改页面大小取决于体系结构,建议保留默认的 4K 大小。

不过,更好的方法可能是使用大页面,更灵活,更强大。他们在那里展示


推荐阅读