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:
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.
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.
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 expiresregularly 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 theasynchronous 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.