Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement



  1. pkmap_countis scanned in full. Entries with counter value 1 are set to 0, and the associated
    entry is deleted from the page table, thus finally removing the mapping.

  2. Finally, all TLB entries present for thePKMAParea are flushed using theflush_tlbkernel
    rangefunction.


TemporaryKernelMappings


Thekmapfunction just described must not be used in interrupt handlers because it can sleep. If there are
no free positions in thepkmaparray, it goes to sleep until the situation improves. The kernel therefore
provides an alternative mapping function thatexecutes atomically and is logically namedkmap_atomic.
A major advantage of this function is that it is faster than a normalkmap. However, it mustnotbe used
in code that can potentially go to sleep. It is therefore ideal for short code sections that quickly require a
temporary page.

The definition ofkmap_atomicis architecture-specific for IA-32, PPC, and Sparc32, but the three imple-
mentations differ only in very minor details. Their prototype is identical.

void *kmap_atomic(struct page *page, enum km_type type)

pageis a pointer to the management structure of the highmem page, andtypedefines the type of map-
ping required.^26

<asm-arch/kmap_types.h>
enum km_type {
KM_BOUNCE_READ,
KM_SKB_SUNRPC_DATA,
...
KM_PTE0,
KM_PTE1,
...
KM_SOFTIRQ1,
KM_TYPE_NR
};

The fixmap mechanism discussed in Section 3.4.2 makes the memory needed to create atomic mappings
available in the kernel address space. An area that can be used to map highmem pages is set up between
FIX_KMAP_BEGINandFIX_KMAP_ENDin thefixed_addressesarray. The exact position is calculated on
the basis of the CPU currently active and the desired mapping type.

idx = type + KM_TYPE_NR*smp_processor_id();
vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);

In the fixmap area, there is a ‘‘window‘‘for each processor in the system. It contains just one entry for each
mapping type, as demonstrated in Figure 3-42 (KM_TYPE_NRis not a separate type but simply indicates
how many entries there are inkm_type). This arrangement makes it clear why functions may not block
when they usekmap_atomic. If they did, another process could create a mapping of the same type behind
their backs and overwrite the existing entries.

(^26) The contents of the structure differ according to architecture, but the differences are so insignificant that they are not worth
describing.

Free download pdf