首先提供Gustavo Duarte写的三篇非常精彩的文章:
1. Anatomy of a Program in Memory
2. How The Kernel Manages Your
3. Page Cache, the Affair Between Memory and Files
然后看看Linux下malloc的实现原理:
1. Doug Lea. A Memory Allocator
2. ptmalloc原理分析
看完上面的文章,我们对Linux的内存管理就有了大概的印象,也知道了malloc和mmap对于OS而言意味着什么。剩下的有几个问题:
1. 在申请大于一定阈值(128K)时,malloc为什么要使用mmap
Efficiency Considerations for malloc 写道
As opposed to other versions, the malloc in the GNU C Library does not round up block sizes to powers of two, neither for large nor for small sizes. Neighboring chunks can be coalesced on a free no matter what their size is. This makes the implementation suitable for all kinds of allocation patterns without generally incurring high memory waste through fragmentation.
Very large blocks (much larger than a page) are allocated with mmap (anonymous or via /dev/zero) by this implementation. This has the great advantage that these chunks are returned to the system immediately when they are freed. Therefore, it cannot happen that a large chunk becomes "locked" in between smaller ones and even after calling free wastes memory. The size threshold for mmap to be used can be adjusted with mallopt. The use of mmap can also be disabled completely
2. 处理文件时,是不是使用memory-mapped-file都要优于标准IO
关于这个问题,可以先了解一下memory mapped file 的优缺点。一个明显的问题是当文件大于虚拟地址空间时,将无法一次性将文件映射到虚拟地址空间里面。此外,也有报告支持在特定的场景下,标准IO要优于memory mapped file。
3. 对于非匿名memory mapping,如果文件被修改了,内存中的相应内容会被修改吗?
不会。
4. 应用中如果需要大块的内存,使用malloc还是mmap?各有什么优缺点?
分享到:
相关推荐
天大 操作系统 课程 linux 内存管理 实验报告
linux内存管理 linux内存管理 linux内存管理
linux内存管理源代码导读 pdf格式
linux 内存管理学习总结 学习心得 内存管理纲要
linux内存管理工具
个人多年学习并总结的有关Linux内存管理的笔记,希望对Linux内核爱好者有所帮助!
Linux内存管理编程技术.doc
我不可能完全理解LINUX内存管理的精髓,肯定有很多地方理解错误。希望大 家能够指正,以便提高,谢谢。 学习方法: 可能您第一次阅读的时候很多地方都不理解,不用担心。那您可能需要阅读一些 文件系统的知识。 或者...
整个内存管理系统可以分为2部分来看待: 第一部分是对物理内存的管理, 第二部分是对虚拟内存的管理. 物理内存管理的对象是板载的物理内存(DDRAM), 它把物理内存按页划分, 并把这些页放到一个池子里面. 物理内存管理...
Linux内存管理实验.pdf
一种Linux内存管理机制.pdf
Linux内存管理ppt讲义,希望对你的工作学习有所帮助。
《深入理解LINUX内存管理》学习笔记c.PDF
详细介绍linux内核内存管理,从内核思想详细介绍伙伴算法、slab内存管理
《深入理解LINUX内存管理》学习笔记b.PDF
Linux内存管理 vs. Windows 2000内存管理
很清晰的描述了linux内存虚拟及物理内存的划分,包括: node介绍 zone介绍 3G~4G内核空间布局 内核整体mm管理结构
与内存管理系统相关的各种flags汇总如下: 每个物理page有自己的flags, 定义在struct page -> unsigned long flags; 详情见2.2.2节的《page》 每个内存块(多个page组成一个内存块)有自己的pageblock_flags, ...
介绍Linux的内存管理系统,例如虚拟地址空间及地址映射。
linux内存管理(重要)