Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp150904imw; Wed, 13 Jul 2022 21:36:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ugC958bZliF0rKnwIgoBO4PBgUM3BBzKV1OsEjUV9YMbUm+r+4zzgoMlnm5a3jmBxakKxh X-Received: by 2002:a05:6402:5189:b0:43a:c55c:cf00 with SMTP id q9-20020a056402518900b0043ac55ccf00mr9765159edd.390.1657773406857; Wed, 13 Jul 2022 21:36:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657773406; cv=none; d=google.com; s=arc-20160816; b=AsUBbOr0dc8jqeuiQASb1LbRenLX2EwTCBzvPAZWInWQ1zvuIjpCNQ9Aup+XneeV3m eCX3RbeWWEbR/YG7GbgmDgBOgOw0Zd8eklauntaYzy3c4VBe4bxsvLf8KY9zfXByVnKQ KHRR/BHcMwEbjkWkpFtn+OPhhi3LQ966xIsJhYQnrsW6NcHis+FCh1mXq6tcl78sURLw 7b8MnIkHfGG+rngk/3pYxtJPL6uJNQCCMSDYotMqpTmuSf6TZx1TyY3f5us8dw+v5y0/ T4FHHkR41veub5atI/tM+kEMvwSjuPlZ4qh4ZxSFP1MNCS+k2VVcr5gQ1xQYRC1AUhh+ mQkA== 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 :dkim-signature; bh=CM1fnHF5+SZu84iYIKJ8/xtAtt5Of29zh4flgmzpzHg=; b=MmASWohXgG7EWV7DOb/FVMTnGaca3L0oO9Ln0QcbILfHSd9cIl+72mwXFqykG5aX8R edIs3eCz7mKKDFN+KA7/XCwbPQ8EnKAIBhchvjvsDx5akCRIaiilcXQghqcq+FoGlzgY i6o702E8sYDadlUL0F0WgXEO9zcHkKGOzK6Ky3utqnG1O4k0fRG+ZSUkngThgZGRSqL1 zE89B60ki6wkAectgI5G5k3VghFYxCN3ofSATTRaL+cja2xts5n/TeNoztqWee5H5Vzg r0MlMJ8cA7Nfx/XPy8AX7UxA8bRqRNQCENwnm58XoCp74jyHx9iifWoEByam0EqZst7E jLzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=BwviJmTV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e41-20020a056402332900b0043a86563d91si852017eda.39.2022.07.13.21.36.21; Wed, 13 Jul 2022 21:36:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=BwviJmTV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235858AbiGNE3b (ORCPT + 99 others); Thu, 14 Jul 2022 00:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236288AbiGNE2C (ORCPT ); Thu, 14 Jul 2022 00:28:02 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7CFE2FFC7 for ; Wed, 13 Jul 2022 21:24:36 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1657772675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CM1fnHF5+SZu84iYIKJ8/xtAtt5Of29zh4flgmzpzHg=; b=BwviJmTV1NrutOKVW7t2ZR6/VQYai6/hAH0p6/moeb7eViAcHkhWJ74cRMf/BH6aWMBfOt JTXER4Pykc+d0ZrjjBIFmZ9MbvYJR0obkimJH7iVtGyJTVv3Re+3nv86VDVzq29/4mFDg3 m+chYuz91PWa0PJiptIsKIaUEdj78/w= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [mm-unstable PATCH v7 1/8] mm/hugetlb: check gigantic_page_runtime_supported() in return_unused_surplus_pages() Date: Thu, 14 Jul 2022 13:24:13 +0900 Message-Id: <20220714042420.1847125-2-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naoya Horiguchi I found a weird state of 1GB hugepage pool, caused by the following procedure: - run a process reserving all free 1GB hugepages, - shrink free 1GB hugepage pool to zero (i.e. writing 0 to /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages), then - kill the reserving process. , then all the hugepages are free *and* surplus at the same time. $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages 3 $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/free_hugepages 3 $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/resv_hugepages 0 $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/surplus_hugepages 3 This state is resolved by reserving and allocating the pages then freeing them again, so this seems not to result in serious problem. But it's a little surprising (shrinking pool suddenly fails). This behavior is caused by hstate_is_gigantic() check in return_unused_surplus_pages(). This was introduced so long ago in 2008 by commit aa888a74977a ("hugetlb: support larger than MAX_ORDER"), and at that time the gigantic pages were not supposed to be allocated/freed at run-time. Now kernel can support runtime allocation/free, so let's check gigantic_page_runtime_supported() together. Signed-off-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- v4 -> v5: - drop additional gigantic_page_runtime_supported() checks. v2 -> v3: - Fixed typo in patch description, - add !gigantic_page_runtime_supported() check instead of removing hstate_is_gigantic() check (suggested by Miaohe and Muchun) - add a few more !gigantic_page_runtime_supported() check in set_max_huge_pages() (by Mike). --- mm/hugetlb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a4506ed1f1db..cf8ccee7654c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2432,8 +2432,7 @@ static void return_unused_surplus_pages(struct hstate *h, /* Uncommit the reservation */ h->resv_huge_pages -= unused_resv_pages; - /* Cannot return gigantic pages currently */ - if (hstate_is_gigantic(h)) + if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) goto out; /* -- 2.25.1