分代垃圾收集和增量垃圾收集有什么区别?

发布于 2024-10-18 16:10:53 字数 111 浏览 2 评论 0原文

我认为这两种方法(分代和增量)都是使垃圾收集暂停更快的不同方法。但是分代和增量之间有什么区别呢?它们如何工作?哪一种更适合实时软件/产生更少的长时间停顿?

另外,Boehm GC 是其中之一吗?

I think that both (generational and incremental) are different approaches to make the garbage collection pauses faster. But what are the differences between generational and incremental? How do they work? And which one is better for real time software / produces less long pauses?

Also, the Boehm GC is any of those?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

诗酒趁年少 2024-10-25 16:10:53

分代 GC 始终是增量的,因为它不会在一个周期内收集所有无法访问的对象。相反,增量 GC 不一定采用生成方案来决定收集或不收集哪些不可达对象。

分代 GC 大致根据它们的最后一次使用(可以说是它们的年龄)将无法访问的对象划分为不同的集合。基本理论是最近创建的对象很快就会变得无法访问。因此,具有“年轻”对象的集合是在早期阶段收集的。

增量GC可以用上述分代方案来实现,但是可以采用不同的方法来决定应该清除哪组对象。

人们可以查看此维基百科页面并进一步向下,有关两种 GC 方法的更多信息。

根据 Boehm 的网站,他的 GC 是增量式和分代式的:

收集器使用标记-清除
算法。它提供增量和
世代收藏
操作系统提供
正确的虚拟内存支持。

就实时环境而言,有几篇学术研究论文描述了进行垃圾收集的新颖而巧妙的方法:

A generational GC is always incremental, because it does not collect all unreachable objects during a cycle. Conversely, an incremental GC does not necessarily employ a generation scheme to decide which unreachable objects to collect or not.

A generational GC divides the unreachable objects into different sets, roughly according to their last use - their age, so to speak. The basic theory is that objects that are most recently created, would become unreachable quickly. So the set with 'young' objects is collected in an early stage.

An incremental GC may be implemented with above generational scheme, but different methods can be employed to decide which group of objects should be sweeped.

One might look at this wikipedia page and further downward, for more information on both GC methods.

According to Boehm's website, his GC is incremental and generational:

The collector uses a mark-sweep
algorithm. It provides incremental and
generational collection under
operating systems which provide the
right kind of virtual memory support.

As far as a real time environment is concerned, there are several academic research papers describing new and ingenious ways to do garbage collection:

木槿暧夏七纪年 2024-10-25 16:10:53

增量垃圾收集器是任何可以增量运行的垃圾收集器(意味着它可以做一些工作,然后做更多的工作,然后再做一些工作),而不是必须运行整个收集而无需中断。这与旧的停止世界垃圾收集器形成鲜明对比,旧的垃圾收集器在没有任何其他代码能够在对象上工作的情况下进行标记和清除。但需要明确的是:增量垃圾收集器实际上是否与在同一对象上执行的其他代码并行运行并不重要,只要它是可中断的(为此,它必须区分脏和干净)对象)。

分代垃圾收集器区分旧对象、中对象和新对象。然后,它可以对新对象(关键字“Eden”)进行复制 GC,对旧对象进行标记和清除,并对介质对象进行不同的可能性(取决于实现)。根据实现,区分对象代的方式是通过内存中占​​用的区域或通过标志。分代 GC 的挑战是保持从一代到另一代引用的对象列表是最新的。

Boem 是一种增量分代 GC,如下所述:http://en.wikipedia.org/wiki/Boehm_garbage_collector

An incremental garbage collector is any garbage-collector that can run incrementally (meaning that it can do a little work, then some more work, then some more work), instead of having to run the whole collection without interruption. This stands in contrast to old stop-the-world garbage collectors that did e.g. a mark&sweep without any other code being able to work on the objects. But to be clear: Whether an incremental garbage collector actually runs in parallel to other code executing on the same objects is not important as long as it is interruptable (for which it has to e.g. distinguish between dirty and clean objects).

A generational garbage collector differentiates between old, medium and new objects. It can then do copying GC on the new objects (keyword "Eden"), mark&sweep for the old objects and different possibilities (depending on implementation) on the medium objects. Depending on implementation the way the generations of objects are distinguished is either by region occupied in memory or by flags. The challenge of generational GC is to keep lists of objects that refer from one generation to the other up to date.

Boem is an incremental generational GC as cited here: http://en.wikipedia.org/wiki/Boehm_garbage_collector

冷了相思 2024-10-25 16:10:53

http://www.memorymanagement.org/glossary/i.html#incremental .垃圾.收集

一些跟踪垃圾收集算法可能会在中间暂停
一个收集周期,同时变异器继续,但不会结束
数据不一致。此类收集器可以增量运行并且
适合在交互式系统中使用。

原始垃圾收集器(1),一旦开始收集周期,
必须要么完成任务,要么放弃迄今为止的所有工作。这是
通常是适当的限制,但当系统
必须保证响应时间;例如,在具有用户的系统中
接口和实时硬件控制系统。此类系统
可能会使用增量垃圾收集,以便时间紧迫的
处理和垃圾收集可以有效地进行
并行,没有浪费精力。

http://www.memorymanagement.org/glossary/g.html# Generational .垃圾.收集

分代垃圾收集正在跟踪垃圾收集
利用世代假设。物品已收集
世代相传。新对象分配在最年轻的或
苗圃一代,如果存活下来,则晋升为老一代。
老一代的对象被谴责的频率较低,从而节省了 CPU
时间。

对象引用较年轻的对象通常很少见。
因此,一代中的对象通常很少引用
年轻一代的对象。这意味着扫描旧
在收集年轻一代的过程中,可以
通过记忆集可以更有效地完成。

在一些纯函数式语言(即不更新)中,所有
引用在时间上是向后的,在这种情况下,记忆集是
不必要的。

Boehm-Demers-Weiser 具有增量模式,您可以通过调用 GC_enable_incremental 来启用该模式。请参阅 http://www.hpl.hp.com/personal/Hans_Boehm/ gc/gcinterface.html

http://www.memorymanagement.org/glossary/i.html#incremental.garbage.collection

Some tracing garbage collection algorithms can pause in the middle of
a collection cycle while the mutator continues, without ending up with
inconsistent data. Such collectors can operate incrementally and are
suitable for use in an interactive system.

Primitive garbage collectors(1), once they start a collection cycle,
must either finish the task, or abandon all their work so far. This is
often an appropriate restriction, but is unacceptable when the system
must guarantee response times; for example, in systems with a user
interface and in real-time hardware control systems. Such systems
might use incremental garbage collection so that the time-critical
processing and the garbage collection can proceed effectively in
parallel, without wasted effort.

http://www.memorymanagement.org/glossary/g.html#generational.garbage.collection

Generational garbage collection is tracing garbage collection that
makes use of the generational hypothesis. Objects are gathered
together in generations. New objects are allocated in the youngest or
nursery generation, and promoted to older generations if they survive.
Objects in older generations are condemned less frequently, saving CPU
time.

It is typically rare for an object to refer to a younger object.
Hence, objects in one generation typically have few references to
objects in younger generations. This means that the scanning of old
generations in the course of collecting younger generations can be
done more efficiently by means of remembered sets.

In some purely functional languages (that is, without update), all
references are backwards in time, in which case remembered sets are
unnecessary.

The Boehm-Demers-Weiser has an incremental mode that you can enable by calling GC_enable_incremental. See http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcinterface.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文