免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 11743 | 回复: 5
打印 上一主题 下一主题

linux 保留内存是咋回事?大侠们? 我的就剩这点了... [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-12 21:28 |只看该作者 |倒序浏览
本帖最后由 armips 于 2011-01-12 21:30 编辑

是个嵌入式的小板,内存总共16M

系统启动的时候打印出:
Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory: 16MB = 16MB total
Memory: 12916k/12916k available, 3468k reserved, 0K highmem
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)
    vmalloc : 0xc1800000 - 0xf4000000   ( 808 MB)
    lowmem  : 0xc0000000 - 0xc1000000   (  16 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .init : 0xc0008000 - 0xc0021000   ( 100 kB)
      .text : 0xc0021000 - 0xc02fa000   (2916 kB)
      .data : 0xc0310000 - 0xc03292a0   ( 101 kB)
Hierarchical RCU implementation.
        RCU-based detection of stalled CPUs is disabled.
        Verbose stalled-CPUs detection is disabled.
NR_IRQS:208
MXC IRQ initialized

启动后查看内存命令显示如下:
[root@localhost /]# free
              total         used         free       shared      buffers
  Mem:        13016         4760         8256            0          220
Swap:            0            0            0
Total:        13016         4760         8256
[root@localhost /]#


谁能帮忙分析下,上面的那个3468k reserved是干什么的?

操作系统内核的代码数据占用的内存是在free命令里显示的used里面 还是在上面的reserved里面??

多谢!!

论坛徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16赛季CBA联赛之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金鸡报晓
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年纪念徽章
日期:2016-11-09 13:19:1015-16赛季CBA联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
2 [报告]
发表于 2011-01-13 08:20 |只看该作者
你可以在源码里grep 这个打印的消息,看看在什么情况下才打印这个数字,这个数字由哪些操作改变

论坛徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16赛季CBA联赛之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金鸡报晓
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年纪念徽章
日期:2016-11-09 13:19:1015-16赛季CBA联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
3 [报告]
发表于 2011-01-13 08:22 |只看该作者
我感觉就是因为创建文件系统要以一个单位创建了,如果剩下的不能构成一个基本单位,就留着不用。就是reserve。

论坛徽章:
0
4 [报告]
发表于 2011-01-14 09:31 |只看该作者
本帖最后由 armips 于 2011-01-14 10:05 编辑

感谢 二楼的回复 grep命令还真狠:

grep -R 'Memory' ./linux-2.6.36 | grep 'reserved' > mygrep.txt

.....
./linux-2.6.36/arch/arm/mm/init.c:        printk(KERN_NOTICE "Memory: %luk/%luk available, %luk reserved, %luK highmem\n",
.....


void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
{
        int i;

        memblock_init();
        for (i = 0; i < mi->nr_banks; i++)
                memblock_add(mi->bank.start, mi->bank.size);

        /* Register the kernel text, kernel data and initrd with memblock. */
#ifdef CONFIG_XIP_KERNEL
        memblock_reserve(__pa(_data), _end - _data);
#else
        memblock_reserve(__pa(_stext), _end - _stext);
#endif
#ifdef CONFIG_BLK_DEV_INITRD
        if (phys_initrd_size) {
                memblock_reserve(phys_initrd_start, phys_initrd_size);

                /* Now convert initrd to virtual addresses */
                initrd_start = __phys_to_virt(phys_initrd_start);
                initrd_end = initrd_start + phys_initrd_size;
        }
#endif

        arm_mm_memblock_reserve();

        /* reserve any platform specific memblock areas */
        if (mdesc->reserve)
                mdesc->reserve();

        memblock_analyze();
        memblock_dump_all();
}

这个函数保留了内存, 包括linux内核占用的代码数据段空间, initrd占用的空间 以及一些平台相关的内存

系统启动打印信息:
Memory: 16MB = 16MB total
Memory: 12920k/12920k available, 3464k reserved, 0K highmemVirtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)
    vmalloc : 0xc1800000 - 0xf4000000   ( 808 MB)
    lowmem  : 0xc0000000 - 0xc1000000   (  16 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .init : 0xc0008000 - 0xc0021000   ( 100 kB) ---->(系统启动过程中 以__init宏标识的函数占用的空间 被vmlinux.lds标识为 __init_begin __init_end 启动init进程前被释放掉 :Freeing init memory: 100K)
      .text : 0xc0021000 - 0xc02fa000   (2916 kB)
      .data : 0xc0310000 - 0xc03292a0   ( 101 kB)


保留内存3464K中 linux内核占用了100+2916+101=3117K
加上boot的时候参数等平台空间占用32K = 3149K
其它还差3464-3149=315K 没有着落
其它还包括影射的向量表4K
还有可能是系统管理内存的页表占用空间等其它的占用

系统启动成功后 Freeing init memory: 100K
所以用free命令看会多了100K

而free命令中看到的used基本是缓存 buffer占用的,为了提高i/o速度的缓存,很多都并非真正应用
在我应用中去试图malloc更多的内存的时候 used中很多都能被malloc出来的.

论坛徽章:
22
丑牛
日期:2014-08-15 14:32:0015-16赛季CBA联赛之同曦
日期:2017-12-14 15:28:14黑曼巴
日期:2017-08-10 08:14:342017金鸡报晓
日期:2017-02-08 10:39:42黑曼巴
日期:2016-11-15 15:48:38CU十四周年纪念徽章
日期:2016-11-09 13:19:1015-16赛季CBA联赛之同曦
日期:2016-04-08 18:00:03平安夜徽章
日期:2015-12-26 00:06:30程序设计版块每日发帖之星
日期:2015-12-03 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-09 06:20:002015亚冠之吉达阿赫利
日期:2015-07-03 08:39:42
5 [报告]
发表于 2011-01-14 11:30 |只看该作者
回复 4# armips


    呵呵,學習了。lz結貼 好習慣

论坛徽章:
0
6 [报告]
发表于 2011-01-15 02:20 |只看该作者
不错
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP