1

There is docker container with java application inside.

docker inspect dbc237493367 | grep -P '((Memory)|(Pid))'

"Pid": 16283,
"PidMode": "",
"Memory": 10737418240,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": -1,
"MemorySwappiness": -1,
"PidsLimit": 0,

ps auxw | grep 16283

/usr/lib/jvm/java-8-openjdk-amd64/bin/java -Xms9000m -Xmx9000m -XX:MaxPermSize=1024m -XX:ReservedCodeCacheSize=512m ...

cat /proc/16283/status | grep -i vm

VmPeak: 20807456 kB
VmSize: 19735624 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:   6967836 kB
VmRSS:   3356220 kB
VmData: 19661552 kB
VmStk:       140 kB
VmExe:         4 kB
VmLib:     17964 kB
VmPTE:     24956 kB
VmPMD:        92 kB
VmSwap:  6283192 kB

docker --version

Docker version 1.12.2, build bb80604

So:
1) docker container max memory set to 10gb
2) java application max memory set to 9gb
3) VmSwap value is 6gb ...

Question:
how can that be possible? Why swap memory is used?

030
  • 5,731
  • 12
  • 61
  • 107
Oleg Golovanov
  • 193
  • 3
  • 6
  • 1
    It is by the way a bit snug to put a 9GB Heap in a 10GB memory. JVM needs some overhead, especially if you use many threads, lots of direct buffers or large applications with high usage in metaspace. – eckes May 07 '17 at 16:19

2 Answers2

0

The Linux kernel has a value called swappiness, which tells it how much of the memory to use before it starts using swap. By default it is usually somewhere around 60%, so it doesn't wait to use all of your memory before putting stuff in swap. That's probably a good idea; it takes time to put switch stuff to swap. The kernel leaves extra memory when it can to save itself that time.

There's more info on why it's like that in this questioon

EDIT: Any idea where the -1 swappiness is coming from? I'm curious, I've never seen that before. Have you tried setting it to 0?

dogoncouch
  • 176
  • 5
  • Here is some background on swappiness with docker (I am however not sure why the original question shows swappiness=-1 on the inspect result, maybe this means inherit?): http://stackoverflow.com/questions/25767224/change-swappiness-for-docker-container – eckes May 07 '17 at 16:23
0

Thanks for the tips people wrote here.

So, i did 2 things:
1) increased container memory cause -Xmx does not include memory needed for threads ( threads count * stack size ), and my application use thousands of threads
2) changed "docker run" memory options from "--memory 10G" to "--memory 10G --memory-swap=10G --memory-swappiness=0"

So, now i expect swap no more to be used.

Oleg Golovanov
  • 193
  • 3
  • 6