Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the DefaultMaxDirectMemory configuration #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions calculator/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ func (c Calculator) Calculate() ([]fmt.Stringer, error) {
headRoom := c.headRoom()

directMemory := j.MaxDirectMemory
if directMemory == nil {
d := memory.DefaultMaxDirectMemory
directMemory = &d
if directMemory != nil {
options = append(options, *directMemory)
}

Expand All @@ -69,12 +67,12 @@ func (c Calculator) Calculate() ([]fmt.Stringer, error) {
options = append(options, *stack)
}

overhead := c.overhead(headRoom, directMemory, metaspace, reservedCodeCache, stack)
overhead := c.overhead(headRoom, metaspace, reservedCodeCache, stack)
available := memory.Size(*c.TotalMemory)

if overhead > available {
return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s, %s x %d threads",
overhead, available, directMemory, metaspace, reservedCodeCache, stack, *c.ThreadCount)
return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s x %d threads",
overhead, available, metaspace, reservedCodeCache, stack, *c.ThreadCount)
}

heap := j.MaxHeap
Expand All @@ -85,8 +83,8 @@ func (c Calculator) Calculate() ([]fmt.Stringer, error) {
}

if overhead+memory.Size(*heap) > available {
return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s, %s, %s x %d threads",
overhead+memory.Size(*heap), available, directMemory, heap, metaspace, reservedCodeCache, stack, *c.ThreadCount)
return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s, %s x %d threads",
overhead+memory.Size(*heap), available, heap, metaspace, reservedCodeCache, stack, *c.ThreadCount)
}

return options, nil
Expand All @@ -104,9 +102,8 @@ func (c Calculator) metaspace() memory.MaxMetaspace {
return memory.MaxMetaspace((*c.LoadedClassCount * 5800) + 14000000)
}

func (c Calculator) overhead(headRoom memory.Size, directMemory *memory.MaxDirectMemory, metaspace *memory.MaxMetaspace, reservedCodeCache *memory.ReservedCodeCache, stack *memory.Stack) memory.Size {
func (c Calculator) overhead(headRoom memory.Size, metaspace *memory.MaxMetaspace, reservedCodeCache *memory.ReservedCodeCache, stack *memory.Stack) memory.Size {
return headRoom +
memory.Size(*directMemory) +
memory.Size(*metaspace) +
memory.Size(*reservedCodeCache) +
memory.Size(int64(*stack)*int64(*c.ThreadCount))
Expand Down
16 changes: 6 additions & 10 deletions calculator/calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ func TestCalculator(t *testing.T) {

it("uses default and calculated values", func() {
g.Expect(c.Calculate()).To(ConsistOf(
memory.DefaultMaxDirectMemory,
memory.MaxMetaspace(19800000),
memory.DefaultReservedCodeCache,
memory.DefaultStack,
memory.MaxHeap(231858240),
memory.MaxHeap(242344000),
))
})

Expand All @@ -58,10 +57,11 @@ func TestCalculator(t *testing.T) {
c.JvmOptions.MaxDirectMemory = &d

g.Expect(c.Calculate()).To(ConsistOf(
memory.MaxDirectMemory(1048576),
memory.MaxMetaspace(19800000),
memory.DefaultReservedCodeCache,
memory.DefaultStack,
memory.MaxHeap(241295424),
memory.MaxHeap(242344000),
))
})

Expand All @@ -70,10 +70,9 @@ func TestCalculator(t *testing.T) {
c.JvmOptions.MaxMetaspace = &m

g.Expect(c.Calculate()).To(ConsistOf(
memory.DefaultMaxDirectMemory,
memory.DefaultReservedCodeCache,
memory.DefaultStack,
memory.MaxHeap(250609664),
memory.MaxHeap(261095424),
))
})

Expand All @@ -82,10 +81,9 @@ func TestCalculator(t *testing.T) {
c.JvmOptions.ReservedCodeCache = &r

g.Expect(c.Calculate()).To(ConsistOf(
memory.DefaultMaxDirectMemory,
memory.MaxMetaspace(19800000),
memory.DefaultStack,
memory.MaxHeap(482467904),
memory.MaxHeap(492953664),
))
})

Expand All @@ -94,10 +92,9 @@ func TestCalculator(t *testing.T) {
c.JvmOptions.Stack = &s

g.Expect(c.Calculate()).To(ConsistOf(
memory.DefaultMaxDirectMemory,
memory.MaxMetaspace(19800000),
memory.DefaultReservedCodeCache,
memory.MaxHeap(231858240),
memory.MaxHeap(242344000),
))
})

Expand All @@ -106,7 +103,6 @@ func TestCalculator(t *testing.T) {
c.JvmOptions.MaxHeap = &h

g.Expect(c.Calculate()).To(ConsistOf(
memory.DefaultMaxDirectMemory,
memory.MaxMetaspace(19800000),
memory.DefaultReservedCodeCache,
memory.DefaultStack,
Expand Down
2 changes: 0 additions & 2 deletions memory/max_direct_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"strings"
)

const DefaultMaxDirectMemory = MaxDirectMemory(10 * Mibi)

var maxDirectMemoryRE = regexp.MustCompile(fmt.Sprintf("^-XX:MaxDirectMemorySize=(%s)$", sizePattern))

type MaxDirectMemory Size
Expand Down