优先级垃圾回收:对软件缓存的显式GC支持
Prioritized Garbage Collection: Explicit GC Support for Software Caches
摘要:
程序员经常用空间换取时间来提高性能,通常是以缓存或备忘录的形式。然而,在Java或JavaScript等托管语言中,这种空间-时间权衡是复杂的。使用更多的空间意味着更高的垃圾回收成本,特别是在可用内存有限的情况下。现有的运行时系统对空间敏感的算法提供了有限的支持,迫使程序员在配置方面做出困难且往往脆弱的选择。本文提出了优先级的垃圾回收,一个合作的程序设计语言和运行时解决这个问题。优先级GC提供了一个类似于软引用的接口,称为优先级引用,它标识收集器可以在必要时急切地回收的对象。关键的区别在于定义策略的API,该策略控制何时清除优先级引用以及清除的顺序。应用程序代码为每个引用指定一个优先级值和一个目标内存界限。收集器回收引用,优先级最低的引用优先,直到缓存的总内存占用量符合限制。我们使用这个API来实现一个空间感知的最近最少使用(LRU)缓存,称为Sache,它是现有缓存(如Google的Guava库)的直接替代品。垃圾收集器会根据可用的内存和工作负载自动增长和收缩Sache,而程序员只需要提供最少的配置信息。使用Sache,应用程序几乎不可能遇到由软件缓存引起的内存泄漏、内存压力或内存不足崩溃。
英文摘要:
Programmers routinely trade space for time to increase performance, often in the form of caching or memoization. In managed languages like Java or JavaScript, however, this space-time tradeoff is complex. Using more space translates into higher garbage collection costs, especially at the limit of available memory. Existing runtime systems provide limited support for space-sensitive algorithms, forcing programmers into difficult and often brittle choices about provisioning. This paper presents prioritized garbage collection, a cooperative programming language and runtime solution to this problem. Prioritized GC provides an interface similar to soft references, called priority references, which identify objects that the collector can reclaim eagerly if necessary. The key difference is an API for defining the policy that governs when priority references are cleared and in what order. Application code specifies a priority value for each reference and a target memory bound. The collector reclaims references, lowest priority first, until the total memory footprint of the cache fits within the bound. We use this API to implement a space-aware least-recently-used (LRU) cache, called a Sache, that is a drop-in replacement for existing caches, such as Google's Guava library. The garbage collector automatically grows and shrinks the Sache in response to available memory and workload with minimal provisioning information from the programmer. Using a Sache, it is almost impossible for an application to experience a memory leak, memory pressure, or an out-of-memory crash caused by software caching.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。