Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp01.tex V1 - 09/04/2008 6:08pm Page 1119

Appendix A: Architecture Specifics


The pre-processor constant__KERNEL__must always be defined before the file is
linked into the kernel sources; otherwise, only data type names prefixed with a
double underscore are defined (for example,__u32) to prevent overlaps with
definitions in the userspace namespace.

A.3 Alignment


The alignment of data on certain memory addresses is necessary to make the best possible use of proces-
sor caches and to boost performance. Some architecturesmandatethat data types of a particular length
have a specific alignment. Even architectures that are able to handle random alignment can read and
write certain alignments faster than when access is unaligned. Alignment is typically on byte addresses
that are divisible without remainder by the byte length of the data type. In certain situations, the required
alignment may be a little larger. Relevant information is given in the architecture documentation of the
processor in question. The alignment of a data type on its own length is referred to asnatural alignment.

It may be necessary to access non-aligned data types at some points in the kernel. The various architec-
tures must therefore define two macros for this purpose (in<asm-arch/unaligned.h>):

❑ get_unaligned(ptr)de-references a pointer at an unaligned memory location.
❑ put_unaligned(val, ptr)writesvalto a memory location specified byptrthat is unaligned
(and not suitable for direct access).

These support access by, for example, copying the value to another memory location and accessing it
there. When the GCC organizes memory forstructsorunions, it automatically selects the appropriate
alignment so that the programmer is not required to do this.

A.4 Memory Pages


Memory pages are 4 KiB in size on many but not all architectures. More modern processors also sup-
port sizes up to several MiB. The following macros must be defined in the architecture-specific file
asm-arch/page.hto indicate the page size used:

❑ PAGE_SHIFTspecifies the binary logarithm of the page size. (The kernel implicitly assumes that
the page size can be represented as a power of 2, as is true on all architectures supported.)
❑ PAGE_SIZEspecifies the size of a memory page in bytes.
❑ PAGE_ALIGN(addr)aligns any address on the page boundary.

Two standard operations on pages must also be implemented, generally by means of optimized assem-
bler commands:

❑ clear_page(start)deletes the page beginning atstartby filling it with null bytes.
❑ copy_page(to, from)copies the page data at positionfromto positionto.

ThePAGE_OFFSETmacro specifies the position in virtual address space where the physical pages are to be
mapped. On most architectures, this implicitly defines the size of the user address space or the division
Free download pdf