强制 Linux 只使用超过 4G 的内存? [英] Force Linux to use only memory over 4G?

查看:10
本文介绍了强制 Linux 只使用超过 4G 的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Linux 设备驱动程序,它连接到一个设备,理论上,该设备可以使用 64 位地址执行 DMA.我想测试一下,看看这是否真的有效.

I have a Linux device driver that interfaces to a device that, in theory, can perform DMA using 64-bit addresses. I'd like to test to see that this actually works.

有没有一种简单的方法可以强制 Linux 机器不使用物理地址 4G 以下的任何内存?内核镜像内存不足也没关系;我只是希望能够强制一种情况,即我知道所有动态分配的缓冲区,并且为我分配的任何内核或用户缓冲区都无法在 32 位中寻址.这有点蛮力,但比我能想到的任何其他方法都更全面.

Is there a simple way that I can force a Linux machine not to use any memory below physical address 4G? It's OK if the kernel image is in low memory; I just want to be able to force a situation where I know all my dynamically allocated buffers, and any kernel or user buffers allocated for me are not addressable in 32 bits. This is a little brute force, but would be more comprehensive than anything else I can think of.

这应该可以帮助我发现 (1) 未正确配置或未加载完整地址(或只是简单损坏)的硬件以及 (2) 意外和不必要地使用反弹缓冲区(因为无处可反弹到).

This should help me catch (1) hardware that wasn't configured correctly or loaded with the full address (or is just plain broken) as well as (2) accidental and unnecessary use of bounce buffers (because there's nowhere to bounce to).

澄清:我运行的是 x86_64,所以我不关心大多数旧的 32 位寻址问题.我只想测试一个驱动程序是否可以使用 64 位物理地址正确连接大量缓冲区.

clarification: I'm running x86_64, so I don't care about most of the old 32-bit addressing issues. I just want to test that a driver can correctly interface with multitudes of buffers using 64-bit physical addresses.

推荐答案

/usr/src/linux/Documentation/kernel-parameters.txt

        memmap=exactmap [KNL,X86] Enable setting of an exact
                        E820 memory map, as specified by the user.
                        Such memmap=exactmap lines can be constructed based on
                        BIOS output or other requirements. See the memmap=nn@ss
                        option description.

        memmap=nn[KMG]@ss[KMG]
                        [KNL] Force usage of a specific region of memory
                        Region of memory to be used, from ss to ss+nn.

        memmap=nn[KMG]#ss[KMG]
                        [KNL,ACPI] Mark specific memory as ACPI data.
                        Region of memory to be used, from ss to ss+nn.

        memmap=nn[KMG]$ss[KMG]
                        [KNL,ACPI] Mark specific memory as reserved.
                        Region of memory to be used, from ss to ss+nn.
                        Example: Exclude memory from 0x18690000-0x1869ffff
                                 memmap=64K$0x18690000
                                 or
                                 memmap=0x10000$0x18690000

如果您将 memmap=4G$0 添加到内核的启动参数中,将无法再访问较低的 4GB 物理内存.此外,您的系统将不再启动……但是这里的一些变体 (memmap=3584M$512M?) 可能允许 4GB 以下的足够内存供系统启动,但不足以让您的驱动程序的 DMA 缓冲区将在那里分配.

If you add memmap=4G$0 to the kernel's boot parameters, the lower 4GB of physical memory will no longer be accessible. Also, your system will no longer boot... but some variation hereof (memmap=3584M$512M?) may allow for enough memory below 4GB for the system to boot but not enough that your driver's DMA buffers will be allocated there.

这篇关于强制 Linux 只使用超过 4G 的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆