ThreadPriorityPolicy settings for non-root users

Baesken, Matthias matthias.baesken at
Wed Dec 19 17:13:56 UTC 2018

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