Chinaunix

标题: Linux 2.6内核内存初始化问题 [打印本页]

作者: zd零    时间: 2010-06-30 21:49
标题: Linux 2.6内核内存初始化问题
在阅读Linux 2.6.12内核内存页表初始化函数kernel_physical_mapping_init中one_page_table_init函数代码如下:
  1. void * __init __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal)
  2. {
  3.         pg_data_t *pgdat = pgdat_list;
  4.         void *ptr;

  5.         for_each_pgdat(pgdat)
  6.                 if ((ptr = __alloc_bootmem_core(pgdat->bdata, size,
  7.                                                 align, goal)))
  8.                         return(ptr);

  9.         /*
  10.          * Whoops, we cannot satisfy the allocation request.
  11.          */
  12.         printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size);
  13.         panic("Out of memory");
  14.         return NULL;
  15. }
复制代码
这段代码我怎么读也读不懂!请大家指导我一下,不胜感激,谢谢!!!

作者: accessory    时间: 2010-07-01 00:38
具体啥地方不懂?这个函数本身就是在启动时保留一部分内存,不行就PANIC.
作者: superfight    时间: 2010-07-01 10:16
这是在bitmap阶段进行的内存分配~  每个bit对应一页内存~
for_each_pgdat(pgdat) 就是历遍bitmap
__alloc_bootmem_core就是从bitmap中分配内存~
作者: zd零    时间: 2010-07-01 13:28
one_page_table_init函数的功能是为系统全局目录中的当前页目录申请空间,设置页目录项。可是这段代码怎么实现的申请空间啊?
作者: accessory    时间: 2010-07-01 22:59
then you should read : __alloc_bootmem_core()
作者: zd零    时间: 2010-07-02 08:49
回复 5# accessory


    我正在阅读这个函数__alloc_bootmem_core(),可感觉太难了,读不懂啊!问一下读这个函数之前是不是必须把setup_arch()中的setup_memory()函数看懂才可阅读__alloc_bootmem_core()函数啊?
作者: accessory    时间: 2010-07-03 02:07
google this book:

understanding the Linux virtual memory manager
作者: zd零    时间: 2010-07-03 09:04
回复 7# accessory


    OK!下载到了!谢谢!谢谢!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2