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 F07ECD1119B for ; Mon, 4 Nov 2024 02:33:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FDC26B007B; Sun, 3 Nov 2024 21:33:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AA556B0082; Sun, 3 Nov 2024 21:33:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4721E6B0083; Sun, 3 Nov 2024 21:33:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 28D4C6B007B for ; Sun, 3 Nov 2024 21:33:40 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A831F1602F4 for ; Mon, 4 Nov 2024 02:33:39 +0000 (UTC) X-FDA: 82746841422.02.EE83B4C Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf18.hostedemail.com (Postfix) with ESMTP id 8628B1C000C for ; Mon, 4 Nov 2024 02:33:23 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=nF3ibdzt; spf=pass (imf18.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730687398; 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:dkim-signature; bh=v1/peVX+FsyEZ3e/HuCFZ4YVCmzU5pF7SqzFiNM/ok0=; b=XHs02NiIigQ5A5Vq22Orq0ptt+Q8vXNINVQpCJH/k2BVGssdIwABXaMAApCs5AYi6WMqOj GtyoepvLlF7nJrEBaCnGG0L+kZatJPmq83JGo2cXgr6H1QJxkClF5zsvGr4jDshgc1o+aC 8dFaMmLiBAFocktwUnxPjwLxhlt5UZI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=nF3ibdzt; spf=pass (imf18.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730687398; a=rsa-sha256; cv=none; b=jO18ZDgeiuqByCOx6d7h8U/bX5SsrCi2eH5d7GZbk48mG7NIgTy2BkXFtNjQqxNJfwrxW3 O2BhTPEBB4K3xyvdLx3/nkK3sgRvmqLnLCKyyVpLZ9w7idyleaAUEh6//i/7Dvr4wuIKq4 rSnkm+2C+3VUjhMpbAOwAL74JyXGVD8= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1730687614; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=v1/peVX+FsyEZ3e/HuCFZ4YVCmzU5pF7SqzFiNM/ok0=; b=nF3ibdzt8SMIifbblHV5nAEq1IPJGB0e3080baIMIKgofLaEDiXfz9FvbU1GEVVgBOVqPqZBq+zPzpT7RPSPPDF4zo+kzpgHPpwHedzaGGBm0i41ddD4CPZa28CL94YXlobDBzH4e4hq3EYUNYnkt3RjVgXAXs51BHVQIUwz6To= Received: from 30.74.144.113(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WIZh3ES_1730687612 cluster:ay36) by smtp.aliyun-inc.com; Mon, 04 Nov 2024 10:33:33 +0800 Message-ID: Date: Mon, 4 Nov 2024 10:33:32 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/5] mm: shmem: override mTHP shmem default with a kernel parameter To: =?UTF-8?Q?Ma=C3=ADra_Canal?= , Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Lance Yang Cc: linux-mm@kvack.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com References: <20241101165719.1074234-2-mcanal@igalia.com> <20241101165719.1074234-6-mcanal@igalia.com> From: Baolin Wang In-Reply-To: <20241101165719.1074234-6-mcanal@igalia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8628B1C000C X-Stat-Signature: 5r1qa66xe6ydaht9sgswikumbeh1jgqt X-Rspam-User: X-HE-Tag: 1730687603-521375 X-HE-Meta: U2FsdGVkX1/SG+/lwIbb5BX7ddwOaTIZnTEypwfzI/6mOFas81Z58ER4r7zjrR0GxqO3qHB2xgHtq4897JouYWzOZUC8czcIHh9B8yY4HDwGhkhhf9t6Gw5cFneElhLCN75DdhUKLr5FAlp7ceplqy8DQkv8o+b3+A6J1bkPX8E23xcd/N58uXFjm/ZgzNjIMm1Yxk7DVXzUYsnR0E38x4mbbXxvJcCIcm2zETU8RcI1R4U39WqN26G6EyeJWjnM3pY1+ZEfHZZT7WgCMV4MIPXwVVUC9TThHdxEXSLlcWaGjEI6vi8TYbONawUs/n3RdM4EbRQniJV1ZOxpooVswrXT/TzzgxDmuibs6HuBIIJtLTk+9xlXHDESis50/JNH8t/mAyiPyk1R/MM/j7Hj4Nxsraqroc8ZKtzoZ4TI4lUmlI48vXORW0tNM1VFF1brbrXfX+Mz6LMQgR7aiL3+hSZwaKQ9Zrpkfgj+BAvr9eB6uObitpm+CfBtvrku4ggvYcV0ZYQ5nvffbF8o5tP0lKGOgYghBbRUZn7orYCvH+gZM1gcN+GWDdsh+uWA8kaQ8EQh+Xw3J2djanNI267H/0yQzKtlYe0+EkzJXkFU82BTPExBgD3bJncEBhAkZzfWAIAri+rchvoz0Q5wBdQ++GZs7079jQRwW5fP3a617xs8YgNcUGPP6/DTLf9h3svCj762RtCdkAbZIv5JwYvU7LgGZFajebne9vwol0yRAF5jCQzgaQDmmvyDSRGM4hjIBbxpBu+Eu2/SHiloijFZSF/xLRas5NnBB+KxCjwF5Rn/0qGvbvDXlHtHDvjBPZPlXqWChau6rwY9izNEAr2rzD9e/TgxGzPyPEmBqt1YqRdSNX11b7dbYRHhWNQaSPH/cmI/jlSVmAh1KgSy81yzLb8apGa7o98io7Zc88OoSPtXGl5X/t+9Sbut1dayvWWuXnSINbfTLAbkBMjQQ8l QhtsQrRh lZsLMnZqOe+hNQmEES2CZ/fDHoW3FilXvjjP+7/nMN8XjuTRMGoFUUOPxDo5itLrudbYI3PVY4U91oHfwYR1/1PWuetn8vxXhbt0quCQ1cE7C6x3rJWdlyfr915VT9Mx9eVGD5HTvSrgkX/aF9hGz8y0+/z+QjFJUbnf06bVFEWfVzRN08g/4ylCHHL0mybbZWXpfDR+D6T0VLuRHDalDNn3yvQ9o97pUPInN3AHYlAD1GPboSl5RpTAuFL+sKRfm2/VTilUcZs8qOU+JoQd1LOq14BWHa4PJPb9Zp4RNeATRQBUJX9b0aUzJQiHCElBj46ry5foJTuoBzsm5cuQgerhWljOFrAClSTPCfvh1B5JFZDg= 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: On 2024/11/2 00:54, Maíra Canal wrote: > Add the ``thp_shmem=`` kernel command line to allow specifying the > default policy of each supported shmem hugepage size. The kernel parameter > accepts the following format: > > thp_shmem=[KMG],[KMG]:;[KMG]-[KMG]: > > For example, > > thp_shmem=16K-64K:always;128K,512K:inherit;256K:advise;1M-2M:never;4M-8M:within_size > > Some GPUs may benefit from using huge pages. Since DRM GEM uses shmem > to allocate anonymous pageable memory, it’s essential to control the huge > page allocation policy for the internal shmem mount. This control can be > achieved through the ``transparent_hugepage_shmem=`` parameter. > > Beyond just setting the allocation policy, it’s crucial to have granular > control over the size of huge pages that can be allocated. The GPU may > support only specific huge page sizes, and allocating pages larger/smaller > than those sizes would be ineffective. > > Signed-off-by: Maíra Canal > --- > .../admin-guide/kernel-parameters.txt | 10 ++ > Documentation/admin-guide/mm/transhuge.rst | 17 +++ > mm/shmem.c | 105 +++++++++++++++++- > 3 files changed, 131 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index acabb04d0dd4..b48d744d99b0 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -6700,6 +6700,16 @@ > Force threading of all interrupt handlers except those > marked explicitly IRQF_NO_THREAD. > > + thp_shmem= [KNL] > + Format: [KMG],[KMG]:;[KMG]-[KMG]: > + Control the default policy of each hugepage size for the > + internal shmem mount. is one of policies available > + for the shmem mount ("always", "inherit", "never", "within_size", > + and "advise"). > + It can be used multiple times for multiple shmem THP sizes. > + See Documentation/admin-guide/mm/transhuge.rst for more > + details. > + > topology= [S390,EARLY] > Format: {off | on} > Specify if the kernel should make use of the cpu > diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst > index 9c6f6da612c4..5034915f4e8e 100644 > --- a/Documentation/admin-guide/mm/transhuge.rst > +++ b/Documentation/admin-guide/mm/transhuge.rst > @@ -332,6 +332,23 @@ allocation policy for the internal shmem mount by using the kernel parameter > seven valid policies for shmem (``always``, ``within_size``, ``advise``, > ``never``, ``deny``, and ``force``). > > +In the same manner as ``thp_anon`` controls each supported anonymous THP > +size, ``thp_shmem`` controls each supported shmem THP size. ``thp_shmem`` > +has the same format as ``thp_anon``, but also supports the policy > +``within_size``. > + > +``thp_shmem=`` may be specified multiple times to configure all THP sizes > +as required. If ``thp_shmem=`` is specified at least once, any shmem THP > +sizes not explicitly configured on the command line are implicitly set to > +``never``. > + > +``transparent_hugepage_shmem`` setting only affects the global toggle. If > +``thp_shmem`` is not specified, PMD_ORDER hugepage will default to > +``inherit``. However, if a valid ``thp_shmem`` setting is provided by the > +user, the PMD_ORDER hugepage policy will be overridden. If the policy for > +PMD_ORDER is not defined within a valid ``thp_shmem``, its policy will > +default to ``never``. > + > Hugepages in tmpfs/shmem > ======================== > > diff --git a/mm/shmem.c b/mm/shmem.c > index dfcc88ec6e34..d2bf98aece40 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -136,6 +136,7 @@ static unsigned long huge_shmem_orders_always __read_mostly; > static unsigned long huge_shmem_orders_madvise __read_mostly; > static unsigned long huge_shmem_orders_inherit __read_mostly; > static unsigned long huge_shmem_orders_within_size __read_mostly; > +static bool shmem_orders_configured __initdata; > #endif > > #ifdef CONFIG_TMPFS > @@ -5027,7 +5028,8 @@ void __init shmem_init(void) > * Default to setting PMD-sized THP to inherit the global setting and > * disable all other multi-size THPs. > */ > - huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER); > + if (!shmem_orders_configured) > + huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER); > #endif > return; > > @@ -5195,6 +5197,107 @@ static int __init setup_transparent_hugepage_shmem(char *str) > } > __setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); > > +static char str_dup[PAGE_SIZE] __initdata; > +static int __init setup_thp_shmem(char *str) > +{ > + char *token, *range, *policy, *subtoken; > + unsigned long always, inherit, madvise, within_size; > + char *start_size, *end_size; > + int start, end, nr; > + char *p; > + > + if (!str || strlen(str) + 1 > PAGE_SIZE) > + goto err; > + strscpy(str_dup, str); > + > + always = huge_shmem_orders_always; > + inherit = huge_shmem_orders_inherit; > + madvise = huge_shmem_orders_madvise; > + within_size = huge_shmem_orders_within_size; > + p = str_dup; > + while ((token = strsep(&p, ";")) != NULL) { > + range = strsep(&token, ":"); > + policy = token; > + > + if (!policy) > + goto err; > + > + while ((subtoken = strsep(&range, ",")) != NULL) { > + if (strchr(subtoken, '-')) { > + start_size = strsep(&subtoken, "-"); > + end_size = subtoken; > + > + start = get_order_from_str(start_size, > + THP_ORDERS_ALL_FILE_DEFAULT); > + end = get_order_from_str(end_size, > + THP_ORDERS_ALL_FILE_DEFAULT); > + } else { > + start_size = end_size = subtoken; > + start = end = get_order_from_str(subtoken, > + THP_ORDERS_ALL_FILE_DEFAULT); > + } > + > + if (start == -EINVAL) { > + pr_err("invalid size %s in thp_shmem boot parameter\n", > + start_size); > + goto err; > + } > + > + if (end == -EINVAL) { > + pr_err("invalid size %s in thp_shmem boot parameter\n", > + end_size); > + goto err; > + } I have the same feeling that these are redundant checks. Otherwise look good to me. Reviewed-by: Baolin Wang