Chapter3:MemoryManagement
pcp = &p->pcp[1]; /* cold*/
pcp->count = 0;
pcp->high = 2 * batch;
pcp->batch = max(1UL, batch/2);
INIT_LIST_HEAD(&pcp->list);
}
0
5
10
15
20
25
30
35
0 100 200 300 400 500 600 700
Batch size
Zone memory [MiB]
4 KiB Pages8 KiB Pages
16 KiB Pages
0
5
10
15
20
25
30
35
0 20000 40000 60000 80000100000120000140000160000180000200000
Batch size
Pages in Zone
Figure 3-17: Batch sizes dependent on the amount of memory present (left-hand side) on the zone for
various page sizes. The graph on the right-hand side shows the dependency against the number of pages
present in a zone.
As the lower limit used for hot pages is 0 and the upper limit is6batch, the average number of pages in
the cache will be around4batchbecause the kernel tries to not let the caches drain too much.batch*4,
however, corresponds to a thousandth of the totalnumber of zone pages (this is also the reason why
zone_batchsizetried to optimize the batch size for 25 percent of one-thousandth of the total pages). The
size of the L2 cache on IA-32 processors is in the range between 0.25 and 2 MiB, so it makes no sense to
keep much more memory in a hot-n-cold cache than would fit into this space. As a rule of thumb, the
cache size is one-thousandth of the main memory size; consider that current systems are equipped with
between 1 and 2 GiB of RAM per CPU, so the rule is reasonable. The computed batch size will thus likely
allow that the pages on the hot-n-cold cache fit into the CPU’s L2 cache.
The watermarks of the cold list are slightly lower because cold pages not held in the cache are used only
for actions that arenotperformance-critical (such actions are,of course, in the minority in the kernel,).
Only double of thebatchvalue is used as the upper limit.
Thepcp->batchsize determines how many pages are used at once when the list needs to be refilled. For
performance reasons, a whole chunk of pages rather than single pages is added to the list.
The number of pages in each zone is output at the end ofzone_pcp_inittogether with the calculated
batchsizes as shown in the boot logs (for a system with 4 GiB of RAM in the example below).
root@meitner #dmesg | grep LIFO
DMA zone: 2530 pages, LIFO batch:0
DMA32 zone: 833464 pages, LIFO batch:31
Normal zone: 193920 pages, LIFO batch:31