Linux内存管理(二十三):CMA 分配器详解

源码基于:Linux 5.4

0.前言

CMA(Contiguous Memory Allocator),称为连续内存分配器,用于分配连续的大块内存。

在启动过程中,从整个 memory 中配置一段连续的内存用于CMA(Reserved memory),

  • 设备驱动不用时,内存管理系统将该区域用于分配和管理可移动类型页面;
  • 设备驱动使用时,用于连续内存分配,如果已经分配的页面需要进行迁移;

此外,CMA 还可以与 DMA 子系统集成在一起,使用 DMA 的设备驱动程序无需使用单独的 CMA API。

1. CMA 的数据结构

1.1 struct cma

mm/cma.h

struct cma {
	unsigned long   base_pfn;
	unsigned long   count;
	unsigned long   *bitmap;
	unsigned int order_per_bit; /* Order of pages represented by one bit */
	struct mutex    lock;
#ifdef CONFIG_CMA_DEBUGFS
	struct hlist_head mem_head;
	spinlock_t mem_head_lock;
#endif
	const char *name;
};

base_pfn:CMA区域的物理地址的起始页帧号;

count:CMA区域总的页数ÿ

猜你喜欢

转载自blog.csdn.net/jingerppp/article/details/130325591