Skip to content

Commit

Permalink
Using --memlimit to forbid OOMs
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Nov 14, 2024
1 parent 2447102 commit aca4930
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
23 changes: 20 additions & 3 deletions scripts/theta-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ grep -o "openjdk $JAVA_VERSION" <<< "$(java --version)" >/dev/null || {
exit 1
}


determine_memlimit() {
cgroup_file="/proc/self/cgroup"
if [[ -f "$cgroup_file" ]]; then
memory_cgroup=$(grep memory "$cgroup_file" | cut -d: -f3)
if [[ ! -z "$memory_cgroup" ]]; then
echo $memory_cgroup
memory_limit_file="/sys/fs/cgroup/memory${memory_cgroup}/memory.limit_in_bytes"
if [[ -f "$memory_limit_file" ]]; then
cat "$memory_limit_file"
return 0
fi
fi
fi
echo 0
}

remove_property() {
local args=()
local skip=0
Expand All @@ -34,7 +51,7 @@ remove_property() {
}

if [ "$1" == "--version" ]; then
LD_LIBRARY_PATH=$scriptdir/lib java -Xss120m -Xmx14210m -jar "$scriptdir"/theta.jar --version
LD_LIBRARY_PATH=$scriptdir/lib java -jar "$scriptdir"/theta.jar --version
else
modified_args=$(remove_property "${@:2}")
property=$(cat .property && rm .property)
Expand All @@ -56,8 +73,8 @@ else
transformed_property="$property"
fi

echo LD_LIBRARY_PATH="$scriptdir"/lib java -Xss120m -Xmx14210m -jar "$scriptdir"/theta.jar $modified_args --input "$IN" --property "$transformed_property" --smt-home "$scriptdir"/solvers
LD_LIBRARY_PATH="$scriptdir"/lib java -Xss120m -Xmx14210m -jar "$scriptdir"/theta.jar $modified_args --input "$IN" --property "$transformed_property" --smt-home "$scriptdir"/solvers
echo LD_LIBRARY_PATH="$scriptdir"/lib java -Xss120m -Xmx14210m -jar "$scriptdir"/theta.jar $modified_args --input "$IN" --property "$transformed_property" --smt-home "$scriptdir"/solvers --memlimit "$(determine_memlimit)"
LD_LIBRARY_PATH="$scriptdir"/lib java -Xss120m -Xmx14210m -jar "$scriptdir"/theta.jar $modified_args --input "$IN" --property "$transformed_property" --smt-home "$scriptdir"/solvers --memlimit "$(determine_memlimit)"

if [ "$(basename "$property")" == "termination.prp" ]; then
echo "Not yet mapping witnesses from '$transformed_property' to '$property', hoping for the best"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ class InProcessChecker<F : SpecFrontendConfig, B : SpecBackendConfig>(
getGson(xcfa).toJson(processConfig)
}

val heapSize =
"-Xmx${if(config.backendConfig.memlimit == 0L) 1420L else config.backendConfig.memlimit/1024/1024 }m"
logger.write(Logger.Level.INFO, "Starting process with $heapSize of heap\n")

val pb =
NuProcessBuilder(
listOf(
ProcessHandle.current().info().command().orElse("java"),
"-Xss120m",
"-Xmx14210m",
heapSize,
"-cp",
File(XcfaCli::class.java.protectionDomain.codeSource.location.toURI()).absolutePath,
XcfaCli::class.qualifiedName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ data class BackendConfig<T : SpecBackendConfig>(
var timeoutMs: Long = 0,
@Parameter(names = ["--in-process"], description = "Run analysis in process")
var inProcess: Boolean = false,
@Parameter(
names = ["--memlimit"],
description = "Maximum memory to use when --in-process (in bytes, 0 for default)",
)
var memlimit: Long = 0L,
override var specConfig: T? = null,
) : SpecializableConfig<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fun boundedPortfolio25(
backendConfig =
BackendConfig(
backend = Backend.BOUNDED,
memlimit = portfolioConfig.backendConfig.memlimit,
solverHome = portfolioConfig.backendConfig.solverHome,
timeoutMs = 0,
specConfig =
Expand Down Expand Up @@ -93,6 +94,7 @@ fun boundedPortfolio25(
backendConfig =
BackendConfig(
backend = Backend.MDD,
memlimit = portfolioConfig.backendConfig.memlimit,
solverHome = portfolioConfig.backendConfig.solverHome,
timeoutMs = 0,
specConfig =
Expand Down

0 comments on commit aca4930

Please sign in to comment.