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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83188C433EF for ; Sat, 23 Jul 2022 02:56:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8834A6B0071; Fri, 22 Jul 2022 22:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 832616B0073; Fri, 22 Jul 2022 22:56:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7228D6B0074; Fri, 22 Jul 2022 22:56:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 60BB26B0071 for ; Fri, 22 Jul 2022 22:56:09 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EFC9C40EA5 for ; Sat, 23 Jul 2022 02:56:08 +0000 (UTC) X-FDA: 79716850416.18.735BAFF Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf11.hostedemail.com (Postfix) with ESMTP id E836B40017 for ; Sat, 23 Jul 2022 02:56:06 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LqW8908tszjWx1; Sat, 23 Jul 2022 10:53:13 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) 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; Sat, 23 Jul 2022 10:56:00 +0800 Subject: Re: [PATCH 5/5] hugetlbfs: fix confusing hugetlbfs stat To: Mike Kravetz CC: , , , References: <20220721131637.6306-1-linmiaohe@huawei.com> <20220721131637.6306-6-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: Date: Sat, 23 Jul 2022 10:56:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658544967; a=rsa-sha256; cv=none; b=WRWAmHsog74PEOQCwI04wMzxatLmu11si4P1GHshBKp9YlUaXB6gVWNIE/+wvpu7kNShLC TMa5eQDY2bCBhneF9LvzWdxhYSohVHFEmZGmgDmjwZ3dlnnJ5vHw2nNJl/vL5dFatCawpL QMX+FuwfyxKcvX/3ty1rXoD2Ux8QxbA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.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=1658544967; 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=c4jPplDkhrFdyRi1eUNiwITgkZ/erM7FZarPC7Ub84I=; b=yL24dsO8mzh1hgpckpUY0w+Z/dhBdIfe5c/CfGo7epwjC7GXlGr47NquXveg5R+QKckWuh MDWZQeTWGud59FzA8U5ZEioC8wJPleCqtXtSB+Bs3aeBD11VFYJiBmb1y7ox0TFXFj5WAP O0/BlbZIZNlvSGH8EZs6KXWbJvNbsCM= X-Rspamd-Server: rspam12 Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-Stat-Signature: rd6oftnbootnp4w6a8m5obq5k3yqrb6d X-Rspamd-Queue-Id: E836B40017 X-HE-Tag: 1658544966-61107 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: On 2022/7/23 6:55, Mike Kravetz wrote: > On 07/22/22 14:38, Miaohe Lin wrote: >> On 2022/7/22 8:28, Mike Kravetz wrote: >>> On 07/21/22 21:16, Miaohe Lin wrote: >>>> 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. >>> >>> Just curious, where are you seeing values reported as -1? The check >> >> From the standard statvfs() function. >> >>> for sbinfo->spool was supposed to handle these cases. Seems like it >> >> sbinfo->spool could be created when ctx->max_hpages == -1 while >> ctx->min_hpages != -1 in hugetlbfs_fill_super. >> >>> should handle the max_hpages == -1 case. But, it doesn't look like it >>> considers the max_inodes == -1 case. >>> >>> If I create/mount a hugetlb filesystem without specifying size or nr_inodes, >>> df seems to report zero instead of -1. >>> >>> Just want to understand the reasoning behind the change. > > Thanks for the additional information (and test program)! > >>>From the hugetlbfs documentation: > "If the ``size``, ``min_size`` or ``nr_inodes`` option is not provided on > command line then no limits are set." > > So, having those values set to -1 indicates there is no limit set. > > With this change, 0 is reported for the case where there is no limit set as > well as the case where the max value is 0. IMHO, 0 should not be a valid max value otherwise there will be no hugetlb pages to use. It should mean there's no limit. But maybe I'm wrong. > > There may be some value in reporting -1 as is done today. There still be a inconsistency: If the ``size`` and ``min_size`` isn't specified, then reported max value is 0. But if ``min_size`` is specified while ``size`` isn't specified, the reported max value is -1. > > To be honest, I am not sure what is the correct behavior here. Unless > there is a user visible issue/problem, I am hesitant to change. Other > opinions are welcome. Yes, it might be better to keep it as is. Maybe we could change the comment to reflect what the current behavior is like below? diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 44da9828e171..f03b1a019cc0 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1080,7 +1080,7 @@ static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf) buf->f_bsize = huge_page_size(h); if (sbinfo) { spin_lock(&sbinfo->stat_lock); - /* If no limits set, just report 0 for max/free/used + /* If no limits set, just report 0 or -1 for max/free/used * blocks, like simple_statfs() */ if (sbinfo->spool) { spin_lock_irq(&sbinfo->spool->lock); > No strong opinion to keep this patch or above change. Many thanks for your comment and reply. :)