Tuning of JVM Optimizations large Memory paging (largepage)

Source: Internet
Author: User

Transferred from: http://cjjwzs.iteye.com/blog/1059381

This article will be from the principle of memory paging, how to adjust the paging size two sections, to explain to you how largepage to the performance of the JVM, and at the end of the text pointed out the side effects of the large page. OK, let's get started!

How memory paging size improves performance

First, we need to review a small subset of the principles of computer composition, which is good for understanding the high memory paging as well as the performance improvement of the JVM.

What is memory paging?
We know that the CPU accesses memory by addressing it. The addressing width of the 32-bit CPU is 0~0XFFFFFFFF, and the computed size is 4G, which means that the maximum supported physical memory is 4G.

However, in the course of practice, encountered such a problem, the program needs to use 4G of memory, and the available physical memory is less than 4G, causing the program to reduce memory consumption.
In order to solve such problems, modern CPUs introduced the MMU (Memory Management unit RAM Management Unit).

The core idea of the MMU is to replace the physical address with the virtual address, that is, when the CPU is addressing, and the MMU is responsible for mapping the virtual address to physical addresses.
The introduction of the MMU solves the limitation of physical memory, which is the same as using 4G memory for the program.

Memory Paging (Paging) is a memory management mechanism proposed on the basis of the use of MMU. It splits the virtual address and physical address by a fixed size (4K) into pages and page frames (page frame) and guarantees that the page is the same size as the page frame.

This mechanism, from the data structure, guarantees efficient access to memory and enables the OS to support non-contiguous memory allocations.
When the program memory is not enough, you can also transfer the infrequently used physical memory pages to other storage devices, such as disk, which is familiar with the virtual memory.

As mentioned above, the virtual address and physical address need to be mapped to make the CPU work properly.
mapping requires the mapping table to be stored. In modern CPU architectures, mapping relationships are typically stored in physical memory where a page table is called. page table in the modern operating system by the Global Directory (PGD)-The intermediate directory (PMD)-page table entry (PTE) three-layer tree, sometimes different books but the same meaning, but only draw more pictures less.

Further optimization, introduction of TLB (translation lookaside buffer, page table register buffer)
As we know from the previous section, the page table is stored in memory. We know that the CPU accesses the memory through the bus, certainly slower than the direct access register.
To further optimize performance, the Modern CPU architecture introduces the TLB to cache part of the frequently accessed page table content.

Why should I support large memory paging?
The TLB is limited, no doubt about it. tlb miss occurs when the TLB's storage limit is exceeded, and then the OS commands the CPU to access the page table in memory. If the TLB miss is frequent, the performance of the program will drop quickly.

In order for the TLB to store more page address mappings, our approach is to increase the paging size of the memory.

If a page 4M, compared to a page 4K, the former can allow the TLB to store more than 1000 page address mapping relationship, performance improvement is relatively considerable.

Adjusting OS and JVM memory paging

There are some limitations and setup steps to enable large memory pages under Linux and Windows.

Linux:
Limit: Requires 2.6 kernel or 2.4 kernel has been hit large memory page patch.
To confirm support, please hit the following command at the terminal:

# Cat/proc/meminfo | grep Huge
hugepages_total:0
hugepages_free:0
hugepagesize:2048 KB

If you have the output of the Hugepage typeface, your OS is supported for large memory paging. Hugepagesize is the default large memory page size.
Next, in order for the JVM to adjust the size of the large memory page, you need to set the OS shared memory segment maximum and the number of large memory pages.

Shared memory segment maximum value
It is recommended that this value is greater than the Java Heap size, which sets 4G of memory in this example.

# echo 4294967295 >/proc/sys/kernel/shmmax

Note This value cannot exceed 4GB on a 32-bit operating system

Number of large memory pages

# echo 154 >/proc/sys/vm/nr_hugepages

This value is typically a Java process that consumes the largest memory/single page size, such as Java Settings 1.5G, a single page 10M, then the number is 1536/10 = 154.
Note: Since proc is a memory FS, it is recommended that you write a script to the init phase (rc.local) in order not to let your settings be flushed out after a reboot.

A more convenient way is to

echo "vm.nr_hugepages=154" >>/etc/sysctl.conf

Verify that the settings are in effect by using the following command

grep hugepages_total/proc/meminfo

The result should be the value you set previously 154

Single Page size adjustment

Add parameter-xx:largepagesizeinbytes=10m when JVM is enabled

——————————————————————

In fact, in addition to the JVM can use large pages to improve performance, there is an application more memory-intensive scenario , that is, the database. This part of the recommendation was early in the tuning of the database.

Tuning of JVM Optimizations large Memory paging (largepage)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.