Linux中的内存分配和释放之__alloc_boot函数分析
对于这个函数,其实是很多宏定义调用的函数,其中alloc_bootmem_low_pages(x)是其中一个调用它的宏,大家可以认为这些宏只是把这个__alloc_bootmem实质性的函数进行了封装。#define alloc_bootmem_low_pages(x)相当于__alloc_bootmem((x), PAGE_SIZE, 0),就是从0地址开始的低端内存分配按页大小对齐的内存。好了,为了了解这个函数是怎么运行的,我们就从它的源头开始讲起吧。
我们回到paging_init()这个函数,在上诉的文章的bootmem_init()函数返回之后,就接着回到paging_init()。
memcpy(&meminfo, mi, sizeof(meminfo));//这里起到更新的作用。
/*
* allocate the zero page. Note that we count on this going ok.
*/
zero_page = alloc_bootmem_low_pages(PAGE_SIZE);//从0地址低端内存开始分配1页空闲内存,将该页的页帧位码表置1,并将这也得得内容全部清0.我们还是仔细点来分析这段代码吧。
void * __init __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal)//size是申请的内存大小,align是决定的起始地址开始的内存对齐方式,goal是分配内存的起始地址,如果不行的话就从0地址开始。
{
pg_data_t *pgdat = pgdat_list;//这个就是那个指向discontig_node_data[0]的链表。
void *ptr;
for_each_pgdat(pgdat)//这是一个宏定义:#define for_each_pgdat(pgdat) for (pgdat = pgdat_list; pgdat; pgdat = pgdat->pgdat_next)。其实很简单,就是通过这个链表从0号内存node开始遍历所有的discontig_node_data[n]。
if ((ptr = __alloc_bootmem_core(pgdat->bdata, size,align, goal)))//调用分配内存核心函数,我们在下面紧接着的位置介绍。
return(ptr);
/*
* Whoops, we cannot satisfy the allocation request.
*/
printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size);
panic("Out of memory");
return NULL;
}
static void * __init __alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size,unsigned long align, unsigned long goal)//这里和前面的__alloc_bootmem()不同的地方就是在第一项,对于这一项我们是比较熟悉的。
{
unsigned long offset, remaining_size,
相关文档:
The Linux USB input subsystem is a single, harmonized way to manage all input devices. This is a relatively new approach for Linux, with the system being partly incorporated in kernel version 2.4 and fully integrated in the 2.5 development series.
This article covers four basic areas: a descripti ......
o: 编译的目标文件
a: 静态库,其实就是把若干o文件打了个包
so: 动态链接库(共享库)
lo: 使用libtool编译出的目标文件,其实就是在o文件中添加了一些信息
la: 使用libtool编译出的库文件,其实是个文本文件,记录同名动态库和静态库的相关信息
1 libtool的工作原理
libtool 是一个通用库支持脚本,将使用 ......
一、下载安装程序
1、 下载内核源码(linux-2.6.33.tar.bz2),位置:https://www.kernel.org
2、 下载最新版的module-init-tools(module-init-tools-3.8.tar.bz2)和modutils(modutils-2.4.26-1.src.rpm)的源码
位置:http://www.kernel.org/pub/linux/kernel/people/rusty/modules/
位置:http://www. ......
-----------------------------
Based on Fedora 8 version:
-----------------------------
1. No common command like ifconfig in os?
Root cause is the standard search path not include /sbin and /usr/sbin. Try to include them in /etc/profile. As belows:
#Kenny add /sbin and /usr/sbin here.
&n ......