RFR: 8261401: Add sanity check for UseSHM large pages similar to the one used with hugetlb large pages [v2]

Thomas Stuefe stuefe at openjdk.java.net
Wed Feb 10 18:47:41 UTC 2021


On Wed, 10 Feb 2021 18:28:51 GMT, Stefan Johansson <sjohanss at openjdk.org> wrote:

>> When large pages are enabled on Linux (using -XX:+UseLargePages), both UseHugeTLBFS and UseSHM can be used. We prefer to use HugeTLBFS and first do a sanity check to see if this kind of large pages are available and if so we disable UseSHM.
>> 
>> The problematic part is when HugeTLBFS pages are not available, then we disable this flag and without doing any sanity check for UseSHM, we mark large pages as enabled using SHM. One big problem with this is that SHM also requires the same type of explicitly allocated huge pages as HugeTLBFS and also privileges to lock memory. So it is likely that in the case of not being able to use HugeTLBFS we probably can't use SHM either.
>> 
>> A fix for this would be to do a similar sanity check as currently done for HugeTLBFS and if it fails disable UseLargePages since we will always fail such allocation attempts anyways. 
>> 
>> The proposed sanity check consist of two part, where the first is just trying create a shared memory segment using `shmget()` with SHM_HUGETLB to use large pages. If this fails there is no idea in trying to use SHM to get large pages.
>> 
>> The second part checks if the process has privileges to lock memory or if there will be a limit for the SHM usage. I think this would be a nice addition since it will notify the user about the limit and explain why large page mappings fail. The implementation parses `/proc/self/status` to make sure the needed capability is available.
>> 
>> This change needs two tests to be updated to handle that large pages not can be disabled even when run with +UseLargePages. One of these tests are also updated in [PR#2486](https://github.com/openjdk/jdk/pull/2486) and I plan to get that integrated before this one.
>
> Stefan Johansson has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Thomas review
>   
>   Removed check for IPC_LOCK capability. If a large page mapping fails
>   the errno is already present in the warning printed out. We could
>   look at improving this to better explain when EPERM vs ENOMEM occurs.

Looks almost good. Minor nit below.

src/hotspot/os/linux/os_linux.cpp line 3781:

> 3779:   }
> 3780: 
> 3781:   log_warning(pagesize)("UseLargePages disabled, no large pages configured and available on the system.");

IIUC here we end up if UseLargePages=true (by default or not) and we were unable to get any of our APIs to work? Should this be an unconditional printout? At least make it only unconditional if UseLargePages==true is not default? I know its only a theoretical problem now since default is false.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2488


More information about the hotspot-dev mailing list