造成panic_oom问题的测试代码

写一个内核模块,来构造内核模块出现panic oom,主要采用vmalloc函数:

#include <linux/module.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>

static int __init ko_test_init(void)
{
        int i;
        u64 size = 1024*1024*1024*2UL;
        for (i = 0; i < 500; i++) {
                char *p = vmalloc(size);
                memset(p, 0, size);
        }
        return 0;
}
static void __exit ko_test_exit(void)
{
}

module_init(ko_test_init);
module_exit(ko_test_exit);
MODULE_LICENSE("GPL");

对应的Makefile文件为:

MODULE := oom
KVER := $(shell uname -r)

ifdef CUSTOM_LINUX_SRC_PATH
        KDIR := $(CUSTOM_LINUX_SRC_PATH)
else
        KDIR ?= /usr/src/kernels/$(KVER)
endif

all: clean default

default:
        $(MAKE) -C $(KDIR) M=${shell pwd}   modules

clean:
        $(RM) -rf .*.cmd *.o .*.d .*.tmp .*.o *.mod.c *.ko .tmp_versions *.scc *.ld.script *.symvers *.order

install:
        cp *.ko $(DIR)

obj-m := $(MODULE).o

 

posted @ 2019-08-27 15:30  行木辛  阅读(452)  评论(0编辑  收藏  举报