我开发了一个嵌入式Linux系统的应用程序,它可以进行很多UDP数据包传输。应用程序在应用程序开始时执行所有内存分配,然后重用已分配的内存以避免碎片。
我在桌面上运行了一个massif pro-filer,用于堆栈和堆,并且值不会变大。
但是,在嵌入式系统上运行很长时间后,应用程序将退出并显示以下错误消息。这个漏出的堆还是过度使用堆栈?
2013 Jun 18 16:30:52+00:00 sys-nam kernel [warning] sh invoked oom-killer: gfp_mask=0x4d0, order=0, oom_adj=0
2013 Jun 18 16:30:52+00:00 sys-nam kernel [warning] Call Trace:
2013 Jun 18 16:30:52+00:00 sys-nam kernel [warning] [<ffffffff8010f448>] dump_stack+0x8/0x34
2013 Jun 18 16:30:52+00:00 sys-nam kernel [warning] [<ffffffff802ff9e0>] T.659+0xd8/0x270
2013 Jun 18 16:30:52+00:00 sys-nam kernel [warning] [<ffffffff802ffcb8>] __out_of_memory+0x140/0x1f0
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff802ffddc>] out_of_memory+0x74/0xe8
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff80304588>] __alloc_pages_nodemask+0x718/0x730
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff8031ab18>] __pte_alloc+0x48/0x200
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff8031be9c>] handle_mm_fault+0x11cc/0x1698
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff8031c4e4>] __get_user_pages+0x17c/0x3f8
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff8034111c>] get_arg_page+0x3c/0xd0
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff8034131c>] copy_strings+0x16c/0x328
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff803414f0>] copy_strings_kernel+0x18/0x30
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff80387294>] compat_do_execve+0x214/0x3e8
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff80260188>] sys32_execve+0x38/0x68
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff80103ac4>] handle_sysn32+0x44/0x84
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning]
2013 Jun 18 16:30:53+00:00 sys-nam kernel [info] Mem-Info:
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] DMA32 per-cpu:
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] CPU 0: hi: 186, btch: 31 usd: 167
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] CPU 1: hi: 186, btch: 31 usd: 144
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] Normal per-cpu:
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] CPU 0: hi: 18, btch: 3 usd: 15
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] CPU 1: hi: 18, btch: 3 usd: 5
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] active_anon:6581 inactive_anon:6576 isolated_anon:0
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] active_file:3 inactive_file:30 isolated_file:0
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] unevictable:213762 dirty:1 writeback:0 unstable:0
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] free:969 slab_reclaimable:3240 slab_unreclaimable:4064
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] mapped:1590 shmem:31 pagetables:212 bounce:0
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] DMA32 free:3536kB min:3240kB low:4048kB high:4860kB active_anon:26324kB inactive_anon:26304kB active_file:100kB inactive_file:0kB unevictable:623504kB isolated(anon):0kB isolated(file):0kB present:729420kB mlocked:0kB dirty:0kB writeback:0kB mapped:1828kB shmem:124kB slab_reclaimable:5352kB slab_unreclaimable:13676kB kernel_stack:1152kB pagetables:848kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:239 all_unreclaimable? no
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] lowmem_reserve[]: 0 77 77
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] Normal free:420kB min:352kB low:440kB high:528kB active_anon:0kB inactive_anon:0kB active_file:12kB inactive_file:40kB unevictable:231544kB isolated(anon):0kB isolated(file):0kB present:79360kB mlocked:0kB dirty:4kB writeback:0kB mapped:4532kB shmem:0kB slab_reclaimable:7608kB slab_unreclaimable:2580kB kernel_stack:784kB pagetables:0kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? no
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] lowmem_reserve[]: 0 0 0
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] DMA32: 330*4kB 20*8kB 4*16kB 3*32kB 1*64kB 3*128kB 2*256kB 0*512kB 0*1024kB 1*2048kB 0*4096kB = 4648kB
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] Normal: 70*4kB 16*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 408kB
2013 Jun 18 16:30:54+00:00 sys-nam kernel [warning] 213845 total pagecache pages
2013 Jun 18 16:30:54+00:00 sys-nam kernel [info] 261888 pages RAM
2013 Jun 18 16:30:54+00:00 sys-nam kernel [info] 25027 pages reserved
2013 Jun 18 16:30:54+00:00 sys-nam kernel [info] 9701 pages shared
2013 Jun 18 16:30:54+00:00 sys-nam kernel [info] 233184 pages non-shared
2013 Jun 18 16:30:54+00:00 sys-nam kernel [err] Out of memory: kill process 7747 (sh) score 7766 or a child
2013 Jun 18 16:30:54+00:00 sys-nam kernel [err] Killed process 7752 (wglADBPServer)
答案 0 :(得分:3)
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff802ffddc>] out_of_memory+0x74/0xe8
2013 Jun 18 16:30:53+00:00 sys-nam kernel [warning] [<ffffffff80304588>] __alloc_pages_nodemask+0x718/0x730
由于调用new
,malloc
,allocate
等,因此在调用{{1}期间发生错误时,很可能您的堆空间不足例行公事。
在代码中查找分配堆内存的所有代码实例,并确保在使用完内存后释放内存。