Is it possible to reduce the amount of swap space that Neo4j uses?

I have a database that is roughly 1200GB. I am running it on a server with 128GB of RAM, and 32GB of swap memory. These are my neo4j.conf settings:


Over time (roughly 2-3 weeks), the swap space on my server gradually fills up until it hits the maximum swap size. At this point the server starts "thrashing" and slows down noticeably. Here's a screenshot:

When this happens I usually have to do a hard-kill of Neo4j. After that the swap space gets freed up:

I'm guessing that for some reason a lot of the pagecache is being moved from RAM to Swap Memory over time, eventually exceeding the swap space available.

Is it possible to prevent Neo4j from moving so much memory to the swap space? Ideally I'd like for as much of the pagecache as possible to remain in RAM.

I have tried changing the swappiness setting on my Ubuntu server to 10 (and then to 5), but the swap memory still seems to be filling up with the Neo4j cache.

I would just disable swap on the server. Usually that's more suitable for end-user computers but not servers as you actually never want stuff from RAM swapped to disk.

So your Neo4j server should use in total 80G of memory (plus some extra that Lucene grabs behind the scenes but which should go away in 3.4/3.5. with the native indexes).

Hey there,

There's a KB article detailing Neo4j's memory consumption (here: Understanding memory consumption - Knowledge Base).
It'd be good to first see exactly what is using the memory, if you run Neo4j with:


added to the neo4j.conf file you should be able to then execute

jcmd <PID> VM.native_memory summary (obvs with your PID)

to see where the memory is being used.

If it is Native Memory using it up, you can change the Max Direct Memory allocated but...

This is something we strongly suggest you talk to us about changing - they are sensitive settings

With that said, you'd need to set 2 settings:

-XX:MaxDirectMemorySize=#g (where # is a number)



You need to carefully monitor the server, look in the logs for OutOfMemory messages etc as you may need to tweak the values up if you went too aggressive.

I hope that helps :/

1 Like

So I guess setting


should help Greg?

Yes, but I would probably start with 50% of the heap and then work down - depends on how much 'tweakability' you have :)

Thank you both. I have turned swap off, and everything is running nicely at the moment.

sudo swapoff -a

I will look in to the more advanced changes you have mentioned. Thank you.