From patchwork Fri Nov 1 16:38:42 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: 13859596 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 88529E6F06C for ; Fri, 1 Nov 2024 16:44:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 124CE6B0096; Fri, 1 Nov 2024 12:44:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ADD96B0098; Fri, 1 Nov 2024 12:44:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E69DB6B0099; Fri, 1 Nov 2024 12:44:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C5F886B0096 for ; Fri, 1 Nov 2024 12:44:07 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 58853A09CC for ; Fri, 1 Nov 2024 16:44:07 +0000 (UTC) X-FDA: 82738096602.20.480E4C8 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf08.hostedemail.com (Postfix) with ESMTP id B762A160029 for ; Fri, 1 Nov 2024 16:43:46 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=DAf8W6rj; spf=pass (imf08.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=1730479400; 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=i9TYeBbaX8MX0Qf6OMRV+OUUwQ2cgyiHJ7M70yZnn8kvl8HkoznkuabqBmSCk4vBu4xjUZ +5/lPckZ4bNB7kw6NsepDGkroaVyqB/33W8KlblUIEmHrZ80/Qqk7ohfpdYT7Yi5eM/pGQ ISh8WmLTUzWcRNXBnTw0juvVhTivrkQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730479400; a=rsa-sha256; cv=none; b=my8ANW/tFpXFi7eSRfnRSbld18jzdXI6R0cNja9Ocq9FcywLDLzEwPMUnC9X6V5JWJImKT hWVQoqSadAEi+E8UysZBcSRK+ZX0JiFXrual117ooDGqeTV27yLzdIg8SCwIo1E5nk8jPM xEbF/i1P6VufE6Bme8WN8iY+EWoYd7M= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=DAf8W6rj; spf=pass (imf08.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=8BSVR7eAERprKgDeJ6doXC6uVFc0KlLSJulHHmYrLgw=; b=DAf8W6rj4sGQ1pVJpVHNr5uElU qF5GdXXIFPvp3rk4vrHyP7cDCSJQJM/Ose1bN/RPcg9s89Oqj7P/skzNqCAp4meggmmtuqpU3+EXy l4bX/eZ+BovJ3kiVQsLBwSUqR41dHNaymaCn45L71Ov8m1J8TeJSS7SnNnIIv7Q1Jz50QltIJYvgz qLNFXvx4TndNwVbCc0Ugto+36fnTECzGMZ4LeRgQG2I6380kAxsDoHsLeg9cLxp2rTsE9IE1FYe0I 4PV3SplVuI6NN3ol/q6aXTLSTukPhfmdBDbCOQPX2JBSWU/ptIMRxtvNL3rVUu+/mFH9G8iSAae49 MmM/IAsQ==; 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 1t6ukf-000V38-0G; Fri, 01 Nov 2024 17:43: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 v4 1/5] mm: fix docs for the kernel parameter ``thp_anon=`` Date: Fri, 1 Nov 2024 13:38:42 -0300 Message-ID: <20241101164313.1073238-3-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101164313.1073238-2-mcanal@igalia.com> References: <20241101164313.1073238-2-mcanal@igalia.com> MIME-Version: 1.0 X-Stat-Signature: gr3q99xx8dmxh1n87eejpd36z5twsyk4 X-Rspam-User: X-Rspamd-Queue-Id: B762A160029 X-Rspamd-Server: rspam02 X-HE-Tag: 1730479426-770145 X-HE-Meta: U2FsdGVkX1+FvrmIpwhivY4lK5SWwktVyNvsb1lABsb14/5TKCicIo6DkM0JSV0cvlGeDYokw6sS129jxsOMz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AZlcBrRleCmES5juoA/v16TATIrnKS7kAuqS3cF6dmlhN8wqNPlL8tWgW2H8AkrvwG7CrQecv82El0TonlVjSMN2v5616ItT8RX6EgDHB5kBvdBbVwoQkRxAbTU3RbrqIuizCjnRY4Xg0iqKE4KQY2VsIjqx7Jk9lP4c03hx8qhI3R/kLMZIkmymYqyCKmA2AL1/FxDZ4LiheR82YKIhfFO3mcOIn0Xm5EQjheqdBnHWh00eJLDBhckLiR6FL+8Gg= 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:38:43 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: 13859597 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 0AEA9E6F06C for ; Fri, 1 Nov 2024 16:44:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 961AB6B007B; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EB106B0098; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78B6D6B0099; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5B1B96B007B for ; Fri, 1 Nov 2024 12:44:15 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 18BE81C6C11 for ; Fri, 1 Nov 2024 16:44:15 +0000 (UTC) X-FDA: 82738097988.30.A4D125A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf30.hostedemail.com (Postfix) with ESMTP id C1A9280010 for ; Fri, 1 Nov 2024 16:43:19 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="qiA7Eq/b"; 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=1730479371; 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=bXwgm/jSDTpE9I+2mFT7TuPEr+yEX6ONKQIxzHmjeqD1+2BJnMaq5H7BViGI0JVZBln/DL 2jyLh75KPu08Op0skcS553rf5Hh3j+fT4n+uggmIpeaQSM5qLmWRQT19eFP/bodj93ndhS EzFDFo4WrCtICLAwV1iBJ3Bv3L5Oets= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730479371; a=rsa-sha256; cv=none; b=R0xoe/FdyFgTqVSlqF0JclgeMN73ZygxCzwIiYFTXQNxPV+F0/r93iK2GEEpVe20isQFJj tVEMFyYU4I4qtQq8VprwOhV27DLT7QFukNok0GEf5Q1xGxYp6rdpbTmuDUpruxOjbmU1tB teraM28cUF1PPhnv73wYhwZhFFkBkrE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="qiA7Eq/b"; 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=O29dCXx+phviG21mQhq8obCWSt3spMP5spSqVzL91xU=; b=qiA7Eq/bD8O0eblUzP9hCRlr5a NsvTgI4r510BprM4uej05UY3od4QuFC/TCQpye+vDEnlnoS4eE8AyoHopD+npkMNo9uVXhTKo9198 +t7CUNvWlZ6G8Ypmxofvy3AqEanBfK81C6JiY51aiE1UPBYBhH/AMnski9wojybXzO57s0xv9xG3c t9tNJDhkZNnZmlUC90Jm8PvZuFQl5RaD3w7G6uMf25KzIB9rPHnBGAZc+BQqYZDy8CuULIXng0c8I BOXJoaB7aTIgGEKJW5/xNaHN2ZQEdmg4kkYWIFP7Jm3+24hOMsX0GOhDjKZLAM71lvWH7QZtyUS0Z 9xjc5yPQ==; 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 1t6ukl-000V38-VM; Fri, 01 Nov 2024 17:44:04 +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 v4 2/5] mm: shmem: control THP support through the kernel command line Date: Fri, 1 Nov 2024 13:38:43 -0300 Message-ID: <20241101164313.1073238-4-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101164313.1073238-2-mcanal@igalia.com> References: <20241101164313.1073238-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: 3hjdgsfydk31mbttzj7ezm1y1ghs9ozt X-Rspamd-Queue-Id: C1A9280010 X-Rspam-User: X-HE-Tag: 1730479399-721988 X-HE-Meta: U2FsdGVkX1+HQik4xkQ+pu91hsq9jhwVH86yLW8CmV34KTw8eLsIXEA34IVMKfrXcRh6Db1Jo5563ttdaSzRWUWEOqMNr75wq5VCdZGvVOlkxsgxEWqdvtvspxYzL2aFz4XbOfpOYh/3ik26/GPqCwr27TkCtRGjnRCjwFOBYY6mEaqNY+TLrYGjY9ELi/RK4GyOOMmt1vQH/8yhXzkR2uMriww38XqwhhMKNCnMyuisDCSrLtsvwxzn3wuFdT3MILERpIYK7gqO9SvnVLyksR0LRpoHnSXtcPFcupdrWiEVcGZcvwSisPIrDUW8Q5mdxeeDl3PlgIPVNGGvZcd30QnXdGcmmM2k0U4l1XMjUw/k01/IBETVnvQuzbkS2ckXWK8v9C7Z0Uqcs1MAPiNrLlfB/7UwgWuKiSixwyZXrWJMgyTqNfXCXHwk6pvPxWP1xvtRyJD+hrCtt6f/ShNBZwbPcDbaziygTZRv04VAtv7cCUxS9jTAoVnL1HeGPLGyyC/ulhnvQkahf1ipnvTQzm6+iO3UDibOrjHOn0sf9HdnWyu5UQvwBW8sg6yv4gbDKC82ZQrqXjykh/rjVr/3PXMjJYVP2IyBj5vD6frT50ZSQjcXmtjgh3CTdZb6wJObpIIC1IO6G4yB6Vn15NTVy88/o4x1rkXUtI85d5Q3bcGqcg7QSAf/Dj6ieGHgzg99jRkU7iRZLWyCbKwGJ2BXaG7WcQnuMvYU/9wmt1/L1f9gj5qR4NUEoShbRuhgjjVkMjkxzkgZl19ReF7lHJoR88xUwkfzrG70pmlvt+k2OIgweYu29zEnR16sw+KubnETyiB90Xr0IZDS95hBPAnlWhLbfhEyVwLzzwCDQUB29Fjvr7QhSYbvC+62zB8BZLuquSxxjvaHofKy5aLrPTqK3Y25/pCNV7vpzkIofqAZ+kDgZvHdU66E4q3RR/5mZf//fHkLpK7IR3jSOBBlUBV B3o3HChf PhR6OcTR7dlcLQR5gT9akKyQ0fYS8T0EwKYI1Edjlv3p+MqMFWsTsnLS0ju8rDXh71tDVMJWf3m3ypW2+7O3cUHilV9GFIGqMvWf7Lkge55kTZHJlqEjPbZoQ3TOkzCRFSzOml22wHAdDvA4H9LG6Ye3FYPpyQYPR1u3Gq8xufTynm6eduhRBbuzIYoLTQU0NhWvtlPLz53CsBF/Yy0jtlvDwVPMPAv5HraSKGt8p/hi+Ua6fAfKYGHLF+yrraQi/rB2FBSBFu4OAymhKA07WEi2SP838C45WVbF++Oa0NwdGANrOqHbqu3GH7ONMk9sv/plfyzHZxege+5GMa3eCJPD6RXW6TaqHjLj0fhSWO7gcOMOi1c0Dynl8RGYmEMi4u4DI 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:38:44 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: 13859598 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 5A14DE6F06C for ; Fri, 1 Nov 2024 16:44:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE03B6B0099; Fri, 1 Nov 2024 12:44:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E69776B009A; Fri, 1 Nov 2024 12:44:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE30E6B009B; Fri, 1 Nov 2024 12:44:22 -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 AC3386B0099 for ; Fri, 1 Nov 2024 12:44:22 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6881B40200 for ; Fri, 1 Nov 2024 16:44:22 +0000 (UTC) X-FDA: 82738098828.02.853EEDE Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf03.hostedemail.com (Postfix) with ESMTP id 9387720015 for ; Fri, 1 Nov 2024 16:44:07 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=WFYfnakS; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf03.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=1730479404; a=rsa-sha256; cv=none; b=kcHMsJ348rsJJJpaCgCd1GOJHaevlUoyvoRdvuMOMQVYHEdsp0PE5qL8pNZWxWDgS0I6xh 8oUuZtTRomw3N+Qx5b369XZphqYzgewIW4VWCBLaMQSRS36WkCviDUnFDrehvpyYDyR6fE wi/Q6HKIxbAGX3OwJSQkGZUkIbNUjAQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=WFYfnakS; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf03.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=1730479404; 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=o9wsenaQ3AcpIiJeQpHBb8YYNhX0DwDwcM2h4qRlEQY=; b=keq6ruMC3DTR7Abbm2lJ1AqPCPgYhHTtHNAyQh09Tt6uVKaP714ugwNMLWOf4zI6xEbqWY /lf0YF3Rxyh0wZIWr6F6JYweOacyMlcRm4vbn3KwbD6AG3rJnWaSuUKE7LTvyy54hcKbV4 2zT+ZYBx8f4b2SojbEj9hn/RzIycR+s= 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=o9wsenaQ3AcpIiJeQpHBb8YYNhX0DwDwcM2h4qRlEQY=; b=WFYfnakSNgP4L62dn4dpHzoQTp oTIAJ63pkIHMWhmJYgJvWLh9xLVz9HOXa4LBuzpP5XBmceLm6cvI5r7dVkU5EcQRmOY5IeTHuaYm/ 4TNKjWRHBuyfiDAu8/kQPp6V+t9nEuWFAQ+8z4K9MZ3cP7oKuomzIPHQFyfPKqGXeXWSB36dhiVfD THzf0TuFA1d70IFdifNe98fhpGbMcC0vFpxwNMd0tlr/4YM458fGi8ADVhIyt10qbG7yTum3C7VzQ zhYhR5aW1QoslBer7qF6dqt6CES3vKwY2ofV0wgYt5C8yn0sJgx7C/kk5t8x+CKEYcaxKivnPAO6b yflGv1+Q==; 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 1t6uks-000V38-7H; Fri, 01 Nov 2024 17:44:10 +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 v4 3/5] mm: move ``get_order_from_str()`` to internal.h Date: Fri, 1 Nov 2024 13:38:44 -0300 Message-ID: <20241101164313.1073238-5-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101164313.1073238-2-mcanal@igalia.com> References: <20241101164313.1073238-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 9387720015 X-Rspamd-Server: rspam01 X-Stat-Signature: fhjiaaes5iwwwukawcytyeofpqcircbq X-HE-Tag: 1730479447-635085 X-HE-Meta: U2FsdGVkX19wCYKsxsY3Y1VkUVX2EGNvud5fGPQqjiXGL1jnP6n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HtNsybZPI0TaiLCwqPt3kRWW+wOBSDBir5I9rVi+amqMKJYgvTmGAnATZIpUXwa8/t9JFl9E5LPnkzLFErP+yubDSfd0tWmZZIXDbhGZoZw8Ir6nzMZaLFqLq2WBaA4eDYQUgtioiYzhcGtAlV+m2ufn5xn8iQdQ2lNcYhFeiGqoik6u3NnlUJ5R4Bf6z+C5Z70BYg/tPD0RrSoguUYmcGTJsmXwsnf2tBfKEBxMKepUnKqYpgyiM0eXOV6B96sNLeU3 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: From: Maíra Canal 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 --- 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:38:45 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: 13859599 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 CE678E6F06C for ; Fri, 1 Nov 2024 16:44:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62D456B0095; Fri, 1 Nov 2024 12:44:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B69D6B009A; Fri, 1 Nov 2024 12:44:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 431096B009B; Fri, 1 Nov 2024 12:44:29 -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 263196B0095 for ; Fri, 1 Nov 2024 12:44:29 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9FB0D120A14 for ; Fri, 1 Nov 2024 16:44:28 +0000 (UTC) X-FDA: 82738099122.28.E21CBFB Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf16.hostedemail.com (Postfix) with ESMTP id 7EED9180004 for ; Fri, 1 Nov 2024 16:43:58 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=DTlsWWg0; spf=pass (imf16.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=1730479250; 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=326LQ5a1f2v3ZLzduLtg3uK45EQenW+uWabI6Ia2etrG88EOQIfmQLYQJIlMg46wFSWoHy zd/qQrO9TWN4RUWxoACzI0rSjNBxE/jcKq6lgIlAaMtId8nDPVmPow3TojTWbh+J9T6lHj YZM1PdJCayP1bAkYFZHj+624ohIOTqM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=DTlsWWg0; spf=pass (imf16.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730479250; a=rsa-sha256; cv=none; b=Kcy9+IF7lNfQbparXlo0W8g/kElMeSXXBZqMbbj2B/69ZqGxTCEIfP12/axUsSQG4N4eU1 n2iUelLcVuhqUh8/dOxr6hEqc0rFmYRK/vu15a7RKdL3S8nMRSzDaIzTAzLAtGXq4nenTm lsyaf1w1vkXkcefgD070ETUnv7wWg74= 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=DTlsWWg0Wijq14RqoJhZkEnqlL elgbY19g+M5Fug9QCtz/IwcNcP9ijmE9Y1riDR7lCj/biYkL82qm2zMY6ZAzHV2wNbeaeKTAYsvOS icgBmpdB372QKoCLDOfNSle9+grrsh5pA5pQVD1pT3wg+HwND/BJXr5M7elDkwF2/D9lAVKpyaF4P qrxth8UW+WsLOwpOaUAsoKxx9bggGFtzG2SpzM4sYbSttlTOPmDM/4qEGGDXSHVNRZZg5xr1LL78P JEmU3CjTPt5Ze6fCpiGq+Hu5mGRknwTqyAGaUbOjt5PEb+aI5tzJYDgmYpTpkbHkDzXZvxQpu6avz to26xp8w==; 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 1t6uky-000V38-Bg; Fri, 01 Nov 2024 17:44:17 +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 v4 4/5] mm: shmem: override mTHP shmem default with a kernel parameter Date: Fri, 1 Nov 2024 13:38:45 -0300 Message-ID: <20241101164313.1073238-6-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101164313.1073238-2-mcanal@igalia.com> References: <20241101164313.1073238-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7EED9180004 X-Stat-Signature: 9jbzss5w8urkn4xc9dsowrsjpdixfrck X-Rspam-User: X-HE-Tag: 1730479438-577861 X-HE-Meta: U2FsdGVkX19e1XhXdsmGIoXY/37XgHmDh54/y1wk6hf3KvoH4iunl1rb6d2d0/C7fZ2EYAaapbITt/fq6zcWrP5n+ZgEfduMD3QBTT1VSRIr8xB2teL0D3UrZA43lDFHdPMrM++LMo+05acZ8xYNVg1BDybIcuqQruBfTA+PdkTbcp+rVnNUxl7ymCyHF0GDjVsq4uCsRCxDuBBm7aeGlkVz8z8PAyxA70jVBuGyEuh7Qtbxv5Tu5xnOsIpn5IzX1ftvLy6VtH2kR66hLEi8rqNj5Fs8fnz6WXNgr5WX9lITwJsiYndR1LJmrg5lTVtSV2wDpjlB9DOtJsNzKvz4PSHmBopZFpMsCI8svMDW6lgkmqJh4BHXZGl+XFN0BkY4VnSPauBDP6ully7P5jh5nRCuANx/k4qH+cUfuDKDNRHMX3lGpXeeGf/vyyLct3JLUTVNmEc2dyPw2x8A0nt07NbOarJsiQYiO9GtTtJpzcH2NEQjUWUFdD6Y6fgt11zOmii+RYcTDPrkq90cLRFRlH7P69Nm74+B25PrCJ5kZagxroR8bgMACjp2ykG51CEBXTJ77AgZXN8pM8Nw7Gr/A+4gtdmflEas4HcLDlPuyQ+mpyvkiKydXlRnJtc8IKhHDaZmx+0iqOFtpdpRWGtLXYd7mFaKQdYJ7DsIf7O1hSxrX293RAxlVW/2aTUA89sR9hObhMMrX3tdXM+AX+N5ISNEOvbQ1BTUwz3B2FCs995Dx2v87uXeR3dANJ3dH5NacoVE81PnS/BIsibIvvcOErpClLHw2HYwqnmeSaEY8+KGXa56niyozLOoygdO0N+y46Fq7jpjnweH1v4D5aagnPxR83t+QkF667SoJJ+c17nvZTkXEiGpdi68sC6/61zCoKfhn+2QAjqtnv5PC1MURTiLK5k29v3KoAb7C613YgCT0wOLarOxNxf+lU3dJWsNaTjCkF1FQW+OjwTFLA1 w3CPNXbJ DqxL8xOlWhvXD40UpwrLr0f1eH4s0XiNQqYKC/5VA1td0xRcUO38/cri2VM6HJqxByaBnXy6w/ZEjcGGqpvcS7yl4xt6b3F+zPKou/wTC58dxwsKVJRRED6Pr3Yyo2akfdsV9k4ihcHgVIy2+uAGMLeRY9grluvBZY/EA6bsDcFqEmCrd0RtaJ4IA6vzVrDKdcEx4sRQRpUpJxOSJ1Z7t66IDxtvXVWgCHJEZlq5fqPW3ABho3Y8430qCxhyQIMDVztH3Hjb7slRd/6oFfFjojFdioK3Lwo3htqL7R+MJniBlSnsibQ3/IGKxPGpkQfG2CXv3QtJse7op8Eo= 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 --- .../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:38:46 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: 13859600 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 C5B63E6F06E for ; Fri, 1 Nov 2024 16:44:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5918F6B009A; Fri, 1 Nov 2024 12:44:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51BAC6B009B; Fri, 1 Nov 2024 12:44:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3949B6B009C; Fri, 1 Nov 2024 12:44:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1F6966B009A for ; Fri, 1 Nov 2024 12:44:34 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C95E516024E for ; Fri, 1 Nov 2024 16:44:33 +0000 (UTC) X-FDA: 82738098954.15.EB9E577 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf29.hostedemail.com (Postfix) with ESMTP id CDA32120022 for ; Fri, 1 Nov 2024 16:43:53 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=eQ+iv6hm; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf29.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=1730479352; a=rsa-sha256; cv=none; b=JoLmDgNYTqMsTrzxIxtnSomDi8w1P/nS0jh7bZIMJsgBN1e5+3Gb7rnwCthfR11glQpODg Doew4ixC/4hkS2j5Prv5kNhoY4wtq8LbXnJ5j5q2NY976vIRF+HOrA2kUaSmMV3/syY7gW XAeEnlKq5gQmKmEZaG5uo1dsbKX3RHo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=eQ+iv6hm; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf29.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=1730479352; 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=E/KHWDpIc8NwWlPa2hRPqQcfcjj2dskUsZhuqQf7VJTBfGBbXMtEYsFWbiI5hfyKjLIcs/ QL0KLJ8HQfKQ7j8R7Say/ZjU2l9ElNifZzx9puhfCEM1dxCf0hwdrgZJAEdJe3ByZpAew3 hUi3yk1XlR1VB4TeStzwvh/OI4PjqTw= 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=eQ+iv6hmi1RyhhdT/7e0AJyq0B jnteK/4rybFsrn3485KaB8QP2pVyhzHadOOUIz/oxg3ZidSZ7ij8xA+/uIxEuPw12rRql3VrwOjcE W+G2UjuHUX5HL9dKwAZKKp1xHKX4lQIJ6e06etrULMGih7yS61+d6YlpnPOCf+AAEv9TZmd5TwEwe oonSy4aLoCg4zwQRF3Wrb+PAmlz3jrLapEt6eklaoa6t4W7rEa6FpBnZO5YlLzn0vvyJAfiWQK0uS 6r+04wDfA8S/4kJpypl+TGZtiAFIVCN45jmmjHOOVwP6/RWoivCXcWlWNHt++4t4lzcMQmgJvTfvO ApQitRBA==; 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 1t6ul5-000V38-3t; Fri, 01 Nov 2024 17:44:24 +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 v4 5/5] mm: huge_memory: Use strscpy() instead of strcpy() Date: Fri, 1 Nov 2024 13:38:46 -0300 Message-ID: <20241101164313.1073238-7-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101164313.1073238-2-mcanal@igalia.com> References: <20241101164313.1073238-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: CDA32120022 X-Stat-Signature: pg7go3gec3yiygefyh9hubh4qtqdi3w7 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1730479433-460831 X-HE-Meta: U2FsdGVkX1+HhW+yCtcaiWAQZZplaMMMPnyfTcVWy1upj4POZmz9ZHXzqaT8GDLbhVZIFrchdChcznknPvq6VmabtKsNsI9EufNQ6OOP+Fmvh3I4xODplpPeBgorW+SrdnB7A4Gg7NxFO7HoLmWPSSE/Q+QN/8x6bO1D+46fGjUJ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W/K7aVuzvm69obvhTitvMhiQkv5ejL68NNFa1p58dqVkATtziOuCyBYGA+tw+BacFR9zoceW0fTRiADYzRhE0WlEse+KDFrxqaf2JzJ8keLY/AOz4N73hGJCEmObp7nN2Uj9SqwI17lLkHYVDLbMCXfPgZiS/dE= 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;