Fsbufferc

#define BH_LRU_SIZE 8

struct bh_lru {

struct buffer_head *bhs[BH_LRU_SIZE];

static DEFINE_PER_CPU(struct bh_lru, bh_lrus) = {{ NULL }};

It is defined in a C file and not in a header file — as usual, an indication for the rest of the kernel code that the cache data structures should (and, besides, can!) not be addressed directly but by means of the dedicated helper functions discussed below.

bhs is an array of pointers to buffer heads and is used as a basis for implementing the LRU algorithm (eight entries are used as the pre-processor definition shows). The kernel uses define_per_cpu to instantiate an instance for each CPU of the system to improve utilization of the CPU caches.

The cache is managed and utilized by two public functions provided by the kernel: lookup_bh_lru checks whether a required entry is present in the cache, and bh_lru_install adds new buffer heads to the cache.

The function implementations hold no surprises since they merely implement the algorithm described above.14 All they need do is select the corresponding array for the current CPU at the start of the action using

14Or as aptly put by a comment in the kernel code: The LRU management algorithm is dopey-but-simple. Sorry.

Continue reading here: Fsbufferc

Was this article helpful?

0 0