虚拟内存内存碎片

CUDA虚拟内存管理:从碎片化困境到高效内存利用的艺术 本文深入探讨了CUDA虚拟内存管理(VMM)技术如何解决显存碎片化问题,提升高性能计算场景下的内存利用效率。通过对比传统`cudaMalloc`与VMM API的核心设计,详细解析了地址空间与物理内存解耦、按需映射等关键技术,并提供了OLAP等动态场景中的优化实践方案。 阅读详情

I've heard the term "memory fragmentation" used a few times in the context of C++ dynamic memory allocation. I've found some questions about how to deal with memory fragmentation, but can't find a direct question that deals with it itself. So:

  • What is memory fragmentation?
  • How can I tell if memory fragmentation is a problem for my application? What kind of program is most likely to suffer?
  • What are good common ways to deal with memory fragmentation?

Also:

  • I've heard using dynamic allocations a lot can increase memory fragmentation. Is this true? In the context of C++, I understand all the standard containers (std::string, std::vector, etc) use dynamic memory allocation. If these are used throughout a program (especially std::string), is memory fragmentation more likely to be a problem?
  • How can memory fragmentation be dealt with in an STL-heavy application?
link | improve this question

 
Lots of great answers, thanks everyone! –  AshleysBrain Sep 22 '10 at 16:48
2 
There are already plenty of great answers, but here's some pictures from an actual application (Firefox) where memory fragmentation was a big problem: blog.pavlov.net/2007/11/10/memory-fragmentation –  Marius Gedminas Sep 28 '10 at 2:42
feedback

10 Answers

up vote 45 down vote accepted

Imagine that you have a "large" (32 bytes) expanse of free memory:

----------------------------------
|                                |
----------------------------------

Now, allocate some of it (5 allocations):

----------------------------------
|aaaabbccccccddeeee              |
----------------------------------

Now, free the first four allocations but not the fifth:

----------------------------------
|              eeee              |
----------------------------------

Now, try to allocate 16 bytes. Oops, I can't, even though there's nearly double that much free.

On systems with virtual memory, fragmentation is less of a problem than you might think, because large allocations only need to be contiguous in virtual address space, not in physical address space. So in my example, if I had virtual memory with a page size of 2 bytes then I could make my 16 byte allocation with no problem. Physical memory would look like this:

----------------------------------
|ffffffffffffffeeeeff            |
----------------------------------

whereas virtual memory (being much bigger) could look like this:

------------------------------------------------------...
|              eeeeffffffffffffffff                   
------------------------------------------------------...

The classic symptom of memory fragmentation is that you try to allocate a large block and you can't, even though you appear to have enough memory free. Another possible consequence is the inability of the process to release memory back to the OS (because there's some object still in use in all the blocks it has allocated from the OS, even though those blocks are now mostly unused).

Tactics to prevent memory fragmentation in C++ work by allocating objects from different areas according to their size and/or their expected lifetime. So if you're going to create a lot of objects and destroy them all together later, allocate them from a memory pool. Any other allocations you do in between them won't be from the pool, hence won't be located in between them in memory, so memory will not be fragmented as a result.

Generally you don't need to worry about it much, unless your program is long-running and does a lot of allocation and freeing. It's when you have mixtures of short-lived and long-lived objects that you're most at risk, but even then malloc will do its best to help. Basically, ignore it until your program has allocation failures or unexpectedly causes the system to run low on memory (catch this in testing, for preference!).

The standard libraries are no worse than anything else that allocates memory, and standard containers all have an Alloc template parameter which you could use to fine-tune their allocation strategy if absolutely necessary.

link | improve this answer
 
7 
+1 for the visual example. –  Kelly French Sep 22 '10 at 15:11
 
So each character is a byte? Which would make your "large expanse" == 32 bytes (I'm guessing -- didn't count) :) Nice example, but mentioning the units before the last line would be helpful. :) –  jalf Sep 22 '10 at 15:11
 
@jalf: Yep. I wasn't going to mention units at all, then realised at the end I had to. Was working on it while you were commenting. –  Steve Jessop Sep 22 '10 at 15:15
 
It was pretty hard to choose an "answer" - lots of great answers here and I'd encourage anyone interested to read all of them. Still, I think you covered all the important points here. –  AshleysBrain Sep 22 '10 at 16:54
feedback

What is memory fragmentation?

Memory fragmentation is when most of your memory is allocated in a large number of non-contiguous blocks, or chunks - leaving a good percentage of your total memory unallocated, but unusable for most typical scenarios. This results in out of memory exceptions, or allocation errors (i.e. malloc returns null).

The easiest way to think about this is to imagine you have a big empty wall that you need to put pictures of varying sizes on. Each picture takes up a certain size and you obviously can't split it into smaller pieces to make it fit. You need an empty spot on the wall, the size of the picture, or else you can't put it up. Now, if you start hanging pictures on the wall and you're not careful about how you arrange them, you will soon end up with a wall that's partially covered with pictures and even though you may have empty spots most new pictures won't fit because they're larger than the available spots. You can still hang really small pictures, but most ones won't fit. So you'll have to re-arrange (compact) the ones already on the wall to make room for more..

Now, imagine that the wall is your (heap) memory and the pictures are objects.. That's memory fragmentation..

How can I tell if memory fragmentation is a problem for my application? What kind of program is most likely to suffer?

A telltale sign that you may be dealing with memory fragmentation is if you get many allocation errors, especially when the percentage of used memory is high - but not you haven't yet used up all the memory - so technically you should have plenty of room for the objects you are trying to allocate.

When memory is heavily fragmented, memory allocations will likely take longer because the memory allocator has to do more work to find a suitable space for the new object. If in turn you have many memory allocations (which you probably do since you ended up with memory fragmentation) the allocation time may even cause noticeable delays.

What are good common ways to deal with memory fragmentation?

Use a good algorithm for allocating memory. Instead of allocating memory for a lot of small objects, pre-allocate memory for a contiguous array of those smaller objects. Sometimes being a little wasteful when allocating memory can go along way for performance and may save you the trouble of having to deal with memory fragmentation.

link | improve this answer
 
6 
+1. I just deleted my proposed answer becasue your "pictures on the wall" metaphor is really, really a good, clear one. –  ctacke Sep 22 '10 at 15:03
 
I would like it more if you emphasized the fact that the pictures must have varying sizes. Otherwise, no fragmentation will happen. –  Björn Pollex Sep 22 '10 at 15:06
1 
I've added that.. thanks Space_C0wb0y –  Miky Dinescu Sep 22 '10 at 15:13
 
Interestingly, main memory databases are becoming somewhat practical these days (with really much memory being available). In this context it is worth noting that, as for HDDs, reading continuous lines from RAM is much faster than if the data is fragmented. –  Björn Pollex Sep 22 '10 at 15:16
1 
Nice visual analogy with the pictures on the walls, but main memory isn't two dimensional! Still, nice answer though, thanks. –  AshleysBrain Sep 22 '10 at 16:51
feedback

Memory fragmentation is the same concept as disk fragmentation: it refers to space being wasted because the areas in use are not packed closely enough together.

Suppose for a simple toy example that you have ten bytes of memory:

 |   |   |   |   |   |   |   |   |   |   |
   0   1   2   3   4   5   6   7   8   9

Now let's allocate three three-byte blocks, name A, B, and C:

 | A | A | A | B | B | B | C | C | C |   |
   0   1   2   3   4   5   6   7   8   9

Now deallocate block B:

 | A | A | A |   |   |   | C | C | C |   |
   0   1   2   3   4   5   6   7   8   9

Now what happens if we try to allocate a four-byte block D? Well, we have four bytes of memory free, but we don't have four contiguous bytes of memory free, so we can't allocate D! This is inefficient use of memory, because we should have been able to store D, but we were unable to. And we can't move C to make room, because very likely some variables in our program are pointing at C, and we can't automatically find and change all of these values.

How do you know it's a problem? Well, the biggest sign is that your program's virtual memory size is considerably larger than the amount of memory you're actually using. In a real-world example, you would have many more than ten bytes of memory, so D would just get allocated starting a byte 9, and bytes 3-5 would remain unused unless you later allocated something three bytes long or smaller.

In this example, 3 bytes is not a whole lot to waste, but consider a more pathological case where two allocations of a a couple of bytes are, for example, ten megabytes apart in memory, and you need to allocate a block of size 10 megabytes + 1 byte. You have to go ask the OS for over ten megabytes more virtual memory to do that, even though you're just one byte shy of having enough space already.

How do you prevent it? The worst cases tend to arise when you frequently create and destroy small objects, since that tends to produce a "swiss cheese" effect with many small objects separated by many small holes, making it impossible to allocate larger objects in those holes. When you know you're going to be doing this, an effective strategy is to pre-allocate a large block of memory as a pool for your small objects, and then manually manage the creation of the small objects within that block, rather than letting the default allocator handle it.

In general, the fewer allocations you do, the less likely memory is to get fragmented. However, STL deals with this rather effectively. If you have a string which is using the entirety of its current allocation and you append one character to it, it doesn't simply re-allocate to its current length plus one, it doubles its length. This is a variation on the "pool for frequent small allocations" strategy. The string is grabbing a large chunk of memory so that it can deal efficiently with repeated small increases in size without doing repeated small reallocations. All STL containers in fact do this sort of thing, so generally you won't need to worry too much about fragmentation caused by automatically-reallocating STL containers.

Although of course STL containers don't pool memory between each other, so if you're going to create many small containers (rather than a few containers that get resized frequently) you may have to concern yourself with preventing fragmentation in the same way you would for any frequently-created small objects, STL or not.

link | improve this answer
 
feedback
  • What is memory fragmentation?

Memory fragmentation is the problem of memory becoming unusable even though it is theoretically available. There are two kinds of fragmentation: internal fragmentation is memory that is allocated but cannot be used (e.g. when memory is allocated in 8 byte chunks but the program usually asks for only 4 bytes). external fragmentation is the problem of free memory becoming divided into many small chunks so that large allocation requests cannot be met although there is enough overall free memory.

  • How can I tell if memory fragmentation is a problem for my application? What kind of program is most likely to suffer?

memory fragmentation is a problem if your program uses much more system memory than its actual paylod data would require (and you've ruled out memory leaks).

  • What are good common ways to deal with memory fragmentation?

Use a good memory allocator. IIRC, those that use a "best fit" strategy are generally much superior at avoiding fragmentation, if a little slower. However, it has also been shown that for any allocation strategy, there are pathological worst cases. Fortunately, the typical allocation patterns of most applications are actually relatively benign for the allocators to handle. There's a bunch of papers out there if you're interested in the details:

  • Paul R. Wilson, Mark S. Johnstone, Michael Neely and David Boles. Dynamic Storage Allocation: A Survey and Critical Review. In Proceedings of the 1995International Workshop on Memory Management, Springer Verlag LNCS, 1995
  • Mark S.Johnstone, Paul R. Wilson. The Memory Fragmentation Problem: Solved?In ACM SIG-PLAN Notices, volume 34 No. 3, pages 26-36, 1999
  • M.R. Garey, R.L. Graham and J.D. Ullman. Worst-Case analysis of memory allocation algorithms. In Fourth Annual ACM Symposium on the Theory of Computing, 1972
link | improve this answer
 
feedback

Update:
Google TCMalloc: Thread-Caching Malloc
It has been found that it is quite good at handling fragmentation in a long running process.


I have been developing a server application that had problems with memory fragmentation on HP-UX 11.23/11.31 ia64.

It looked like this. There was a process that made memory allocations and deallocations and ran for days. And even though there were no memory leaks memory consumption of the process kept increasing.

About my experience. On HP-UX it is very easy to find memory fragmentation using HP-UX gdb. You set a break-point and when you hit it you run this command: info heap and see all memory allocations for the process and the total size of heap. Then your continue your program and then some time later your again hit the break-point. You do again info heap. If the total size of heap is bigger but the number and the size of separate allocations are the same then it is likely that you have memory allocation problems. If necessary do this check few fore times.

My way of improving the situation was this. After I had done some analysis with HP-UX gdb I saw that memory problems were caused by the fact that I used std::vector for storing some types of information from a database. std::vector requires that its data must be kept in one block. I had a few containers based on std::vector. These containers were regularly recreated. There were often situations when new records were added to the database and after that the containers were recreated. And since the recreated containers were bigger their did not fit into available blocks of free memory and the runtime asked for a new bigger block from the OS. As a result even though there were no memory leaks the memory consumption of the process grew. I improved the situation when I changed the containers. Instead of std::vector I started using std::deque which has a different way of allocating memory for data.

I know that one of ways to avoid memory fragmentation on HP-UX is to use either Small Block Allocator or use MallocNextGen. On RedHat Linux the default allocator seems to handle pretty well allocating of a lot of small blocks. On Windows there is Low-fragmentation Heap and it adresses the problem of large number of small allocations.

My understanding is that in an STL-heavy application you have first to identify problems. Memory allocators (like in libc) actually handle the problem of a lot of small allocations, which is typical for std::string (for instance in my server application there are lots of STL strings but as I see from running info heap they are not causing any problems). My impression is that you need to avoid frequent large allocations. Unfortunately there are situations when you can't avoid them and have to change your code. As I say in my case I improved the situation when switched to std::deque. If you identify your memory fragmention it might be possible to talk about it more precisely.

link | improve this answer
 
feedback

Memory fragmentation is most likely to occur when you allocate and deallocate many objects of varying sizes. Suppose you have the following layout in memory:

obj1 (10kb) | obj2(20kb) | obj3(5kb) | unused space (100kb)

Now, when obj2 is released, you have 120kb of unused memory, but you cannot allocate a full block of 120kb, because the memory is fragmented.

Common techniques to avoid that effect include ring buffers and object pools. In the context of the STL, methods like std::vector::reserve() can help.

link | improve this answer
 
feedback

When you want to add an item on the heap what happens is that the computer has to do a search for space to fit that item. That's why dynamic allocations when not done on a memory pool or with a pooled allocator can "slow" things down. For a heavy STL application if you're doing multi-threading there is the Hoard allocator or the TBB Intel version.

Now, when memory is fragmented two things can occur:

  1. There will have to be more searches to find a good space to stick "large" objects. That is, with many small objects scattered about finding a nice contigous chunk of memory could under certain conditions be difficult (these are extreme.)
  2. Memory is not some easily read entity. Processors are limited to how much they can hold and where. They do this by swapping pages if an item they need is one place but the current addresses are another. If you are constantly having to swap pages, processing can slow down (again, extreme scenarios where this impacts performance.) See this posting on virtual memory.
link | improve this answer
 
feedback

What is memory fragmentation?

When your app uses dynamic memory, it allocates and frees chunks of memory. In the beginning, the whole memory space of your app is one contiguous block of free memory. However, when you allocate and free blocks of different size, the memory starts to get fragmented, i.e. instead of a big contiguous free block and a number of contiguous allocated blocks, there will be a allocated and free blocks mixed up. Since the free blocks have limited size, it is difficult to reuse them. E.g. you may have 1000 bytes of free memory, but can't allocate memory for a 100 byte block, because all the free blocks are at most 50 bytes long.

Another, unavoidable, but less problematic source of fragmentation is that in most architectures, memory addresses must be aligned to 2, 4, 8 etc. byte boundaries (i.e. the addresses must be multiples of 2, 4, 8 etc.) This means that even if you have e.g. a struct containing 3 char fields, your struct may have a size of 12 instead of 3, due to the fact that each field is aligned to a 4-byte boundary.

How can I tell if memory fragmentation is a problem for my application? What kind of program is most likely to suffer?

The obvious answer is that you get an out of memory exception.

Apparently there is no good portable way to detect memory fragmentation in C++ apps. See this answer for more details.

What are good common ways to deal with memory fragmentation?

It is difficult in C++, since you use direct memory addresses in pointers, and you have no control over who references a specific memory address. So rearranging the allocated memory blocks (the way the Java garbage collector does) is not an option.

A custom allocator may help by managing the allocation of small objects in a bigger chunk of memory, and reusing the free slots within that chunk.

link | improve this answer
 
feedback

This is a super-simplified version for dummies.

As objects get created in memory, they get added to the end of the used portion in memory.

If an object that is not at the end of the used portion of memory is deleted, meaning this object was in between 2 other objects, it will create a "hole".

This is what's called fragmentation.

link | improve this answer
 
feedback

Memory fragmentation occurs because memory blocks of different sizes are requested. Consider a buffer of 100 bytes. You request two chars, then an integer. Now you free the two chars, then request a new integer- but that integer can't fit in the space of the two chars. That memory cannot be re-used because it is not in a large enough contiguous block to re-allocate. On top of that, you've invoked a lot of allocator overhead for your chars.

Essentially, memory only comes in blocks of a certain size on most systems. Once you split these blocks up, they cannot be rejoined until the whole block is freed. This can lead to whole blocks in use when actually only a small part of the block is in use.

The primary way to reduce heap fragmentation is to make larger, less frequent allocations. In the extreme, you can use a managed heap that is capable of moving objects, at least, within your own code. This completely eliminates the problem - from a memory perspective, anyway. Obviously moving objects and such has a cost. In reality, you only really have a problem if you are allocating very small amounts off the heap often. Using contiguous containers (vector, string, etc) and allocating on the stack as much as humanly possible (always a good idea for performance) is the best way to reduce it. This also increases cache coherence, which makes your application run faster.

What you should remember is that on a 32bit x86 desktop system, you have an entire 2GB of memory, which is split into 4KB "pages" (pretty sure the page size is the same on all x86 systems). You will have to invoke some omgwtfbbq fragmentation to have a problem. Fragmentation really is an issue of the past, since modern heaps are excessively large for the vast majority of applications, and there's a prevalence of systems that are capable of withstanding it, such as managed heaps.


虚拟内存碎片整理 一款可以整理虚拟内存,提升电脑运行速度的软件》 立即下载

相关推荐

手把手教你校准垂起固定翼(VTOL)遥控器与电调:从零到飞的完整流程

本文详细介绍了垂起固定翼(VTOL)遥控器与电调的校准流程,从基础认知到飞行前检查,涵盖遥控器通道配置、电调校准、舵机方向调整等关键步骤。通过图文并茂的指导,帮助无人机爱好者安全完成VTOL调试,确保首飞成功。特别强调多旋翼模式、过渡模式和固定翼模式的设置要点,适合新手和进阶用户参考。

jenkins8butler的博客 355

Linux内存分析 | 基础概念

什么是虚存: 虚存提供了软件控制的内存地址集合,使得每一个进程有一个自己的对计算机物理内存的视图。 虚存地址只有在给定上下文的情况下有意义,比如在一个指定进程的上下文中。相同的虚存地址在不同的上下文中可能同时具有不同的含义。 虚存地址的宽度为CPU寄存器的宽度。在32位系统中,每个进程有4G的虚存空间,这通常比系统实际内存要多。 虚存地址由处理器的MMU进行翻译,使用页表这种数据结构来吧虚...

JH_Zhai的博客 1335

用Isaac Sim复现经典案例:手把手教你写Python脚本控制机械臂抓取(附避障算法调试心得)

本文详细介绍了如何使用NVIDIA Isaac Sim仿真系统复现机械臂抓取经典案例,包括Python脚本编写、避障算法调试等关键步骤。通过URDF模型导入、关节控制逻辑实现和RMPFlow避障配置等实战演示,帮助开发者快速掌握机器人仿真技术,特别分享了官方文档未提及的实用调试技巧和性能优化策略。

weixin_30632089的博客 406

操作系统-内存管理/1

操作系统的内存管理第一篇

m0_60476942的博客 1320

brpc组件bvar源码解析(一)简介、使用和类的关系

bvar是brpc中的一个重要组件,brpc内部有很多builtin监控都是bvar实现的。 brpc文档介绍bvar“几乎不会给程序增加性能开销,也快于竞争频繁的原子操作”。它的原理是:多线程累加一个计数器时,每个线程只累加私有的变量而不参与全局竞争,因此写时没有锁的竞争;在读取时累加所有线程的私有变量。虽然读比之前慢多了,但写就快多了,因此它使用写多读少的场景,例如统计、监控场景。 1.使用 // bvar::Adder<T>用于累加,下面定义了一个统计read error总数的Adder。

华秋实的专栏 1851

【深度学习新浪潮】智能体在图像处理领域的技术突破与实践指南

智能体正在重构图像处理的技术版图:从多智能体分工的"专业化协作",到多模态统一的"极简架构",再到工具增强的"实战能力",技术突破不断降低开发门槛并拓展应用边界。对于开发者而言,2025年的核心机遇在于结合具体场景选择成熟框架(如医疗用IteR-MRL、工业用NVIDIA NIM),通过微调与工具集成快速落地解决方案。随着硬件成本下降与开源生态完善,图像处理智能体将从当前的"高端场景赋能"走向"千行百业普及",真正成为数字世界的"视觉感知与操作核心"。

专注:太空算力、AI infra、异构调度、大模型成本工程 438

“实战深度学习”-缺陷:ran out of memory错误解决办法

调整代码在Data这部分使用cpu。设置较小的batch size。

文山 3672

直捣黄龙~

这篇文章描述了一个矩阵寻路问题,要求计算从起点到终点的最短路径数量及长度。主要思路是通过BFS算法解决:首先标记哨兵警戒区域为禁区,然后从起点出发进行广度优先搜索,记录每个位置的最短步数和路径条数。当到达终点时,输出路径数和步数;若不可达则返回(0,0)。算法使用队列实现BFS,同时处理路径统计和步数记录,适用于网格寻路类问题。

面试高手的博客 215

操作系统之内存管理

如果程序要访问虚拟地址的时候,由操作系统转换成不同的物理地址,这样不同的进程运行的时候,写入的是不同的物理地址,这样就不会冲突了。这个内存交换空间,在 Linux 系统里,也就是我们常看到的 Swap 空间,这块空间是从硬盘划分出来的,用于内存与硬盘的空间交换。内部内存碎片,程序所有的内存都被装载到了物理内存,但是这个程序有部分的内存可能并不是很常使用,这也会导致内存的浪费;每个进程分配独立的一套虚拟地址,互不干涉。对于多进程的系统来说,用分段的方式,内存碎片是很容易产生的,产生了内存碎片,那不得不重新。

2203_75872574的博客 114

华为OD机试新系统真题 【查找最佳充电策略】

华为OD机试 新系统真题【查找最佳充电策略】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【查找最佳充电策略】多语言题解。

qq_45776114的博客 430

Image Sensor卷帘曝光(Rolling Shutter)基本原理以及对曝光行的通俗理解

由于CMOS sensor的曝光方式是一行一行的方式进行的,任何一个pixel的曝光时间是一样的,也就是同一行上的每个pixel的曝光开始点和曝光的时间都是一模一样的,所以同一行的所有点所接受到的能量是一样的,而在不同行之间虽然曝光时间都是一样的,但是曝光的开始点是不同的,所以不同行之间所接受到的能量是不一定相同的。至此完成了这一行的曝光。还是以桶装水为比喻: 排成一行的桶(桶的数量和每个桶的大小确定),每一曝光行为单位的时间内每一个桶加水都是一样,需要多少个曝光行才能使的所有水桶加起来的水达到1L。

大熊 3921

外部碎片和内部碎片

 外部碎片,是由于大量信息由于先后写入、置换、删除而形成的空间碎片。  内部碎片,是由于存量信息容量与最小存储空间单位不完全相符而造成的空间碎片。还是沿用上面的例子,这次我们的6间仓库目前都是空置的,但是假设我们管理仓库的最小空间单位是间,今天运来了容量为2.5间仓库的货物,那也要占用我们1-3号3间仓库,尽管3号仓库还闲置着一半的空间,但是这半间仓库已经不能再利用了(因为是以间为最小单位么);...

deeplan_1994的博客 1204

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

虚拟内存与物理内存与内存碎片-杂谈

内存杂谈 虚拟内存与物理内存 为什么要有虚拟内存??? 1.每个进程有独立的虚拟地址空间,进程访问的虚拟地址并不是真正的物理地址(每个进程都假设自己看到的是完整的从0开始的内存) 2.程序可以使用一系列虚拟地址来访问大于可用物理内存的内存缓冲区。当物理内存的供应量变小时,内存管理器会将物理内存页(通常大小为 4 KB)保存到磁盘文件。数据或代码页会根据需要在物理内存与磁盘之间移动。(如linux...

pursue_my_life的博客 2394

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

虚拟内存碎片的检测和EXCHANGE的内存优化(转)

转自:Winmag亚洲技术社区 www.winmag.com.cn 作者:yinjie本文部分内容参考自KB.一、概述:什么是虚拟内存?我们使用的计算机都是基于X86的32位操作系统,而计算机是以二进制来描述的。因此2^32=4096MB=4GB。也就是说,一个32位计算机上运行的进程,最大寻址空间为4GB,这就是我们说的虚拟地址空间。它和实际的物理内存空间并无关联。当某一进程将属于它的虚拟内存用...

编程开发资料库 378

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【操作系统核心详解】段式存储与页式存储:区别、碎片及虚拟内存的本质

内存管理中的分段与分页是操作系统的核心概念。分段将程序按逻辑划分(如代码段、数据段),采用变长段和二维地址;分页则对物理内存进行固定大小的机械划分,使用一维地址。分段会产生外部碎片,分页会产生内部碎片。现代系统常采用段页式结合的方式,通过虚拟内存技术打破"一次性"和"驻留性"限制,利用请求调页和页面置换实现高效内存管理。分页因其固定大小特性成为虚拟内存的理想基础,而分段则提供保护功能。理解这些机制对掌握操作系统原理至关重要。

hour_go的博客 1300

分页与段式存储管理:从内存碎片到虚拟内存的核心原理

内存管理是操作系统的核心基础,其核心目标是高效利用物理内存并保障程序安全运行。从原理上看,早期单一连续分配会导致严重的内存碎片化问题,影响多道程序并发效率。为解决此矛盾,现代系统主要采用分页和段式两种管理模型。分页存储管理通过将地址空间划分为固定大小的页,利用页表实现虚拟地址到物理地址的映射,其优势在于消除外部碎片、支持虚拟内存技术,并能通过页表项实现内存保护。段式存储管理则按程序逻辑模块划分段,天然贴合代码、数据、堆栈等结构,通过段表进行基址寻址和越界检查,强化了安全保护。这两种思想最终在段页式存储管理中

weixin_33767813的博客 486

操作系统4小时速成:复习内存管理,内部碎片和外部碎片,页式存储管理,段式存储管理,段页式存储管理,虚拟内存,页面置换算法,LRU内存替换算法

操作系统4小时速成:复习内存管理,内部碎片和外部碎片,页式存储管理,段式存储管理,段页式存储管理,虚拟内存,页面置换算法,LRU内存替换算法

weixin_46838716的博客 838

操作系统内存管理深度精讲,虚拟内存与物理内存、分页机制、页表映射、缺页中断、内存碎片、OOM溢出底层原理

我们完成了操作系统进程管理、线程管理、并发锁与死锁全套体系,彻底搞懂了CPU如何调度、线程如何并发、如何保证线程安全、如何避免服务死锁卡死。内存管理。CPU负责调度执行,内存负责承载程序运行。内存泄漏、内存暴涨、OOM进程被杀、内存碎片、程序崩溃、段错误,根源全部来自内存管理机制。绝大多数开发者只会说“内存溢出就是内存不够用”,但完全不懂:1. 为什么每个进程都有独立的4G虚拟地址空间?2. 物理内存明明不足,为什么系统还能跑大量程序?3. 分页机制、页表映射到底解决了什么核心问题?

2401_86195313的博客 319

什么是虚拟内存?

什么是虚拟内存呢?先查一下维基百科: 虚拟内存是计算机系统内存管理的一种技术。它使得应用程序认为它拥有连续可用的内存(一个连续完整的地址空间),而实际上,它通常是被分隔成多个物理内存碎片,还有部分暂时存储在外部磁盘存储器上,在需要时进行数据交换。与没有使用虚拟内存技术的系统相比,使用这种技术的系统使得大型程序的编写变得更容易,对真正的物理内存(例如RAM)的使用也更有效率。 对虚拟内存的定义是...

zhanyd的博客 2万+

虚拟内存笔记(一)

虚拟内存管理是操作系统的重要功能,它允许程序使用超过物理内存的内存空间。分段和分页是两种主要的技术,分段将内存分为可变大小的段,而分页则将内存分为固定大小的页。研究表明,操作系统从分段转向分页是为了解决分段的局限性,如外部碎片和低效的内存交换。分页:将物理内存和虚拟内存划分为固定大小的页(例如4KB)。进程的地址空间被划分为页,操作系统通过页表将虚拟页映射到物理页框(frame)。这种方法允许非连续内存分配,适合现代操作系统。分段。

Jerry的博客 960

什么是内存碎片

想象一下,您拥有“大”(32字节)的空闲内存空间: ---------------------------------- | | ---------------------------------- 现在,分配其中一些(5个分配): ---------------------------------- |aaaabbccccccdde...

qq_39529180的博客 55

虚拟内存空间完全归还原因定位与引发的严重问题和应对策略的探索

家具搬走了,房间还占着;房间切碎了,大箱子进不来。“彻底退房间,操作系统才会收回虚拟空间。我们继续深入,进一步形象解释和技术剖析“地垫搬走了,地毯还空着;碎片太多,大垫子放不下。“彻底归还,需整块释放;碎片太多,重启最快。

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 720

【CPU】MMU的分页机制与内存碎片

是指在内存中存在许多小的、不连续的空闲空间,这些空间虽然总和起来可能足够大,但由于它们是分散的、不连续的,无法用于存储一个完整的程序或数据块。

qq_54177358的博客 867

到底什么是虚拟内存?

首先学过单片机的同学应该知道单片机是没有操作系统的,编写好的程序是靠工具烧录的,运行的程序是直接访问物理地址的,这时如果两个程序同时写入一块相同位置的物理地址就会造成崩溃。而在我们操作系统的多进程环境下,为了多个进程间的内存地址互不影响,相互隔离,操作系统提出了虚拟内存去解决。也就是给每一个进程都分配一套独立的虚拟地址,至于虚拟地址最终怎么落实映射到物理地址上对于我们来说是透明的,全盘交给操作系统处理。

weixin_73650594的博客 1229

操作系统内存碎片

内存碎片无法被利用的内存,分为外部碎片和内部碎片。分段机制会导致外部碎片,分页机制会导致内部碎片。

Roger_Spencer的博客 1124
上一篇: VC线程池,拿来就用
下一篇: Linux 文件系统剖析
wangjunhe
博客等级 码龄20年 31粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值