Cilkmem: Algorithms for Analyzing the Memory High-Water Mark of Fork-Join Parallel Programs

Tim Kaler, William Kuszmaul, Tao B. Schardl, Daniele Vettorel

TL;DR

Cilkmem is a dynamic-analysis tool that determines the "Memory High-Water Mark" (MHWM)—the worst-case memory consumption—of a parallel program across all possible execution schedules. It introduces two novel algorithms: an exact one that scales with the number of processors and a linear-time approximation that provides a 2-approximation guarantee regardless of processor count.

What Problem Does This Paper Address?

In parallel computing, specifically recursive fork-join models like Cilk, memory usage is non-deterministic. Because a scheduler decides which tasks run on which processors at any given time, one execution might use very little memory while another—due to different "stealing" patterns by idle processors—might use orders of magnitude more.

Standard memory profilers (like Valgrind or memusage) only report the peak memory of a single execution. This is insufficient for software engineers who need to guarantee that their program won't crash due to Out-of-Memory (OOM) errors on a massively parallel system. The core challenge is that computing the absolute worst-case memory usage for an arbitrary parallel program is a theoretically "hard" problem (related to poset chain optimization) that usually requires expensive, non-linear computation.

Methods

The authors model parallel programs as Series-Parallel Directed Acyclic Graphs (DAGs), where edges represent "strands" of code and vertices represent fork/join points. They propose two primary approaches:

  1. Exact Algorithm (ExactOn): An online algorithm that computes the exact MHWM for $p$ processors in $O(T_1 \cdot p)$ time, where $T_1$ is the total work (serial execution time). It uses a sophisticated dynamic programming approach to track memory allocations and "suspended" components as the program executes.
  2. Approximate Threshold Algorithm (ApproxOn): This algorithm addresses the "approximate threshold problem": given a memory limit $M$, will the program exceed $M/2$, or is it guaranteed to stay below $M$? By focusing on a subset of execution states called "stripped robust antichains," this algorithm runs in $O(T_1)$ time—meaning its overhead is independent of the number of processors being simulated.

Cilkmem is implemented as a tool within the Tapir/LLVM compiler using the CSI (Compiler-Inserted Instrumentation) framework. It intercepts memory calls (malloc, free) and parallel control flow instructions to build its internal model on the fly.

Datasets

The researchers evaluated Cilkmem using:

  • Cilkbench Suite: A collection of 10 parallel applications including matrix multiplication (Strassen), N-body simulation, LU decomposition, and sorting (Qsort).
  • Real-world Case Study: A large-scale image-alignment pipeline used in brain connectomics (mapping neural connections), which processes thousands of 8.5 MB image tiles.

Key Insights and Ideas

  • The "Memory Explosion" Trap: The paper demonstrates how a simple recursive program can use $O(1)$ memory on one processor but $O(n)$ memory on two processors simply because a "thief" processor can steal and execute allocations that would otherwise happen sequentially.
  • Online vs. Offline: Unlike previous theoretical models that required storing the entire execution DAG (which is memory-intensive), Cilkmem processes the program as it runs, keeping only the metadata necessary to compute the high-water mark.
  • Independence from $p$: The most significant "aha" moment is the approximation algorithm. By relaxing the requirement for an exact answer, the authors found a way to bound memory usage in linear time, making it feasible to analyze programs destined for supercomputers with thousands of cores on a standard workstation.
  • Suspended Components: The math accounts for "suspended" memory—allocations made by a parent task that remain in memory while child tasks run in parallel.

Key Results

  • Low Performance Overhead: For the exact algorithm at $p=128$, the geometric-mean multiplicative overhead was only 1.54x. The approximation algorithm was even faster, with a 1.36x overhead.
  • Scalability: The approximation algorithm successfully analyzed programs for up to $p=4096$ processors with no increase in runtime overhead.
  • Practical Bug Finding: In the image-alignment case study, Cilkmem identified a previously unknown issue where memory usage increased by 350 MB per processor. It pinpointed the exact lines in the source code (sift.cpp) responsible for the unexpected memory blow-up, allowing developers to fix the scaling issue.

Limitations and Future Work

  • Serial Analysis: Currently, Cilkmem runs the target program on a single thread to perform the analysis. While the result predicts $p$-processor behavior, the analysis itself is not yet parallelized.
  • Series-Parallel Constraint: The algorithms are optimized for fork-join (series-parallel) structures. While many parallel programs fit this model, extending these efficient bounds to arbitrary DAGs remains a difficult open problem.
  • Deterministic Assumption: The tool assumes the program is deterministic (no data races). If a program has races that change its memory allocation behavior, the predictions may not hold.

Summary updated

Abstract

Software engineers designing recursive fork-join programs destined to run on massively parallel computing systems must be cognizant of how their program's memory requirements scale in a many-processor execution. Although tools exist for measuring memory usage during one particular execution of a parallel program, such tools cannot bound the worst-case memory usage over all possible parallel executions. This paper introduces Cilkmem, a tool that analyzes the execution of a deterministic Cilk program to determine its p-processor memory high-water mark (MHWM), which is the worst-case memory usage of the program over all possible p-processor executions. Cilkmem employs two new algorithms for computing the p-processor MHWM. The first algorithm calculates the exact p-processor MHWM in O(T1 ·p) time, where T1 is the total work of the program. The second algorithm solves, in O(T1) time, the approximate threshold problem, which asks, for a given memory threshold M, whether the p-processor MHWM exceeds M/2 or whether it is guaranteed to be less than M. Both algorithms are memory efficient, requiring O(p·D) and O(D) space, respectively, where D is the maximum call-stack depth of the program's execution on a single thread. Our empirical studies show that Cilkmem generally exhibits low overheads. Across ten application benchmarks from the Cilk-bench suite, the exact algorithm incurs a geometric-mean multiplicative overhead of 1.54 for p=128, whereas the approximation-threshold algorithm incurs an overhead of 1.36 independent of p. In addition, we use Cilkmem to reveal and diagnose a previously unknown issue in a large image-alignment program contributing to unexpectedly high memory usage under parallel executions.
BibTeX
@inproceedings{kaler2020cilkmem,
  author = {Tim Kaler and William Kuszmaul and Tao B. Schardl and Daniele Vettorel},
  title = {{Cilkmem: Algorithms for Analyzing the Memory High-Water Mark of Fork-Join Parallel Programs}},
  booktitle = {APOCS},
  year = {2020},
  url = {https://openreview.net/forum?id=qhY7VGWQtP9},
}

Loading related content...

Figure