# Swap vs -XX:+AlwaysPreTouch

**URL:** https://discuss.elastic.co/t/swap-vs-xx-alwayspretouch/103620
**Category:** Elasticsearch
**Created:** [October 11, 2017, 9:42pm UTC](https://discuss.elastic.co/t/swap-vs-xx-alwayspretouch/103620 "2017-10-11T21:42:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![abhijat](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@abhijat](https://discuss.elastic.co/u/abhijat)
#### Post date: [October 11, 2017, 9:42pm UTC](https://discuss.elastic.co/t/swap-vs-xx-alwayspretouch/103620/1 "2017-10-11T21:42:52Z")

</div>

For newer elasticsearch versions... I guess v5.0 and above... I see that we have jvm.options file. In that file we have the JVM flag `-XX:+AlwaysPreTouch` set by default.

As I understand, this flag tells the OS to map the memory pages to the java process at the time of process initialization versus at incrementally at runtime.

As per the oracle page on jvm settings - [Java HotSpot VM Options](http://www.oracle.com/technetwork/articles/java/vmoptions-jsp-140102.html), AlwaysPreTouch does the following:

> Pre-touch the Java heap during JVM initialization. Every page of the heap is thus demand-zeroed during initialization rather than incrementally during application execution

My question is:

> If this flag is already set during ES startup then why do we need to turn off swap in the OS?

---

<div class="post-metadata">

### Author: ![abhijat](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@abhijat](https://discuss.elastic.co/u/abhijat)
#### Post date: [October 12, 2017, 6:14pm UTC](https://discuss.elastic.co/t/swap-vs-xx-alwayspretouch/103620/2 "2017-10-12T18:14:52Z")

</div>

Does anyone from elasticsearch team know about this one? or should I be asking this on a different forum?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 9, 2017, 6:21pm UTC](https://discuss.elastic.co/t/swap-vs-xx-alwayspretouch/103620/3 "2017-11-09T18:21:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
