From patchwork Mon Jun 18 09:18:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10470377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9FD0A6032A for ; Mon, 18 Jun 2018 09:18:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23C5428847 for ; Mon, 18 Jun 2018 09:18:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1866D2884B; Mon, 18 Jun 2018 09:18:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9791428847 for ; Mon, 18 Jun 2018 09:18:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A8386B0008; Mon, 18 Jun 2018 05:18:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5503D6B026D; Mon, 18 Jun 2018 05:18:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 376C56B0008; Mon, 18 Jun 2018 05:18:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f197.google.com (mail-wr0-f197.google.com [209.85.128.197]) by kanga.kvack.org (Postfix) with ESMTP id D20656B0269 for ; Mon, 18 Jun 2018 05:18:30 -0400 (EDT) Received: by mail-wr0-f197.google.com with SMTP id w9-v6so11536406wrl.13 for ; Mon, 18 Jun 2018 02:18:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=fp6+t6mBoBDIs63II/jtj9NitcOikokCQoqwqYQKgb8=; b=r0PLADtcHHr5s/RZ/exlj3+xzqKO+O6z+anM1RhZPW8O6PXN/OAmN6UTtH0YWFawDf H6+YKmMnW53TUOPDPt3uD/PlCGGUHm6AH4GQwO774gO1q0us9fTPLn3Cofgs8VIu4hIf pqYrDVdtWTH/8y4a8dzBSy/FrAk39C9pRvWaJKJO0zSDuQPel2nr9hG++ZZx9LgREnGp 21C1a5w1Q7sVCx2eR1UyBNz8a/+azvsiOY4lEwwmsAiQLjVA8AZj6rXkeQWytxbmCnXv y9VzsqeMGDJYWcfcH6Uo7C22VrQpPuo3CMq1bXaA8K7waEFOzzMgzq9lYma64cI/rkF5 WsIg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Gm-Message-State: APt69E1X46hkGyyUQokQ/PyzgfhNYmlf1HlC+WOiBpR3HvEfJ2y148hi 0U5riTbi/4xJG0Tw7sJhGH8sqVrNCaLHyjdTh4tH25v9BEx9q6Siks1kgWC7z8xFkJFHl+CvJGH Bep40tDIBsQTZPdEA6HmpkOZJVeWCVZAn5oauipaeEBesZoaiSmuV2cYAlEo1AuU0Xw== X-Received: by 2002:a50:b2e1:: with SMTP id p88-v6mr10548163edd.297.1529313510419; Mon, 18 Jun 2018 02:18:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJynou5bLWbeAxychkNnd39hNEnyDlIhrfeUWbKefdYBC5CjWG7K0QyhPyQCEVqUwx4VVCZ X-Received: by 2002:a50:b2e1:: with SMTP id p88-v6mr10548109edd.297.1529313508951; Mon, 18 Jun 2018 02:18:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529313508; cv=none; d=google.com; s=arc-20160816; b=MMFWreoprrM88wYYMD/22nQtGkaa4nZGBSgDmTh5EG3fIdh96bePKOfgTYKf4TnvlR x5UFH4vZZ2cGkxE3Ee2qrJYTa6jbQ1H9Skn93Bj2XjH3Int2AdzM2aoaccm4yTfPNH6f /2brvFwlhwnPdetgUt2FqiWdnDU93aYrGTU635qkbyQlxtRDIMMgNJRsS6Uh16tAKxNy 1wFILye0fV8A8IdV/6ETQ5rPAQ2BCMS/W/tH1IAzK3aXDwsIZJT/eitvEne5h2h/uiYm Tu4D82sui0Qp27ETxeITqiAOisjouPFNhhlwAOZZQsXKqC+/3K7sBlY6wCvIIxg+3C7p JXJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=fp6+t6mBoBDIs63II/jtj9NitcOikokCQoqwqYQKgb8=; b=QBK3WFdMOUNWGq7RNSiFsAF1YeYCtJo8valLLd+7HnFbprnF3B1Cnv2rTzXUtwI0YG gzjKdqhphiFqMJE1dq6AsSg1VnPX6LwDmlQkut7zXP8LB0nMiOywgRwNYIY28gPUJ/nW ySZiM5Xgni7sfibxa4ivlr01tezw4/DKn539MoIu4MDookLwB3JRIL1/84U3JZGsS9tI E6qTLsjKqIWqgCdAZ/2v39p7y7+XRun2Rty30mBA7hAYYRxY9L61f9vU8vT57bKQEGcZ 6unizOPbJ5IgbweCPwSIPIiYvc4Th72zBAQTyIJ8RfiwK/z+H3PZ3c4EHsRrA5CvMsYu kemg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz Received: from mx2.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id f16-v6si5785357ede.13.2018.06.18.02.18.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 18 Jun 2018 02:18:28 -0700 (PDT) Received-SPF: pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E829FAE14; Mon, 18 Jun 2018 09:18:27 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin , Michal Hocko , Johannes Weiner , linux-api@vger.kernel.org, Christoph Lameter , David Rientjes , Mel Gorman , Matthew Wilcox , Vlastimil Babka Subject: [PATCH v2 7/7] mm, slab: shorten kmalloc cache names for large sizes Date: Mon, 18 Jun 2018 11:18:08 +0200 Message-Id: <20180618091808.4419-8-vbabka@suse.cz> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618091808.4419-1-vbabka@suse.cz> References: <20180618091808.4419-1-vbabka@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Kmalloc cache names can get quite long for large object sizes, when the sizes are expressed in bytes. Use 'k' and 'M' prefixes to make the names as short as possible e.g. in /proc/slabinfo. This works, as we mostly use power-of-two sizes, with exceptions only below 1k. Example: 'kmalloc-4194304' becomes 'kmalloc-4M' Suggested-by: Matthew Wilcox Signed-off-by: Vlastimil Babka --- mm/slab_common.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 8a30d6979936..462509978ec0 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1045,15 +1045,15 @@ const struct kmalloc_info_struct kmalloc_info[] __initconst = { {"kmalloc-16", 16}, {"kmalloc-32", 32}, {"kmalloc-64", 64}, {"kmalloc-128", 128}, {"kmalloc-256", 256}, {"kmalloc-512", 512}, - {"kmalloc-1024", 1024}, {"kmalloc-2048", 2048}, - {"kmalloc-4096", 4096}, {"kmalloc-8192", 8192}, - {"kmalloc-16384", 16384}, {"kmalloc-32768", 32768}, - {"kmalloc-65536", 65536}, {"kmalloc-131072", 131072}, - {"kmalloc-262144", 262144}, {"kmalloc-524288", 524288}, - {"kmalloc-1048576", 1048576}, {"kmalloc-2097152", 2097152}, - {"kmalloc-4194304", 4194304}, {"kmalloc-8388608", 8388608}, - {"kmalloc-16777216", 16777216}, {"kmalloc-33554432", 33554432}, - {"kmalloc-67108864", 67108864} + {"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} }; /* @@ -1103,6 +1103,21 @@ 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) { @@ -1110,7 +1125,7 @@ new_kmalloc_cache(int idx, int type, slab_flags_t flags) if (type == KMALLOC_RECLAIM) { flags |= SLAB_RECLAIM_ACCOUNT; - name = kasprintf(GFP_NOWAIT, "kmalloc-rcl-%u", + name = kmalloc_cache_name("kmalloc-rcl", kmalloc_info[idx].size); BUG_ON(!name); } else { @@ -1159,8 +1174,7 @@ void __init create_kmalloc_caches(slab_flags_t flags) if (s) { unsigned int size = kmalloc_size(i); - char *n = kasprintf(GFP_NOWAIT, - "dma-kmalloc-%u", size); + const char *n = kmalloc_cache_name("dma-kmalloc", size); BUG_ON(!n); kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(