Skip to content

MaxDirectMemorySize memory size reported by -XX:+PrintFlagsFinal is incorrect (i.e it's -1 by default) #16637

Closed

Description

@grcevski

Elasticsearch uses few math formulas for basic JVM ergonomics when launching without explicit heap size settings. We look at the max available heap and the max direct memory on the system, and then we use them to determine what's a good heap size for the JVM.

Running the following command below produces this output with j9:

java -XX:+PrintFlagsFinal
[Global flags]
   size_t MaxHeapSize                              = 16828923904                               {product} {ergonomic}
 uint64_t MaxDirectMemorySize                      = 18446744073709551615                      {product} {ergonomic}

Running Hotspot with the same produces:

   size_t MaxHeapSize                              = 16835936256                               {product} {ergonomic}
 uint64_t MaxDirectMemorySize                      = 0                                         {product} {default}

According to the Java SE docs, it should be 0 if it's not specified:

Sets the maximum total size (in bytes) of the New I/O (the java.nio package) direct-buffer allocations. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. By default, the size is set to 0, meaning that the JVM chooses the size for NIO direct-buffer allocations automatically.
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html (search for XX:MaxDirectMemorySize)

j9 version:

java version "17.0.6-ea" 2023-01-17
IBM Semeru Runtime Open Edition 17.0.6.0-december_22-preview_1 (build 17.0.6-ea+6)
Eclipse OpenJ9 VM 17.0.6.0-december_22-preview_1 (build criu-preview-december_22-release-6c898853679, JRE 17 Linux amd64-64-Bit Compressed References 20230117_95 (JIT enabled, AOT enabled)
OpenJ9   - 6c898853679
OMR      - 6124dbc41
JCL      - 220b5cb074a based on jdk-17.0.6+6)

OS/System information:

/proc/version
Linux version 5.15.0-56-generic (buildd@lcy02-amd64-004) (gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022

/proc/meminfo
MemTotal:       65738028 kB
MemFree:        53102960 kB
MemAvailable:   61846336 kB
Buffers:          271448 kB
Cached:          8842196 kB
SwapCached:            0 kB
Active:          4515964 kB
Inactive:        7250184 kB
Active(anon):       1944 kB
Inactive(anon):  2643288 kB
Active(file):    4514020 kB
Inactive(file):  4606896 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Dirty:               196 kB
Writeback:             0 kB
AnonPages:       2652516 kB
Mapped:           369096 kB
Shmem:              4224 kB
KReclaimable:     347240 kB
Slab:             529764 kB
SReclaimable:     347240 kB
SUnreclaim:       182524 kB
KernelStack:       11520 kB
PageTables:        19088 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    34966160 kB
Committed_AS:    8048312 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       91468 kB
VmallocChunk:          0 kB
Percpu:            39552 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      545300 kB
DirectMap2M:    16119808 kB
DirectMap1G:    50331648 kB

Activity

  1. pshipton commented on Jan 31, 2023

    @pshipton
    Member
  2. grcevski commented on Jan 31, 2023

    @grcevski
    Author

    I took a look at the code that prints the Hotspot compatible flags output, so I it can easily be tweaked for the printout so Java programs can find this setting. Strangely enough, the Hotspot JCL treats -1 as unset (or empty setting), but prints 0.

  3. pshipton commented on Jan 31, 2023

    @pshipton
    Member

    #16639 should fix it.

  4. mstoodle commented on Jan 31, 2023

    @mstoodle
    Contributor

    nice catch, @grcevski , thanks for pointing it out!

  5. grcevski commented on Jan 31, 2023

    @grcevski
    Author

    Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions