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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0167FC433EF for ; Fri, 22 Jul 2022 06:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234286AbiGVGiT (ORCPT ); Fri, 22 Jul 2022 02:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbiGVGiR (ORCPT ); Fri, 22 Jul 2022 02:38:17 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 137BF15A3B for ; Thu, 21 Jul 2022 23:38:16 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Lq073327nz1M8KS; Fri, 22 Jul 2022 14:35:27 +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; Fri, 22 Jul 2022 14:38:13 +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: Fri, 22 Jul 2022 14:38:10 +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: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. I wrote a test program: #include #include int main(void) { struct statvfs buf; if (statvfs("/root/huge/", &buf) == -1) { printf("statvfs() error\n"); return -1; } printf("f_blocks %lld, f_bavail %lld, f_bfree %lld, f_files %lld, f_ffree %lld\n", buf.f_blocks, buf.f_bavail, buf.f_bfree, buf.f_files, buf.f_ffree); return 0; } And test it in my env: [root@localhost ~]# mount -t hugetlbfs none /root/huge/ [root@localhost ~]# ./stat f_blocks 0, f_bavail 0, f_bfree 0, f_files 0, f_ffree 0 [root@localhost ~]# umount /root/huge/ [root@localhost ~]# mount -t hugetlbfs -o min_size=32M none /root/huge/ [root@localhost ~]# ./stat f_blocks -1, f_bavail -1, f_bfree -1, f_files -1, f_ffree -1 [root@localhost ~]# umount /root/huge/ [root@localhost ~]# mount -t hugetlbfs -o min_size=32M,size=64M none /root/huge/ [root@localhost ~]# ./stat f_blocks 32, f_bavail 32, f_bfree 32, f_files -1, f_ffree -1 [root@localhost ~]# umount /root/huge/ [root@localhost ~]# mount -t hugetlbfs -o min_size=32M,size=64M,nr_inodes=1024 none /root/huge/ [root@localhost ~]# ./stat f_blocks 32, f_bavail 32, f_bfree 32, f_files 1024, f_ffree 1023 [root@localhost ~]# umount /root/huge/ Or am I miss something? > Thanks.