From patchwork Thu Aug 17 03:51:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Song X-Patchwork-Id: 13355941 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 AC80AC0015E for ; Thu, 17 Aug 2023 03:52:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14DF528002D; Wed, 16 Aug 2023 23:52:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FCE5280006; Wed, 16 Aug 2023 23:52:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F077228002D; Wed, 16 Aug 2023 23:52:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DD6E6280006 for ; Wed, 16 Aug 2023 23:52:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9CE25A0CA3 for ; Thu, 17 Aug 2023 03:52:52 +0000 (UTC) X-FDA: 81132225384.02.377B46D Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf03.hostedemail.com (Postfix) with ESMTP id 747052000B for ; Thu, 17 Aug 2023 03:52:49 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf03.hostedemail.com: domain of liusong@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=liusong@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692244371; a=rsa-sha256; cv=none; b=QssGS6UKIB9RzcVde0IZJou3uoFJNAB2Xw3Wxk1fe6Wqq7v9mxYAayTLiOiz1QWxOGLbWc Uo/YLar/vQuFNeaJPL8BsOVy+Pl13Fc9atHThFixaygnw92FVfnddThY9dtWpH893o4kG8 Z0Du9iOxiZZ4cAkrBENQyqlOiu6OWbc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf03.hostedemail.com: domain of liusong@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=liusong@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692244371; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=UEeJzCJm9jCKgv459OqEdG3+liuKzfufYsfwT23RAbA=; b=HpcXZXUIguYAjqcIPr2mQ1MjeiqiuXncco9rGTlKbxtEfmfK+ZjfRI+0kgMF53i/Rh0ziZ LswdUBX9JhwvEJJEnCdWC6Tqg5Eh0Sx0DKUWgaAvTj7u2/F0d7AEjl+mS2zlNFQxnE4WUV EV5OoI77xbhsYldNYydvrbiTmrTnCHw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=liusong@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0VpyHzpK_1692244315; Received: from localhost(mailfrom:liusong@linux.alibaba.com fp:SMTPD_---0VpyHzpK_1692244315) by smtp.aliyun-inc.com; Thu, 17 Aug 2023 11:52:44 +0800 From: Liu Song To: 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 Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, liusong@linux.alibaba.com Subject: [PATCH] mm/khugepaged: increase transparent_hugepage_recommend_disable parameter to disable active modification of min_free_kbytes Date: Thu, 17 Aug 2023 11:51:55 +0800 Message-Id: <20230817035155.84230-1-liusong@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 747052000B X-Stat-Signature: 5j4m5p7oxweg6z5s8wt76agq9oshfkmz X-Rspam-User: X-HE-Tag: 1692244369-502443 X-HE-Meta: U2FsdGVkX19184zBVt/sHBvVYrrIPh3RoOQ+tjmv876OZ1FtJqjjbHQwAsnSQG8pSfCiRCIBPuiighjAOxDKtNu7Jfh8g2umyy9BGAmUWevu1DKE4glCm/0JM1kLhbBS7Dg5fHPjAskKVra2Xqyt5SwODh5IZ6VhLTC6c/g6w1y17wljS4kTimzo5CHcslFwzCpRAFUWXc0Cfbm0rwf0NnoEZ5q5aYtNmUSkr4lSeWCfm8NtHqpl+FPS8KYXLT6E2PrfkDHacYgSrDc9IT0JnnfgBjCSZjn3NPA34FYBj6JI2xMp9vPePnpzJMlmQt2lMCl9OumRh/danNutiklKmUDeqx9e/Jm6d1M1xbTeC5XxqWLH6fY2/koULRbb3z6BHFL99R8tWlEuxosHAg4NFZ1Z7y4v7EwviX9IJfmzlhw/YuU/fLJoa8wuHS7J6KQqk+GHRIpg5Y8uXSWqy0YZKj8kA4q6EgGaB1/WeiaQCjDSBphj83/gTVdFSAYQMacL6kw32u0k2BhLE1nSvjVSwnbIYNO6b0zDSEYDcCSBBWiq+pCwnk/VE/o+M77QoQl44aqxl9VjQO9xaNHcPNGXavnGYCGLIgN305Sb0dbjL0E1nJlTFHqyBPoJGquqqkUhkPYLhckn3ynf3l7fJejNWimetLilw+d4bYCoA8nBSxhfM4vfsFIFzbXZmI47AWMqa/DXmU1+ckAdO4LmYc7tYX+kgblUpol1yeb29desxRnrBw+LqsWds0wUPO9jKhUAloTdkdzWNMPnYcnnQcom/6zr1oHPbw/LvpNcV5V2Oo/Ckgv6CkSE87A5FhfjHfi9LjEigvJwgMt7v4u2C/N84LA8CQafYaKa4K/z8PQmCfqPFnrxet6Ng2gcA594B67BFR9xDSwLE4IXKb+FC6d9lm0uykGczdGE3VkJcUBOVtCMsAk3IwF57ufG0kHTS7o/wOEEZJAymjQD2vEL/FT xfPgvDsp TtZpA0hIw5mwRaqpMnPM4LxMvI1TYDrzKmy0e940DDk2ndbRFclFEeOHwhvkgXiAKCUWvZxOO69yOZOxLTY8wMRQeNKW0yTQdzEEUGBTkdgP/tBc2dFHIhFWtPpEQGQh7McAF 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: 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. 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;