Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于使用stress测试内存限制的问题 ? #69

Open
blacklad opened this issue Mar 7, 2020 · 2 comments
Open

关于使用stress测试内存限制的问题 ? #69

blacklad opened this issue Mar 7, 2020 · 2 comments

Comments

@blacklad
Copy link

blacklad commented Mar 7, 2020

在书中通过sudo sh -c "echo "100m " > memory.limit_in_bytes " 将内存最大限制为100m,
然后执行了 stress --vm-bytes 200m --vm-keep -m 1 后 在top中看到了内存被限制到了100m.

但是我理解当申请的内存超过限制的内存时,不是直接会被kill掉?
下面是我执行后的结果,不是太明白书中的运行后可以看到内存被限制而不是直接提示失败?

stress: info: [4] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
stress: FAIL: [4] (415) <-- worker 5 got signal 9
stress: WARN: [4] (417) now reaping child worker processes
stress: FAIL: [4] (421) kill error: No such process
stress: FAIL: [4] (451) failed run completed in 0s
2020/03/07 15:52:22 exit status 1
@ahojcn
Copy link

ahojcn commented Mar 9, 2020

@blacklad

你可以了解一下这个文件:

root@ubuntu:/sys/fs/cgroup/memory# cat memory.oom_control
oom_kill_disable 0
under_oom 0

这个文件里面包含了一个控制是否为当前 cgroup 启动 OOM-killer 的标识。如果写0到这个文件,将启动OOM-killer,当内核无法给进程分配足够的内存时,将会直接kill掉该进程;如果写1到这个文件,表示不启动OOM-killer,当内核无法给进程分配足够的内存时,将会暂停该进程直到有空余的内存之后再继续运行;同时,memory.oom_control还包含一个只读的under_oom字段,用来表示当前是否已经进入oom状态,也即是否有进程被暂停了。

@ahojcn
Copy link

ahojcn commented Mar 9, 2020

@blacklad
补充一下,还有这个文件:

memory.swappiness

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants