JVM Tunings for the Operating System
There are several tunings that the JVM can use to improve the way in which it uses OS
Discussions about memory allocation and swapping occur in terms of pages. A page is a unit
of memory by which operating systems manage physical memory. It is the minimum unit of
allocation for the operating system: when 1 byte is allocated, the operating system must al-
locate an entire page. Further allocations for that program come from that same page until it
is filled, at which point a new page is allocated.
The operating system allocates many more pages than can fit in physical memory, which is
why there is paging: pages of the address space are moved to and from swap space (or other
storage depending on what the page contains). This means there must be some mapping
between these pages and where they are currently stored in the computer's RAM. Those
mappings are handled in two different ways. All page mappings are held in a global page
table (which the OS can scan to find a particular mapping), and the most frequently used
mappings are held in translation lookaside buffers (TLBs). TLBs are held in a fast cache, so
accessing pages through a TLB entry is much faster than accessing it through the the page
Machines have a limited number of TLB entries, so it becomes important to maximize the hit
rate on TLB entries (it functions as a least recently used cache). Since each entry represents a
page of memory, it is often advantageous to increase the page size used by an application. If
each page represents more memory, fewer TLB entries are required to encompass the entire
program, and it is more likely that a page will be found in the TLB when required. This is
true in general for any program, and so is also true in specific for things like Java application
servers or other Java programs with even a moderately sized heap.
Java supports this with the -XX:+UseLargePages option. The default value of this flag varies
depending on the operating system configuration. On Windows, large pages must be enabled
in the OS. In Windows terms, this means giving individual users the ability to lock pages into
memory, which is possible only on server versions of Windows. Even so, the JVM on Win-
dows defaults to using regular pages unless the UseLargePages flag is explicitly enabled.
On Linux, the UseLargePages flags is not enabled by default, and the OS must also be con-
figured to support large pages.