From patchwork Tue Jul 31 09:06:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10550497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD6B6139A for ; Tue, 31 Jul 2018 09:07:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAE9129FB4 for ; Tue, 31 Jul 2018 09:07:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEBB12A206; Tue, 31 Jul 2018 09:07:26 +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 965AE29FB4 for ; Tue, 31 Jul 2018 09:07:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 146BA6B026A; Tue, 31 Jul 2018 05:07:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 09F6E6B026E; Tue, 31 Jul 2018 05:07:04 -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 CFABD6B026F; Tue, 31 Jul 2018 05:07:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 7D45D6B026B for ; Tue, 31 Jul 2018 05:07:04 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id u4-v6so9054741pgr.2 for ; Tue, 31 Jul 2018 02:07:04 -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=LzPHsjWwFDpL1zC34y1Rxpr3uNE34eqWyprZiH7q9xI=; b=A9fvlGmCfEcC4pml8Rtx8t9rNsHCoVxBJLlbj0DDiagY6bO58ixqcw/KR9/Jg7uL5K AxRDnbiZEaVZg8ayfD+LAF6nYYEEcR5IeNUyCZ0FX+AohuD55qEdp+0Vt0RT1p9VoMf/ HLKkCSVQ0+qdUm7yNMPw4NQtO2GHNWHiccAi0MSdIEQTsQKEFveggQR1i5yTFZ1vuoxH 1FBeEFBrkpj4NHO4PwJUwuXWDKJ75qZcoLdkIdObUXhneOeFGN0v9IJ0AOTb2ammzhKz FsVLKWbj0QE1sj34cYhwcpxbHD+VQJ+o/W85ay+S67ZQDaPbBymkLaZefjNqmST+J8Rw 4BLA== 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: AOUpUlEqhSggPx0Rj3p5hdFIttC3028jctj2XY+GesIz5ahcgbcdI6RS /gz78QQnb+yckL277Czb/VzxN7Uo2oshJ18LfyZKCdAOYy6mG/wGwOM67LqX/Yj/jUbIzFeKdeX 5YbpyNYq/+O5Vmb64vZP0sfbOivC+rfYgkiAIX4ezwagcLqay/jON7tKfwcKd20P4BQ== X-Received: by 2002:a62:98d6:: with SMTP id d83-v6mr21612196pfk.186.1533028024200; Tue, 31 Jul 2018 02:07:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd7XDJyDIdKVoA+sAG3eUWonIjhOAdHf+4a3bBlv9sLuIgsgkoEDzXMTeNxtim+O0TyOV5D X-Received: by 2002:a62:98d6:: with SMTP id d83-v6mr21612139pfk.186.1533028023390; Tue, 31 Jul 2018 02:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533028023; cv=none; d=google.com; s=arc-20160816; b=i4RFZX4TI+pY0EkA5zl7X6GDpgo4w/0+x2hRmuxRIU5Wtboewk8f2Mkg1/MS+huAhg z+O7dK7c7p315O+QiSZPtOYsnxgat6/ov1r0Xc86h5UQG4E/LlYYhU0Y0Huapgc1O9NC QUDi9T2KcMIm3ABSW/OqfAZcP1aQuY1z2qU0j5G74kfLjAXlKF7tI0I6LhbskcAfx33N ssQ1H/gfPPpYKX9Rqfm35EW+euD30Q+cd7V6Ow7PFC6GhbBL4dI9CMmbY3bSUU0IZF5w XbJEk9vSr7oDJY7zAaDUaxTNVI0cx4taBNZ7Mzovxl4E3hZx3rqaTEzwyZJK+oOAOKa7 eX4w== 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=LzPHsjWwFDpL1zC34y1Rxpr3uNE34eqWyprZiH7q9xI=; b=ET7Z/25jzSMG5paAvSuijezfvR4+3R6N1PGJO9EroaC2+yqEmrEBTI2J9n/eRyYQrn /66IhNBWIS0KZVRHca/5R2OcJsZ872nbOlFwrML9SDgfvggup3O9AL4I3VCVTwhgA/uU cRnaWN8JbYjmG/FWPoOZxSEF/B0qLmiReO0LqN8/LqEbu+HNi6nrlqYjZvHZBpyRORtf DrNpQpa1fYzM8L0VMSsz0+mRUEpux0BXuKvcI55daWPBCDuqe7rYMIpkwpLUJRZbn95R 3MS7U6NAgfBgwLvqtDa6e8qbMtvCQVZkC3813Z7HYn38ysVKZuT+4XewcaNbSRfS6VaL DNhg== 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 mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id m11-v6si6161325pgk.468.2018.07.31.02.07.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Jul 2018 02:07:03 -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 relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 99E36AECB; Tue, 31 Jul 2018 09:06:58 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Roman Gushchin , Michal Hocko , Johannes Weiner , Christoph Lameter , David Rientjes , Joonsoo Kim , Mel Gorman , Matthew Wilcox , Vlastimil Babka Subject: [PATCH v4 6/6] mm, slab: shorten kmalloc cache names for large sizes Date: Tue, 31 Jul 2018 11:06:49 +0200 Message-Id: <20180731090649.16028-7-vbabka@suse.cz> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180731090649.16028-1-vbabka@suse.cz> References: <20180731090649.16028-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 Acked-by: Mel Gorman Acked-by: Christoph Lameter Acked-by: Roman Gushchin --- 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 03f40b273ea3..a07fcb2551f6 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1050,15 +1050,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} }; /* @@ -1108,6 +1108,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) { @@ -1115,7 +1130,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 { @@ -1164,8 +1179,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(