From patchwork Tue Oct 24 13:45:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13434529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0DCDC25B6C for ; Tue, 24 Oct 2023 13:46:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FE8B6B0254; Tue, 24 Oct 2023 09:46:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 686846B0255; Tue, 24 Oct 2023 09:46:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D9ED6B0256; Tue, 24 Oct 2023 09:46:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2C9DB6B0254 for ; Tue, 24 Oct 2023 09:46:47 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ED76012030D for ; Tue, 24 Oct 2023 13:46:46 +0000 (UTC) X-FDA: 81380480412.16.A4FBC14 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf02.hostedemail.com (Postfix) with ESMTP id F3A3080019 for ; Tue, 24 Oct 2023 13:46:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gtCqJx+B; spf=pass (imf02.hostedemail.com: domain of 3w8o3ZQYKCGgYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3w8o3ZQYKCGgYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698155205; a=rsa-sha256; cv=none; b=EszlQ6d33kGo6AyjhgqG1HADAuHDALSqsmY1U/SAOwF1B5s8Iwh1zbJPoKmjBOtZ8H8bu6 9G8hQgYyhfEGQISaFOHuKwUbal7h+TiYxV1rKi2YaVp0pu8XYMTe4hNMjP7/k5r7JYKFGv FSk4rL96ZHzCLhTTiVu9tkDMX34ujeY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gtCqJx+B; spf=pass (imf02.hostedemail.com: domain of 3w8o3ZQYKCGgYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3w8o3ZQYKCGgYaXKTHMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698155205; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C4ig+ghmPhQV+NN9gQrUnAhQK6p3EzwOX4/nD/QGc34=; b=2gAgbeehXEDG0+QVpMqNcGCsMFRxyxpkv7bMnk4r9eYXIppQEwmWBLtBjS2qSKCgI7EQtT xfiYOL1e7UOe+hJuahKRojktOc1DvkyqFwoqnSp4iNipwwJ3B2fvb5e8O4Kjpj/xL9rwyQ lYpnwinRtpi26sSUt76ay8UkVCeCsiI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5a7af69a4baso59606037b3.0 for ; Tue, 24 Oct 2023 06:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698155204; x=1698760004; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=C4ig+ghmPhQV+NN9gQrUnAhQK6p3EzwOX4/nD/QGc34=; b=gtCqJx+B5A4SJHkuOTdOV6ver2DjCd0oTV6rOa/47rJswVqnGEGNUpOfe7ylsFZLb1 mWn+rGndFCrlNSbrmh8K4G7FMW4lOsxoJTFQHvy7ink2hc/3cdDpAnbXEKhnKVziJNlQ MIShsj03vBDO8rKcr8zFCGJdeRIyXJ6JUnvSe4ROg2bHTG+gcmyR+yu1Tet5nqr79Rdr RGlU2yg05HEfQqPuyxeZe0gO1lk56wGMPbOAVhZZ2qkk8mTD0oZRpDGjftxB2l8gLhC2 gb2jycYNWC6f/i5WpswqdM4mcxiW44XZy/hB4cGXF7RkAN+Xkk8vbhFRmfeqVJXt2l05 8kRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698155204; x=1698760004; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=C4ig+ghmPhQV+NN9gQrUnAhQK6p3EzwOX4/nD/QGc34=; b=jp4ABf7w37M3FDeJqm2HVRNVlDhkg9Xu0KrCYwWkbwMkoaz8VJe7/4INVf8rOJXeRD BXlKw/x1KtYiS2BPfnOCogmOVjcNLO0U0MItZx4p5Jvs0ZybQ7F7op0vXy3we+fTJR5S u4jkAehUrMzI5iwxqkFYZRrrU8nyLZsbOZ7FfiyrN10fN5z/bXp42XyS2w+o5AKttW/j Bupniyj3BJsiDnjeZlm7JthQ7RXUPOV+yNldMOFhfztTH4bjd4mo2nj5uc2oROFG4CQM 2IAPw3pSIMOCTSvbPk5JPE4825WHwccGIWWNGbkbDk2xDwdKjCNc/d/RidpOTa0bYMCa j3GQ== X-Gm-Message-State: AOJu0YwYduJJOV7fhxD5hMKJgMEYfUDz0aDnr207n50ZeVeaXTuxO+OG Eu4l3txQMxkrbai2KpDe+bIXK2/eCPk= X-Google-Smtp-Source: AGHT+IH/oTVJ1Mu9lou4puXON+M9/Y6l8UTmlhuGUIs6R4EkfIBTFxk7sH9NDcndoJzEgmocQcXHiryGytM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:45ba:3318:d7a5:336a]) (user=surenb job=sendgmr) by 2002:a25:d7d8:0:b0:d9a:da03:97e8 with SMTP id o207-20020a25d7d8000000b00d9ada0397e8mr212597ybg.2.1698155203948; Tue, 24 Oct 2023 06:46:43 -0700 (PDT) Date: Tue, 24 Oct 2023 06:45:58 -0700 In-Reply-To: <20231024134637.3120277-1-surenb@google.com> Mime-Version: 1.0 References: <20231024134637.3120277-1-surenb@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024134637.3120277-2-surenb@google.com> Subject: [PATCH v2 01/39] lib/string_helpers: Add flags param to string_get_size() From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, ldufour@linux.ibm.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org, Andy Shevchenko , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , "Michael S. Tsirkin" , Jason Wang , " =?utf-8?q?Noralf_Tr=C3=B8nnes?= " X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: F3A3080019 X-Stat-Signature: b48hfa7mw9gqkzznyu87cw7tpm1uyqim X-Rspam-User: X-HE-Tag: 1698155204-97687 X-HE-Meta: U2FsdGVkX18xh6VGze4nwfxIJVxnnKwyFRLVWs1urpB6vN/rcScb7Nl755PTQ8tPIsS84I3/ttBWUjiCeSNOIP4xLN2uRGZyBbges1XNKty42VXCGIogivuML8Zph1/eeMUnQXz2kgzRY5nvyHy6xKPk3XY5nqFS4eAYPBveUMljuOXNzwM0gnUdNBxOEl66c8yr3wnW3dgfsdYxYcNznsHEhNiHczTypkKe7fTeMlpfxM9wwPcWKhElIuirr7OANlPOUYaVaexRnNF6VxXUjx3d6OH7dAMtVNPL7oNKnrn59B+ENpN8OoQP9xvn01uvWjHZ+/bEgE6+zhnl9KphmCMUVf3rC2FaO402kZSXsfAHnv08MhHpPzgnjRm3wpcdK8/R5p6BFpVcm41LbD3LuUNEviY5+zAaWU6ot/3xnGiyM/bzS15sYkJR2TgO5jA8+diWDMe2VijFfuQHEBTeZ7C+FsgMMCsd4l2rSHZEqIYKIJtcoUzu7d97XLm1DWWfsvQGkm3VewQ6zhXRjmA+esIj/NTYtpK2cUozkYonlbpbEVwBiGJSFjbgU2xJKVKqQCWAgK22PJXTZOztUO+qYqE5M8tpqC/SuNzTBpAtcV2SrbeHzr6C3ZchGDE9SrP7yXIjjc3KHwKmhyqjjuAP7ErO1K31jaDQwF2k+PXw6Pg/RWsA5Qbw8g4MxAqs7MC0SU7oI9noT8TcKI1ATaHxsXUrvniBOELNVflp10YBA5mKgxWEWwlkgHBW/R2cApzYGOMo8Es7Kv+GzpnbolgeTrvTuIrXIYsNeYSDyp1kawsdXMTJRv8nXLUBhEOe9gO7e7uAHXeGBpqjXU3WwoYt87VpQuwIQeg45aUVexjq0/9vOC/ZI3yREHD9/8cCnKqK2hU+Tyu+zA+mWvGrqMOtXASEPTXj52roxG9fZWiFqWHEsZnStkuY/5G9xR7rZ4/WU8LFrRiArTuJ3wnCv3X uF8KNk6G iFLBe96fBeoDFMYUGJN3SLt2LhwEa0HOFN+ahXaBUXW2oQ3wqJzBWt7clF9mPabUDPE12Yr0wGVu10k7EyIrBmv6V4wY29x1ZP4Fw3WTDSUaaT5OokaPhLwzkSg9HW5AnHQKKas9yGwmhQUK9zYOstDAz1wyMjN8G4IhpSl6/eA/nnfpbiYu1OM7Gw8lKbbOZQVaaSQabD4SrvSWujmO5RZE82rUzZVfqL9sDK1CECSFu+JfFAq7OafTytY4EU/14DLGYjtbnx1BVgjh9lg+TzR9jPvzvojoKYBbi/TKGJzuPc4nSQvey7ifSdyfbkQRYj2PGEV+4OxMjVNRIe0l9rGGo0K4sTcwMiDSh+FZXpcEiqE34I9uuigt9JR5vkitEhhWytdM4awYeHjlI6f6OM99cv84Zmj9p96TjU+tIF2iaakTybH0xrzoFDNvKJvY4PnyxzBXAkyeCmRg9T4FQIa7pN/igBcioGdUygJThCstpHquQtis9oLyREjTvCpORCAWIGXGgiXySzyYeaxH60DTfDh4LlGKWh9oWAiRCAEukQVGZJyQa3hc8FQAKRmqVV6wHSFM1jRreaGfPrWqn7vskeOOn2pc/oZHn+yoUyu+FBtrB1OLezT8i7rm/8FIkkplVr2WJ5T2WKFSM84irmWu10mNI3M2FOMvW6fgmY5T9w4lSRPR6dwUASLY0/KfRxk/VzXkHxKfsGrHbb0pWZdjzyzM7aiTbD5+lXDGYd/vNstWNxKqkL+TDC9aiLYUxBlP4qFG0VQOjS+/NyERQUJgmEEeBlHkE/9v/sVQZFuZwJ6n5IWI5CjM+hhJzxYpLrupiF5B2JGFTURzMish51DYE7hlJDrT1O8+JJ2xYqhVEkEIdm9w5AzKEP3ZlGhGqFSo9rEumpseQcoHW5Ts/MRZND1QR1cLdlroqthQhxhXsy4+ncHBIZmb3u8QQk6Qw2K7vD1Ys29sEy4W+ouO6Qwyv8QAj ZHdunwdb XdE1M+ElXCw= 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: List-Subscribe: List-Unsubscribe: From: Kent Overstreet The new flags parameter allows controlling - Whether or not the units suffix is separated by a space, for compatibility with sort -h - Whether or not to append a B suffix - we're not always printing bytes. Signed-off-by: Kent Overstreet Signed-off-by: Suren Baghdasaryan Cc: Andy Shevchenko Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: "Noralf Trønnes" Cc: Jens Axboe --- arch/powerpc/mm/book3s64/radix_pgtable.c | 2 +- drivers/block/virtio_blk.c | 4 ++-- drivers/gpu/drm/gud/gud_drv.c | 2 +- drivers/mmc/core/block.c | 4 ++-- drivers/mtd/spi-nor/debugfs.c | 6 ++--- .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 4 ++-- drivers/scsi/sd.c | 8 +++---- include/linux/string_helpers.h | 13 +++++----- lib/string_helpers.c | 24 +++++++++++++------ lib/test-string_helpers.c | 4 ++-- mm/hugetlb.c | 8 +++---- 11 files changed, 44 insertions(+), 35 deletions(-) diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c index c6a4ac766b2b..27aa5a083ff0 100644 --- a/arch/powerpc/mm/book3s64/radix_pgtable.c +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c @@ -260,7 +260,7 @@ print_mapping(unsigned long start, unsigned long end, unsigned long size, bool e if (end <= start) return; - string_get_size(size, 1, STRING_UNITS_2, buf, sizeof(buf)); + string_get_size(size, 1, STRING_SIZE_BASE2, buf, sizeof(buf)); pr_info("Mapped 0x%016lx-0x%016lx with %s pages%s\n", start, end, buf, exec ? " (exec)" : ""); diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 1fe011676d07..59140424d755 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -986,9 +986,9 @@ static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize) nblocks = DIV_ROUND_UP_ULL(capacity, queue_logical_block_size(q) >> 9); string_get_size(nblocks, queue_logical_block_size(q), - STRING_UNITS_2, cap_str_2, sizeof(cap_str_2)); + STRING_SIZE_BASE2, cap_str_2, sizeof(cap_str_2)); string_get_size(nblocks, queue_logical_block_size(q), - STRING_UNITS_10, cap_str_10, sizeof(cap_str_10)); + 0, cap_str_10, sizeof(cap_str_10)); dev_notice(&vdev->dev, "[%s] %s%llu %d-byte logical blocks (%s/%s)\n", diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c index 9d7bf8ee45f1..6b1748e1f666 100644 --- a/drivers/gpu/drm/gud/gud_drv.c +++ b/drivers/gpu/drm/gud/gud_drv.c @@ -329,7 +329,7 @@ static int gud_stats_debugfs(struct seq_file *m, void *data) struct gud_device *gdrm = to_gud_device(entry->dev); char buf[10]; - string_get_size(gdrm->bulk_len, 1, STRING_UNITS_2, buf, sizeof(buf)); + string_get_size(gdrm->bulk_len, 1, STRING_SIZE_BASE2, buf, sizeof(buf)); seq_printf(m, "Max buffer size: %s\n", buf); seq_printf(m, "Number of errors: %u\n", gdrm->stats_num_errors); diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 3a8f27c3e310..411dc8137f7c 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2511,7 +2511,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, blk_queue_write_cache(md->queue.queue, cache_enabled, fua_enabled); - string_get_size((u64)size, 512, STRING_UNITS_2, + string_get_size((u64)size, 512, STRING_SIZE_BASE2, cap_str, sizeof(cap_str)); pr_info("%s: %s %s %s%s\n", md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), @@ -2707,7 +2707,7 @@ static int mmc_blk_alloc_rpmb_part(struct mmc_card *card, list_add(&rpmb->node, &md->rpmbs); - string_get_size((u64)size, 512, STRING_UNITS_2, + string_get_size((u64)size, 512, STRING_SIZE_BASE2, cap_str, sizeof(cap_str)); pr_info("%s: %s %s %s, chardev (%d:%d)\n", diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c index 6e163cb5b478..a1b61938fee2 100644 --- a/drivers/mtd/spi-nor/debugfs.c +++ b/drivers/mtd/spi-nor/debugfs.c @@ -85,7 +85,7 @@ static int spi_nor_params_show(struct seq_file *s, void *data) seq_printf(s, "name\t\t%s\n", info->name); seq_printf(s, "id\t\t%*ph\n", SPI_NOR_MAX_ID_LEN, nor->id); - string_get_size(params->size, 1, STRING_UNITS_2, buf, sizeof(buf)); + string_get_size(params->size, 1, STRING_SIZE_BASE2, buf, sizeof(buf)); seq_printf(s, "size\t\t%s\n", buf); seq_printf(s, "write size\t%u\n", params->writesize); seq_printf(s, "page size\t%u\n", params->page_size); @@ -130,14 +130,14 @@ static int spi_nor_params_show(struct seq_file *s, void *data) struct spi_nor_erase_type *et = &erase_map->erase_type[i]; if (et->size) { - string_get_size(et->size, 1, STRING_UNITS_2, buf, + string_get_size(et->size, 1, STRING_SIZE_BASE2, buf, sizeof(buf)); seq_printf(s, " %02x (%s) [%d]\n", et->opcode, buf, i); } } if (!(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) { - string_get_size(params->size, 1, STRING_UNITS_2, buf, sizeof(buf)); + string_get_size(params->size, 1, STRING_SIZE_BASE2, buf, sizeof(buf)); seq_printf(s, " %02x (%s)\n", SPINOR_OP_CHIP_ERASE, buf); } diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c index 14e0d989c3ba..7d5fbebd36fc 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c @@ -3457,8 +3457,8 @@ static void mem_region_show(struct seq_file *seq, const char *name, { char buf[40]; - string_get_size((u64)to - from + 1, 1, STRING_UNITS_2, buf, - sizeof(buf)); + string_get_size((u64)to - from + 1, 1, STRING_SIZE_BASE2, + buf, sizeof(buf)); seq_printf(seq, "%-15s %#x-%#x [%s]\n", name, from, to, buf); } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 83b6a3f3863b..c37593f76b65 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2689,10 +2689,10 @@ sd_print_capacity(struct scsi_disk *sdkp, if (!sdkp->first_scan && old_capacity == sdkp->capacity) return; - string_get_size(sdkp->capacity, sector_size, - STRING_UNITS_2, cap_str_2, sizeof(cap_str_2)); - string_get_size(sdkp->capacity, sector_size, - STRING_UNITS_10, cap_str_10, sizeof(cap_str_10)); + string_get_size(sdkp->capacity, sector_size, STRING_SIZE_BASE2, + cap_str_2, sizeof(cap_str_2)); + string_get_size(sdkp->capacity, sector_size, 0, + cap_str_10, sizeof(cap_str_10)); sd_printk(KERN_NOTICE, sdkp, "%llu %d-byte logical blocks: (%s/%s)\n", diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 9d1f5bb74dd5..a54467d891db 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -17,15 +17,14 @@ static inline bool string_is_terminated(const char *s, int len) return memchr(s, '\0', len) ? true : false; } -/* Descriptions of the types of units to - * print in */ -enum string_size_units { - STRING_UNITS_10, /* use powers of 10^3 (standard SI) */ - STRING_UNITS_2, /* use binary powers of 2^10 */ +enum string_size_flags { + STRING_SIZE_BASE2 = (1 << 0), + STRING_SIZE_NOSPACE = (1 << 1), + STRING_SIZE_NOBYTES = (1 << 2), }; -void string_get_size(u64 size, u64 blk_size, enum string_size_units units, - char *buf, int len); +int string_get_size(u64 size, u64 blk_size, enum string_size_flags flags, + char *buf, int len); int parse_int_array_user(const char __user *from, size_t count, int **array); diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 9982344cca34..b1496499b113 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -19,11 +19,17 @@ #include #include +enum string_size_units { + STRING_UNITS_10, /* use powers of 10^3 (standard SI) */ + STRING_UNITS_2, /* use binary powers of 2^10 */ +}; + /** * string_get_size - get the size in the specified units * @size: The size to be converted in blocks * @blk_size: Size of the block (use 1 for size in bytes) - * @units: units to use (powers of 1000 or 1024) + * @flags: units to use (powers of 1000 or 1024), whether to include space + * separator * @buf: buffer to format to * @len: length of buffer * @@ -32,14 +38,16 @@ * at least 9 bytes and will always be zero terminated. * */ -void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, - char *buf, int len) +int string_get_size(u64 size, u64 blk_size, enum string_size_flags flags, + char *buf, int len) { + enum string_size_units units = flags & flags & STRING_SIZE_BASE2 + ? STRING_UNITS_2 : STRING_UNITS_10; static const char *const units_10[] = { - "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" + "", "k", "M", "G", "T", "P", "E", "Z", "Y" }; static const char *const units_2[] = { - "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" + "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" }; static const char *const *const units_str[] = { [STRING_UNITS_10] = units_10, @@ -126,8 +134,10 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, else unit = units_str[units][i]; - snprintf(buf, len, "%u%s %s", (u32)size, - tmp, unit); + return snprintf(buf, len, "%u%s%s%s%s", (u32)size, tmp, + (flags & STRING_SIZE_NOSPACE) ? "" : " ", + unit, + (flags & STRING_SIZE_NOBYTES) ? "" : "B"); } EXPORT_SYMBOL(string_get_size); diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 9a68849a5d55..0b01ffca96fb 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -507,8 +507,8 @@ static __init void __test_string_get_size(const u64 size, const u64 blk_size, char buf10[string_get_size_maxbuf]; char buf2[string_get_size_maxbuf]; - string_get_size(size, blk_size, STRING_UNITS_10, buf10, sizeof(buf10)); - string_get_size(size, blk_size, STRING_UNITS_2, buf2, sizeof(buf2)); + string_get_size(size, blk_size, 0, buf10, sizeof(buf10)); + string_get_size(size, blk_size, STRING_SIZE_BASE2, buf2, sizeof(buf2)); test_string_get_size_check("STRING_UNITS_10", exp_result10, buf10, size, blk_size); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 52d26072dfda..37f2148d3b9c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3228,7 +3228,7 @@ static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) if (i == h->max_huge_pages_node[nid]) return; - string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); + string_get_size(huge_page_size(h), 1, STRING_SIZE_BASE2, buf, 32); pr_warn("HugeTLB: allocating %u of page size %s failed node%d. Only allocated %lu hugepages.\n", h->max_huge_pages_node[nid], buf, nid, i); h->max_huge_pages -= (h->max_huge_pages_node[nid] - i); @@ -3290,7 +3290,7 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) if (i < h->max_huge_pages) { char buf[32]; - string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); + string_get_size(huge_page_size(h), 1, STRING_SIZE_BASE2, buf, 32); pr_warn("HugeTLB: allocating %lu of page size %s failed. Only allocated %lu hugepages.\n", h->max_huge_pages, buf, i); h->max_huge_pages = i; @@ -3336,7 +3336,7 @@ static void __init report_hugepages(void) for_each_hstate(h) { char buf[32]; - string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); + string_get_size(huge_page_size(h), 1, STRING_SIZE_BASE2, buf, 32); pr_info("HugeTLB: registered %s page size, pre-allocated %ld pages\n", buf, h->free_huge_pages); pr_info("HugeTLB: %d KiB vmemmap can be freed for a %s page\n", @@ -4227,7 +4227,7 @@ static int __init hugetlb_init(void) char buf[32]; string_get_size(huge_page_size(&default_hstate), - 1, STRING_UNITS_2, buf, 32); + 1, STRING_SIZE_BASE2, buf, 32); pr_warn("HugeTLB: Ignoring hugepages=%lu associated with %s page size\n", default_hstate.max_huge_pages, buf); pr_warn("HugeTLB: Using hugepages=%lu for number of default huge pages\n",