From patchwork Fri Nov 1 16:54:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 13859615 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 5FC28E6F070 for ; Fri, 1 Nov 2024 16:58:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBD646B0096; Fri, 1 Nov 2024 12:58:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1FFB6B0098; Fri, 1 Nov 2024 12:58:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C99426B0099; Fri, 1 Nov 2024 12:58:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AB4216B0096 for ; Fri, 1 Nov 2024 12:58:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 63A0F140BE9 for ; Fri, 1 Nov 2024 16:58:01 +0000 (UTC) X-FDA: 82738132302.19.BBB39D5 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf11.hostedemail.com (Postfix) with ESMTP id A922D40028 for ; Fri, 1 Nov 2024 16:57:24 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=BI9jEnho; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf11.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730480160; a=rsa-sha256; cv=none; b=WcwRY48roZSoFzBsRh7b8pybtcwME8R7hkOsIsCb34KVNVngUejM/Dz2w1z0cb0riZMzEP ex1YH4Cl79GfKo0PrxG/fUDp7JKvZZ8t3W8x24VxuAbkNOcMUfKLdTZ2SG/4jCOKzKxRJN w4iHcjVjv276RvsjQ5HeIn887O5qlWg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=BI9jEnho; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf11.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730480160; 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=8BSVR7eAERprKgDeJ6doXC6uVFc0KlLSJulHHmYrLgw=; b=hCcQweosUoRaKJ7IUSttPdyNyisaZhr7yR+4h1hBc5e9+hpDIflhnrZy+G/+xnck76mi42 0QHHWvPJlNb9K2Tyf7laXXU2exm8RbIxipqhjmkF7zyHRJ1mdBv96MPvQ8+fLF7XNQ7kQx JEk56CdKllWVX8qt+OyRAH1vNinB5zU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=8BSVR7eAERprKgDeJ6doXC6uVFc0KlLSJulHHmYrLgw=; b=BI9jEnhon5ednLcCmYInr+vw6p mIMSqT39GTQyH04EYJP41wvD8Djx7wWK39wltY/y6DRYGVP9S2R+TcJZGtmSsYCf+q6g1ZeMSEtB5 kdbOUT86ij9a9EBhfo+8pAvicmbS1LUUdJFoWGxB0c+CU3+mkFxB2I4c7nZWpW08NEbe6kL41Y9nH dhbtEGveDTYllp9w0+roP8S67cDXZ+P/kW7PyvlF+eTVhcoMlrdDospIAYIMSaS5OWEohPedrAVV6 ADkLuALzBPrdSM/jj62rXeUWKDo8DeR1OQjQ9tfwdZR+WvCfRO4g68wOkXKXLJitwbcIne4miQwOE 8EOqjoJQ==; Received: from [187.36.213.55] (helo=morissey..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6uy6-000VPu-FY; Fri, 01 Nov 2024 17:57:51 +0100 From: =?utf-8?q?Ma=C3=ADra_Canal?= To: Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Baolin Wang , 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, =?utf-8?q?Ma=C3=ADra_Canal?= Subject: [PATCH v5 1/5] mm: fix docs for the kernel parameter ``thp_anon=`` Date: Fri, 1 Nov 2024 13:54:05 -0300 Message-ID: <20241101165719.1074234-3-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101165719.1074234-2-mcanal@igalia.com> References: <20241101165719.1074234-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A922D40028 X-Stat-Signature: tokbw7uru6rybwpbtjcwkedwn1f3st8g X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1730480244-142717 X-HE-Meta: U2FsdGVkX1/dlPV5ZlU/xLciKKFArlnEQAw1XnECyEKo07vZKjneJ0RSmIE+zjYK8EyIIIyct2ggOZQ+JftXvEzddEoE3B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0oF3g73d3ZagFkfZWBJ4lFBfP+wOSgEH6NSpH9qZ4iLOl4Y2UcIkfh+QY3lVKjddIlGSpTP69OZwM4BajvebAkN/DMejoHa+klVSRp88XlEtEArvJTiJTUIuZ65Wu1aT1urKgwfCjkwP/ify4kZo0DD/Y5bhlSwuGyvE0C81HSfL2tQdcP4ANtVOrSPKW7WjGiP5d8Qo/Xj3lLdMewURVxilVXFfgkrBuBi1m66aJHrTfWBcksnLVcmgpOj6aZTbq+iH3oBfPW9mxZeCnAJVHqJm1Dt4qjPU2slr+32VdeAtrfJH7ywxDB5YSaNqEn+OcgGXVNFvDkmYAMFdGw9eQ== 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: If we add ``thp_anon=32,64K:always`` to the kernel command line, we will see the following error: [ 0.000000] huge_memory: thp_anon=32,64K:always: error parsing string, ignoring setting This happens because the correct format isn't ``thp_anon=,[KMG]:```, as [KMG] must follow each number to especify its unit. So, the correct format is ``thp_anon=[KMG],[KMG]:```. Therefore, adjust the documentation to reflect the correct format of the parameter ``thp_anon=``. Fixes: dd4d30d1cdbe ("mm: override mTHP "enabled" defaults at kernel cmdline") Signed-off-by: Maíra Canal Acked-by: Barry Song Acked-by: David Hildenbrand --- Documentation/admin-guide/kernel-parameters.txt | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 1518343bbe22..1666576acc0e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6688,7 +6688,7 @@ 0: no polling (default) thp_anon= [KNL] - Format: ,[KMG]:;-[KMG]: + Format: [KMG],[KMG]:;[KMG]-[KMG]: state is one of "always", "madvise", "never" or "inherit". Control the default behavior of the system with respect to anonymous transparent hugepages. diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 5caa3fb2feb1..abdf10a1c7db 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -303,7 +303,7 @@ control by passing the parameter ``transparent_hugepage=always`` or kernel command line. Alternatively, each supported anonymous THP size can be controlled by -passing ``thp_anon=,[KMG]:;-[KMG]:``, +passing ``thp_anon=[KMG],[KMG]:;[KMG]-[KMG]:``, where ```` is the THP size (must be a power of 2 of PAGE_SIZE and supported anonymous THP) and ```` is one of ``always``, ``madvise``, ``never`` or ``inherit``. From patchwork Fri Nov 1 16:54:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 13859616 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 F3FAFE6F070 for ; Fri, 1 Nov 2024 16:58:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 918466B0083; Fri, 1 Nov 2024 12:58:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C7C66B0098; Fri, 1 Nov 2024 12:58:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 741B76B0099; Fri, 1 Nov 2024 12:58:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 566EA6B0083 for ; Fri, 1 Nov 2024 12:58:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0A421C0AB2 for ; Fri, 1 Nov 2024 16:58:08 +0000 (UTC) X-FDA: 82738133142.15.0A4B04A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf28.hostedemail.com (Postfix) with ESMTP id 7D6A5C0016 for ; Fri, 1 Nov 2024 16:57:37 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=p6BC5Tlk; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf28.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730480123; 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=O29dCXx+phviG21mQhq8obCWSt3spMP5spSqVzL91xU=; b=eKG8s/JvmYBmVx4Di3lt2qqg4HlPxLCuIndAQltSGnDwz50jpE/OzGjm83dZ+m4g55ABZ7 fdZDflj6lHrM2zIwInKTwkUBdsidnMzqEUf03q5PNEEEiRuwGE8KP4xmzC03lhS6ZGZz/c AcVKW4DHXQVAsaTBX0c8SHNB4JjOovw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=p6BC5Tlk; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf28.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730480123; a=rsa-sha256; cv=none; b=VcgXze2RGPtJci3kSBhXhHR6LwruBG30o0VpPrf0yHh3oO7+b5HqFNEXjDf2xM6Q1MmrH4 TZMqgHOLcOat52Ap4pZRewNGqBJpngsRTqxVWS3M+guI+rIaP23Cv6mpWWo0shk/A5uGy3 eBDAZKA6axaDmFG2YjmLXRabU6jFadg= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=O29dCXx+phviG21mQhq8obCWSt3spMP5spSqVzL91xU=; b=p6BC5TlkYl1DzocJbUreIvt+mi QUQiD0X/QqVmAhFfPnCZ0DyuPHPVxcnHzKJTX/fRHHEJVi+LWZZniaI6ZUEQdH8tf44MPaga+ZUMj ySQK/up940WgZ4PCL+0aZt81SPtTbPe9oEzbihUalr1uYIZZFReb3bpLOXAeFNZ9JsRkI95c639/U /OFsyRR2hq+0+T2EIGYWzWIuN4F98W+cBP3IYlg93OwCFZc3dXF5e1VnCLHa2O6CuPiXolUXFD4wJ KDoQlnKnfojnzTuBXLo/muxVEAlqtrxx68QdYsqySbyJyb+eU8uTTvBcDO/fQF6iKZeuwehieC/M0 9f2QG4Iw==; Received: from [187.36.213.55] (helo=morissey..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6uyD-000VPu-14; Fri, 01 Nov 2024 17:57:57 +0100 From: =?utf-8?q?Ma=C3=ADra_Canal?= To: Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Baolin Wang , 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, =?utf-8?q?Ma=C3=ADra_Canal?= Subject: [PATCH v5 2/5] mm: shmem: control THP support through the kernel command line Date: Fri, 1 Nov 2024 13:54:06 -0300 Message-ID: <20241101165719.1074234-4-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101165719.1074234-2-mcanal@igalia.com> References: <20241101165719.1074234-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7D6A5C0016 X-Stat-Signature: ranq4gy75grgn774dggt95ktzkdgwf4u X-Rspam-User: X-HE-Tag: 1730480257-345745 X-HE-Meta: U2FsdGVkX1/kj+7juHK5gS8PkHZY5xc5qKKrWBmkQ+wPmc5wrize2RsG5LOfxQX4VTbzVBlEGto5YYfRped2pUMIyAedRAfBx/tLBQWaBWmXm1LZz41QsV8Lctr7cBDv7c/KmePS3Q/nXOMYqXxWhupFaMuR/J+y2O0+4StrQlxnxMAX16UDQhp8HlSRcbkIWuGCaHj8t4Erp2Ijg4CyOy45nULtEsED+zY3Tsz0P9drvvUZtM62jI7aJqhbK7D72NvDrCMTf9+HKuUjv5RW6vS2JO7wEfBVsydvqHDLREb43t4uKoBSIuUyCXYlPvfjIE2faSo/3wyXrCXuWjCnSBaGzXNdM7+qgWTozpCYVmiLHxtvzCu2zxcV4+PEY3V6A/pVN7qc3uMekENjo5Uc++vBYW3OSSNJjxmb3Jp8GHVtglmyYxxjQPa6/cLBM6OKoyS50NmC9mp7iOoljfnpE4YeTXu0vDZWXsmxrxJyuOZ328WfMNcCKx1xnGzC1HHks1zWDQc44NU6BnuFwou2Ks4zQWpmkvChm10kNEeZXNAMhc+j5GAuitexgQ7cNIZcIYXhzEbtlrVFIK9wHAy68NzzoJ0kd7nWuqWsBsv59kLwtObe5lQSGUWsiX6Yu00Y3W7U2qZlDE+vugFJO51keV9ItHARMXP4xuAaQ1hCSmx6jrwT3KVRnbUaXqvny6gQC4m5NSHx5LIPLVCWoV0xQQTcU2peCr6asau8oJasvKXbNRMGyZztMbkMk4AoJm00HTc20amrS++K4TdAKqK4yTvnGXXH+4U4lgZywM8DR6ubCDHUO7FcWjQTXOiAn0DF4P2KUsKccTlm9wKMnnfE0w2TYLr1wCuFjoibsESrNzA6YunYr4GZpHn7cpzIZ9rZmmT743m/8pOYIQhGOJbO5P/Maw7t8yyy5JoNWtlU62JWMOR7o27GaEU3j9diaN3s9UojrDxcR5OKZhz1ybl 0ZYEauxz FG3TKk2cMY/E0gTqhEyvLEiPVA4pC6avXPddGy5XK1EdMM/QV3naeGuhAnz65BpAj9Fg5F/0gFmKBzbkKGjLYxeX4MQprp1paUXMMVQP0vsNLv09tAbQ9RSb8huXVrkNdETDIoVM2yn+9ZNOjartVKBH462NWsmzxnkM8/+c5ZxAyFDuSknh8PuAZFqBLc/D4vlgivGbYoTQWRQBJrylQPaiOCuuBeGutfuASSaT/0s1vxRzSzWZAKb/hqgSy+WStjlsSiY7631+trZ7ycwbUL2Ps2a+2/FDEikTTwmkJD3nWNO+VCyiIMSh2yGe8LsNInJtNMHdjMqpolFElwp8Guw4b1dHsEdBNLECHslTlYM4coS5kz3IgtWskXBsQWjlrtaO5 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: Add a new kernel command line to control the hugepage allocation policy for the internal shmem mount, ``transparent_hugepage_shmem``. The parameter is similar to ``transparent_hugepage`` and has the following format: transparent_hugepage_shmem= where ```` is one of the seven valid policies available for shmem. Configuring the default huge page allocation policy for the internal shmem mount can be beneficial for DRM GPU drivers. Just as CPU architectures, GPUs can also take advantage of huge pages, but this is possible only if DRM GEM objects are backed by huge pages. Since GEM uses shmem to allocate anonymous pageable memory, having control over the default huge page allocation policy allows for the exploration of huge pages use on GPUs that rely on GEM objects backed by shmem. Signed-off-by: Maíra Canal Reviewed-by: Baolin Wang Acked-by: David Hildenbrand --- .../admin-guide/kernel-parameters.txt | 7 ++ Documentation/admin-guide/mm/transhuge.rst | 6 ++ mm/shmem.c | 72 +++++++++++++------ 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 1666576acc0e..acabb04d0dd4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6926,6 +6926,13 @@ See Documentation/admin-guide/mm/transhuge.rst for more details. + transparent_hugepage_shmem= [KNL] + Format: [always|within_size|advise|never|deny|force] + Can be used to control the hugepage allocation policy for + the internal shmem mount. + See Documentation/admin-guide/mm/transhuge.rst + for more details. + trusted.source= [KEYS] Format: This parameter identifies the trust source as a backend diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index abdf10a1c7db..9c6f6da612c4 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -326,6 +326,12 @@ PMD_ORDER THP policy will be overridden. If the policy for PMD_ORDER is not defined within a valid ``thp_anon``, its policy will default to ``never``. +Similarly to ``transparent_hugepage``, you can control the hugepage +allocation policy for the internal shmem mount by using the kernel parameter +``transparent_hugepage_shmem=``, where ```` is one of the +seven valid policies for shmem (``always``, ``within_size``, ``advise``, +``never``, ``deny``, and ``force``). + Hugepages in tmpfs/shmem ======================== diff --git a/mm/shmem.c b/mm/shmem.c index 275251abd596..dfcc88ec6e34 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -582,24 +582,39 @@ static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, } } -#if defined(CONFIG_SYSFS) static int shmem_parse_huge(const char *str) { + int huge; + + if (!str) + return -EINVAL; + if (!strcmp(str, "never")) - return SHMEM_HUGE_NEVER; - if (!strcmp(str, "always")) - return SHMEM_HUGE_ALWAYS; - if (!strcmp(str, "within_size")) - return SHMEM_HUGE_WITHIN_SIZE; - if (!strcmp(str, "advise")) - return SHMEM_HUGE_ADVISE; - if (!strcmp(str, "deny")) - return SHMEM_HUGE_DENY; - if (!strcmp(str, "force")) - return SHMEM_HUGE_FORCE; - return -EINVAL; + huge = SHMEM_HUGE_NEVER; + else if (!strcmp(str, "always")) + huge = SHMEM_HUGE_ALWAYS; + else if (!strcmp(str, "within_size")) + huge = SHMEM_HUGE_WITHIN_SIZE; + else if (!strcmp(str, "advise")) + huge = SHMEM_HUGE_ADVISE; + else if (!strcmp(str, "deny")) + huge = SHMEM_HUGE_DENY; + else if (!strcmp(str, "force")) + huge = SHMEM_HUGE_FORCE; + else + return -EINVAL; + + if (!has_transparent_hugepage() && + huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) + return -EINVAL; + + /* Do not override huge allocation policy with non-PMD sized mTHP */ + if (huge == SHMEM_HUGE_FORCE && + huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) + return -EINVAL; + + return huge; } -#endif #if defined(CONFIG_SYSFS) || defined(CONFIG_TMPFS) static const char *shmem_format_huge(int huge) @@ -5066,15 +5081,7 @@ static ssize_t shmem_enabled_store(struct kobject *kobj, huge = shmem_parse_huge(tmp); if (huge == -EINVAL) - return -EINVAL; - if (!has_transparent_hugepage() && - huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY) - return -EINVAL; - - /* Do not override huge allocation policy with non-PMD sized mTHP */ - if (huge == SHMEM_HUGE_FORCE && - huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER)) - return -EINVAL; + return huge; shmem_huge = huge; if (shmem_huge > SHMEM_HUGE_DENY) @@ -5171,6 +5178,25 @@ struct kobj_attribute thpsize_shmem_enabled_attr = __ATTR(shmem_enabled, 0644, thpsize_shmem_enabled_show, thpsize_shmem_enabled_store); #endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_SYSFS */ +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) + +static int __init setup_transparent_hugepage_shmem(char *str) +{ + int huge; + + huge = shmem_parse_huge(str); + if (huge == -EINVAL) { + pr_warn("transparent_hugepage_shmem= cannot parse, ignored\n"); + return huge; + } + + shmem_huge = huge; + return 1; +} +__setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #else /* !CONFIG_SHMEM */ /* From patchwork Fri Nov 1 16:54:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 13859617 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 D3633E6F070 for ; Fri, 1 Nov 2024 16:58:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F4A36B0099; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 680056B009A; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F8046B009B; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2D2956B0099 for ; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DD96F160B1F for ; Fri, 1 Nov 2024 16:58:14 +0000 (UTC) X-FDA: 82738133562.18.23EB59F Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf05.hostedemail.com (Postfix) with ESMTP id 685A9100002 for ; Fri, 1 Nov 2024 16:57:19 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=S3IrxxJW; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf05.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730480211; 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=CkGKvkV3mc7ind0IGB8Z7rq8Fs5Gz/hW7rWK8pt2t0Q=; b=PzDPz9pgoWB8ANEyD1Pt3ZJN6KquKrOmagcVX6umoQ03YH/QcRTBUXhZGsotqdl2t+BSI8 aW6f984hM/1pf4ZWHttekUcfVOx45MsWgPXQ0nRGcoJ9cIJh9GFGzeiW/eu3jvUmMbIz2s SjAHfDZ+1QOdOvzCdbbVC0agLl4fTYw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=S3IrxxJW; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf05.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730480211; a=rsa-sha256; cv=none; b=mLYCD1WAEjMr95Zq8lnrPwxjrip4jd3ZqUaJGmWwju80KIxkeRIoDAv5A056QnBQ70adLX jviupu5g5ZRpoXdhzZAwisxal2bDqEDALTQD0Bpu2scopyH8ndxDxfrW8VNxTENOrHfLcH vJwvyvnjr1upyQcOPp6yPCgFrsuukTw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CkGKvkV3mc7ind0IGB8Z7rq8Fs5Gz/hW7rWK8pt2t0Q=; b=S3IrxxJWRTtT5fHJKdV2venR33 ozEECWoZpl/tQV/QbSa7EDzHaCXu+o/ivjtn4mwaNPAplGnvQJQvYZU2ag/yo3q6fEOZw0zB6/Gfh 0OSV4Nd7PXCmRbdZqRGK+stMdW2N/eOCIiS/bT1GW7anznvh/UtpU4amuZmhv3AfFLrkUC1SuhXj7 vIUZFt0at6Jc9vezFXf7Abz6VlKT2zkuC1UsWsSQQbC3xJRagkVSsvF6tNnIKwClVJYg1/zuIlljQ /FFyHvnnW21rRgPr2En8tCizZD4BYd1Wj0RIFmZ9fiomODnAdyuCy8p+lDfMH1S9YB7RcNpvDv6IF C+ZJeDqw==; Received: from [187.36.213.55] (helo=morissey..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6uyK-000VPu-6X; Fri, 01 Nov 2024 17:58:05 +0100 From: =?utf-8?q?Ma=C3=ADra_Canal?= To: Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Baolin Wang , 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, =?utf-8?q?Ma=C3=ADra_Canal?= Subject: [PATCH v5 3/5] mm: move ``get_order_from_str()`` to internal.h Date: Fri, 1 Nov 2024 13:54:07 -0300 Message-ID: <20241101165719.1074234-5-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101165719.1074234-2-mcanal@igalia.com> References: <20241101165719.1074234-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 685A9100002 X-Stat-Signature: db5tuwy8wsf5wp4z8tf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GxT3/G9Xl7HnqIaBX3jd0aRt2yaFJJgn9XxiaP5vT1q3vZ6+FtYPsCPB/CW7y9T2qSXvLdLDFfjLyZX4Y5iCbToJQs52Eam7y6jvWZfv4O3B9zhWHX5IytMUiHT6OVFhLbtdRkchhe+CBmBLIk3lIyKrDVQ1uo/CKNhcmWJiYBphZQ/2owANjr2SvxG/xfe25oOKmaNHW3DOb5x5JOQIvOCbOhTGQpUY7pA9AmEgX2cF1TqWA2QvAO0hbmJwC1I3gMulCLveBQOd7AayJK2STzQsoA8mlnVYsUZHLXv4YTuPI7ZBdQMKGBYZPS0EY/ngwjC0hrzyNWJgf2fJKvecLHVWvjFeoyys 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: In order to implement a kernel parameter similar to ``thp_anon=`` for shmem, we'll need the function ``get_order_from_str()``. Instead of duplicating the function, move the function to a shared header, in which both mm/shmem.c and mm/huge_memory.c will be able to use it. Signed-off-by: Maíra Canal Reviewed-by: Baolin Wang --- mm/huge_memory.c | 38 +++++++++++++++----------------------- mm/internal.h | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f92068864469..a6edbd8c4f49 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -958,26 +958,6 @@ static int __init setup_transparent_hugepage(char *str) } __setup("transparent_hugepage=", setup_transparent_hugepage); -static inline int get_order_from_str(const char *size_str) -{ - unsigned long size; - char *endptr; - int order; - - size = memparse(size_str, &endptr); - - if (!is_power_of_2(size)) - goto err; - order = get_order(size); - if (BIT(order) & ~THP_ORDERS_ALL_ANON) - goto err; - - return order; -err: - pr_err("invalid size %s in thp_anon boot parameter\n", size_str); - return -EINVAL; -} - static char str_dup[PAGE_SIZE] __initdata; static int __init setup_thp_anon(char *str) { @@ -1007,10 +987,22 @@ static int __init setup_thp_anon(char *str) start_size = strsep(&subtoken, "-"); end_size = subtoken; - start = get_order_from_str(start_size); - end = get_order_from_str(end_size); + start = get_order_from_str(start_size, THP_ORDERS_ALL_ANON); + end = get_order_from_str(end_size, THP_ORDERS_ALL_ANON); } else { - start = end = get_order_from_str(subtoken); + start_size = end_size = subtoken; + start = end = get_order_from_str(subtoken, + THP_ORDERS_ALL_ANON); + } + + if (start == -EINVAL) { + pr_err("invalid size %s in thp_anon boot parameter\n", start_size); + goto err; + } + + if (end == -EINVAL) { + pr_err("invalid size %s in thp_anon boot parameter\n", end_size); + goto err; } if (start < 0 || end < 0 || start > end) diff --git a/mm/internal.h b/mm/internal.h index d5b93c5b6364..5a7302baeed7 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1291,6 +1291,28 @@ static inline bool alloc_zeroed(void) &init_on_alloc); } +/* + * Parses a string with mem suffixes into its order. Useful to parse kernel + * parameters. + */ +static inline int get_order_from_str(const char *size_str, + unsigned long valid_orders) +{ + unsigned long size; + char *endptr; + int order; + + size = memparse(size_str, &endptr); + + if (!is_power_of_2(size)) + return -EINVAL; + order = get_order(size); + if (BIT(order) & ~valid_orders) + return -EINVAL; + + return order; +} + enum { /* mark page accessed */ FOLL_TOUCH = 1 << 16, From patchwork Fri Nov 1 16:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 13859618 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 E18EEE6F071 for ; Fri, 1 Nov 2024 16:58:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B83C6B009A; Fri, 1 Nov 2024 12:58:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 741176B009B; Fri, 1 Nov 2024 12:58:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BB426B009C; Fri, 1 Nov 2024 12:58:23 -0400 (EDT) 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 374E16B009A for ; Fri, 1 Nov 2024 12:58:23 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CB8DBAAB4F for ; Fri, 1 Nov 2024 16:58:22 +0000 (UTC) X-FDA: 82738133772.05.005467F Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf30.hostedemail.com (Postfix) with ESMTP id 5B68880010 for ; Fri, 1 Nov 2024 16:57:27 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=L0ixQzk5; spf=pass (imf30.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730480168; 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=Ys/vY/e+8yfzEKIu4LKRRFsTDzyvnthR/qzPM3DoISA=; b=hDFatPhDnZGe3f875z4xMpGH+GTuC2W04DGoLZqMJ1x7IguzA2CX2AoYVHl+tLTuHac+Uf 2wh9M316CNoDbPio9goiSb2t5M2qut9QpgBFDp1ENsP++fTCZaVDQOOEZDPYjYdyrQZD8P kZOPb3GA/31QUwDKh7BLqCkCa48q/RE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730480168; a=rsa-sha256; cv=none; b=hBoETOSukswQg4z/RbRxffZgbT99KsJ8LH7AKtpIhT2RcR6d0B7tnT2PNZsdWASVdSy+kc sTbOGZqaxw4qRmySwNTZSuNSNJ/cpG4u9+UOS0AiLEbN5Ep0lQmZtnN9mQyJNs5KhGMrLe Php1vVZo1OXbWusF0wr5JiaC4aCjQKU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=L0ixQzk5; spf=pass (imf30.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ys/vY/e+8yfzEKIu4LKRRFsTDzyvnthR/qzPM3DoISA=; b=L0ixQzk5rq1dwuZsLc85aKbjG6 DAAXXvrSlteNqKUke8PbLf3vBNPrMAOM34JG4VCZVKC6ajdzj5OU2oaaC77BC7JfRpwKnDRcvVwSc +3QYDyAqKYcIm0G/DOXybSkBhzfv/I2klwXRJgts6ftfa9RTM64lgA3BcXW3+anSPMCXZ8IJ7Aass F0+84tV+OUgvxfFcfDK6gUVp2eiyZ+JCYbxOv2uz56Mx5EFbP1ZlKLyiEzNsomfZmc3wqKAnxh2Yg ZdrTRfXJtpPkmDFYe5Rdq2BH/ia1U+T0KujDqpsCN+BrU1aSrtkEW6fsiHvJbY7Ng+jSShxl52vNe 6yR4etKg==; Received: from [187.36.213.55] (helo=morissey..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6uyR-000VPu-59; Fri, 01 Nov 2024 17:58:11 +0100 From: =?utf-8?q?Ma=C3=ADra_Canal?= To: Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Baolin Wang , 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, =?utf-8?q?Ma=C3=ADra_Canal?= Subject: [PATCH v5 4/5] mm: shmem: override mTHP shmem default with a kernel parameter Date: Fri, 1 Nov 2024 13:54:08 -0300 Message-ID: <20241101165719.1074234-6-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101165719.1074234-2-mcanal@igalia.com> References: <20241101165719.1074234-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5B68880010 X-Stat-Signature: i9nn6uqc1q67k7gzph1qx4p4sya39e98 X-HE-Tag: 1730480247-912017 X-HE-Meta: U2FsdGVkX1+jeQ2dKNIMe9WUcyCQF2aMak30rlRLEGYevIjoguBye/dox7iQNJ7Sejt8N5UEeyJz+h9qneCv3pI3w6JIcQ4/PLRkEp0ewOt/N8En3zUmoaVcXEZbuqDqHUv12cQNRbNhM0hKCRLCbLdCDaBDu0Cc4KtbF1QgFewTAk7Fh0sX/3o5YlMf/PJmweyVR+8wfF/IgwESGuQEHFogHGAX+vG5rpC0SN9oFu5pmUgmfocHwY79nc1FfvWld7iYZrpq0Z3UWrb8P2BXt5IwusX5S97JvcEMJjejlbMZgnCpT1spa+TQCyCiBgrhA3c7u/zVv7h5cLSt3LtSMdzVqpT0BF7afhcAONZMy9yJohpdDHhFJJe8cRBx1X+rwORHnaXhiVAT2Z9seOEZAPreqiEcSYMdlVzjOsOV8isdnz0b4Qm6nUNum+HLLgHJ1LtcMwY+OE85eFQxn5+95Sjpb/1WwtqaGicvJJUwHpPx1Ag+SMOiK00kDmKKM/5xQRlX4HouWnCnm0PIGHsOV49FyqYHgKJYv5klHox+GN6x4jPFieS8zdWBcXQP4wcOFhtKtaNFZamrmp19xxxtoDKh/gvXy3SK869DWPLpCVIZ2P2fJtiIXgj/NhLWMlvp3+HFKrWZow43C0B08nA9+8pumzrqd7eEqD+5WklHb/WxyOCqf+vOmDqqozAU4qluZsPWfY9h+D/AS4dS82hjmhcivZYUTyu67nh3WoGZKohqD/gl/jBOnQq7uQWixfwKi1fv2f/V1GTeTbe2BlHomqcmzpBvxt5SGHHQQDiVvjaoL6UQJNnXs3QRDsQoztVQafZkQsdBfOdIJuMZ8E+iiip3jGlsErBeJC6MBhr6ZDmbWgE9YDd7MP4ZJwZf35gwHbXnpYBk89mqTS3pDTOLdrjqEP+FjKtC+L0Mhmi8oUtkwXlbnk8JHqsw1011LKlp+LzkpOy9lQesMAF1/aZ u32iDYuz SKVITR5q9V1F6RHXdVnUwK+m+r3FqIr2iNsOvgZTYN02KbndsM8DoHulFHoJ/GO96jJmjoFU817sfHs1xgk2cTYVqvI6EyZM3soW1W+IawpkMFKr0z8/WnoZCOXnNTGjfaGS2nbTTyfFdomxHj0e1K0pn0FdiLoOQF1tAqvnFDvow3TtZRReQDqu0PMSwuoJ4yYYCDlOqP0S2evToyOHFKa7WeEZA0yyjvrtP4Ys8wOxF3APz/wHfA5cjuKpqBPSU/azaOWKQSqU1ZDHDhAjkTOXpfd6IbdOQ7UKotheaFtbee1vPGBZiXgBtO8UQkaYYlPOGigi/h4rYu+U= 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: 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 Reviewed-by: Baolin Wang --- .../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; + } + + if (start < 0 || end < 0 || start > end) + goto err; + + nr = end - start + 1; + if (!strcmp(policy, "always")) { + bitmap_set(&always, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "advise")) { + bitmap_set(&madvise, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "inherit")) { + bitmap_set(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else if (!strcmp(policy, "within_size")) { + bitmap_set(&within_size, start, nr); + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + } else if (!strcmp(policy, "never")) { + bitmap_clear(&inherit, start, nr); + bitmap_clear(&madvise, start, nr); + bitmap_clear(&always, start, nr); + bitmap_clear(&within_size, start, nr); + } else { + pr_err("invalid policy %s in thp_shmem boot parameter\n", policy); + goto err; + } + } + } + + huge_shmem_orders_always = always; + huge_shmem_orders_madvise = madvise; + huge_shmem_orders_inherit = inherit; + huge_shmem_orders_within_size = within_size; + shmem_orders_configured = true; + return 1; + +err: + pr_warn("thp_shmem=%s: error parsing string, ignoring setting\n", str); + return 0; +} +__setup("thp_shmem=", setup_thp_shmem); + #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #else /* !CONFIG_SHMEM */ From patchwork Fri Nov 1 16:54:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 13859619 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 3D0B8E6F06F for ; Fri, 1 Nov 2024 16:58:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9AA96B009B; Fri, 1 Nov 2024 12:58:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4A556B009C; Fri, 1 Nov 2024 12:58:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC4C66B009D; Fri, 1 Nov 2024 12:58:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 919D96B009B for ; Fri, 1 Nov 2024 12:58:29 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 36A64402C5 for ; Fri, 1 Nov 2024 16:58:29 +0000 (UTC) X-FDA: 82738133478.19.225ABBB Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf24.hostedemail.com (Postfix) with ESMTP id 7348D180018 for ; Fri, 1 Nov 2024 16:58:23 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=Hd0ON5do; spf=pass (imf24.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730480262; 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=SzEBSUiqX9q6QOwH+3lfpF0a+846J9p9dlVHwog/yj4=; b=3Rm4D581ERT+4MeRJqX/1bcmp7q0xYmLwfC5ZzAWnwu5ki8pV47sUoJQ4ZfVxMapWf/Pvf sG+sd6GXwoq1Ky7X3vJcP/CkuFgf1m2yi3T3SUIPdPePSrVX3Vcg+FdEJ7PQkmU64KYpav hzruRCKqsnUCv74TpPQI5mfEwjrFt8Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730480262; a=rsa-sha256; cv=none; b=JpVpJA7xlWorIePn/akbyYX9dE1cW/EX74tto2/wefbilkiBjKLnxlTKSpg0Xhl6l9yAWq 1nt/tg10aV4IywEPEwIFokeYWwCr4mSa6XwIenXSmlaTCHGg4Khccklvi/Vj6cKvIx+vKW G0q1yId4FCVY9pKeMq2twe3W2s5EpFU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=Hd0ON5do; spf=pass (imf24.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com; dmarc=pass (policy=none) header.from=igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SzEBSUiqX9q6QOwH+3lfpF0a+846J9p9dlVHwog/yj4=; b=Hd0ON5dofM+K8sGFGpSRovkF3c FpYVxRSX8UhzNY0CqbcP+N9S74zKJ2vyl75TGIaexlVAudkVi32l77OhZLN+3H5A/5IUAo/xZUQW4 eXV4ypO5+apa0WBZJSGTeR8MJN+X45kCACF633xB4uJnmGCOZlafw+2wSn3yXxiyqQ/YnxAYuJsux E3h6yC+Xk2StrDO5W3tT3vmk/4sljHnMEGgIPSpzX/9ZYK4SnhaoOK5gwoB8PCoW2BABBcwS/8A8I Tef0giUQ9VqWFBKuSrsrAwtxOR2nCn/rmP/gGptZUZ2/Sf1EwRRpIuTwJChaa3wyMEIEcDN8ypOV0 CTQDricw==; Received: from [187.36.213.55] (helo=morissey..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6uyX-000VPu-N0; Fri, 01 Nov 2024 17:58:18 +0100 From: =?utf-8?q?Ma=C3=ADra_Canal?= To: Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Baolin Wang , 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, =?utf-8?q?Ma=C3=ADra_Canal?= Subject: [PATCH v5 5/5] mm: huge_memory: Use strscpy() instead of strcpy() Date: Fri, 1 Nov 2024 13:54:09 -0300 Message-ID: <20241101165719.1074234-7-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101165719.1074234-2-mcanal@igalia.com> References: <20241101165719.1074234-2-mcanal@igalia.com> MIME-Version: 1.0 X-Stat-Signature: rft58jjy31ufso1r3ya3s17s38se4s48 X-Rspam-User: X-Rspamd-Queue-Id: 7348D180018 X-Rspamd-Server: rspam02 X-HE-Tag: 1730480303-501517 X-HE-Meta: U2FsdGVkX19PxUxyzgRtJpiLr58dDSD5XxvxuSzhVAzMa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/i5fariYXscf1WmGiPr+GuPjLo8Z3SkvFoYnJxApdCdkVgKxA/0EiUvCo54oSNY+/AZE+0Qe60oyj9vIipb9mmEa+xo/6qKDIwgCNXc4foWFqCAeJOx2gPB06IlSjJj553ZfLUEG+NzKfxIrRjvEH3Qia4d0zOUmGoi9pdWQPlANa6SGRFkSWXB39YxPHl+xfScUMfmL7E5HmP3Na6S/6Bvz+6/SkWnIAQS2ZmPA5YaL87LU5pWtqf21YAyB5VRwy4dCG7YMn+BTiLQrhSlySU/KM= 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: Replace strcpy() with strscpy() in mm/huge_memory.c strcpy() has been deprecated because it is generally unsafe, so help to eliminate it from the kernel source. Link: https://github.com/KSPP/linux/issues/88 Signed-off-by: Maíra Canal Reviewed-by: Lance Yang --- mm/huge_memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a6edbd8c4f49..1ebe18ec4560 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -969,7 +969,7 @@ static int __init setup_thp_anon(char *str) if (!str || strlen(str) + 1 > PAGE_SIZE) goto err; - strcpy(str_dup, str); + strscpy(str_dup, str); always = huge_anon_orders_always; madvise = huge_anon_orders_madvise; @@ -4167,7 +4167,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, tok = strsep(&buf, ","); if (tok) { - strcpy(file_path, tok); + strscpy(file_path, tok); } else { ret = -EINVAL; goto out;