OS and JVM Tuning: Garbage Collection, Heap Sizing and Kernel Settings

Big Data and Hadoop Administrator 15 min min read Updated: Nov 17, 2026 Advanced
OS and JVM Tuning: Garbage Collection, Heap Sizing and Kernel Settings
Advanced Topic 3 of 3

Why JVM Tuning Matters

A NameNode with a long garbage collection pause stops answering heartbeats. After a few seconds ZooKeeper may declare it dead and fail over, or DataNodes may time out. Stable memory and short pauses are core admin work.

Heap Sizing

DaemonTypical heapRule
NameNode16 to 200+ GBAbout 1 GB per million blocks as a start, plus 20 to 30 percent headroom. Watch actual usage after full GC
DataNode2 to 8 GBGrows with block count per node
ResourceManager8 to 32 GBDepends on apps and nodes
NodeManager1 to 4 GBContainers run in separate JVMs
JournalNode1 to 4 GBSmall
Hive Metastore, HS24 to 32 GBDepends on tables and sessions
Do not set heap too close to RAM: Leave memory for the OS page cache, the thread stacks, direct memory and other daemons. Also keep heap below about 32 GB if you can, because compressed object pointers stop working above that and objects grow.

NameNode JVM Options (G1GC Example)

bash # hadoop-env.sh export HDFS_NAMENODE_OPTS=" -Xms96g -Xmx96g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+ParallelRefProcEnabled -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=32m -XX:+AlwaysPreTouch -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/hadoop/nn-heap.hprof -Xlog:gc*:file=/var/log/hadoop/nn-gc.log:time,uptime,level,tags:filecount=10,filesize=100m $HDFS_NAMENODE_OPTS" export HDFS_DATANODE_OPTS="-Xms4g -Xmx4g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 $HDFS_DATANODE_OPTS"
OptionPurpose
-Xms = -XmxFixed heap, no resizing pauses
UseG1GC, MaxGCPauseMillisPredictable pauses on large heaps
InitiatingHeapOccupancyPercentStart concurrent cycle earlier to avoid full GC
AlwaysPreTouchTouch all memory at startup (slower start, steadier runtime)
HeapDumpOnOutOfMemoryErrorEvidence for post-mortem
GC log flagsNeeded to tune. Flag syntax depends on the Java version (above is Java 11+)
Java version: Use a Java version supported by your Hadoop release (Hadoop 3.4 and 3.5 support Java 8, 11 and 17, check the release notes). Some JVM flags are removed in newer versions, so test them.

Read a GC Log

bash # find the longest pauses grep -E "Pause (Young|Full|Remark|Cleanup)" /var/log/hadoop/nn-gc.log | awk '{print $NF, $0}' | sort -rn | head grep -c "Pause Full" /var/log/hadoop/nn-gc.log # Full GCs: should be zero in normal operatio
ObservationMeaningAction
Full GC eventsHeap too small or fragmentationIncrease heap, lower IHOP, fix leak
Young pauses > 1 sLarge young gen or slow CPU/memoryTune region size, reduce churn (fewer small files)
Heap after GC climbingNamespace growth or leakPlan capacity, heap dump analysis
Humongous allocationsObjects bigger than half a regionIncrease G1HeapRegionSize

Kernel and OS Settings

bash # /etc/sysctl.d/99-hadoop.conf vm.swappiness = 1 vm.overcommit_memory = 1 vm.max_map_count = 262144 net.core.somaxconn = 8192 net.ipv4.tcp_max_syn_backlog = 8192 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_rmem = 4096 87380 16777216 net.ipv4.tcp_wmem = 4096 65536 16777216 net.ipv4.ip_local_port_range = 10000 65000 fs.file-max = 1000000 # apply: sysctl --system # /etc/security/limits.d/hadoop.conf hdfs - nofile 128000 hdfs - nproc 65536 yarn - nofile 128000 yarn - nproc 65536
bash # transparent huge pages OFF (can cause latency spikes) echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag cat /sys/kernel/mm/transparent_hugepage/enabled # mount options for data disks (fstab): noatime,nodiratime # I/O scheduler for HDD: mq-deadline; for NVMe: none cat /sys/block/sdb/queue/scheduler

Time, Swap and NUMA

  • chrony running and synced (Kerberos needs it)
  • Swap disabled or swappiness=1: swapping a JVM heap causes huge pauses
  • On large multi-socket servers check NUMA behaviour (numactl --hardware). Bind or interleave for the NameNode if you see imbalance
  • Reserve memory for the OS page cache (Kafka, HBase, DataNode benefit)

Verify After Changes

bash cat /proc/$(pgrep -f proc_namenode | head -1)/limits | grep -i "open files" jcmd $(pgrep -f proc_namenode | head -1) VM.flags | tr ' ' '\n' | grep -E "Xmx|UseG1GC" jstat -gcutil $(pgrep -f proc_namenode | head -1) 5000 3
Plan heap growth: Keep a chart of NameNode heap used after GC against block count. When it reaches 70 percent, schedule a heap increase and restart through failover during a maintenance window.

Conclusion

Size JVM heaps from real metadata and workload, use G1GC with logging and heap dumps, turn off swapping and huge pages, raise file limits, and verify with jstat and GC logs. Stable GC means stable HA.

Quick Summary: fixed heap, G1GC + GC logs; swappiness 1; THP off; nofile 128000.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators