|
自己的板子使用的是At91Rm9200 + Linux-2.6.14.6 + uClibc-0.9.27
其他都正常!就是malloc是总是返回成功,但是实际板子上只有16MB的内存,除去内核和RAMDISK的开销,实际可用内存也就6,7MB,但是每次Malloc必成功,返回有效的虚拟地址,但是你去写这些地址,就会出错!!
感觉就像是malloc分配了虚拟地址,但是没有划分实际的物理内存,所以无论怎么申请内存都可以成功
测试程序:
- #include "stdio.h"
- #include "stdlib.h"
- #include <unistd.h>
- #include <errno.h>
- main()
- {
- #define N (1024*1024)
- char *t;
- int i,j;
- j=0;
- while(1){
- t = malloc(N);
- printf("******* %d %d\n",errno,ENOMEM);
- printf("%d-> 0x%.8X\n",j,t);
- j++;
- if ( t ) {
- for(i=0;i<N;i++)
- t[i]=i;
- //free(t);t=NULL;
- }
- usleep(500000);
- }
- }
复制代码
出错的信息:
# ./tst
******* 0 12
0-> 0x4006F008
******* 0 12
1-> 0x40170008
******* 0 12
2-> 0x40271008
******* 0 12
3-> 0x40372008
******* 0 12
4-> 0x40473008
******* 0 12
5-> 0x40574008
******* 0 12
6-> 0x40675008
******* 0 12
7-> 0x40776008
oom-killer: gfp_mask=0x400d2, order=0
Mem-info:
DMA per-cpu:
cpu 0 hot: low 2, high 6, batch 1 used:2
cpu 0 cold: low 0, high 2, batch 1 used:1
Normal per-cpu: empty
HighMem per-cpu: empty
Free pages: 752kB (0kB HighMem)
Active:2552 inactive:470 dirty:0 writeback:0 unstable:0 free:188 slab:263 mapped:2396 pagetables:25
DMA free:752kB min:512kB low:640kB high:768kB active:10208kB inactive:1880kB present:16384kB pages_scanned:3330 all_unreclaimable? no
lowmem_reserve[]: 0 0 0
Normal free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0
HighMem free:0kB min:128kB low:160kB high:192kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0
DMA: 58*4kB 1*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 1*512kB 0*1024kB 0*2048kB 0*4096kB = 752kB
Normal: empty
HighMem: empty
Free swap: 0kB
4096 pages of RAM
230 free pages
519 reserved pages
263 slab pages
115 pages shared
0 pages swap cached
Out of Memory: Killed process 715 (tst).
Killed
# |
|