page_address_init 函数

本文深入解析了Linux内核中页地址初始化函数page_address_init的工作原理。该函数主要用于初始化全局变量page_address_pool,支持无法直接映射的高内存。此外,还介绍了page_address_htable的作用及其初始化过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[start_kernel() --> page_address_init()]

page_address_init() do nothing when all RAM can be mapped directly, otherwise, do following operations: 

 // mm\highmem.c:

static struct page_address_map page_address_maps[LAST_PKMAP];

void __init page_address_init(void)
{
    int i;

    INIT_LIST_HEAD(&page_address_pool);
    for (= 0; i < ARRAY_SIZE(page_address_maps); i++)
        list_add(&page_address_maps[i].list, &page_address_pool);
    for (= 0; i < ARRAY_SIZE(page_address_htable); i++) {
        INIT_LIST_HEAD(&page_address_htable[i].lh);
        spin_lock_init(&page_address_htable[i].lock);
    }
    spin_lock_init(&pool_lock);
}


page_address_pool is a global variable.

 // mm\highmem.c:

/*
 * page_address_map freelist, allocated from page_address_maps.
 */

static struct list_head page_address_pool;    /* freelist */
static spinlock_t pool_lock;            /* protects page_address_pool */


page_address_htable[] is also a global variable.

 // mm\highmem.c:

/*
 * Hash table bucket
 */

static struct page_address_slot {
    struct list_head lh;            /* List of page_address_maps */
    spinlock_t lock;            /* Protect this bucket's list */
} ____cacheline_aligned_in_smp page_address_htable[1<<PA_HASH_ORDER];


There is a very important data structure: struct page_address_map, this structure's main purpose is to maintain the association of struct page and its virtual memory. However, this will be wasteful if the page has a linear association with its virtual memory. This becomes necessary when the addressing is hashed. 

 // mm\highmem.c:


/*
 * Describes one page->virtual association
 */

struct page_address_map {
    struct page *page;
    void *virtual;
    struct list_head list;
};



Summary:
1. The main purpose of page_address_init() is to initiate global variable page_address_pool, which is used to support high memory that cannot be directly mapped.

page_address_pool is a list header pointing to lots of struct page_address_map connected each other using list.

2. page_address_htable[] is used to hold the list of entry that hash to the same bucket. page_address_init() initiates it.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值