Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3220749ybe; Sun, 15 Sep 2019 10:10:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+T4VguQS7R9xy7UP6aMGvJJ0zcmRrDHG7/JF/u8R6xVb3mQ70EIO5jjU5YErX722NbiYb X-Received: by 2002:a50:9512:: with SMTP id u18mr57183988eda.182.1568567448405; Sun, 15 Sep 2019 10:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568567448; cv=none; d=google.com; s=arc-20160816; b=oemIylZ3rtwHnlE21yeC79hWdWOyRaKuXqsAIMrcsnMmnlv4y+gN8vLVg70Cqwuupd hSPYsb16pr1+Je6/BPLLp91t4hQCPs4Aiy+m1D+bjnba6iiEEJ5OI3B1tOBsrPsvQHM/ J5qo7/7e4KdIUj/mQUOJguIGUzj/q+csPzrC6ZLJUd7+Ep5+cPDrQQK3qDh+ZLqqH00k 056JG2OXr9RFJtNbVU0vIcJQ31ffC1O+xPqivHRPBCBJbhQcHXAVzTnsbVrgFsMePt/U Ja3PzMmNwHL79BeQ9UoZ5KlPwa7NjZ+iDT1/vEqVrfRaZwaRY0pE77S90h/IRmBLRF4V w9Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7ScgMFAOOXn7zrz2ktcww61aqak7m9GXt4/M+m23yyA=; b=C3SIh0GenWzl/bsErV29mzIIzY+IJPj+l44RW577i5EqTmVMpAbrnAXb3Dhesfr0u+ DhvUk0YdniE6AMsdwLp4+jVJ6iI1SPOOSANag8Ix6qDM4454+qtX0jVXxFZBtVy9VpNZ xGgKi3XOu734Gdn1bY6kXr2vDg/simFKWh2N8s5hL9HcqS7zU+MeGgLwiwG21akSV392 DG7MgdH9nkYQQMwxv1frCyyl+o+sSVMg1EIg1EoOptLk98X3sDu6f7cOF8eiF/pR6DLT BkmjC+iivRJNE9G/PiXQv9KDSr/QXa/jAY1sxzNKNNREMagP4dPjOs9HxpexSFzavUfA J+LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Sp1XzEd3; 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 fj16si19049506ejb.385.2019.09.15.10.10.24; Sun, 15 Sep 2019 10:10:48 -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=Sp1XzEd3; 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 S1726846AbfIORId (ORCPT + 99 others); Sun, 15 Sep 2019 13:08:33 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46634 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbfIORIc (ORCPT ); Sun, 15 Sep 2019 13:08:32 -0400 Received: by mail-pf1-f194.google.com with SMTP id q5so21114873pfg.13 for ; Sun, 15 Sep 2019 10:08:32 -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 :mime-version:content-transfer-encoding; bh=7ScgMFAOOXn7zrz2ktcww61aqak7m9GXt4/M+m23yyA=; b=Sp1XzEd3rkJfEnkIGsDJcKtNpdhp4yxHnchwkC9ODTY22PnGtD2Nh2zFoP8Lq0zF0e ficitKUIBZIjMwECXfmlvCJE/99wdG6AIw2DJd8jR7pwrsX//Kf0KT6TZuLXOhT0FV9y BmjooFsPYGP64KTPypasx/vpqAzvAtQB4aOauYCn9H6BXdsoOAsYoVSfN6QsRwLAoESU orYMHzmR5D+uYs6kbXWH7TZP2a+tgJCOfMW+tHtpMBH7ks3v3GDSLWkundsC3xmnC9JK fIW972HidzezEEVDWRnEsopt2ke9wVAGHiLwzcKNx/0V8bWlfxGBg5y3qSsgGCOXy9H4 SvrQ== 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:mime-version:content-transfer-encoding; bh=7ScgMFAOOXn7zrz2ktcww61aqak7m9GXt4/M+m23yyA=; b=ad3Ndt7qvLJqN8S7PHzuysMfGoR0RqhB2MMIniMFzZDTfGL3d/wndgWne30T6qtrZE t7bfyltlyeJ2BthfmJtiu3gIPazG34qGgi96TP3EfMitDit+mm7423ShvuanZ2dGwL/R DexrwDqPV6NR7fktVWUKZMDkIYUoDsFPGalxOS2V1zTNftIB2Yd8PNSAdqtp8rAOTAeM WvVoEmiRE1k9CVcRhduNrHSL8xZCf9eYOdYWooiZYAhVDFP8sSOQ9q+vYwxvA+6Aan2h XT3pzFz7ltRu5/xdb0ilyICY+jwNRtq6q+y9vJHYsfH98eK31flXpuOtN6pP6ZSiLnF/ Mbiw== X-Gm-Message-State: APjAAAXsSjlLua0ZgWiv4+zfMbsOftsg7JJI/+Mb33DBws6FLGSWrAi1 U8xP+JHXcVKaZ4/uu3iq3+w= X-Received: by 2002:a17:90a:bf8c:: with SMTP id d12mr15761216pjs.111.1568567312089; Sun, 15 Sep 2019 10:08:32 -0700 (PDT) Received: from localhost.localdomain.localdomain ([2408:823c:c11:160:b8c3:8577:bf2f:3]) by smtp.gmail.com with ESMTPSA id r28sm62279134pfg.62.2019.09.15.10.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2019 10:08:31 -0700 (PDT) From: Pengfei Li To: akpm@linux-foundation.org Cc: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, guro@fb.com, Pengfei Li Subject: [RESEND v4 1/7] mm, slab: Make kmalloc_info[] contain all types of names Date: Mon, 16 Sep 2019 01:08:03 +0800 Message-Id: <20190915170809.10702-2-lpf.vector@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190915170809.10702-1-lpf.vector@gmail.com> References: <20190915170809.10702-1-lpf.vector@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 9df370558e5d..c42b6211f42e 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 9057b8056b07..2fc8f956906a 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 807490fe217a..002e16673581 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 SET_KMALLOC_SIZE(__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 SET_KMALLOC_SIZE(__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} + SET_KMALLOC_SIZE(0, 0), + SET_KMALLOC_SIZE(96, 96), + SET_KMALLOC_SIZE(192, 192), + SET_KMALLOC_SIZE(8, 8), + SET_KMALLOC_SIZE(16, 16), + SET_KMALLOC_SIZE(32, 32), + SET_KMALLOC_SIZE(64, 64), + SET_KMALLOC_SIZE(128, 128), + SET_KMALLOC_SIZE(256, 256), + SET_KMALLOC_SIZE(512, 512), + SET_KMALLOC_SIZE(1024, 1k), + SET_KMALLOC_SIZE(2048, 2k), + SET_KMALLOC_SIZE(4096, 4k), + SET_KMALLOC_SIZE(8192, 8k), + SET_KMALLOC_SIZE(16384, 16k), + SET_KMALLOC_SIZE(32768, 32k), + SET_KMALLOC_SIZE(65536, 64k), + SET_KMALLOC_SIZE(131072, 128k), + SET_KMALLOC_SIZE(262144, 256k), + SET_KMALLOC_SIZE(524288, 512k), + SET_KMALLOC_SIZE(1048576, 1M), + SET_KMALLOC_SIZE(2097152, 2M), + SET_KMALLOC_SIZE(4194304, 4M), + SET_KMALLOC_SIZE(8388608, 8M), + SET_KMALLOC_SIZE(16777216, 16M), + SET_KMALLOC_SIZE(33554432, 32M), + SET_KMALLOC_SIZE(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.21.0