Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED]Setting maximum RAM usage for a single process
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
AndrewAmmerlaan
Developer
Developer


Joined: 25 Jun 2014
Posts: 266
Location: Nijmegen

PostPosted: Sat Oct 11, 2014 2:14 pm    Post subject: [SOLVED]Setting maximum RAM usage for a single process Reply with quote

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
View user's profile Send private message
SlashBeast
Retired Dev
Retired Dev


Joined: 23 May 2006
Posts: 2922

PostPosted: Sat Oct 11, 2014 4:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Sat Oct 11, 2014 8:43 pm    Post subject: Reply with quote

Code:
help ulimit
Back to top
View user's profile Send private message
AndrewAmmerlaan
Developer
Developer


Joined: 25 Jun 2014
Posts: 266
Location: Nijmegen

PostPosted: Sun Oct 12, 2014 2:42 pm    Post subject: Reply with quote

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

steveL wrote:
Code:
help ulimit

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
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Sun Oct 12, 2014 3:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
AndrewAmmerlaan
Developer
Developer


Joined: 25 Jun 2014
Posts: 266
Location: Nijmegen

PostPosted: Sun Oct 12, 2014 4:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Sun Oct 12, 2014 7:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Sun Oct 12, 2014 9:05 pm    Post subject: Reply with quote

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

steveL wrote:
Code:
help ulimit

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
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Mon Oct 13, 2014 8:22 am    Post subject: Reply with quote

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
View user's profile Send private message
AndrewAmmerlaan
Developer
Developer


Joined: 25 Jun 2014
Posts: 266
Location: Nijmegen

PostPosted: Mon Oct 13, 2014 4:07 pm    Post subject: Reply with quote

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

steveL wrote:
Code:
help ulimit

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
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Mon Oct 13, 2014 9:23 pm    Post subject: Reply with quote

AndrewAmmerlaan wrote:
thanks for your help, I actually haven't written a script before, so I'm reading this basic tutorial I found online.

You're very welcome :-)

The latter statement worries me, because 99% of the tutorials online are absolutely rubbish; TLDP/ABS being the classic exemplar (since so many Linux distro-developers learnt from it, and it is truly bad.) The wooledge.org BASH Guide was written to counter that problem (after the BashFAQ had been going for a few years.)

Here's the content of /msg friendlyToaster bash (on IRC: chat.freenode.net)
man bash | http://wiki.bash-hackers.org/doku.php?id=scripting:basics | http://mywiki.wooledge.org/BashGuide | http://www.grymoire.com/Unix/index.html | http://mywiki.wooledge.org/BashFAQ | http://mywiki.wooledge.org/BashPitfalls | http://www.shelldorado.com/ | #bash
Back to top
View user's profile Send private message
AndrewAmmerlaan
Developer
Developer


Joined: 25 Jun 2014
Posts: 266
Location: Nijmegen

PostPosted: Tue Oct 14, 2014 7:35 am    Post subject: Reply with quote

steveL wrote:
AndrewAmmerlaan wrote:
thanks for your help, I actually haven't written a script before, so I'm reading this basic tutorial I found online.

You're very welcome :-)

The latter statement worries me, because 99% of the tutorials online are absolutely rubbish; TLDP/ABS being the classic exemplar (since so many Linux distro-developers learnt from it, and it is truly bad.) The wooledge.org BASH Guide was written to counter that problem (after the BashFAQ had been going for a few years.)

Here's the content of /msg friendlyToaster bash (on IRC: chat.freenode.net)
man bash | http://wiki.bash-hackers.org/doku.php?id=scripting:basics | http://mywiki.wooledge.org/BashGuide | http://www.grymoire.com/Unix/index.html | http://mywiki.wooledge.org/BashFAQ | http://mywiki.wooledge.org/BashPitfalls | http://www.shelldorado.com/ | #bash


Thanks for the advice, I will start reading as soon as possible. :D
_________________
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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
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