在64位地堆碎片碎片

2023-09-07 23:34:46 作者:这时代、狗比人忠

在过去,当我长时间运行的C ++守护进程的工作,我不得不处理堆碎片问题。喜欢让我的大分配池技巧是必要的,以防止耗尽连续的堆空间。

这仍然是一个问题,一个64位的地址空间? PERF不是我关注的问题,所以我会preFER简化我的code而不是像缓冲池处理了。有没有人有任何关于这个问题的经历或故事?我使用的Linux,但我想许多相同的问题也适用于Windows操作系统。

解决方案   

这仍然是一个问题,一个64位的地址空间?

没有,它是不是仍然是个问题。

星之卡比 64 水晶碎片下载,街机星之卡比 64 水晶碎片下载,单机星之卡比 64 水晶碎片下载 66游戏网

您是正确的,它是在32位系统上的问题,但它不再是64位系统的问题。

虚拟地址空间是如此之大,在64位系统(2 ^ 48字节的今天x86_64的处理器的瞬间,并将逐步增加至2 ^ 64新x86_64的处理器问世),即运行的连续由于碎片虚拟地址空间实际上是不可能的(为所有,但一些高度人为的边界情况)。

(它是直觉的所造成的事实,64是一个常见的​​错误唯一双32,导致人们认为在64位的地址空间是某种大致双32位之一。事实上全64位的地址空间为4十亿倍大如32位的地址空间。)

换句话说,如果它把你的32位守护进程的一个星期以片段到一个阶段,它无法分配X字节的块,比它会采取以最小的千年以片段今天的x86_64的处理器,48位地址空间,并会采取 8000万年以分片规划完整的64位地址空间的未来。

In the past, when I've worked on long-running C++ daemons I've had to deal with heap fragmentation issues. Tricks like keeping a pool of my large allocations were necessary to keep from running out of contiguous heap space.

Is this still an issue with a 64 bit address space? Perf is not a concern for me, so I would prefer to simplify my code and not deal with things like buffer pools anymore. Does anyone have any experience or stories about this issue? I'm using Linux, but I imagine many of the same issues apply to Windows.

解决方案

Is this still an issue with a 64 bit address space?

No, it is not still an issue.

You are correct that it was an issue on 32-bit systems, but it no longer is an issue on 64-bit systems.

The virtual address space is so large on 64-bit systems (2^48 bytes at the moment on todays x86_64 processors, and set to increase gradually to 2^64 as new x86_64 processors come out), that running out of contiguous virtual address space due to fragmentation is practically impossible (for all but some highly contrived corner cases).

(It is a common error of intuition caused by the fact that 64 is "only" double 32, that causes people to think that a 64-bit address space is somehow roughly double a 32-bit one. In fact a full 64-bit address space is 4 billion times as big as a 32-bit address space.)

Put another way if it took your 32-bit daemon one week to fragment to a stage where it couldn't allocate an x byte block, than it would take at minimum one thousand years to fragment today's x86_64 processors 48-bit address spaces, and it would take 80 million years to fragment the future planned full 64-bit address space.