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 8A619C36010 for ; Mon, 7 Apr 2025 07:23:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1353280002; Mon, 7 Apr 2025 03:23:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC3C0280001; Mon, 7 Apr 2025 03:23:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98B70280002; Mon, 7 Apr 2025 03:23:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7AF65280001 for ; Mon, 7 Apr 2025 03:23:15 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 85B65160E6D for ; Mon, 7 Apr 2025 07:23:16 +0000 (UTC) X-FDA: 83306406792.27.175D62F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf01.hostedemail.com (Postfix) with ESMTP id 04BB540007 for ; Mon, 7 Apr 2025 07:23:13 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744010594; 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=AmBz2E0z9oFRdX+9XcsKDmVnvrG6OTxt8D+CKt7C+zM=; b=YWBpHoU2JBdpY7wgv6iAwfQsEJ6fsKR0IFOglae4lzmBtuLHMT/u8cM8YTa/pSnEFvp9Ro moqAcnwrAWaTcjA24oBJyWAq2rn0xJqKMr5I2ScFASrg0wHrvCrnovZRH5rKCZbSwZw1LX J2hn8gbxioVPo/D7eMZsEH3nhg34N/4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744010594; a=rsa-sha256; cv=none; b=r1DpEJLaDn7qww7wx+UeLLxmMqvh/kDH00iMu0c9JsLSfIto350iNw1FlqAPymRdoc1ier fXi1zamSbl94XlCH1kX5IW0kdcI+CL9v9u1RelEYqKEIpMV1XNzBDBBrXJOUNJObqjGvnU wLheS1fbIHAWEZTWQDznvo54KHtSyb0= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ZWLDX0fQXzvWtF; Mon, 7 Apr 2025 15:19:08 +0800 (CST) Received: from kwepemo200002.china.huawei.com (unknown [7.202.195.209]) by mail.maildlp.com (Postfix) with ESMTPS id 22E051800D9; Mon, 7 Apr 2025 15:23:10 +0800 (CST) Received: from [10.174.179.13] (10.174.179.13) by kwepemo200002.china.huawei.com (7.202.195.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 7 Apr 2025 15:23:09 +0800 Message-ID: <18dde837-3fb0-43b0-5d02-f78948d68d77@huawei.com> Date: Mon, 7 Apr 2025 15:23:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v2] mm/hugetlb: fix set_max_huge_pages() when there are surplus pages To: Oscar Salvador CC: , , , , References: <20250401082339.676723-1-tujinjiang@huawei.com> From: Jinjiang Tu In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.13] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemo200002.china.huawei.com (7.202.195.209) X-Rspamd-Server: rspam01 X-Stat-Signature: h1tzsau7s6pg7ihu95izkjbccgf7a3ga X-Rspam-User: X-Rspamd-Queue-Id: 04BB540007 X-HE-Tag: 1744010593-94647 X-HE-Meta: U2FsdGVkX19V6sHgU2DMzdapqQsUwjnQRuqcs+xDpQ82+vx4Tq4BFGLiAfLRvhOoQzVBrvjOK/mcp7PUfjefy5n5P/HtmzC+HQQ06VffKI1XZfULHJ2SCakryJtsxZEPpnX6M7XWBv/vyx0EUlhjvibHBCeT1I+heGvLS869tB1IqiVYwXsM3IXCEXWF8eernBt05XdtySs0L0LImCkbrIIFMbVD9Nf/3f2JXasSRZEnj9u1zlNWBp+jG9sBZ6LzQHlM9hV6XECtEfvuM9Ji9XJ8S247N0XIA2M9RiExt7doLQNBcaTm8SPPMv3fXInPg5HsKaLwrbq98hkdkSFK7vevLzjPhzUYd+TQ9BOTJ9Faqx/mVqrGDpRP7ukUYMVVxF3Mojg3P7dP9nxsuHPB7SdbfXEKpsqGiTym4td+liRsfVEzyDBX/ogqyzWximABZ5KVHVf8etrj7oKawl4aclbUdkT8C+0N2QR/KnZ3WZ8iPytiApQo8ybrypTuaLjpXvWN/6YjBJaoysSAxMHWgLlFAeH3mOrXHiYX4OEc3y6OBBTwlP3HRQgQ7KFmJ/1iLcy2nBJEG7hEYzVal3HDjiMx3gqM/yseUlySbJXF2eAP6/fqU/P12rrJA/Le6GM75kzdI8wfjj8rkklB25WxrseHzICt5T/f9fVdM8LRIM1R77fmIHuKhTGJQyGzWuaLJnJPSh8SsKeqgGuT7+I6iSNK8tBPOxVNBht1WZX2tgIgXavfts4gaYSacYAdMU8uVfQmGCaJVMxfBDk/nJU/cSUEmTYM7J6N7s/lJ8OxwmNRrrbWJvBQHVuf+ev8TTCPZdisuS4BrJb2N6b8+vGkVYwp1N6BMtiNmM3rf3cCIlQMuNDcJB0ZT7buzuu2/Ia08qZj9XypISel18f8K1tSMxHjLjch+RM/zC6dR+ZczUXclHuWioZowXM/FVTXZNcvbr1p+CJzaVnaEl5VAI/ p1ZwkM7t +G3QwmFw+AZh5kh9fL1fP/xfPa+TWCmKSKlanjJmVmbx3xFwyjsLvcgA+sFJsGvyVbeoKxUHVKSh/fcm04b7XPak0myXO/f8rULc7llhb0meotN3Gtw0L7PdRibeF3TfdnUrwGGvXhRVUVqBpxu3BrgCLeVxRb8hO1gdGjgXm9+9IqgB5ZYNTOLkjRWIJ58zgVRr7cLT+QSqumTM= 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: List-Subscribe: List-Unsubscribe: 在 2025/4/4 21:18, Oscar Salvador 写道: > On Thu, Apr 03, 2025 at 04:26:36PM +0200, Oscar Salvador wrote: >> Unfortunately, this will not fly. > I did not spend much time, but solving the problem of hvo free pages > becoming surplus not being accounted twice, should not the following > fix the entire problem? Sorry for late replay. > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 39f92aad7bd1..6e9534a825ed 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3825,6 +3825,7 @@ static int adjust_pool_surplus(struct hstate *h, nodemask_t *nodes_allowed, > static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, > nodemask_t *nodes_allowed) > { > + unsigned long substract; > unsigned long min_count; > unsigned long allocated; > struct folio *folio; > @@ -3960,7 +3961,12 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, > * and won't grow the pool anywhere else. Not until one of the > * sysctls are changed, or the surplus pages go out of use. > */ > - min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages; > + if (h->free_huge_pages > persistent_huge_pages(h)) > + substract = h->free_huge_pages - h->surplus_huge_pages; h->free_huge_pages may be less than h->surplus_huge_pages > + else > + h->free_huge_pages; > + > + min_count = h->resv_huge_pages + persistent_huge_pages(h) - substract; > min_count = max(count, min_count); > try_to_free_low(h, min_count, nodes_allowed); > I tries the following diff, and the problem is solved. diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 39f92aad7bd1..4afcd5ce417c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3826,6 +3826,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,                               nodemask_t *nodes_allowed)  {         unsigned long min_count; +       unsigned long persistent_free_count;         unsigned long allocated;         struct folio *folio;         LIST_HEAD(page_list); @@ -3960,7 +3961,14 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,          * and won't grow the pool anywhere else. Not until one of the          * sysctls are changed, or the surplus pages go out of use.          */ -       min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages; +       persistent_free_count = h->free_huge_pages; +       if (h->free_huge_pages > persistent_huge_pages(h)) { +               if (h->free_huge_pages > h->surplus_huge_pages) +                       persistent_free_count -= h->surplus_huge_pages; +               else +                       persistent_free_count = 0; +       } +       min_count = h->resv_huge_pages + persistent_huge_pages(h) - persistent_free_count;         min_count = max(count, min_count);         try_to_free_low(h, min_count, nodes_allowed); Thanks for reviewing.