OOM-kill a process from user with highest memory consumption?
I have a multi-user system, where active users should get a fair share of the available memory.
Can I set up Linux to kill a process of the user with the highest total memory consumption?
This will happen when the system is out of memory. I suppose the largest of this user's processes should be killed.
I don't want to set memory limits on users, since their number varies and because there would be wasted memory if most of the users are not working. Killing the largest process would work, but it should be per user. Otherwise one user might spawn many small processes and cause another user's medium process to be killed.
linux process users out-of-memory multiuser
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have a multi-user system, where active users should get a fair share of the available memory.
Can I set up Linux to kill a process of the user with the highest total memory consumption?
This will happen when the system is out of memory. I suppose the largest of this user's processes should be killed.
I don't want to set memory limits on users, since their number varies and because there would be wasted memory if most of the users are not working. Killing the largest process would work, but it should be per user. Otherwise one user might spawn many small processes and cause another user's medium process to be killed.
linux process users out-of-memory multiuser
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
I suspect that's only possible if you make every user run in their own container. I think that wouldn't have any impact on performance, the difficulty would be the initial setup.
– Gilles
Mar 8 '16 at 22:46
I'm not an expert, but I can ask people to help. With containers, will a lone user be able to use the whole machine? Are containers hard to set up? I was thinking of making OOM score adjustments according to user memory usage. Does that make sense?
– Gerenuk
Mar 9 '16 at 9:24
I'm not an expert either. AFAIK the system keeps track of memory used by each container. You can set a limit per container, but you don't have to. The problem about “user memory usage” is that not only does Linux not keep track of it, but it isn't a well-defined notion, because memory can't be accounted per process: a lot of memory is used by multiple processes (in particular file cache). This is still true with containers but there is more separation so you get a more accurate picture (but not perfect).
– Gilles
Mar 9 '16 at 10:22
The details aside, hard limits on memory isn't the solution here, since it would mean there are hard limits for users. I want users to have 50% when there are two users online and 100% if they are alone. This would be solved "naturally", by killing a processes from the greediest user, when memory runs out.
– Gerenuk
Mar 9 '16 at 12:02
add a comment |
I have a multi-user system, where active users should get a fair share of the available memory.
Can I set up Linux to kill a process of the user with the highest total memory consumption?
This will happen when the system is out of memory. I suppose the largest of this user's processes should be killed.
I don't want to set memory limits on users, since their number varies and because there would be wasted memory if most of the users are not working. Killing the largest process would work, but it should be per user. Otherwise one user might spawn many small processes and cause another user's medium process to be killed.
linux process users out-of-memory multiuser
I have a multi-user system, where active users should get a fair share of the available memory.
Can I set up Linux to kill a process of the user with the highest total memory consumption?
This will happen when the system is out of memory. I suppose the largest of this user's processes should be killed.
I don't want to set memory limits on users, since their number varies and because there would be wasted memory if most of the users are not working. Killing the largest process would work, but it should be per user. Otherwise one user might spawn many small processes and cause another user's medium process to be killed.
linux process users out-of-memory multiuser
linux process users out-of-memory multiuser
edited Mar 8 '16 at 22:45
Gilles
542k12810991616
542k12810991616
asked Mar 8 '16 at 12:16
GerenukGerenuk
1666
1666
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
I suspect that's only possible if you make every user run in their own container. I think that wouldn't have any impact on performance, the difficulty would be the initial setup.
– Gilles
Mar 8 '16 at 22:46
I'm not an expert, but I can ask people to help. With containers, will a lone user be able to use the whole machine? Are containers hard to set up? I was thinking of making OOM score adjustments according to user memory usage. Does that make sense?
– Gerenuk
Mar 9 '16 at 9:24
I'm not an expert either. AFAIK the system keeps track of memory used by each container. You can set a limit per container, but you don't have to. The problem about “user memory usage” is that not only does Linux not keep track of it, but it isn't a well-defined notion, because memory can't be accounted per process: a lot of memory is used by multiple processes (in particular file cache). This is still true with containers but there is more separation so you get a more accurate picture (but not perfect).
– Gilles
Mar 9 '16 at 10:22
The details aside, hard limits on memory isn't the solution here, since it would mean there are hard limits for users. I want users to have 50% when there are two users online and 100% if they are alone. This would be solved "naturally", by killing a processes from the greediest user, when memory runs out.
– Gerenuk
Mar 9 '16 at 12:02
add a comment |
I suspect that's only possible if you make every user run in their own container. I think that wouldn't have any impact on performance, the difficulty would be the initial setup.
– Gilles
Mar 8 '16 at 22:46
I'm not an expert, but I can ask people to help. With containers, will a lone user be able to use the whole machine? Are containers hard to set up? I was thinking of making OOM score adjustments according to user memory usage. Does that make sense?
– Gerenuk
Mar 9 '16 at 9:24
I'm not an expert either. AFAIK the system keeps track of memory used by each container. You can set a limit per container, but you don't have to. The problem about “user memory usage” is that not only does Linux not keep track of it, but it isn't a well-defined notion, because memory can't be accounted per process: a lot of memory is used by multiple processes (in particular file cache). This is still true with containers but there is more separation so you get a more accurate picture (but not perfect).
– Gilles
Mar 9 '16 at 10:22
The details aside, hard limits on memory isn't the solution here, since it would mean there are hard limits for users. I want users to have 50% when there are two users online and 100% if they are alone. This would be solved "naturally", by killing a processes from the greediest user, when memory runs out.
– Gerenuk
Mar 9 '16 at 12:02
I suspect that's only possible if you make every user run in their own container. I think that wouldn't have any impact on performance, the difficulty would be the initial setup.
– Gilles
Mar 8 '16 at 22:46
I suspect that's only possible if you make every user run in their own container. I think that wouldn't have any impact on performance, the difficulty would be the initial setup.
– Gilles
Mar 8 '16 at 22:46
I'm not an expert, but I can ask people to help. With containers, will a lone user be able to use the whole machine? Are containers hard to set up? I was thinking of making OOM score adjustments according to user memory usage. Does that make sense?
– Gerenuk
Mar 9 '16 at 9:24
I'm not an expert, but I can ask people to help. With containers, will a lone user be able to use the whole machine? Are containers hard to set up? I was thinking of making OOM score adjustments according to user memory usage. Does that make sense?
– Gerenuk
Mar 9 '16 at 9:24
I'm not an expert either. AFAIK the system keeps track of memory used by each container. You can set a limit per container, but you don't have to. The problem about “user memory usage” is that not only does Linux not keep track of it, but it isn't a well-defined notion, because memory can't be accounted per process: a lot of memory is used by multiple processes (in particular file cache). This is still true with containers but there is more separation so you get a more accurate picture (but not perfect).
– Gilles
Mar 9 '16 at 10:22
I'm not an expert either. AFAIK the system keeps track of memory used by each container. You can set a limit per container, but you don't have to. The problem about “user memory usage” is that not only does Linux not keep track of it, but it isn't a well-defined notion, because memory can't be accounted per process: a lot of memory is used by multiple processes (in particular file cache). This is still true with containers but there is more separation so you get a more accurate picture (but not perfect).
– Gilles
Mar 9 '16 at 10:22
The details aside, hard limits on memory isn't the solution here, since it would mean there are hard limits for users. I want users to have 50% when there are two users online and 100% if they are alone. This would be solved "naturally", by killing a processes from the greediest user, when memory runs out.
– Gerenuk
Mar 9 '16 at 12:02
The details aside, hard limits on memory isn't the solution here, since it would mean there are hard limits for users. I want users to have 50% when there are two users online and 100% if they are alone. This would be solved "naturally", by killing a processes from the greediest user, when memory runs out.
– Gerenuk
Mar 9 '16 at 12:02
add a comment |
1 Answer
1
active
oldest
votes
The below will kill the process using the most memory on the box. Is that what you were looking for, or does it have to be the process of the user who is using the most memory (which may not be the greatest offender and reason for the memory shortage)?
#!/bin/bash
free=`awk '/^Mem/ {print $3}' <(free -m)`
psout=`ps axo pid,args,pmem,rss,vsz --sort -pmem,-rss,-vsz | head -2`
pid=`echo $psout | cut -d " " -f 6`
if (( $free < 1 )); then
kill -9 $pid
fi;
Edit: I see your reasoning now, will attempt to modify the above code.
Edit 2: Since I don't have to complete this project today, let me put you on the right path. You can download smem (python script) from the below URL:
https://www.selenic.com/smem/download/
Running as root with -u option will give you the total amount of memory used by each user. Grab that in an array, sort by mem used, then just add a -u to the ps command above to kill the worst offender of that user.
Yes, the victim should be the user who is using the most memory. And his biggest process should be killed. But also note it should be handled the usual automatic way of the Linux OOM killer or something similar. Only the OOM can detect memory overflow without running a script too often.
– Gerenuk
Mar 8 '16 at 16:11
Indeed. It's not for today :) But a solution that integrates with Linux OOM killer would be nicer. Since otherwise I have to probe the memory all the time. Letting it get full is not an option, since then OOM will just kill the largest process. It should be an automatic solution, too.
– Gerenuk
Mar 8 '16 at 16:31
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f268373%2foom-kill-a-process-from-user-with-highest-memory-consumption%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The below will kill the process using the most memory on the box. Is that what you were looking for, or does it have to be the process of the user who is using the most memory (which may not be the greatest offender and reason for the memory shortage)?
#!/bin/bash
free=`awk '/^Mem/ {print $3}' <(free -m)`
psout=`ps axo pid,args,pmem,rss,vsz --sort -pmem,-rss,-vsz | head -2`
pid=`echo $psout | cut -d " " -f 6`
if (( $free < 1 )); then
kill -9 $pid
fi;
Edit: I see your reasoning now, will attempt to modify the above code.
Edit 2: Since I don't have to complete this project today, let me put you on the right path. You can download smem (python script) from the below URL:
https://www.selenic.com/smem/download/
Running as root with -u option will give you the total amount of memory used by each user. Grab that in an array, sort by mem used, then just add a -u to the ps command above to kill the worst offender of that user.
Yes, the victim should be the user who is using the most memory. And his biggest process should be killed. But also note it should be handled the usual automatic way of the Linux OOM killer or something similar. Only the OOM can detect memory overflow without running a script too often.
– Gerenuk
Mar 8 '16 at 16:11
Indeed. It's not for today :) But a solution that integrates with Linux OOM killer would be nicer. Since otherwise I have to probe the memory all the time. Letting it get full is not an option, since then OOM will just kill the largest process. It should be an automatic solution, too.
– Gerenuk
Mar 8 '16 at 16:31
add a comment |
The below will kill the process using the most memory on the box. Is that what you were looking for, or does it have to be the process of the user who is using the most memory (which may not be the greatest offender and reason for the memory shortage)?
#!/bin/bash
free=`awk '/^Mem/ {print $3}' <(free -m)`
psout=`ps axo pid,args,pmem,rss,vsz --sort -pmem,-rss,-vsz | head -2`
pid=`echo $psout | cut -d " " -f 6`
if (( $free < 1 )); then
kill -9 $pid
fi;
Edit: I see your reasoning now, will attempt to modify the above code.
Edit 2: Since I don't have to complete this project today, let me put you on the right path. You can download smem (python script) from the below URL:
https://www.selenic.com/smem/download/
Running as root with -u option will give you the total amount of memory used by each user. Grab that in an array, sort by mem used, then just add a -u to the ps command above to kill the worst offender of that user.
Yes, the victim should be the user who is using the most memory. And his biggest process should be killed. But also note it should be handled the usual automatic way of the Linux OOM killer or something similar. Only the OOM can detect memory overflow without running a script too often.
– Gerenuk
Mar 8 '16 at 16:11
Indeed. It's not for today :) But a solution that integrates with Linux OOM killer would be nicer. Since otherwise I have to probe the memory all the time. Letting it get full is not an option, since then OOM will just kill the largest process. It should be an automatic solution, too.
– Gerenuk
Mar 8 '16 at 16:31
add a comment |
The below will kill the process using the most memory on the box. Is that what you were looking for, or does it have to be the process of the user who is using the most memory (which may not be the greatest offender and reason for the memory shortage)?
#!/bin/bash
free=`awk '/^Mem/ {print $3}' <(free -m)`
psout=`ps axo pid,args,pmem,rss,vsz --sort -pmem,-rss,-vsz | head -2`
pid=`echo $psout | cut -d " " -f 6`
if (( $free < 1 )); then
kill -9 $pid
fi;
Edit: I see your reasoning now, will attempt to modify the above code.
Edit 2: Since I don't have to complete this project today, let me put you on the right path. You can download smem (python script) from the below URL:
https://www.selenic.com/smem/download/
Running as root with -u option will give you the total amount of memory used by each user. Grab that in an array, sort by mem used, then just add a -u to the ps command above to kill the worst offender of that user.
The below will kill the process using the most memory on the box. Is that what you were looking for, or does it have to be the process of the user who is using the most memory (which may not be the greatest offender and reason for the memory shortage)?
#!/bin/bash
free=`awk '/^Mem/ {print $3}' <(free -m)`
psout=`ps axo pid,args,pmem,rss,vsz --sort -pmem,-rss,-vsz | head -2`
pid=`echo $psout | cut -d " " -f 6`
if (( $free < 1 )); then
kill -9 $pid
fi;
Edit: I see your reasoning now, will attempt to modify the above code.
Edit 2: Since I don't have to complete this project today, let me put you on the right path. You can download smem (python script) from the below URL:
https://www.selenic.com/smem/download/
Running as root with -u option will give you the total amount of memory used by each user. Grab that in an array, sort by mem used, then just add a -u to the ps command above to kill the worst offender of that user.
edited Mar 8 '16 at 16:13
answered Mar 8 '16 at 15:37
Alex DAlex D
11
11
Yes, the victim should be the user who is using the most memory. And his biggest process should be killed. But also note it should be handled the usual automatic way of the Linux OOM killer or something similar. Only the OOM can detect memory overflow without running a script too often.
– Gerenuk
Mar 8 '16 at 16:11
Indeed. It's not for today :) But a solution that integrates with Linux OOM killer would be nicer. Since otherwise I have to probe the memory all the time. Letting it get full is not an option, since then OOM will just kill the largest process. It should be an automatic solution, too.
– Gerenuk
Mar 8 '16 at 16:31
add a comment |
Yes, the victim should be the user who is using the most memory. And his biggest process should be killed. But also note it should be handled the usual automatic way of the Linux OOM killer or something similar. Only the OOM can detect memory overflow without running a script too often.
– Gerenuk
Mar 8 '16 at 16:11
Indeed. It's not for today :) But a solution that integrates with Linux OOM killer would be nicer. Since otherwise I have to probe the memory all the time. Letting it get full is not an option, since then OOM will just kill the largest process. It should be an automatic solution, too.
– Gerenuk
Mar 8 '16 at 16:31
Yes, the victim should be the user who is using the most memory. And his biggest process should be killed. But also note it should be handled the usual automatic way of the Linux OOM killer or something similar. Only the OOM can detect memory overflow without running a script too often.
– Gerenuk
Mar 8 '16 at 16:11
Yes, the victim should be the user who is using the most memory. And his biggest process should be killed. But also note it should be handled the usual automatic way of the Linux OOM killer or something similar. Only the OOM can detect memory overflow without running a script too often.
– Gerenuk
Mar 8 '16 at 16:11
Indeed. It's not for today :) But a solution that integrates with Linux OOM killer would be nicer. Since otherwise I have to probe the memory all the time. Letting it get full is not an option, since then OOM will just kill the largest process. It should be an automatic solution, too.
– Gerenuk
Mar 8 '16 at 16:31
Indeed. It's not for today :) But a solution that integrates with Linux OOM killer would be nicer. Since otherwise I have to probe the memory all the time. Letting it get full is not an option, since then OOM will just kill the largest process. It should be an automatic solution, too.
– Gerenuk
Mar 8 '16 at 16:31
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f268373%2foom-kill-a-process-from-user-with-highest-memory-consumption%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I suspect that's only possible if you make every user run in their own container. I think that wouldn't have any impact on performance, the difficulty would be the initial setup.
– Gilles
Mar 8 '16 at 22:46
I'm not an expert, but I can ask people to help. With containers, will a lone user be able to use the whole machine? Are containers hard to set up? I was thinking of making OOM score adjustments according to user memory usage. Does that make sense?
– Gerenuk
Mar 9 '16 at 9:24
I'm not an expert either. AFAIK the system keeps track of memory used by each container. You can set a limit per container, but you don't have to. The problem about “user memory usage” is that not only does Linux not keep track of it, but it isn't a well-defined notion, because memory can't be accounted per process: a lot of memory is used by multiple processes (in particular file cache). This is still true with containers but there is more separation so you get a more accurate picture (but not perfect).
– Gilles
Mar 9 '16 at 10:22
The details aside, hard limits on memory isn't the solution here, since it would mean there are hard limits for users. I want users to have 50% when there are two users online and 100% if they are alone. This would be solved "naturally", by killing a processes from the greediest user, when memory runs out.
– Gerenuk
Mar 9 '16 at 12:02