#!/bin/bash
#
module add apps/java/1.6
java -Xmx1024m HelloWorld
I need to set -XmxYm
where Y
should be the 95% of available memory on the system in Mb.
#!/bin/bash
#
module add apps/java/1.6
java -Xmx1024m HelloWorld
I need to set -XmxYm
where Y
should be the 95% of available memory on the system in Mb.
Here is a script that calls Java with the required heap size.
#!/bin/bash
# Total memory in KB
totalMemKB=$(awk '/MemTotal:/ { print $2 }' /proc/meminfo)
# Percentage of memory to use for Java heap
usagePercent=95
# heap size in KB
let heapKB=$totalMemKB*$usagePercent/100
# heap size in MB
let heapMB=$heapKB/1024
module add apps/java/1.6
java -Xmx${heapMB}m HelloWorld
I strongly advise you to use a lower usagePercent, since a Java application uses more memory than the heap size (for eg. for the PermGen).
As Peter Lawrey said, allocating 95% of memory to the heap is probably not wise.
You can, however, determine memory size by reading the "/proc/meminfo" file. Try
cat /proc/meminfo
MemTotal: 32958996 kB
MemFree: 23461744 kB
Buffers: 133772 kB
Cached: 1651888 kB
SwapCached: 0 kB
Active: 8460504 kB
Inactive: 740048 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 32958996 kB
LowFree: 23461744 kB
SwapTotal: 34996216 kB
SwapFree: 34996216 kB
Dirty: 372 kB
Writeback: 0 kB
AnonPages: 7415344 kB
Mapped: 61260 kB
Slab: 206896 kB
PageTables: 24320 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 51475712 kB
Committed_AS: 18514524 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 282388 kB
VmallocChunk: 34359454135 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB