R2: An Application-Level Kernel for Record and Replay

Zheng Zhang, Zhenyu Guo, Xi Wang, Jian Tang, Xuezheng Liu, Zhilei Xu, Ming Wu, M. Frans Kaashoek, Zheng Zhang 0001Osdi 2008

Introduction

Debugging complex, non-deterministic applications—such as multithreaded servers and distributed systems—is a persistent challenge in software engineering. These systems often suffer from "Heisenbugs," which appear sporadically and vanish during subsequent debugging attempts. Record and Replay (R&R) tools address this by logging external interactions during a "record" phase to ensure perfect reproduction during "replay." However, existing tools often force a trade-off between the heavy overhead of VM-based solutions and the "replay divergence" common in lightweight library-based tools.

Presented at OSDI 2008, R2 introduces a novel "application-level kernel" approach. By treating the boundary between an application and its environment as a configurable interface, R2 provides a flexible, efficient, and faithful R&R framework.

Flexible Interposition

A key innovation of R2 is its ability to allow developers to choose the specific software interface to record. Unlike traditional tools that intercept a fixed set of low-level system calls, R2 allows for "flexible interposition."

Flexible interposition allows developers to choose the optimal 'cut' in the application's call graph.

By choosing the "cut" in the call graph, developers can optimize for performance and log size. For instance, recording at a high-level database API (like SQLite) is often more efficient than recording every individual file I/O operation performed by that database. This flexibility ensures that the tool records only what is necessary for faithful replay while minimizing interference with the application's internal logic.

Isolation and the Mode Bit

To maintain "replay faithfulness," R2 must isolate the application's logic from the side effects of the recording tool itself and the underlying system libraries. R2 achieves this by borrowing the concept of "user" and "kernel" spaces from operating systems.

R2's architecture separates application logic (Replay Space) from library internals (System Space) using a mode bit.

R2 maintains a "mode bit" for each thread. When the application executes, it resides in Replay Space. When it calls an intercepted library function, R2 switches the thread to System Space. This distinction prevents "recursive recording"—a common pitfall where a tool accidentally logs its own internal operations—and ensures that only calls made on behalf of the application are captured.

Automation via Annotations

Manually writing stubs for thousands of library functions is error-prone and labor-intensive. R2 simplifies this process through an annotation-based code generation system. Developers use a set of keywords to describe data flow and synchronization, such as in and out for parameter mutability, bsize(val) for buffer sizes, and sync(key) for managing causal ordering between threads using Lamport clocks.

Using these annotations, R2 can automatically generate the C++ code required for recording and replaying complex interfaces. For the Win32 API, the authors annotated over 1,300 functions, resulting in the auto-generation of approximately 110,000 lines of code—a task that would be nearly impossible to perform manually.

Evaluation and Results

The authors evaluated R2 across a diverse suite of applications, including the Apache web server, MySQL, and various MPI-based distributed benchmarks.

  • Performance: R2 demonstrated low overhead, with the Apache web server experiencing only a 10% performance penalty during recording, making it suitable for production environments.
  • Log Efficiency: By selecting higher-level interfaces, R2 achieved massive reductions in log volume. Recording SQLite at the API level reduced log sizes by 99% compared to recording at the Win32 level.
  • Optimization: The use of specialized annotations like reproduce for MPI applications further reduced log sizes by up to 99.4%.

Conclusion

R2 demonstrates that a flexible, application-level approach to record and replay can overcome the limitations of traditional fixed-interface tools. While it requires some manual effort to annotate new interfaces and does not automatically handle raw shared-memory data races, its ability to provide faithful replay with production-level overhead makes it a powerful asset for debugging complex modern software.

Summary updated

BibTeX
@inproceedings{zhang2008r,
  author = {Zheng Zhang and Zhenyu Guo and Xi Wang and Jian Tang and Xuezheng Liu and Zhilei Xu and Ming Wu and M. Frans Kaashoek and Zheng Zhang},
  title = {{R2: An Application-Level Kernel for Record and Replay}},
  booktitle = {Osdi},
  year = {2008},
}
Figure