Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


variables specify the flags set for the kernel itself when pages are allocated; these settings are
therefore automatically transferred to the kernel pages.
The TLB entries of pages with a set_PAGE_GLOBALbit are not flushed from the TLBs during con-
text switches. Since the kernel is always present at the same location in the virtual address space,
this enhances system performance, a welcome effect as kernel data must be made available as
quickly as possible.

Mapping of the physical pages (or of the first 896 MiB, as discussed above) into virtual address
space as ofPAGE_OFFSETis done with the help ofkernel_physical_mapping_init.Thekernel
successively scans all relevant entries of the various page directories and sets the pointers to the correct
values.

Then the areas for fixmap entries and the persistent kernel mappings are set up. Again, this equates to
filling the page tables with appropriate values.

Once page table initialization withpagetable_inithas been concluded, thecr3register is supplied with
a pointer to the page global directory used (swapper_pg_dir). This is necessary to activate the new page
tables. Reassigning thecr3register has exactly this effect on IA-32 machines.

The TLB entries must also be flushed because they still contain boot memory allocation data.
__flush_all_tlbdoes the necessary work. In contrast to TLB flushes during context switches, pages
with a_PAGE_GLOBALbit are also flushed.

kmap_initinitializes the global variablekmap_pte. The kernel uses this variable to store the page table
entry for the area later used to map pages from the highmem zone into kernel address space. Besides,
the address of the first fixmap area for highmem kernel mappings is stored in the global variable
kmem_vstart.

Initialization of the Hot-n-Cold Cache


I have already mentioned the per-CPU (or hot-n-cold) cache in Section 3.2.2.. Here we deal with the
initialization of the associated data structures and the calculation of the ‘‘watermarks‘‘used to control
cache filling behavior.

zone_pcp_initis responsible for initializing the cache. The kernel calls the function from
free_area_init_nodes, which is, in turn, invoked during boot on both IA-32 and AMD64.

mm/page_alloc.c
static __devinit void zone_pcp_init(struct zone *zone)
{
int cpu;
unsigned long batch = zone_batchsize(zone);

for (cpu = 0; cpu < NR_CPUS; cpu++) {
setup_pageset(zone_pcp(zone,cpu), batch);
}
if (zone->present_pages)
printk(KERN_DEBUG " %s zone: %lu pages, LIFO batch:%lu\n",
zone->name, zone->present_pages, batch);
}
Free download pdf