亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2363 | 回復: 3
打印 上一主題 下一主題

[內(nèi)核入門] kmem_cache_init()的疑問 [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2013-08-30 12:40 |只看該作者 |倒序瀏覽
內(nèi)核版本:v2.6.24
slub內(nèi)存管理模塊
假定環(huán)境:SMP +NUMA

問題:kmem_cache_init()對通用緩存進行初始化,其中調(diào)用了create_kmalloc_cache->kmem_cache_open
->alloc_kmem_cache_cpus->alloc_kmem_cache_cpu,對緩存的cpu_slab[]進行了初始化,但是后來又
調(diào)用了register_cpu_notifier(&slab_notifier); 這會使系統(tǒng)調(diào)用其中包含的函數(shù)slab_cpuup_callback(),
這個函數(shù)對slab_caches鏈表中的緩存(包括以上的通用緩存)重新調(diào)用alloc_kmem_cache_cpu(),這不是重復了嗎?
這個問題上次提過,不過是針對2.6.11版本的,一直沒有得到答復,現(xiàn)在在2.6.24中有同樣的疑問。望大俠們不吝指教。


代碼摘錄如下:
//---------------------------------------------linux/mm/slub.c -------------------------------
static struct notifier_block __cpuinitdata slab_notifier =
        { &slab_cpuup_callback, NULL, 0 };



void __init kmem_cache_init(void)
{
        int i;
        int caches = 0;

        init_alloc_cpu();

#ifdef CONFIG_NUMA
        /*
         * Must first have the slab cache available for the allocations of the
         * struct kmem_cache_node's. There is special bootstrap code in
         * kmem_cache_open for slab_state == DOWN.
         */
        create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
                sizeof(struct kmem_cache_node), GFP_KERNEL);
        kmalloc_caches[0].refcount = -1;
        caches++;

        hotplug_memory_notifier(slab_memory_callback, 1);
#endif

        /* Able to allocate the per node structures */
        slab_state = PARTIAL;

        /* Caches that are not of the two-to-the-power-of size */
        if (KMALLOC_MIN_SIZE <= 64) {
                create_kmalloc_cache(&kmalloc_caches[1],
                                "kmalloc-96", 96, GFP_KERNEL);
                caches++;
        }
        if (KMALLOC_MIN_SIZE <= 12 {
                create_kmalloc_cache(&kmalloc_caches[2],
                                "kmalloc-192", 192, GFP_KERNEL);
                caches++;
        }

        for (i = KMALLOC_SHIFT_LOW; i < PAGE_SHIFT; i++) {
                create_kmalloc_cache(&kmalloc_caches[i],
                        "kmalloc", 1 << i, GFP_KERNEL);
                caches++;
        }


        /*
         * Patch up the size_index table if we have strange large alignment
         * requirements for the kmalloc array. This is only the case for
         * mips it seems. The standard arches will not generate any code here.
         *
         * Largest permitted alignment is 256 bytes due to the way we
         * handle the index determination for the smaller caches.
         *
         * Make sure that nothing crazy happens if someone starts tinkering
         * around with ARCH_KMALLOC_MINALIGN
         */
        BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
                (KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));

        for (i = 8; i < KMALLOC_MIN_SIZE; i +=
                size_index[(i - 1) / 8] = KMALLOC_SHIFT_LOW;

        slab_state = UP;

        /* Provide the correct kmalloc names now that the caches are up */
        for (i = KMALLOC_SHIFT_LOW; i < PAGE_SHIFT; i++)
                kmalloc_caches[i]. name =
                        kasprintf(GFP_KERNEL, "kmalloc-%d", 1 << i);

#ifdef CONFIG_SMP
        register_cpu_notifier(&slab_notifier);
        kmem_size = offsetof(struct kmem_cache, cpu_slab) +
                                nr_cpu_ids * sizeof(struct kmem_cache_cpu *);
#else
        kmem_size = sizeof(struct kmem_cache);
#endif


        printk(KERN_INFO "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
                " CPUs=%d, Nodes=%d\n",
                caches, cache_line_size(),
                slub_min_order, slub_max_order, slub_min_objects,
                nr_cpu_ids, nr_node_ids);
}

論壇徽章:
6
金牛座
日期:2013-10-08 10:19:10技術(shù)圖書徽章
日期:2013-10-14 16:24:09CU十二周年紀念徽章
日期:2013-10-24 15:41:34獅子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亞洲杯之阿聯(lián)酋
日期:2015-05-09 14:36:15
2 [報告]
發(fā)表于 2013-08-30 14:04 |只看該作者
本帖最后由 瀚海書香 于 2013-08-30 14:30 編輯

回復 1# aweii
你說的這個代碼在v2.6.34中已經(jīng)解決了。
git log ff12059ed14b0773d7bbef86f98218ada6c20770 -p
commit ff12059ed14b0773d7bbef86f98218ada6c20770
Author: Christoph Lameter <cl@linux-foundation.org>
Date:   Fri Dec 18 16:26:22 2009 -0600

    SLUB: this_cpu: Remove slub kmem_cache fields
   
    Remove the fields in struct kmem_cache_cpu that were used to cache data from
    struct kmem_cache when they were in different cachelines. The cacheline that
    holds the per cpu array pointer now also holds these values. We can cut down
    the struct kmem_cache_cpu size to almost half.
   
    The get_freepointer() and set_freepointer() functions that used to be only
    intended for the slow path now are also useful for the hot path since access
    to the size field does not require accessing an additional cacheline anymore.
    This results in consistent use of functions for setting the freepointer of
    objects throughout SLUB.
   
    Also we initialize all possible kmem_cache_cpu structures when a slab is
    created. No need to initialize them when a processor or node comes online.

   
    Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
    Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>

   

論壇徽章:
1
雙魚座
日期:2013-08-28 13:47:26
3 [報告]
發(fā)表于 2013-08-30 16:52 |只看該作者
In version 2.6.24, I saw function 'alloc_kmem_cache_cpus()'  would  just work on  the online cpu, like this:
static int alloc_kmem_cache_cpus(struct kmem_cache *s, gfp_t flags)
{
        int cpu;

        for_each_online_cpu(cpu) {
                struct kmem_cache_cpu *c = get_cpu_slab(s, cpu);

                if (c)
                        continue;

                c = alloc_kmem_cache_cpu(s, cpu, flags);
                if (!c) {
                        free_kmem_cache_cpus(s);
                        return 0;
                }
                s->cpu_slab[cpu] = c;
        }
        return 1;
}

Function 'alloc_kmem_cache_cpu' in called function slab_cpuup_callbackwill be called when some CPUs is coming up as they was off when initialized the cpu_slab[] array.

I guess this mechanism is for cpu state changing.

As 瀚海書香 said:

Also we initialize all possible kmem_cache_cpu structures when a slab is
created. No need to initialize them when a processor or node comes online.

'alloc_kmem_cache_cpus' has been  changed in version 2.6.34.

論壇徽章:
0
4 [報告]
發(fā)表于 2013-08-30 20:09 |只看該作者
兩位說的都很中肯,我茅塞頓開。非常感謝!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP