What Are Lowmem and Highmem in Linux? – Free Linux Device Driver Training

🚀 Learn BLE on Linux (BlueZ) – Programming Part 1

Hands-on Bluetooth Low Energy course. Special price: ₹399

Enroll Now on Udemy →
💬 Need help or career guidance? Ask us!Contact Us →
Kernel VAS Deep Dive: Lowmem, Highmem, Kernel Image & User VAS
Free Linux Kernel Development Course | EmbeddedPathashala — Part 2
📖 Deep Dive
⚙ Kernel Memory
🎓 Free Course
💻 LKM Demo

Continuing the Linux Kernel Virtual Address Space Tour

In Part 1 of this free Linux kernel development course tutorial, we covered the kernel modules region, the KASAN shadow memory region, and the vmalloc region. In this second part, we cover the remaining major regions: the lowmem (direct-mapped) region, the optional highmem region, the kernel static image region, and the user virtual address space (VAS). We also walk through writing an LKM that prints all of these regions — exactly the kind of hands-on code that belongs in a free Linux device drivers course.

4. The Lowmem Region — Direct-Mapped RAM

The lowmem region is perhaps the most important region in the kernel VAS because it is where the Linux kernel maps and manages essentially all of your system’s RAM. It is called the lowmem region because it was historically the lower portion of memory that the kernel could directly access — as opposed to the highmem region which required special handling on 32-bit systems.

The key property of the lowmem region is that it is direct-mapped: there is a fixed, 1:1 (or more precisely 1:1 offset) relationship between a physical address and its kernel virtual address. If you know the physical address of a page frame, you can compute its kernel virtual address simply by adding PAGE_OFFSET. This makes the lowmem region extremely fast to work with — no complex page table lookups are needed beyond the initial setup at boot.

Lowmem Direct Mapping — Physical RAM → Kernel Virtual Address
PHYSICAL MEMORY
Phys 0x00000000 (Page Frame 0)
Phys 0x00001000 (Page Frame 1)
Phys 0x00002000 (Page Frame 2)
…
Phys N
→
+ PAGE_OFFSET
KERNEL VIRTUAL (Lowmem)
KVA = PAGE_OFFSET + 0x0
KVA = PAGE_OFFSET + 0x1000
KVA = PAGE_OFFSET + 0x2000
…
KVA = PAGE_OFFSET + N
Lowmem Region Key Macros
Macro / Symbol Meaning
PAGE_OFFSET Start KVA of the lowmem region. On 32-bit x86 with a standard 3G/1G split this is 0xC0000000. On 64-bit it is architecture-defined (typically 0xFFFF888000000000 on x86_64).
high_memory End KVA of the lowmem region. high_memory - PAGE_OFFSET gives the amount of RAM directly mapped into the kernel (the platform RAM size on most systems).

The 3G/1G VM Split on 32-bit Linux

On a 32-bit Linux system, the total virtual address space is only 4 GB. The traditional split is 3 GB for user space and 1 GB for the kernel — this is the well-known 3G/1G VM split. The kernel segment starts at PAGE_OFFSET = 0xC0000000 (3 GB) and the kernel has only 1 GB of virtual address space for all its needs. This is why the lowmem / highmem distinction was historically so important — when a machine had more than about 896 MB of RAM, the kernel ran out of lowmem space to directly map it all, and needed the highmem mechanism.

On 64-bit systems, this problem disappears entirely. The kernel VAS is enormous and the entire RAM of any practical machine can be direct-mapped into lowmem without issue.

Converting Between Physical and Virtual Addresses

For direct-mapped lowmem pages, the kernel provides two macros for conversion:

/* Physical address → Kernel virtual address (lowmem only) */
void *kva = phys_to_virt(phys_addr);
/* Equivalent: kva = (void *)(phys_addr + PAGE_OFFSET) */

/* Kernel virtual address → Physical address (lowmem only) */
phys_addr_t pa = virt_to_phys(kva);
/* Equivalent: pa = (phys_addr_t)(kva) - PAGE_OFFSET */
⚠ Warning: virt_to_phys() and phys_to_virt() are only valid for lowmem addresses. If you call virt_to_phys() on a vmalloc() address you will get garbage, because vmalloc memory is not direct-mapped. For vmalloc addresses, use vmalloc_to_pfn() or walk the page tables.

5. The Highmem Region (32-bit Systems Only)

The highmem region is a legacy mechanism that only exists on some 32-bit Linux configurations. In modern 64-bit kernels, this region does not exist at all — you will not encounter it on any new hardware or OS installation. However, if you are working on embedded products that still run 32-bit Linux on older ARM or x86 hardware, understanding highmem is important.

Why Does Highmem Exist?

On a 32-bit Linux system with the 3G/1G split, the kernel only has 1 GB of virtual address space. After reserving space for vmalloc, kernel image, and other regions, the lowmem region can only directly map approximately 896 MB of physical RAM. If the system has more RAM than this — say 2 GB — the remaining RAM above the 896 MB boundary cannot be permanently direct-mapped into the kernel segment. This remaining physical memory is called high memory.

To access high memory, the kernel must temporarily map high-memory page frames into a small dedicated window of virtual addresses. This window is the highmem region, and the mechanism is called persistent kernel mappings (PKMAPs).

Highmem Region (32-bit Only)
Macro / Symbol Meaning
PKMAP_BASE Start KVA of the highmem region. The kernel maps high-memory page frames here using kmap() / kmap_atomic().
LAST_PKMAP Total number of persistent kernel mappings available in this window
ZONE_HIGHMEM The memory zone that tracks high-memory page frames
💡 Good to Know: On modern 64-bit Linux (which is essentially all current systems), CONFIG_HIGHMEM is not enabled and the highmem region does not exist. If you check for PKMAP_BASE in a 64-bit kernel header you will not find it defined. This is one area where free Linux kernel development course materials for modern hardware can safely skip most of the highmem complexity.

6. The Kernel Static Image Region

The kernel static image is the compiled, uncompressed kernel binary loaded into memory at boot time. It occupies a fixed range of kernel virtual addresses and is divided into several distinct sections, each with a well-defined purpose. These sections are private to the kernel — their symbols are not exported and therefore cannot be accessed by kernel modules directly.

Linux Kernel Static Image — Sections and Their Symbols
Symbol(s) Section Contents
_text, _etext Text (code) section All compiled kernel machine code. Read-only in modern kernels (W^X policy).
__init_begin, __init_end Init section Code and data marked __init / __initdata. Freed after boot is complete — this is why you see “Freeing unused kernel image memory” in dmesg.
_sdata, _edata Static data section Kernel global variables that are initialised at compile time
__bss_start, __bss_stop BSS section Kernel global variables that are zero-initialised (not stored in the kernel binary on disk — zeroed at boot)
Kernel Static Image — Memory Layout (Top = High Address)
▼ __bss_stop (BSS end)
BSS Section (zeroed globals)
__bss_start → __bss_stop
Static Data Section
_sdata → _edata
Init Section (freed after boot)
__init_begin → __init_end
Text (Code) Section
_text → _etext
▲ _text (kernel code start)

The __init Attribute and Why It Matters for Driver Writers

As a Linux device driver developer, you will use the __init and __exit attributes regularly. Understanding what they do at the memory layout level helps you write better, more memory-efficient drivers.

/* The __init attribute puts this function in the kernel's init section */
/* It gets freed from memory after the kernel finishes booting */
static int __init my_driver_init(void)
{
    pr_info("my_driver: loaded\n");
    /* Do initialisation here */
    return 0;
}

/* The __exit attribute is similarly optimised away for built-in modules */
static void __exit my_driver_exit(void)
{
    pr_info("my_driver: unloaded\n");
}

module_init(my_driver_init);
module_exit(my_driver_exit);

When your driver is compiled as a built-in kernel module (not a .ko file but compiled directly into the kernel image), the code marked __init is placed in the init section. Once the kernel finishes its startup sequence, the entire init section is freed — saving RAM at runtime. If your driver is compiled as a loadable .ko module, the __init attribute still marks the function so the compiler can optimise it, but the memory saving behaviour is slightly different.

7. The User Virtual Address Space (User VAS)

The user VAS is the last (and lowest-addressed) region in our tour. It is the virtual address space that every process running on the system gets. Each process has its own private user VAS, managed by the kernel through a set of Virtual Memory Areas (VMAs) — structures that we covered in earlier lectures in this free Linux kernel development course.

User VAS Key Information
Item Details
TASK_SIZE Total size of the user VAS in bytes. On x86_64 Linux this is typically 128 TB (247 bytes). On 32-bit it is 3 GB with the standard 3G/1G split.
Address range From virtual address 0 (technically 0x10000 — the first page is unmapped to catch NULL dereferences) up to TASK_SIZE - 1
Per-process Each process has its own independent user VAS. The kernel switches page tables on context switch so each process sees only its own memory.
Inspection tool /proc/<pid>/maps — shows all VMAs (memory mappings) of a process

Hands-On: Writing an LKM That Prints All Kernel VAS Regions

Now that we understand all the major kernel VAS regions, let us write a complete loadable kernel module that reads and prints the boundaries of every region we have covered. This is an excellent learning exercise for any free Linux device drivers course — it puts all the theory into working code.

The show_kernelseg Module — Complete Source

The following LKM reads the kernel macros for each region and prints them to the kernel log with pr_info(). You can see the output with dmesg after loading the module. Notice we use %px for addresses and compute sizes in MB for readability.

/* show_kernelseg.c
 * Prints the Linux kernel virtual address space boundaries
 * Part of: Free Linux Kernel Development Course at EmbeddedPathashala
 * License: GPL v2
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>
#include <asm/pgtable.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("EmbeddedPathashala");
MODULE_DESCRIPTION("Show kernel VAS region boundaries");
MODULE_VERSION("1.0");

/* Helper macro: compute size in MB between two addresses */
#define ADDR_SIZE_MB(start, end) \
    ((unsigned long)((end) - (start)) / (1024UL * 1024UL))

static void show_kernelseg_info(void)
{
    pr_info("\n");
    pr_info("=== Kernel VAS Regions [Decreasing Address Order] ===\n");
    pr_info("------------------------------------------------------\n");

#ifdef CONFIG_ARM
    /* ARM 32-bit: vectors table (kernel 4.11+) */
    pr_info("| Vector Table  : 0x%px  [%4lu KB]\n",
        (void *)VECTORS_BASE,
        (unsigned long)PAGE_SIZE / 1024);
#endif

    /* 1. Kernel Modules Region */
    pr_info("| Modules VADDR : 0x%px\n", (void *)MODULES_VADDR);
    pr_info("| Modules END   : 0x%px  [%4lu MB]\n",
        (void *)MODULES_END,
        ADDR_SIZE_MB(MODULES_VADDR, MODULES_END));

#ifdef CONFIG_KASAN
    /* 2. KASAN Shadow Region (64-bit only) */
    pr_info("| KASAN Start   : 0x%px\n", (void *)KASAN_SHADOW_START);
    pr_info("| KASAN End     : 0x%px  [%4lu MB]\n",
        (void *)KASAN_SHADOW_END,
        ADDR_SIZE_MB(KASAN_SHADOW_START, KASAN_SHADOW_END));
#endif

    /* 3. vmalloc Region */
    pr_info("| VMALLOC START : 0x%px\n", (void *)VMALLOC_START);
    pr_info("| VMALLOC END   : 0x%px  [%4lu MB]\n",
        (void *)VMALLOC_END,
        ADDR_SIZE_MB(VMALLOC_START, VMALLOC_END));

    /* 4. Lowmem (Direct-mapped RAM) */
    pr_info("| PAGE_OFFSET   : 0x%px  (lowmem start)\n",
        (void *)PAGE_OFFSET);
    pr_info("| high_memory   : 0x%px  (lowmem end)\n",
        high_memory);

    /* 5. Kernel Static Image */
    pr_info("| _text         : 0x%px  (kernel code start)\n",
        (void *)_text);
    pr_info("| _etext        : 0x%px  (kernel code end)\n",
        (void *)_etext);
    pr_info("| _sdata        : 0x%px  (static data start)\n",
        (void *)_sdata);
    pr_info("| _edata        : 0x%px  (static data end)\n",
        (void *)_edata);
    pr_info("| __bss_start   : 0x%px  (BSS start)\n",
        (void *)__bss_start);
    pr_info("| __bss_stop    : 0x%px  (BSS end)\n",
        (void *)__bss_stop);

    /* 6. User VAS */
    pr_info("| TASK_SIZE     : 0x%px  (user VAS size)\n",
        (void *)TASK_SIZE);

    pr_info("------------------------------------------------------\n");
}

static int __init show_kernelseg_init(void)
{
    pr_info("show_kernelseg: module loaded\n");
    show_kernelseg_info();
    return 0;
}

static void __exit show_kernelseg_exit(void)
{
    pr_info("show_kernelseg: module unloaded\n");
}

module_init(show_kernelseg_init);
module_exit(show_kernelseg_exit);

Makefile for the Module

obj-m += show_kernelseg.o

# If your source has a helper library object, add it here:
# show_kernelseg-objs := show_kernelseg.o klib_llkd.o

KDIR ?= /lib/modules/$(shell uname -r)/build

all:
	make -C $(KDIR) M=$(PWD) modules

clean:
	make -C $(KDIR) M=$(PWD) clean

Build and Run

# Build the module
make

# Load the module
sudo insmod show_kernelseg.ko

# View the output
dmesg | tail -40

# Unload when done
sudo rmmod show_kernelseg

Sample Output (x86_64, Kernel 6.x)

The actual addresses will differ on your machine because of KASLR (Kernel Address Space Layout Randomisation), but the structure will look like this:

[ 1234.567] show_kernelseg: module loaded
[ 1234.568] === Kernel VAS Regions [Decreasing Address Order] ===
[ 1234.568] --------------------------------------------------
[ 1234.568] | Modules VADDR : 0xffffffffc0000000
[ 1234.568] | Modules END   : 0xfffffffffeffffff  [ 256 MB]
[ 1234.568] | VMALLOC START : 0xffffc90000000000
[ 1234.568] | VMALLOC END   : 0xffffe8ffffffffff  [32768 MB]
[ 1234.569] | PAGE_OFFSET   : 0xffff888000000000  (lowmem start)
[ 1234.569] | high_memory   : 0xffff888100000000  (lowmem end)
[ 1234.569] | _text         : 0xffffffff81000000  (kernel code start)
[ 1234.569] | _etext        : 0xffffffff81e00000  (kernel code end)
[ 1234.569] | _sdata        : 0xffffffff82000000  (static data start)
[ 1234.569] | _edata        : 0xffffffff82500000  (static data end)
[ 1234.569] | __bss_start   : 0xffffffff82500000  (BSS start)
[ 1234.569] | __bss_stop    : 0xffffffff82800000  (BSS end)
[ 1234.569] | TASK_SIZE     : 0x00007fffffffffff  (user VAS size)
[ 1234.570] --------------------------------------------------

KASLR — Why Kernel Addresses Change Every Boot

You might wonder why the addresses in the output above will differ from those on your own machine, even if you have the same kernel version. The answer is KASLR — Kernel Address Space Layout Randomisation. Introduced to defend against kernel exploits that depend on knowing fixed kernel addresses, KASLR randomises the base address at which the kernel image is loaded at every boot.

KASLR — Kernel Base Address Changes Every Boot
Boot Kernel _text (example) Note
Boot 1 0xffffffff81000000 Random offset chosen at boot
Boot 2 0xffffffff81c40000 Different random offset
Boot 3 0xffffffff83200000 Different again

KASLR is enabled by default in modern kernels. You can disable it for debugging (never in production) by passing nokaslr on the kernel command line in your bootloader (GRUB) configuration.

Common Mistakes When Working with Kernel VAS

❌ Mistake 1: Using %p to print kernel addresses
Since kernel 4.15, %p hashes pointer values to avoid leaking kernel addresses. Use %px during debugging. Never use %px in production/released driver code.
❌ Mistake 2: Calling virt_to_phys() on vmalloc addresses
virt_to_phys() only works for direct-mapped lowmem addresses. Calling it on a vmalloc() address gives wrong results silently. Use vmalloc_to_pfn() instead.
❌ Mistake 3: Assuming kernel addresses are stable across boots
KASLR randomises kernel addresses every boot. Never hardcode a kernel address. Always use the symbolic macros (PAGE_OFFSET, VMALLOC_START, etc.) or read addresses programmatically from your module.
❌ Mistake 4: Forgetting to enable KASAN during development
KASAN is your best friend when debugging kernel modules. Always build your development kernel with CONFIG_KASAN=y. The performance cost is worth it — it will catch Use After Free and Out-of-Bounds bugs that would otherwise take days to trace.

Summary and Key Takeaways

In this two-part tutorial from the free Linux kernel development course at EmbeddedPathashala, we walked through all seven major regions of the Linux kernel virtual address space:

  • Kernel Modules Region (MODULES_VADDR → MODULES_END) — Where .ko files are loaded
  • KASAN Shadow Region (KASAN_SHADOW_START → KASAN_SHADOW_END) — 1/8th of kernel VAS, used for memory error detection (64-bit only)
  • vmalloc Region (VMALLOC_START → VMALLOC_END) — For large, virtually contiguous but physically scattered allocations
  • Lowmem Region (PAGE_OFFSET → high_memory) — Direct 1:1 mapping of physical RAM; the most important region for everyday kernel memory work
  • Highmem Region (PKMAP_BASE) — Legacy 32-bit mechanism for mapping RAM above the lowmem boundary; absent on 64-bit
  • Kernel Static Image (_text, _sdata, BSS) — The compiled kernel binary sections; freed init section saves RAM after boot
  • User VAS (TASK_SIZE) — Per-process user virtual address space below the kernel segment

We also wrote a complete LKM (show_kernelseg) that reads and prints all region boundaries — a hands-on exercise that brings together everything from this free Linux device drivers course material.

Frequently Asked Questions

Q1: What is the difference between kernel VAS and user VAS?

The kernel VAS is the portion of virtual address space reserved for the Linux kernel — its code, data, memory management structures, and device driver allocations. The user VAS is the portion visible to each individual process. On 64-bit Linux, the kernel VAS occupies the upper half of the 64-bit address space and the user VAS occupies the lower half. The two never overlap. A process can only access its user VAS directly; accessing kernel memory from user space causes a protection fault.

Q2: Why do kernel addresses look different on every boot?

KASLR (Kernel Address Space Layout Randomisation) randomises the base address of the kernel image at every boot to make it harder for attackers to exploit kernel vulnerabilities that rely on knowing fixed addresses. The relative layout of regions within the kernel VAS stays the same, but the absolute virtual addresses shift by a random offset each time the system boots.

Q3: When should I use vmalloc() instead of kmalloc() in a Linux device driver?

Use vmalloc() when you need a large buffer (typically larger than 128 KB) and physical contiguity is not required. If you need physically contiguous memory — for example, for DMA transfers to/from hardware — you must use kmalloc() with GFP_DMA or the DMA API directly. For small, frequently allocated kernel objects, prefer kmalloc() because it is faster (no page table setup overhead).

Q4: What happens to __init functions after the kernel boots?

The kernel places all functions and data marked with __init / __initdata into a dedicated init section of the kernel image. After the kernel completes its boot sequence, it explicitly frees this entire section. This is why you see the message “Freeing unused kernel image (text/rodata/data/bss) memory” in dmesg early in the boot log. This design saves RAM — init code is only needed once and can be discarded permanently after boot.

Q5: Does the highmem region exist on modern 64-bit Linux?

No. The highmem mechanism (PKMAP_BASE, kmap(), ZONE_HIGHMEM) is a legacy feature for 32-bit Linux systems where RAM could exceed the kernel’s direct-mapping capacity. On 64-bit Linux, the kernel VAS is so large that all practical amounts of RAM can be direct-mapped into the lowmem region. CONFIG_HIGHMEM is not set on 64-bit kernels and the highmem region simply does not exist.

Q6: What is %px in printk and when should I use it?

Since Linux kernel 4.15, the %p format specifier in printk() deliberately hashes the pointer value before printing it, to prevent leaking kernel addresses through the dmesg log to potentially unprivileged processes. The %px specifier bypasses this hashing and prints the actual address. Use %px only in debug code during development. Never ship production driver code that uses %px, as it leaks kernel layout information that could assist an attacker.

Q7: How do I check what kernel VAS layout my running system has?

The easiest way is to read /proc/iomem for physical memory layout and /proc/kallsyms for kernel symbol addresses (requires root on most distros, or CONFIG_KALLSYMS_ALL=y). You can also check /proc/vmallocinfo for vmalloc allocations. Writing an LKM like the show_kernelseg module shown in this tutorial gives you the most direct and controllable view.

Q8: Why does the kernel modules region need to be near the kernel image?

On architectures like x86_64, certain branch and call instructions have a limited range — they can only jump to addresses within ±2 GB of the current instruction pointer. If a kernel module’s code were loaded far away from the main kernel text segment, these short-range instructions would not reach kernel functions and the linker would need to insert expensive far-call trampolines. By placing the modules region close to the kernel image, the kernel ensures that direct calls between module code and kernel functions work efficiently without trampolines.

Free Linux Kernel Development Course — Keep Learning

All tutorials at EmbeddedPathashala are permanently free. No registration required. If this helped you, share it with fellow embedded engineers.

embeddedpathashala.com
💬 Need help or career guidance? Ask us!Contact Us →

Leave a Reply

Your email address will not be published. Required fields are marked *

×

🚀 BLE on Linux (BlueZ)

Hands-on course. Only ₹399

Enroll Now →