简体   繁体   English

C ++减少4096字节的内存页面大小

[英]C++ Decrease memory page size from 4096 bytes

Now on my system (debianx64)the page size is 4096 bytes. 现在在我的系统(debianx64)上,页面大小为4096字节。 Is there any possibilty to decrease it? 减少它有可能吗? I would like to store in memory many small pieces but even for 1 byte reserved I can't use another 4095 because of thing added in 1st message here. 我想在内存中存储许多小块但是即使保留1个字节我也不能使用另一个4095,因为这里添加了第一条消息中的东西。 Is it true or am I wrong? 这是真的还是我错了? Is it possible to do it? 有可能吗? Thx for replies. 谢谢回复。

No. 没有。

4096 is the smallest page size provided by the x86 platform. 4096是x86平台提供的最小页面大小。 This is a limitation imposed by the CPU. 这是CPU施加的限制。 It offers larger sizes (up to 4MB, depending on the mode), but this is normally selected by the operating system at boot time. 它提供更大的尺寸(最多4MB,具体取决于模式),但这通常由操作系统在启动时选择。

What you can do is make a relatively large allocation as the backing store for an object pool . 可以做的是将相对较大的分配作为对象池的后备存储。 Then if you need many small objects, they can all be stored within a single page or memory region. 然后,如果您需要许多小对象,它们都可以存储在单个页面或内存区域中。 This is a common idiom for improving performance in memory allocations. 这是提高内存分配性能的常用习惯用法。

Moreover, most sane memory allocators work this way anyway, so it's not necessary to implement an object pool unless you find in profiling that you need it. 此外,大多数理智的内存分配器无论如何都以这种方式工作,因此除非您在分析中发现需要它,否则不必实现对象池。

Page size is an OS-wide item. 页面大小是操作系统范围的项目。 You can't just create a new page size for your application only since the page-fault logic has to work with all other processes. 您不能仅为应用程序创建新的页面大小,因为页面错误逻辑必须与所有其他进程一起使用。

I'm not sure what exactly you're attempting to do. 我不确定你到底想要做什么。 I will say that if you're even worried about this issue, then you need to make your software more cache-friendly by storing and accessing memory consecutively, like in an array. 我会说,如果您甚至担心这个问题,那么您需要通过连续存储和访问内存来使您的软件更加缓存,就像在数组中一样。

Page size (which BTW can't be lowered below 4K on x86 platforms) is most likely irrelevant to your situation. 页面大小(在x86平台上BTW不能低于4K)很可能与您的情况无关。 If you allocate data on the heap, the question of page size will not arise in the manner you assume. 如果在堆上分配数据,页面大小的问题将不会以您假设的方式出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM