aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/admin/jvm/mem_options.go
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-02-03 15:20:23 +0100
committerMartin Polden <mpolden@mpolden.no>2023-02-03 15:35:25 +0100
commite1e94812425a487069bf33f781bec987e9e49874 (patch)
tree4a892c3b5c0a7dee2cb76f9971e538cb4aba8a16 /client/go/internal/admin/jvm/mem_options.go
parenta08ae588d6035b69f0961dff596fc871fd1c4e58 (diff)
Re-organize Go code
Diffstat (limited to 'client/go/internal/admin/jvm/mem_options.go')
-rw-r--r--client/go/internal/admin/jvm/mem_options.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/client/go/internal/admin/jvm/mem_options.go b/client/go/internal/admin/jvm/mem_options.go
new file mode 100644
index 00000000000..f58bb141587
--- /dev/null
+++ b/client/go/internal/admin/jvm/mem_options.go
@@ -0,0 +1,67 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Author: arnej
+
+package jvm
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/vespa-engine/vespa/client/go/internal/admin/trace"
+)
+
+func (opts *Options) getOrSetHeapSize(prefix string, heapSize AmountOfMemory) AmountOfMemory {
+ var missing bool = true
+ for _, x := range opts.jvmArgs {
+ if strings.HasPrefix(x, prefix) {
+ val, err := ParseJvmMemorySpec(strings.TrimPrefix(x, prefix))
+ if err == nil {
+ missing = false
+ heapSize = val
+ }
+ }
+ }
+ if missing {
+ opts.AppendOption(fmt.Sprintf("%s%s", prefix, heapSize.AsJvmSpec()))
+ }
+ return heapSize
+}
+
+func (opts *Options) CurMinHeapSize(fallback AmountOfMemory) AmountOfMemory {
+ return opts.getOrSetHeapSize("-Xms", fallback)
+}
+
+func (opts *Options) CurMaxHeapSize(fallback AmountOfMemory) AmountOfMemory {
+ return opts.getOrSetHeapSize("-Xmx", fallback)
+}
+
+func (opts *Options) AddDefaultHeapSizeArgs(minHeapSize, maxHeapSize AmountOfMemory) {
+ trace.Trace("AddDefaultHeapSizeArgs", minHeapSize, "/", maxHeapSize)
+ minHeapSize = opts.CurMinHeapSize(minHeapSize)
+ maxHeapSize = opts.CurMaxHeapSize(maxHeapSize)
+ opts.MaybeAddHugepages(maxHeapSize)
+}
+
+func (opts *Options) MaybeAddHugepages(heapSize AmountOfMemory) {
+ thpSize := getTransparentHugepageSize()
+ if thpSize.numBytes*2 < heapSize.numBytes {
+ trace.Trace("add UseTransparentHugePages, 2 * thpSize", thpSize, " < maxHeap", heapSize)
+ opts.AddOption("-XX:+UseTransparentHugePages")
+ } else {
+ trace.Trace("no UseTransparentHugePages, 2 * thpSize", thpSize, " >= maxHeap", heapSize)
+ }
+}
+
+func adjustAvailableMemory(measured AmountOfMemory) AmountOfMemory {
+ reserved := 1024 // MB
+ need_min := 64 // MB
+ available := measured.ToMB()
+ if available > need_min+2*reserved {
+ return MegaBytesOfMemory(available - reserved)
+ }
+ if available > need_min {
+ adjusted := (available + need_min) / 2
+ return MegaBytesOfMemory(adjusted)
+ }
+ return MegaBytesOfMemory(need_min)
+}