From patchwork Thu Jul 21 13:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12925109 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 100C3CCA479 for ; Thu, 21 Jul 2022 13:17:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCE218E0001; Thu, 21 Jul 2022 09:16:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C414F8E000F; Thu, 21 Jul 2022 09:16:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0D8C8E0001; Thu, 21 Jul 2022 09:16:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7E9518E000D for ; Thu, 21 Jul 2022 09:16:55 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6100B4098E for ; Thu, 21 Jul 2022 13:16:55 +0000 (UTC) X-FDA: 79711157190.08.E046371 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf13.hostedemail.com (Postfix) with ESMTP id 0CE99200A9 for ; Thu, 21 Jul 2022 13:16:53 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LpY2h2cDfzmV8l; Thu, 21 Jul 2022 21:15:08 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 21 Jul 2022 21:16:51 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH 5/5] hugetlbfs: fix confusing hugetlbfs stat Date: Thu, 21 Jul 2022 21:16:37 +0800 Message-ID: <20220721131637.6306-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220721131637.6306-1-linmiaohe@huawei.com> References: <20220721131637.6306-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658409414; 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; bh=JYFjDUxI/AUexedIePppUKUCucA973bePWmAT+ANa34=; b=WbWTjKL5L0TzunzQ56sJv9L0pAmh1t8vvexkALS7wm5mC4DqUE+e6pH43YhHquhoPlpLvO MAd3jhN/OSnG5mlTej8bjUd3xHdaoO94ruCSKR7kdKAPKb2NS9JxXzyGiipHbptDzOGyl5 O9VuT9y1au/fRLauru/S+a4pWO0J7as= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658409414; a=rsa-sha256; cv=none; b=LxQZNGR+c0/bSrIl9ab0IMDUyduuJWLLhdZsavNU01tZ/utc+ZjlCiVv4z8bpY5OE3BC7L qztf6jgIGvmizazHhPbkMdAlkgTRwV3y2Ibgzv3IMuP6mt5kA4cYNI5Hbal6IppPfYa3b+ sRuByns2Zuck8Pu+Knm/Avz2BE0xqKM= X-Rspamd-Queue-Id: 0CE99200A9 Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 8horacogp78h8g95y59wraqd4hzuw86o X-HE-Tag: 1658409413-756535 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: When size option is not specified, f_blocks, f_bavail and f_bfree will be set to -1 instead of 0. Likewise, when nr_inodes is not specified, f_files and f_ffree will be set to -1 too. Check max_hpages and max_inodes against -1 first to make sure 0 is reported for max/free/used when no limit is set as the comment states. Signed-off-by: Miaohe Lin --- fs/hugetlbfs/inode.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 19fc62a9c2fe..44da9828e171 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1083,16 +1083,20 @@ static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf) /* If no limits set, just report 0 for max/free/used * blocks, like simple_statfs() */ if (sbinfo->spool) { - long free_pages; - spin_lock_irq(&sbinfo->spool->lock); - buf->f_blocks = sbinfo->spool->max_hpages; - free_pages = sbinfo->spool->max_hpages - - sbinfo->spool->used_hpages; - buf->f_bavail = buf->f_bfree = free_pages; + if (sbinfo->spool->max_hpages != -1) { + long free_pages; + + buf->f_blocks = sbinfo->spool->max_hpages; + free_pages = sbinfo->spool->max_hpages + - sbinfo->spool->used_hpages; + buf->f_bavail = buf->f_bfree = free_pages; + } spin_unlock_irq(&sbinfo->spool->lock); - buf->f_files = sbinfo->max_inodes; - buf->f_ffree = sbinfo->free_inodes; + if (sbinfo->max_inodes != -1) { + buf->f_files = sbinfo->max_inodes; + buf->f_ffree = sbinfo->free_inodes; + } } spin_unlock(&sbinfo->stat_lock); }