Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp221772pxb; Sat, 10 Apr 2021 00:27:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9hvOkWvbwSvP7ZQZzSmnQKBZm/SW/D/UZmVdEQvo/i1vVFLIyKppfgMYhMxJeXm40Gbd5 X-Received: by 2002:a65:5088:: with SMTP id r8mr16528124pgp.434.1618039666069; Sat, 10 Apr 2021 00:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618039666; cv=none; d=google.com; s=arc-20160816; b=omF3xphLA5L/AYm33yXuGhGUs+MS+Rl/zjHDrEEeY2azlBMHWQ2C/kA6Afoq4zRz/2 jW9T9X+8XxGL3swyChBveY5Ek96SRovknCTKTUWblMM1Kqg99GFk/P/nkyDAycNTncST HAZgd8951cmYvcLbeqi7tvH73QnIs2+kHn5zncGixAHD5mWKM+GbA4fuoGomHJj17nfh WPOzYMMry7+wIpagwMA9TzI2wi8807mIgR8x3o/Ql/mRe5owq07FXkMkg8Wuar3MiRDP e3hiOhsGD68Y7KUYVz82Kyk8zsVkvNuUhWzCsPm8IVK1HZ+zca2PBflqdzR94FDpkG0G wyug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VyW7tSMFQ2ozhmaEHVRnQ1Tn5wdyNbh7DFPIGSdJfBI=; b=Q6ehcJ1yrnlNlrOwTLPosOnJerull2KqlZUs3/bM9SMMjsX+uwNuy6QYd0/fLLJ4R2 rvkEh4+nYjmwAM2BryH/v/vNRjS0g602rvzFi57j8KDL+2au4p5/XMvx1m+lj/U1spIa c9RoH6pkPUWhYXJI7Tp/+9/GWKoVP2l5aYkUeIpCKwATAXVqwWtS8PHZp3cxCqYx9mVb ckrcaPkkXJH0bh5ciAcWqXV0S/i0s38SmmXGyKZKhB+pCz3zJF6XG0izfZeb7+Quw21Y 2Ug3bsjNKBVdiE5/gClfbXitQE3arjEoggt4CSm2njdr/mvMAOaZu/tqOEHKX2lCk4xj Kmkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si6551988pgh.232.2021.04.10.00.27.34; Sat, 10 Apr 2021 00:27:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234513AbhDJHZJ (ORCPT + 99 others); Sat, 10 Apr 2021 03:25:09 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17306 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234432AbhDJHZD (ORCPT ); Sat, 10 Apr 2021 03:25:03 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FHRKQ2fRDz9xRP; Sat, 10 Apr 2021 15:22:34 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Sat, 10 Apr 2021 15:24:37 +0800 From: Miaohe Lin To: , CC: , , , Subject: [PATCH v2 3/5] mm/hugeltb: clarify (chg - freed) won't go negative in hugetlb_unreserve_pages() Date: Sat, 10 Apr 2021 03:23:46 -0400 Message-ID: <20210410072348.20437-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210410072348.20437-1-linmiaohe@huawei.com> References: <20210410072348.20437-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The resv_map could be NULL since this routine can be called in the evict inode path for all hugetlbfs inodes and we will have chg = 0 in this case. But (chg - freed) won't go negative as Mike pointed out: "If resv_map is NULL, then no hugetlb pages can be allocated/associated with the file. As a result, remove_inode_hugepages will never find any huge pages associated with the inode and the passed value 'freed' will always be zero." Add a comment clarifying this to make it clear and also avoid confusion. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9b4c05699a90..387c9a62615e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5435,6 +5435,9 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end, /* * If the subpool has a minimum size, the number of global * reservations to be released may be adjusted. + * + * Note that !resv_map implies freed == 0. So (chg - freed) + * won't go negative. */ gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed)); hugetlb_acct_memory(h, -gbl_reserve); -- 2.19.1