Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp722384rdb; Fri, 1 Sep 2023 02:11:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhroDtIMhS6QPppX7heOkarE45IQG60RTtULofMvDxRmGd7Pev9fh0g5Ns8o5yWbkXkDe3 X-Received: by 2002:a17:902:ced0:b0:1bf:423:957b with SMTP id d16-20020a170902ced000b001bf0423957bmr2567642plg.26.1693559489418; Fri, 01 Sep 2023 02:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693559489; cv=none; d=google.com; s=arc-20160816; b=v7I0vjnEsWAI7+pjvT0vZyXfSQTt3iWSN09KIzqDGEYtzBfXoNx4E9HU/vEHcAFh5c rB58aA34LrTVcml1ejd3d2nbrLoVmst240qfuEmwzDG/GEThtOsv5IPM50kbTqKvuEN/ g+uUaCXRAxsRQR9DPWSst436xy7UEDQHpRROlcl9kVCpLqOKPfNgtRz71nTIW5qAsGLJ aKkO/535cqaP7T/HBtiAtCoxMHBrX0HSEyCynZXe4mcPrT/9i9XZs5MhDHwPS+6i78Ih NWuSPE9Jy7HzWCxA4kDI2k2Ev7WnRy84nUYfYiZ3P0RJdLqK1NOtelZho56uYuje8pJy cHaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=y40jtcZ2w+W7lOLGOXurSzzbDHItqZx40SUpe/qr848=; fh=EFdPVHkXE+ZApbrOC6MjoI5QNRxJE1QPzUeynh/SEMM=; b=fqKLed7ff/oCjnoXfjsui6WmxWW9VsXaL+H/0YJyY2uOasoQ+CUTZsdqXuptb210co sLHXB1/jyPFBU6brAn5y7GAVEsKr1v8fk9tEjBq59P7VW+5cs79M4ZH5y9SBHKRBc7+H Ti8u6lE5S/kO8FWZBb0nK24KJwxJyic9IxbFeP8crAbndR5q/NlESZa9MeiO+YMXAmxs tORN6voOXNaUNiPNQ58Lf0sph0Q5/8FXh8ciLLXFwaHht5LX0hVHq/zEFA+3uEr1mI1D 14+5p032dytHmuHGrd4c2m+fAiSISrbKmve+vG6ysIC1vDE0N/+pxfDIQFZJkx1yFjjL xQsQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a170902bf4300b001bf20c80680si2495097pls.92.2023.09.01.02.11.24; Fri, 01 Sep 2023 02:11:29 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343633AbjHaObC (ORCPT + 29 others); Thu, 31 Aug 2023 10:31:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbjHaObC (ORCPT ); Thu, 31 Aug 2023 10:31:02 -0400 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A3C4D7; Thu, 31 Aug 2023 07:30:57 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R721e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=liusong@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0VqySyaf_1693492251; Received: from 30.0.139.142(mailfrom:liusong@linux.alibaba.com fp:SMTPD_---0VqySyaf_1693492251) by smtp.aliyun-inc.com; Thu, 31 Aug 2023 22:30:52 +0800 Message-ID: Date: Thu, 31 Aug 2023 22:30:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH] mm/khugepaged: increase transparent_hugepage_recommend_disable parameter to disable active modification of min_free_kbytes To: Yang Shi Cc: corbet@lwn.net, akpm@linux-foundation.org, paulmck@kernel.org, rdunlap@infradead.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, rostedt@goodmis.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230817035155.84230-1-liusong@linux.alibaba.com> From: Liu Song In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 在 2023/8/30 04:04, Yang Shi 写道: > On Wed, Aug 16, 2023 at 8:52 PM Liu Song wrote: >> In the arm64 environment, when PAGESIZE is 4K, the "pageblock_nr_pages" >> value is 512, and the recommended min_free_kbytes in >> "set_recommended_min_free_kbytes" usually does not exceed 44MB. >> >> However, when PAGESIZE is 64K, the "pageblock_nr_pages" value is 8192, >> and the recommended min_free_kbytes in "set_recommended_min_free_kbytes" >> is 8192 * 2 * (2 + 9) * 64K, which directly increases to 11GB. >> >> According to this calculation method, due to the modification of min_free_kbytes, >> the reserved memory in my 128GB memory environment reaches 10GB, and MemAvailable >> is correspondingly reduced by 10GB. >> >> In the case of PAGESIZE 64K, transparent hugepages are 512MB, and we only >> need them to be used on demand. If transparent hugepages cannot be allocated, >> falling back to regular 64K pages is completely acceptable. >> >> Therefore, we added the transparent_hugepage_recommend_disable parameter >> to disable active modification of min_free_kbytes, thereby meeting our >> requirements for transparent hugepages in the 64K scenario, and it will >> not excessively reduce the available memory. > Thanks for debugging this. I agree 11GB for min_free_kbytes is too > much. But a kernel parameter sounds overkilling to me either. IMHO we > just need to have a better scaling for bigger base page size. For > example, we just keep one or two pageblock for min_free_kbytes when > the base page size is bigger than 4K. > Thank you very much for your advice, but how do we determine the number of pageblocks? This is a difficult number to determine. When PAGESIZE is 64K, arm64 supports hugepages of 2M, 512M, and 16G, which can meet the requirements of scenarios that require hugepages. However, transparent huge pages can only support 512M, and 512M is a very large number, so enabling transparent huge pages should be carefully considered, not to mention whether it makes sense to reserve such a large amount of memory. Therefore, I think that in the scenario of 64K PAGESIZE, it might also be a good choice to directly cancel set_recommended_min_free_kbytes? Thanks >> Signed-off-by: Liu Song >> --- >> .../admin-guide/kernel-parameters.txt | 5 +++++ >> mm/khugepaged.c | 20 ++++++++++++++++++- >> 2 files changed, 24 insertions(+), 1 deletion(-) >> >> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt >> index 654d0d921101..612bdf601cce 100644 >> --- a/Documentation/admin-guide/kernel-parameters.txt >> +++ b/Documentation/admin-guide/kernel-parameters.txt >> @@ -6553,6 +6553,11 @@ >> See Documentation/admin-guide/mm/transhuge.rst >> for more details. >> >> + transparent_hugepage_recommend_disable >> + [KNL,THP] >> + Can be used to disable transparent hugepage to actively modify >> + /proc/sys/vm/min_free_kbytes during enablement process. >> + >> trusted.source= [KEYS] >> Format: >> This parameter identifies the trust source as a backend >> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >> index 78fc1a24a1cc..ac40c618f4f6 100644 >> --- a/mm/khugepaged.c >> +++ b/mm/khugepaged.c >> @@ -88,6 +88,9 @@ static unsigned int khugepaged_max_ptes_none __read_mostly; >> static unsigned int khugepaged_max_ptes_swap __read_mostly; >> static unsigned int khugepaged_max_ptes_shared __read_mostly; >> >> +/* default enable recommended */ >> +static unsigned int transparent_hugepage_recommend __read_mostly = 1; >> + >> #define MM_SLOTS_HASH_BITS 10 >> static DEFINE_READ_MOSTLY_HASHTABLE(mm_slots_hash, MM_SLOTS_HASH_BITS); >> >> @@ -2561,6 +2564,11 @@ static void set_recommended_min_free_kbytes(void) >> goto update_wmarks; >> } >> >> + if (!transparent_hugepage_recommend) { >> + pr_info("do not allow to recommend modify min_free_kbytes\n"); >> + return; >> + } >> + >> for_each_populated_zone(zone) { >> /* >> * We don't need to worry about fragmentation of >> @@ -2591,7 +2599,10 @@ static void set_recommended_min_free_kbytes(void) >> >> if (recommended_min > min_free_kbytes) { >> if (user_min_free_kbytes >= 0) >> - pr_info("raising min_free_kbytes from %d to %lu to help transparent hugepage allocations\n", >> + pr_info("raising user specified min_free_kbytes from %d to %lu to help transparent hugepage allocations\n", >> + min_free_kbytes, recommended_min); >> + else >> + pr_info("raising default min_free_kbytes from %d to %lu to help transparent hugepage allocations\n", >> min_free_kbytes, recommended_min); >> >> min_free_kbytes = recommended_min; >> @@ -2601,6 +2612,13 @@ static void set_recommended_min_free_kbytes(void) >> setup_per_zone_wmarks(); >> } >> >> +static int __init setup_transparent_hugepage_recommend_disable(char *str) >> +{ >> + transparent_hugepage_recommend = 0; >> + return 1; >> +} >> +__setup("transparent_hugepage_recommend_disable", setup_transparent_hugepage_recommend_disable); >> + >> int start_stop_khugepaged(void) >> { >> int err = 0; >> -- >> 2.19.1.6.gb485710b >> >>