How To Solve Issues Related to Log – Unable to lock JVM memory. Failed to set working set size. Error code

Prevent Your Next ELK Incident

Try our free Check Up to test if your ES issues are caused from misconfigured settings

Prevent Issue

Updated: Jan-20

In-Page Navigation (click to jump) :

Opster Offer’s World-Class Elasticsearch Expertise In One Powerful Product
Try Our Free ES Check-Up   Prevent Incident

Troubleshooting background

To troubleshoot Elasticsearch log “Unable to lock JVM memory. Failed to set working set size. Error code” it’s important to understand common problems related to Elasticsearch concepts: bootstrap, memory. See detailed explanations below complete with common problems, examples and useful tips.

Memory in Elasticsearch

What is it

Memory is one of the most critical resources to monitor in Elasticsearch. Elasticsearch runs on JVM and uses heap memory areas for query cache, request cache, accessing lucene segments and storing fielddata for aggregations and sorting.

Commos problems and important points
  • The most common error that arises in Elasticsearch is OutOfMemory error. This error comes when the node is not able to cope up with the required heap size space. To avoid this, you need to closely monitor the heap utilization and garbage collector performance.
  • As per the most up-to-date best practices you should not allocate more than 50 percent of total RAM to JVM heap size. Starting from Elasticsearch version 5.x onward this can be set using -Xms and -Xmx parameters inside jvm.options configuration file. The defaults are set to 1 GB for both minimum and maximum heap size.
  • The heap size should not set more than 31 GB in any case to avoid the poor garbage collection.

To help troubleshoot related issues we have gathered selected Q&A from the community and issues from Github , please review the following for further information :

1 Unable to lock JVM Memory: error=12, reason=Cannot allocate memory – Elasticsearch 6.2.4 5.38 K 5

2How to change Elasticsearch max memory size 121.67 K  93

Problem Configuring The Memory/4867

Log Context

Log ”Unable to lock JVM memory. Failed to set working set size. Error code {}” classname is
We have extracted the following from Elasticsearch source code to get an in-depth context :

             // By default; Windows limits the number of pages that can be locked.
            // Thus; we need to first increase the working set size of the JVM by
            // the amount of memory we wish to lock; plus a small overhead (1MB).
            SizeT size = new SizeT(JvmInfo.jvmInfo().getMem().getHeapInit().getBytes() + (1024 * 1024));
            if (!kernel.SetProcessWorkingSetSize(process; size; size)) {
                logger.warn("Unable to lock JVM memory. Failed to set working set size. Error code {}"; Native.getLastError());
            } else {
                JNAKernel32Library.MemoryBasicInformation memInfo = new JNAKernel32Library.MemoryBasicInformation();
                long address = 0;
                while (kernel.VirtualQueryEx(process; new Pointer(address); memInfo; memInfo.size()) != 0) {
                    boolean lockable = memInfo.State.longValue() == JNAKernel32Library.MEM_COMMIT

About Opster

Opster identifies and predicts root causes of Elasticsearch problems, provides recommendations and can automatically perform various actions to prevent issues, optimize performance and save resources.

Learn more: Glossary | Blog| Troubleshooting guides | Error Repository

Need help with any Elasticsearch issue ? Contact Opster