简体   繁体   English

操作系统如何处理虚拟地址空间中的碎片

[英]How os handle fragmentation in virtual address space

据我所知,分页系统确实消除了物理地址空间中的外部碎片,但是虚拟地址空间中的碎片又如何呢?

In modern OSes the virtual address space is used per process (the kernel has it's own dedicated virtual range), which means that the demands are much lower compared to the whole OS. 在现代操作系统中,每个进程都使用虚拟地址空间(内核具有自己的专用虚拟范围),这意味着与整个操作系统相比,其需求要低得多。 The virtual address space is usually large enough (2-3 GB per process on x86 and multiple TB (8 on Windows) on x64 machines), so that fragmentation is not such a big issue as for the OS-wide physical address space. 虚拟地址空间通常足够大(在x86上每个进程2-3 GB,在x64机器上多个TB(Windows上为8)),因此分段不像操作系统范围的物理地址空间那样大。 Still the issue can arise, especially for long running and memory hungry applications on x86 or other 32 bit architectures. 仍然可能出现此问题,特别是对于x86或其他32位体系结构上长时间运行且占用内存的应用程序。 For this the OS provides mechanisms, for example in form of the heap code. 为此,OS提供了机制,例如以堆代码的形式。 An application usually reserves one or more memory ranges as heap(s) when it starts and allocates the required chunks of memory from there later (eg malloc). 应用程序通常在启动时保留一个或多个内存范围作为堆,并在以后从那里分配所需的内存块(例如malloc)。 There are a varity of implementations that handle fragmentation of the heap in different ways. 有各种各样的实现以不同的方式处理堆的碎片。 Windows provides a special low-fragmentation heap implementation that can be used, if desired. Windows提供了一种特殊的低碎片堆实现,如果需要的话,可以使用它。 Everything else is usually up to the application or it's libraries. 其他所有内容通常取决于应用程序或其库。

Let me add a qualification to your statement. 让我在您的声明中加上限定词。 Paging systems nearly eliminate fragmentation in the physical address space when the kernel is pageable. 当内核是可分页的时,分页系统几乎消除了物理地址空间中的碎片。

On some systems, the user mode page tables are themselves pageable. 在某些系统上,用户模式页表本身是可分页的。 On others, they are are physical locations that are not pageable. 在其他位置,它们是不可分页的物理位置。 Then you can get fragmentation. 然后,您将获得碎片。

Fragmentation in the virtual address space tends to occur in heap allocation. 虚拟地址空间中的碎片易于在堆分配中发生。 The challenge of heap managers is to manage the space while minimizing fragmentation. 堆管理器的挑战是在最小化碎片的同时管理空间。

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

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