7 Overview
8 An address space is divided into a number of logically distinct pieces,
9 or arenas: text, data, heap, stack, and so on. Within these arenas we
10 often subdivide further; for example, we use heap addresses not only for
11 the kernel heap (kmem_alloc() space), but also for DVMA, bp_mapin(),
12 /dev/kmem, and even some device mappings.
13
14 The kernel address space, therefore, is most accurately described as a
15 tree of arenas in which each node of the tree imports some subset of its
16 parent. The virtual memory allocator manages these arenas and supports
17 their natural hierarchical structure.
18
19 Arenas
20 An arena is nothing more than a set of integers. These integers most
21 commonly represent virtual addresses, but in fact they can represent
22 anything at all. For example, we could use an arena containing the
23 integers minpid through maxpid to allocate process IDs. For uses of this
24 nature, prefer id_space(9F) instead.
25
26 vmem_create() and vmem_destroy() create and destroy vmem arenas. In
27 order to differentiate between arenas used for adresses and arenas used
28 for identifiers, the VMC_IDENTIFIER flag is passed to vmem_create().
29 This prevents identifier exhaustion from being diagnosed as general
30 memory failure.
31
32 Spans
33 We represent the integers in an arena as a collection of spans, or
34 contiguous ranges of integers. For example, the kernel heap consists of
35 just one span: [kernelheap, ekernelheap). Spans can be added to an arena
36 in two ways: explicitly, by vmem_add(), or implicitly, by importing, as
37 described in Imported Memory below.
38
39 Segments
40 Spans are subdivided into segments, each of which is either allocated or
41 free. A segment, like a span, is a contiguous range of integers. Each
42 allocated segment [addr, addr + size) represents exactly one
43 vmem_alloc(size) that returned addr. Free segments represent the space
44 between allocated segments. If two free segments are adjacent, we
45 coalesce them into one larger segment; that is, if segments [a, b) and
46 [b, c) are both free, we merge them into a single segment [a, c). The
47 segments within a span are linked together in increasing-address order so
48 we can easily determine whether coalescing is possible.
49
50 Segments never cross span boundaries. When all segments within an
51 imported span become free, we return the span to its source.
52
53 Imported Memory
54 As mentioned in the overview, some arenas are logical subsets of other
55 arenas. For example, kmem_va_arena (a virtual address cache that
56 satisfies most kmem_slab_create() requests) is just a subset of
|
7 Overview
8 An address space is divided into a number of logically distinct pieces,
9 or arenas: text, data, heap, stack, and so on. Within these arenas we
10 often subdivide further; for example, we use heap addresses not only for
11 the kernel heap (kmem_alloc() space), but also for DVMA, bp_mapin(),
12 /dev/kmem, and even some device mappings.
13
14 The kernel address space, therefore, is most accurately described as a
15 tree of arenas in which each node of the tree imports some subset of its
16 parent. The virtual memory allocator manages these arenas and supports
17 their natural hierarchical structure.
18
19 Arenas
20 An arena is nothing more than a set of integers. These integers most
21 commonly represent virtual addresses, but in fact they can represent
22 anything at all. For example, we could use an arena containing the
23 integers minpid through maxpid to allocate process IDs. For uses of this
24 nature, prefer id_space(9F) instead.
25
26 vmem_create() and vmem_destroy() create and destroy vmem arenas. In
27 order to differentiate between arenas used for addresses and arenas used
28 for identifiers, the VMC_IDENTIFIER flag is passed to vmem_create().
29 This prevents identifier exhaustion from being diagnosed as general
30 memory failure.
31
32 Spans
33 We represent the integers in an arena as a collection of spans, or
34 contiguous ranges of integers. For example, the kernel heap consists of
35 just one span: [kernelheap, ekernelheap). Spans can be added to an arena
36 in two ways: explicitly, by vmem_add(); or implicitly, by importing, as
37 described in Imported Memory below.
38
39 Segments
40 Spans are subdivided into segments, each of which is either allocated or
41 free. A segment, like a span, is a contiguous range of integers. Each
42 allocated segment [addr, addr + size) represents exactly one
43 vmem_alloc(size) that returned addr. Free segments represent the space
44 between allocated segments. If two free segments are adjacent, we
45 coalesce them into one larger segment; that is, if segments [a, b) and
46 [b, c) are both free, we merge them into a single segment [a, c). The
47 segments within a span are linked together in increasing-address order so
48 we can easily determine whether coalescing is possible.
49
50 Segments never cross span boundaries. When all segments within an
51 imported span become free, we return the span to its source.
52
53 Imported Memory
54 As mentioned in the overview, some arenas are logical subsets of other
55 arenas. For example, kmem_va_arena (a virtual address cache that
56 satisfies most kmem_slab_create() requests) is just a subset of
|