ThreadPriorityPolicy settings for non-root users
David Holmes
david.holmes at oracle.com
Wed Dec 19 22:07:57 UTC 2018
Hi Matthias,
This is a tricky area and it will need quite a bit of thought. The
existing priority related code is very old, intended to address very
specific usecases and basically AFAIK generally completely unused for
years. We actively discourage people from messing with priority. :)
The BSD code was blindly copied from Linux (as was the bulk of the
BSD/OS X port).
I will need to refresh myself on all the gory details so this is not
likely to happen until the New Year as I'll be on Christmas break from
Friday until January 7.
Cheers,
David
On 20/12/2018 3:13 am, Baesken, Matthias wrote:
>
> Hello ,
> currently OpenJDK supports 2 ThreadPriorityPolicy settings, 0 (normal, the default) and 1,
> the so called "aggressive" mode :
>
> "1 : Aggressive. "\
> " Java thread priorities map over to the entire range of "\
> " native thread priorities. Higher Java thread priorities map "\
> " to higher native thread priorities. This policy should be "\
> " used with care, as sometimes it can cause performance "\
> " degradation in the application and/or the entire system. On "\
> " Linux this policy requires root privilege.") \
>
> Currently we check directly for root in os_bsd.cpp and os_linux.cpp (the text in globals.hpp mentions only Linux which seems to be not fully correct):
>
> if (geteuid() != 0) { ... } in function prio_init().
>
> (looks like the check is not done for other platforms).
>
> However the check for root (e.g. on Linux) hinders users to set a ****lower priority**** for a thread (== increase the "niceness" level)
> when running as a non-root user (there might be strange ways from outside the VM with calling scripts and renice but .... ).
>
>
> In older JDKs (e.g. JDK8) there was a "workaround" to use for example ThreadPriorityPolicy=2 to avoid the root-check,
> but this is not possible any more in recent JDKs (10/11) after the range check (0,1) has been introduced for the ThreadPriorityPolicy flag
> (and probably the old workaround was not a good one anyway because it was undocumented).
>
> So do you think we could introduce another XX-flag ( AllowAggressiveThreadPriorityPolicyForAllUsers, or some better name)
> that allows using the "aggressive" mode for non-root users ? Another option would be to add another mode 2 for ThreadPriorityPolicy
> that documents the behavior (like mode 1 but without root-user check).
>
> If I get it right, even setting ***higher prios*** (lower niceness) is possible for non-root users on systems configured in an appropriate way
> (using the CAP_SYS_NICE capability).
>
> But setting lower prio / higher niceness is even possible for normal users NOW without special config, it is just disabled by the root-check
> which is very bad.
>
> Best regards, Matthias
>
More information about the hotspot-dev
mailing list