Biased Reference Counting: Limiting Atomic Operations In

Biased Reference Counting: Limiting Atomic Operations In

Biased Reference Counting: Minimizing Atomic Operations in Garbage Collection Jiho Choi, Thomas Shull, and Josep Torrellas University of Illinois at Urbana-Champaign http://iacoma.cs.uiuc.edu ABSTRACT November 1–4, 2018, Limassol, Cyprus. ACM, New York, NY, USA, 12 pages. Reference counting (RC) is one of the two fundamental approaches https://doi.org/10.1145/3243176.3243195 to garbage collection. It has the desirable characteristics of low memory overhead and short pause times, which are key in today’s 1 INTRODUCTION interactive mobile platforms. However, RC has a higher execution High-level programming languages are widely used today. They time overhead than its counterpart, tracing garbage collection. The provide programmers intuitive abstractions that hide many of the reason is that RC implementations maintain per-object counters, underlying computer system details, improving both programmer which must be continually updated. In particular, the execution time productivity and portability. One of the pillars of high-level pro- overhead is high in environments where low memory overhead is gramming languages is automatic memory management. It frees critical and, therefore, non-deferred RC is used. This is because the programmers from the obligation to explicitly deallocate resources, counter updates need to be performed atomically. by relying on the runtime to automatically handle memory man- To address this problem, this paper proposes a novel algorithm agement. called Biased Reference Counting (BRC), which significantly im- Garbage collection is the process of runtime monitoring the life- proves the performance of non-deferred RC. BRC is based on the time of objects and freeing them once they are no longer necessary. observation that most objects are only accessed by a single thread, There are two main approaches to garbage collection: tracing [28] which allows most RC operations to be performed non-atomically. and reference counting (RC) [17]. Tracing garbage collection main- BRC leverages this by biasing each object towards a specific thread, tains a root set of live objects and finds the set of objects reachable and keeping two counters for each object — one updated by the from this root set. Objects not reachable from the root set are consid- owner thread and another updated by the other threads. This allows ered dead and their resources can be freed. RC garbage collection, on the owner thread to perform RC operations non-atomically, while the other hand, maintains a counter for each object, which tracks the other threads update the second counter atomically. the number of references currently pointing to the object. This We implement BRC in the Swift programming language run- counter is actively updated as references are added and removed. time, and evaluate it with client and server programs. We find that Once the counter reaches zero, the object can be collected. BRC makes each RC operation more than twice faster in the com- Most implementations of managed languages use tracing garbage mon case. As a result, BRC reduces the average execution time of collection, as RC is believed to be slower. This belief stems from the client programs by 22.5%, and boosts the average throughput of fact that most of the tracing garbage collection can be done in the server programs by 7.3%. background, off the critical path, while RC is on the critical path. However, many optimization techniques exist to limit the number CCS CONCEPTS of RC operations and reduce the overhead on the critical path. • Software and its engineering → Garbage collection; Soft- Furthermore, RC has the desirable characteristics of low memory ware performance; Runtime environments; overhead and short pause times. In garbage collection, memory overhead comes from two sources, KEYWORDS namely garbage collector metadata, and objects that are dead but not Reference counting; Garbage collection; Swift yet reclaimed by the garbage collector. While RC adds, as metadata, one counter per object, RC can have low overall memory overhead ACM Reference Format: because it can be designed to free up objects very soon after they Jiho Choi, Thomas Shull, and Josep Torrellas. 2018. Biased Reference Count- become dead. ing:, Minimizing Atomic Operations in Garbage Collection. In International Pause times are times when the application is stopped, to allow conference on Parallel Architectures and Compilation Techniques (PACT ’18), the garbage collector to perform maintenance operations. RC can be designed to have only short pause times — when individual Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed objects are freed up. for profit or commercial advantage and that copies bear this notice and the full citation Overall, the combination of low memory overhead and short on the first page. Copyrights for components of this work owned by others than the pause times makes RC suitable for today’s interactive mobile plat- author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission forms. For this reason, some languages such as Swift [8] use RC. and/or a fee. Request permissions from [email protected]. Unfortunately, RC can have significant execution time overhead PACT ’18, November 1–4, 2018, Limassol, Cyprus when using algorithms that reclaim objects immediately after they © 2018 Copyright held by the owner/author(s). Publication rights licensed to ACM. ACM ISBN 978-1-4503-5986-3/18/11...$15.00 become dead — i.e., non-deferred RC algorithms. For example, we https://doi.org/10.1145/3243176.3243195 find that the non-deferred RC algorithm used in Swift causes Swift PACT ’18, November 1–4, 2018, Limassol, Cyprus Jiho Choi, Thomas Shull, and Josep Torrellas programs to spend 32% of their execution time performing RC 2 BACKGROUND operations. Still, using non-deferred RC is highly desirable when 2.1 Reference Counting it is critical to keep memory overhead to a minimum, as in many mobile platforms. The fundamental idea of RC [17] is to maintain a per-object counter We find that a major reason for this execution time overhead denoting the current number of references to the object. These per- of non-deferred RC is the use of atomic operations to adjust the object counters are updated as references are created, reassigned, reference counters of objects. Note that even if a Swift program and deleted. has little sharing and, in fact, even if it is single-threaded, it may Figure 1 shows a simple program which highlights all possible RC have to use atomic operations. This is because, like many program- operations. The normal program commands are on the numbered ming languages, Swift compiles components separately to allow lines. The RC operations required for each command are on the for maximum modularity. Separate compilation forces the compiler lines directly above the command in gray and are not numbered. to be conservative. Furthermore, Swift is compiled ahead of time, A RC operation on an object obj is described by rc(obj). In this so the compiler cannot leverage program information gathered example, the reference counts of objects obj1, obj2, and obj3 are throughout execution to limit the use of atomic operations. adjusted as different assignments execute. The goal of this paper is to reduce the execution time overhead of non-deferred RC. To accomplish this goal, we propose to replace rc(obj1) = 1 1 var a = new obj the atomic RC operations with biased RC operations. Similar to 1 rc(obj1)++ biased locks [25], our biased operations leverage uneven sharing to 2 var b = a create asymmetrical execution times for RC operations based on rc(obj1)--, rc(obj2) = 1 3 b = new obj the thread performing the operation. Each object is biased toward, 2 rc(obj1)--,rc(obj3) = 1 or favors, a specific thread. This allows an object’s favored thread free(obj1) to perform RC operations without atomic operations, at the cost of 4 a = new obj3 slowing down all the other threads’ RC operations on that object. Figure 1: Basic RC operations. While biased RC operations are very effective in most cases, sometimes multiple threads do try to adjust the reference counter While the idea of RC is straightforward, it should be implemented of the same object. To handle this, we exploit the fact that, unlike carefully to ensure correctness. This is because it is possible to have locking, RC does not require strong exclusivity. While only one data races while adjusting reference counters in otherwise correct thread is allowed to acquire a lock at any given time, it is possible programs. Consider the code example in Figure 2. Note that in the for multiple threads to perform RC operations on an object concur- traditional sense there is no data race in this code. Each thread only rently — if they use multiple counters and eventually merge the reads shared variable g, and all writes are performed to thread-local counters. variables. However, due to both threads adding another reference Based on these ideas, we propose a novel algorithm called Biased to obj, it is possible for the reference counter of obj to be updated Reference Counting (BRC), which significantly improves the perfor- incorrectly without synchronization. In other words, it is possible mance of non-deferred RC. BRC maintains two counters per object for the rc(obj)++ corresponding to the commands on lines 2A — one for the owner thread and another for the other threads. The and 2B to race and produce incorrect results. Hence, updates to an owner thread updates its counter without atomic operations; the object’s reference counter must be done in a synchronized manner. other threads update the other counter with atomic operations.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us