Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp823681ybn; Tue, 24 Sep 2019 10:03:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAAWau6EFd8iAO7/FUEK6GyanyMQlq+/ZCTw7Z20zZjAoep/2fCa6PNLeG5dZxF/CSmSbL X-Received: by 2002:a1c:a8d8:: with SMTP id r207mr1133520wme.135.1569344605580; Tue, 24 Sep 2019 10:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569344605; cv=none; d=google.com; s=arc-20160816; b=CnoV39AQRRx8HUI6Fm5Jzxuo2Qo2hux2uca5PX5uQE4K1qbg3/AvHU0RKsq+6eFir9 lSrwJxTYzXHUhUeHH7faMNQv0NOJq1EJFmOCtcMVJDN1rtFEwddYHiWXou3fxZRKHluf GOxSf9QkHg7JUaeOkm9zHkvpk3kAu2irBA5fu3DximPnkvtU8FxoB04K5itgWNrJwpMf z8Wvh8NUd5wWH/TSCQOh2aqlkAydwFk3pFVWr3RWu6Mx0Q+uyDXl3JUmY0W7yRhM2k6H CtQGAEsFBruMhBtkCBT99dZLpEzDzmNuGUX1yhOlOYIW5HUVZg+Qwufztbu93tOBYrvh 3ApQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=M4+rRs/H04RZSe10IDTw5ZfgZTGQBCZ72q7OalqL7D0=; b=Tn2WLB/gGcz9SwRqLOOeFIpVt7k5aH1IYcxnQHozm7xTNHs3OOEzj623hMIDeIX2mj k6+4V6qmG9k8k2rvkQH2NAMZ9WPpxVzirR0GVJZsabru+ytFzcMADH4l76y+iqS3ugf8 KPhiGegUOT6UHrmnejojuq6++Hv13qOzJbnghaRfCf7kj+FzOgdh7/0gglAaOOacwaHN whuU5vEHgRgTAfGlczMKn1ArV2uDLpWE/vVPH2ZpYDXHElj6ONaLWJ+UeE2CAtLn0GSN B6gtFWVHaa3RLiYh45cyAiDA9AuEU4gq3gitZOEoNaCVsufFsNFIWnIWzZTauAFsUnPH fB6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RRDCtuJJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y47si1521527edd.236.2019.09.24.10.03.01; Tue, 24 Sep 2019 10:03:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RRDCtuJJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394060AbfIWM1y (ORCPT + 99 others); Mon, 23 Sep 2019 08:27:54 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37116 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391000AbfIWM1x (ORCPT ); Mon, 23 Sep 2019 08:27:53 -0400 Received: by mail-pf1-f196.google.com with SMTP id y5so9060075pfo.4 for ; Mon, 23 Sep 2019 05:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=M4+rRs/H04RZSe10IDTw5ZfgZTGQBCZ72q7OalqL7D0=; b=RRDCtuJJ62WelVhAtgnFSuPr/zooWvS53KNzWdT54Xg0udPdRJEqOZur+Y3FkN4yOI v8vbJPvnqpJMHPFaBSNIW0KO2L7rrG0wVYweaW9NE9J/u/lAFnHka/SKXDhnZIY1ibfs xfi1Osdz+ldJ4EYpBD6887wfCvYbcinzqLo/Zjkv72c7IK+Nj/dNKiuWDMPSesoxqf8m 0LNQLElfL7+yto/D79ZGKUQOJvCtcdwZXXoUxl62W1D6pvA5uUZ5QgaYlPeKs+en7ENB JkzriPX4pcVgomQFCuIoJwOkC6GN1L03fxUM2m72IzdM9pblhbiOsZkZbNaJ5hCLtMC5 SNFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=M4+rRs/H04RZSe10IDTw5ZfgZTGQBCZ72q7OalqL7D0=; b=cYcPSGx96jpIXS5n8Te+hnFQg+6u2TUp5yva/UwfVvUv86praZBa3u3rECdVwx5P8h E31MYRvGrTJAaxwK7lnOPOuG4TJ34XKG2+Wv/zhe8rnAk8vX9y3j0POS0BgMjC9izLci eSaO62Ba+4tVmKURSsbTpDMdiWHH1ncVH2yIBnnHwfeRnl/d/DlfdchRWFEyV13R3tlv yozpTYVz+J4SxiyLI4nMH0+D24vhFbDtvqvGPAFv5kwN2E1JNzE/OtZ8pnwl53b6ihXk BhqNmPn8qicK2DTW1rJ1wHjbLYPRuTf1ZcKnUEHRsvOzNwPWRic5mVdBD5msN92I8k6f d8uw== X-Gm-Message-State: APjAAAUH5e4J/nCjZf9vqCqSgRxksRztNwO/I9chmaHtPxkod5jj36zB N2A74MWZ9YhixnpW0wOf5a0= X-Received: by 2002:a63:1d02:: with SMTP id d2mr2831895pgd.190.1569241672831; Mon, 23 Sep 2019 05:27:52 -0700 (PDT) Received: from mi-OptiPlex-7050.mioffice.cn ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id 202sm9692016pfu.161.2019.09.23.05.27.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Sep 2019 05:27:52 -0700 (PDT) From: Pengfei Li To: akpm@linux-foundation.org Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, guro@fb.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Pengfei Li Subject: [PATCH v6 1/3] mm, slab: Make kmalloc_info[] contain all types of names Date: Mon, 23 Sep 2019 20:27:26 +0800 Message-Id: <1569241648-26908-2-git-send-email-lpf.vector@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569241648-26908-1-git-send-email-lpf.vector@gmail.com> References: <1569241648-26908-1-git-send-email-lpf.vector@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are three types of kmalloc, KMALLOC_NORMAL, KMALLOC_RECLAIM and KMALLOC_DMA. The name of KMALLOC_NORMAL is contained in kmalloc_info[].name, but the names of KMALLOC_RECLAIM and KMALLOC_DMA are dynamically generated by kmalloc_cache_name(). This patch predefines the names of all types of kmalloc to save the time spent dynamically generating names. Besides, remove the kmalloc_cache_name() that is no longer used. Signed-off-by: Pengfei Li Acked-by: Vlastimil Babka Acked-by: Roman Gushchin Acked-by: David Rientjes --- mm/slab.c | 2 +- mm/slab.h | 2 +- mm/slab_common.c | 91 ++++++++++++++++++++++++++++++-------------------------- 3 files changed, 51 insertions(+), 44 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 9df3705..c42b621 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -1247,7 +1247,7 @@ void __init kmem_cache_init(void) * structures first. Without this, further allocations will bug. */ kmalloc_caches[KMALLOC_NORMAL][INDEX_NODE] = create_kmalloc_cache( - kmalloc_info[INDEX_NODE].name, + kmalloc_info[INDEX_NODE].name[KMALLOC_NORMAL], kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS, 0, kmalloc_size(INDEX_NODE)); slab_state = PARTIAL_NODE; diff --git a/mm/slab.h b/mm/slab.h index 9057b80..2fc8f95 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -76,7 +76,7 @@ extern struct kmem_cache *kmem_cache; /* A table of kmalloc cache names and sizes */ extern const struct kmalloc_info_struct { - const char *name; + const char *name[NR_KMALLOC_TYPES]; unsigned int size; } kmalloc_info[]; diff --git a/mm/slab_common.c b/mm/slab_common.c index 807490f..4e78490 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1092,26 +1092,56 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) return kmalloc_caches[kmalloc_type(flags)][index]; } +#ifdef CONFIG_ZONE_DMA +#define INIT_KMALLOC_INFO(__size, __short_size) \ +{ \ + .name[KMALLOC_NORMAL] = "kmalloc-" #__short_size, \ + .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #__short_size, \ + .name[KMALLOC_DMA] = "dma-kmalloc-" #__short_size, \ + .size = __size, \ +} +#else +#define INIT_KMALLOC_INFO(__size, __short_size) \ +{ \ + .name[KMALLOC_NORMAL] = "kmalloc-" #__short_size, \ + .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #__short_size, \ + .size = __size, \ +} +#endif + /* * kmalloc_info[] is to make slub_debug=,kmalloc-xx option work at boot time. * kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is * kmalloc-67108864. */ const struct kmalloc_info_struct kmalloc_info[] __initconst = { - {NULL, 0}, {"kmalloc-96", 96}, - {"kmalloc-192", 192}, {"kmalloc-8", 8}, - {"kmalloc-16", 16}, {"kmalloc-32", 32}, - {"kmalloc-64", 64}, {"kmalloc-128", 128}, - {"kmalloc-256", 256}, {"kmalloc-512", 512}, - {"kmalloc-1k", 1024}, {"kmalloc-2k", 2048}, - {"kmalloc-4k", 4096}, {"kmalloc-8k", 8192}, - {"kmalloc-16k", 16384}, {"kmalloc-32k", 32768}, - {"kmalloc-64k", 65536}, {"kmalloc-128k", 131072}, - {"kmalloc-256k", 262144}, {"kmalloc-512k", 524288}, - {"kmalloc-1M", 1048576}, {"kmalloc-2M", 2097152}, - {"kmalloc-4M", 4194304}, {"kmalloc-8M", 8388608}, - {"kmalloc-16M", 16777216}, {"kmalloc-32M", 33554432}, - {"kmalloc-64M", 67108864} + INIT_KMALLOC_INFO(0, 0), + INIT_KMALLOC_INFO(96, 96), + INIT_KMALLOC_INFO(192, 192), + INIT_KMALLOC_INFO(8, 8), + INIT_KMALLOC_INFO(16, 16), + INIT_KMALLOC_INFO(32, 32), + INIT_KMALLOC_INFO(64, 64), + INIT_KMALLOC_INFO(128, 128), + INIT_KMALLOC_INFO(256, 256), + INIT_KMALLOC_INFO(512, 512), + INIT_KMALLOC_INFO(1024, 1k), + INIT_KMALLOC_INFO(2048, 2k), + INIT_KMALLOC_INFO(4096, 4k), + INIT_KMALLOC_INFO(8192, 8k), + INIT_KMALLOC_INFO(16384, 16k), + INIT_KMALLOC_INFO(32768, 32k), + INIT_KMALLOC_INFO(65536, 64k), + INIT_KMALLOC_INFO(131072, 128k), + INIT_KMALLOC_INFO(262144, 256k), + INIT_KMALLOC_INFO(524288, 512k), + INIT_KMALLOC_INFO(1048576, 1M), + INIT_KMALLOC_INFO(2097152, 2M), + INIT_KMALLOC_INFO(4194304, 4M), + INIT_KMALLOC_INFO(8388608, 8M), + INIT_KMALLOC_INFO(16777216, 16M), + INIT_KMALLOC_INFO(33554432, 32M), + INIT_KMALLOC_INFO(67108864, 64M) }; /* @@ -1161,36 +1191,14 @@ void __init setup_kmalloc_cache_index_table(void) } } -static const char * -kmalloc_cache_name(const char *prefix, unsigned int size) -{ - - static const char units[3] = "\0kM"; - int idx = 0; - - while (size >= 1024 && (size % 1024 == 0)) { - size /= 1024; - idx++; - } - - return kasprintf(GFP_NOWAIT, "%s-%u%c", prefix, size, units[idx]); -} - static void __init new_kmalloc_cache(int idx, int type, slab_flags_t flags) { - const char *name; - - if (type == KMALLOC_RECLAIM) { + if (type == KMALLOC_RECLAIM) flags |= SLAB_RECLAIM_ACCOUNT; - name = kmalloc_cache_name("kmalloc-rcl", - kmalloc_info[idx].size); - BUG_ON(!name); - } else { - name = kmalloc_info[idx].name; - } - kmalloc_caches[type][idx] = create_kmalloc_cache(name, + kmalloc_caches[type][idx] = create_kmalloc_cache( + kmalloc_info[idx].name[type], kmalloc_info[idx].size, flags, 0, kmalloc_info[idx].size); } @@ -1232,11 +1240,10 @@ void __init create_kmalloc_caches(slab_flags_t flags) if (s) { unsigned int size = kmalloc_size(i); - const char *n = kmalloc_cache_name("dma-kmalloc", size); - BUG_ON(!n); kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache( - n, size, SLAB_CACHE_DMA | flags, 0, 0); + kmalloc_info[i].name[KMALLOC_DMA], + size, SLAB_CACHE_DMA | flags, 0, 0); } } #endif -- 2.7.4