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:
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).
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...
WARNING WARNING
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)
and
dbms.jvm.additional=-Dio.netty.maxDirectMemory=0
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.