From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A5D2C433E0 for ; Fri, 22 May 2020 06:25:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 056A82072C for ; Fri, 22 May 2020 06:25:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="S48PXV5r" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 056A82072C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 147F380008; Fri, 22 May 2020 02:25:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F9FF80007; Fri, 22 May 2020 02:25:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F297A80008; Fri, 22 May 2020 02:25:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id DB59580007 for ; Fri, 22 May 2020 02:25:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A07414428 for ; Fri, 22 May 2020 06:25:38 +0000 (UTC) X-FDA: 76843368756.17.note54_6b705a8f1343f X-HE-Tag: note54_6b705a8f1343f X-Filterd-Recvd-Size: 4172 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 06:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: Content-Type:MIME-Version:Date:Message-ID:Subject:From:To:Sender:Reply-To:Cc: Content-ID:Content-Description:In-Reply-To:References; bh=QwhmqLhc+bv642fUxaOi43N+DIlQspHRNV2gxfTzFoU=; b=S48PXV5rOEPqzORBMrAaEfqt6d PqxUwtNVO/40WKGpTkyGtkQ+Lj9S4k+xeB5rdn6cVfd5kH1Jk4H5xwXh0Wdgu/Ivi4EXIlg2jLp33 402QXoz7zSrgn4jxyl1p0FBp8+0kYKNfo6aG2mCODLu+OVoM/p56MdhKEueTbjTTKABlG84RyxSuH YUOM0TchSmM9Br+gVK70GBYn6b+3qIfr7iD2hPEuRpB9TLxnWxMZjeyXT5Yo9QGggSrthxRCtsP9D 9ARPgcT565wEApcQ7QI5dO9Ve/HAlvV9tyjseoc9/Phum011rmIRlmc31XDFVbLrYWGCFQHMJnnf8 DTkUD0zQ==; Received: from [2601:1c0:6280:3f0::19c2] by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jc17d-00040o-CK; Fri, 22 May 2020 06:25:33 +0000 To: LKML , Linux MM , Al Viro , Andrew Morton , Hugh Dickins From: Randy Dunlap Subject: [PATCH] mm: swapfile: fix /proc/swaps heading and Size/Used/Priority alignment Message-ID: Date: Thu, 21 May 2020 23:25:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: From: Randy Dunlap Fix the heading and Size/Used/Priority field alignments in /proc/swaps. If the Size and/or Used value is >= 10000000 (8 bytes), then the alignment by using tab characters is broken. This patch maintains the use of tabs for alignment. If spaces are preferred, we can just use a Field Width specifier for the bytes and inuse fields. That way those fields don't have to be a multiple of 8 bytes in width. E.g., with a field width of 12, both Size and Used would always fit on the first line of an 80-column wide terminal (only Priority would be on the second line). There are actually 2 problems: heading alignment and field width. On an xterm, if Used is 7 bytes in length, the tab does nothing, and the display is like this, with no space/tab between the Used and Priority fields. (ugh) Filename Type Size Used Priority /dev/sda8 partition 16779260 2023012-1 To be clear, if one does 'cat /proc/swaps >/tmp/proc.swaps', it does look different, like so: Filename Type Size Used Priority /dev/sda8 partition 16779260 2086988 -1 Signed-off-by: Randy Dunlap Cc: Hugh Dickins Cc: linux-mm@kvack.org Cc: Alexander Viro Cc: Andrew Morton --- mm/swapfile.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- linux-next-20200521.orig/mm/swapfile.c +++ linux-next-20200521/mm/swapfile.c @@ -2753,20 +2753,24 @@ static int swap_show(struct seq_file *sw struct swap_info_struct *si = v; struct file *file; int len; + unsigned int bytes, inuse; if (si == SEQ_START_TOKEN) { - seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n"); + seq_puts(swap,"Filename\t\t\t\tType\t\tSize\t\tUsed\t\tPriority\n"); return 0; } + bytes = si->pages << (PAGE_SHIFT - 10); + inuse = si->inuse_pages << (PAGE_SHIFT - 10); + file = si->swap_file; len = seq_file_path(swap, file, " \t\n\\"); - seq_printf(swap, "%*s%s\t%u\t%u\t%d\n", + seq_printf(swap, "%*s%s\t%u\t%s%u\t%s%d\n", len < 40 ? 40 - len : 1, " ", S_ISBLK(file_inode(file)->i_mode) ? "partition" : "file\t", - si->pages << (PAGE_SHIFT - 10), - si->inuse_pages << (PAGE_SHIFT - 10), + bytes, bytes < 10000000 ? "\t" : "", + inuse, inuse < 10000000 ? "\t" : "", si->prio); return 0; }