View previous topic :: View next topic |
Author |
Message |
AndrewAmmerlaan Developer
Joined: 25 Jun 2014 Posts: 266 Location: Nijmegen
|
Posted: Sat Oct 11, 2014 2:14 pm Post subject: [SOLVED]Setting maximum RAM usage for a single process |
|
|
Hi,
I have this java application, and I set xmx to 2 gb for it, but my computer still runs out of ram, according to ksysguard java uses more then 2 gb, a quick google search motivated me to replace the oracle jre with the jdk package. I opened jconsole and ran the application, and it turns out the application actually uses less then the set 2 gb, which is okay. I did some reading, and discovered that the memory usage of the application can differ, from the RAM usage of the actual process. I would like to do the following: set maximum RAM usage for the java process, and in doing so prevent my computer from running out. I did some research, but I have found no answer to my question, if anyone can help me with this, I would be very grateful. _________________ OS: Gentoo 6.7.3-gentoo-dist, ~amd64, 17.1/desktop/plasma/systemd/merged-usr
MB: MSI Z370-A PRO
CPU: Intel Core i9-9900KS
GPU: Intel Arc A770 16GB & Intel UHD Graphics 630
SSD: Samsung 970 EVO Plus 2 TB
RAM: Crucial Ballistix 32GB DDR4-2400
Last edited by AndrewAmmerlaan on Tue Oct 14, 2014 4:47 pm; edited 1 time in total |
|
Back to top |
|
|
SlashBeast Retired Dev
Joined: 23 May 2006 Posts: 2922
|
Posted: Sat Oct 11, 2014 4:48 pm Post subject: |
|
|
You could create additional cgroup for your process and setting memory limit there, but keep in mind that this could result in freezing the java application rather than limiting its memory usage. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Sat Oct 11, 2014 8:43 pm Post subject: |
|
|
|
|
Back to top |
|
|
AndrewAmmerlaan Developer
Joined: 25 Jun 2014 Posts: 266 Location: Nijmegen
|
Posted: Sun Oct 12, 2014 2:42 pm Post subject: |
|
|
SlashBeast wrote: | You could create additional cgroup for your process and setting memory limit there, but keep in mind that this could result in freezing the java application rather than limiting its memory usage. |
thanks, I installed libcgroup, and set rc_controller_cgroups="YES", and enabled cgroup support in the kernel
but now I don't know how to continue
ulimit is system wide, and not for a single process, correct?? _________________ OS: Gentoo 6.7.3-gentoo-dist, ~amd64, 17.1/desktop/plasma/systemd/merged-usr
MB: MSI Z370-A PRO
CPU: Intel Core i9-9900KS
GPU: Intel Arc A770 16GB & Intel UHD Graphics 630
SSD: Samsung 970 EVO Plus 2 TB
RAM: Crucial Ballistix 32GB DDR4-2400 |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Sun Oct 12, 2014 3:39 pm Post subject: |
|
|
AndrewAmmerlaan wrote: | ulimit is system wide, and not for a single process, correct? |
No. It affects the current process and any children.
It's impossible for a process to change its parent's ulimit, in the same way that it's impossible for it to affect its environment. That's why ulimit is a shell builtin.
There's a sysctl interface, which is what you're likely thinking of, but I don't know much about it, as I do scripting and coding, not admin. Others will be much more knowledgeable than I on that stuff. |
|
Back to top |
|
|
AndrewAmmerlaan Developer
Joined: 25 Jun 2014 Posts: 266 Location: Nijmegen
|
Posted: Sun Oct 12, 2014 4:18 pm Post subject: |
|
|
steveL wrote: | AndrewAmmerlaan wrote: | ulimit is system wide, and not for a single process, correct? |
No. It affects the current process and any children.
It's impossible for a process to change its parent's ulimit, in the same way that it's impossible for it to affect its environment. That's why ulimit is a shell builtin.
There's a sysctl interface, which is what you're likely thinking of, but I don't know much about it, as I do scripting and coding, not admin. Others will be much more knowledgeable than I on that stuff. |
So if I set a ulimit in the terminal, it will apply to that terminal only, and everything that's opened by that terminal?? If so, how can i set a ulimit, when I open a java application, something like:
ulimit -Sf <amount of RAM> and then
java -jar <java pplication.jar>
?? _________________ OS: Gentoo 6.7.3-gentoo-dist, ~amd64, 17.1/desktop/plasma/systemd/merged-usr
MB: MSI Z370-A PRO
CPU: Intel Core i9-9900KS
GPU: Intel Arc A770 16GB & Intel UHD Graphics 630
SSD: Samsung 970 EVO Plus 2 TB
RAM: Crucial Ballistix 32GB DDR4-2400 |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Sun Oct 12, 2014 7:40 pm Post subject: |
|
|
AndrewAmmerlaan wrote: | So if I set a ulimit in the terminal, it will apply to that terminal only, and everything that's opened by that terminal? |
Technically it applies to the shell process, but yes.
Quote: | If so, how can i set a ulimit, when I open a java application, something like:
ulimit -Sf <amount of RAM> and then
java -jar <java pplication.jar> |
Yup :-)
Though -f is file-size (the only portable one according to man 1p ulimit), and you may want to look at hard limits too. When it comes to memory, there's RSS (resident set size) and maximum virtual (but not necessarily allocated: akin to "address space") as well as stack. You likely want to constrain rss (ulimit -m.)
See man 2 getrlimit vs man 3p getrlimit
I don't usually mess with that stuff, since it's config (the most we'd do is use the call with what the admin told us.)
From what I understand you usually have to tune it a bit, after checking htop/top. |
|
Back to top |
|
|
Naib Watchman
Joined: 21 May 2004 Posts: 6051 Location: Removed by Neddy
|
Posted: Sun Oct 12, 2014 9:05 pm Post subject: |
|
|
AndrewAmmerlaan wrote: | SlashBeast wrote: | You could create additional cgroup for your process and setting memory limit there, but keep in mind that this could result in freezing the java application rather than limiting its memory usage. |
thanks, I installed libcgroup, and set rc_controller_cgroups="YES", and enabled cgroup support in the kernel
but now I don't know how to continue
ulimit is system wide, and not for a single process, correct?? | http://wiki.gentoo.org/wiki/OpenRC/CGroups _________________
Quote: | Removed by Chiitoo |
|
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Mon Oct 13, 2014 8:22 am Post subject: |
|
|
Also, you'd more usually run via a wrapper like so:
Code: | #!/bin/bash
ulimit ...
exec java -jar <java pplication.jar> "$@"
| so the running java has the same pid as the shell process. |
|
Back to top |
|
|
AndrewAmmerlaan Developer
Joined: 25 Jun 2014 Posts: 266 Location: Nijmegen
|
Posted: Mon Oct 13, 2014 4:07 pm Post subject: |
|
|
steveL wrote: | Also, you'd more usually run via a wrapper like so:
Code: | #!/bin/bash
ulimit ...
exec java -jar <java pplication.jar> "$@"
| so the running java has the same pid as the shell process. |
thanks for your help, I actually haven't written a script before, so I'm reading this basic tutorial I found online.
Naib wrote: | AndrewAmmerlaan wrote: | SlashBeast wrote: | You could create additional cgroup for your process and setting memory limit there, but keep in mind that this could result in freezing the java application rather than limiting its memory usage. |
thanks, I installed libcgroup, and set rc_controller_cgroups="YES", and enabled cgroup support in the kernel
but now I don't know how to continue
ulimit is system wide, and not for a single process, correct?? | http://wiki.gentoo.org/wiki/OpenRC/CGroups |
I read that, but I didn't understand. It doesn't matter for now, I'll be using ulimit anyway. I'll look into cgroups later. _________________ OS: Gentoo 6.7.3-gentoo-dist, ~amd64, 17.1/desktop/plasma/systemd/merged-usr
MB: MSI Z370-A PRO
CPU: Intel Core i9-9900KS
GPU: Intel Arc A770 16GB & Intel UHD Graphics 630
SSD: Samsung 970 EVO Plus 2 TB
RAM: Crucial Ballistix 32GB DDR4-2400 |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
|
Back to top |
|
|
AndrewAmmerlaan Developer
Joined: 25 Jun 2014 Posts: 266 Location: Nijmegen
|
Posted: Tue Oct 14, 2014 7:35 am Post subject: |
|
|
Thanks for the advice, I will start reading as soon as possible. _________________ OS: Gentoo 6.7.3-gentoo-dist, ~amd64, 17.1/desktop/plasma/systemd/merged-usr
MB: MSI Z370-A PRO
CPU: Intel Core i9-9900KS
GPU: Intel Arc A770 16GB & Intel UHD Graphics 630
SSD: Samsung 970 EVO Plus 2 TB
RAM: Crucial Ballistix 32GB DDR4-2400 |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|