Skip to content

Commit

Permalink
run a tool to propose the crashkernel value (FATE#315241)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Jan 22, 2014
1 parent e2b4d47 commit bbd7675
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 85 deletions.
66 changes: 24 additions & 42 deletions src/modules/Kdump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,51 +668,33 @@ def ReadKdumpKernelParam
true
end

# Propose reserved/allocated memory
#
#
# @return [Boolean] successfull
TEMPORARY_CONFIG_FILE = "/var/lib/YaST2/kdump.sysconfig"

def write_temporary_config_file
# FIXME parameterize Write instead of copying the old config
# NOTE make sure we do not lose 600 mode (cp is ok)
SCR.Execute(path(".target.bash"), "cp #{@kdump_file} #{TEMPORARY_CONFIG_FILE}")
end

PROPOSE_ALLOCATED_MEMORY_MB_COMMAND = "kdumptool --configfile #{TEMPORARY_CONFIG_FILE} calibrate"
# if the command fails
PROPOSE_ALLOCATED_MEMORY_MB_DEFAULT = "128"

# Propose reserved/allocated memory
# Store the result as a string! to @allocated_memory
# @return [Boolean] true, always successful
def ProposeAllocatedMemory
if @allocated_memory == "0"
if Ops.greater_or_equal(@total_memory, 512) &&
Ops.less_than(Ops.divide(@total_memory, 1024), 2)
@allocated_memory = "64"
elsif Ops.greater_or_equal(Ops.divide(@total_memory, 1024), 2)
@allocated_memory = "128"
end
# only propose once
return true if @allocated_memory != "0"

# bnc #431492 - UPT-LTE: /proc/vmcore is empty in kdump kerne
if Arch.ppc64 && @allocated_memory != ""
al_mem = Builtins.tointeger(@allocated_memory)
al_mem = Ops.multiply(al_mem, 2)
@allocated_memory = Builtins.tostring(al_mem)
end
# bnc #446480 - Fine-tune kdump memory proposal
if Arch.ia64 && Ops.greater_or_equal(@total_memory, 1024)
total_memory_gigabyte = Ops.divide(@total_memory, 1024)
if Ops.greater_or_equal(total_memory_gigabyte, 1) &&
Ops.less_than(total_memory_gigabyte, 8)
@allocated_memory = "256"
elsif Ops.greater_or_equal(total_memory_gigabyte, 8) &&
Ops.less_than(total_memory_gigabyte, 128)
@allocated_memory = "512"
elsif Ops.greater_or_equal(total_memory_gigabyte, 128) &&
Ops.less_than(total_memory_gigabyte, 256)
@allocated_memory = "768"
elsif Ops.greater_or_equal(total_memory_gigabyte, 256) &&
Ops.less_than(total_memory_gigabyte, 378)
@allocated_memory = "1024"
elsif Ops.greater_or_equal(total_memory_gigabyte, 378) &&
Ops.less_than(total_memory_gigabyte, 512)
@allocated_memory = "1536"
elsif Ops.greater_or_equal(total_memory_gigabyte, 512) &&
Ops.less_than(total_memory_gigabyte, 768)
@allocated_memory = "2048"
elsif Ops.greater_or_equal(total_memory_gigabyte, 768)
@allocated_memory = "3072"
end
end
write_temporary_config_file
out = SCR.Execute(path(".target.bash_output"), PROPOSE_ALLOCATED_MEMORY_MB_COMMAND)
if out["exit"] == 0
@allocated_memory = out.fetch("stdout", "0").chomp
else
# stderr has been already logged
Builtins.y2error("failed to propose allocated memory")
@allocated_memory = PROPOSE_ALLOCATED_MEMORY_MB_DEFAULT
end
Builtins.y2milestone(
"[kdump] allocated memory if not set in \"crashkernel\" param: %1",
Expand Down
48 changes: 5 additions & 43 deletions test/kdump_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
before(:each) do
Kdump.allocated_memory = "42"
end
it "returns the current value" do
it "proposes the current value" do
Kdump.ProposeAllocatedMemory
expect(Kdump.allocated_memory).to eq "42"
end
Expand All @@ -24,48 +24,10 @@
Kdump.allocated_memory = "0"
end

PHYSICAL_TO_PROPOSED_MB = {
"x86_64" => [
[ 256, 0],
[ 512, 64],
[ 1 * 1024, 64],
[ 2 * 1024, 128],
[ 20 * 1024, 128]
],
"ppc64" => [
[ 256, 0],
[ 512, 128],
[ 1 * 1024, 128],
[ 2 * 1024, 256],
[ 20 * 1024, 256]
],
"ia64" => [
[ 256, 0],
[ 512, 64],
[ 1 * 1024, 256],
[ 2 * 1024, 256],
[ 8 * 1024, 512],
[128 * 1024, 768],
[256 * 1024, 1024],
[378 * 1024, 1536],
[512 * 1024, 2048],
[768 * 1024, 3072]
],
}

PHYSICAL_TO_PROPOSED_MB.each do |arch, pair|
context "on #{arch}" do
before(:each) do
Arch.stub(:architecture) { arch }
end

pair.each do |physical_mb, proposed_mb|
it "proposes #{proposed_mb}MB for #{physical_mb}MB physical memory" do
Kdump.total_memory = physical_mb
Kdump.ProposeAllocatedMemory
expect(Kdump.allocated_memory).to eq proposed_mb.to_s
end
end
context "when the proposal tool is not implemented yet" do
it "proposes a positive integer" do
Kdump.ProposeAllocatedMemory
expect(Kdump.allocated_memory.to_i).to be > 0
end
end
end
Expand Down

0 comments on commit bbd7675

Please sign in to comment.