< Linux Kernel > Garbage Collection

本文介绍了操作系统内核中两种主要的垃圾回收机制:同步和异步。异步垃圾回收通过定期扫描并释放不再使用的数据结构来工作,而同步垃圾回收则在内存紧张时立即触发,以快速释放资源。
Memory is a shared and limited resource and should not be wasted, particularly in the kernel
because it does not use virtual memory. Most kernel subsystems implement some sort of
garbage collection to reclaim the memory held by unused or stale data structure instances.
Depending on the needs of any given feature, you will find two main kinds of garbage
collection:


Asynchronous

This type of garbage collection is unrelated to particular events. A timer that expires
regularly invokes a routine that scans a set of data structures and frees the ones
considered eligible for deletion. The conditions that make a data structure eligible
for deletion depend on the features and logic of the subsystem, but a common
criterion is the presence of a null reference count.


Synchronous

There are cases where a shortage of memory, which cannot wait for the
asynchronous garbage collection timer to kick in, triggers immediate garbage
collection. The criteria used to select the data structures eligible for deletion are not
necessarily the same ones used by asynchronous cleanup (for instance, they could be
more aggressive). See Chapter 33 for an example.


In Chapter 7, you will see how the kernel manages to reclaim the memory used by

initialization routines and that is no longer needed after they have been executed.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值