From patchwork Tue Oct 29 00:13: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: 13854294 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 53281D5B851 for ; Tue, 29 Oct 2024 00:24:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D184C6B00BB; Mon, 28 Oct 2024 20:24:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9F2A6B00BC; Mon, 28 Oct 2024 20:24:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B18566B00BD; Mon, 28 Oct 2024 20:24:08 -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 8F6466B00BB for ; Mon, 28 Oct 2024 20:24:08 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4F78D1A0AB0 for ; Tue, 29 Oct 2024 00:24:08 +0000 (UTC) X-FDA: 82724742072.16.09C7C63 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf15.hostedemail.com (Postfix) with ESMTP id 1018DA002D for ; Tue, 29 Oct 2024 00:23:41 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=XhqzgsmJ; spf=pass (imf15.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=1730161289; 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=x/+J4VNwyIjYndlAztlVz2EFWQN/WXmhUknqKDEMai0=; b=JfeZ31DZJSsroD4qIcXvMO3NYKMet9MkfcDFtx4xRnvNmwMSNfgWuw5ySC8RVYtNio0mNK oCoRVH7i8BjygJw1qNwr6fLmDNvMDn3bgS206YFxWBErqTn9G+Bqg0DsbYTgEstfgU4oyp KX3uttNrepmD0VKGddARArOkVr4h5m4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730161289; a=rsa-sha256; cv=none; b=He5J9n5bee6lm6DzDzmSTstAH69ZiacPY8cU4GF/0L9d93G1UQ3Y/XBpviEwRxz8nnxXJH C6uA47jGKH0JPjHoECNh+cTzzm79p7Rr/B4lTj8LWOkEfHfGF98cF5M91rrfQ/Kd0kD3rT +kimgVl+IA9J/Yu7IJc2TidgYTchd+U= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=XhqzgsmJ; spf=pass (imf15.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=x/+J4VNwyIjYndlAztlVz2EFWQN/WXmhUknqKDEMai0=; b=XhqzgsmJFPEicL7uXc8og75hT6 GoLHVGkfeLhnFeZnqsIp/LmFd5p+DMTqpcTnTZfsMNWPvpMO8cOMAdP9dEL+4qLDcz1l22Axah76m 5i8pvPIen5duuIFzXBoxOYd7BriPN3mw1yLxwqosyH5YEDOg2v6xdKMhLPbcYuoXQTjLTcQWzujZB XazKzT53tLeY4W0J9nnM8LxKURXn5gPxzexKe8HoK0Hdjjkmggv3IrEB7I5A1EbZhEYVL48Tqn11g qvO5YgR8dEtRmTQQpliXY0rpILzWz9KAMN1MJpWzmlWTTPVsq3Aoy6WRl1ZLPYDQa5A48redJ6zTc HrqroFaw==; 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 1t5a1U-00GIrd-TT; Tue, 29 Oct 2024 01:23:49 +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, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Ma=C3=ADra_C?= =?utf-8?q?anal?= Subject: [PATCH v2 1/4] mm: fix docs for the kernel parameter ``thp_anon=`` Date: Mon, 28 Oct 2024 21:13:05 -0300 Message-ID: <20241029002324.1062723-2-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241029002324.1062723-1-mcanal@igalia.com> References: <20241029002324.1062723-1-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1018DA002D X-Stat-Signature: 37mb3jbyb11cid5t44kwigiotrbt5yr9 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1730161421-266040 X-HE-Meta: U2FsdGVkX1/zL47+PqHZEAtnyG1nHC3TEfcNHZFBqgBLTf3F91iGuJam5a7oPXPMP9EZ9aYNfoIRlfa89pj0u6cuijjX+tgSrDHRzGEqHVJT61bNoeBPcOwj712cwwSiz/gKjDwZGwPLQXhlGl8hsPPAaaPjd8dKu9zUB1lVTJBq4fQpgVSN6z/iFwdf2bU4H4AxqASwkwX96bOE/yn9UIWXyk7xXgfXiLa/bsaxJSejxzeUBKfp/pXaGEgnepOMWbblgGNzC0dZcGVdxKak3PwlWaBJM63QM1p41YMXk0sPMauXIHHAU0eDypgavcy5p5nvKKEFEqXS1R2QJ9ar6RIxow9UZKTFhXcshT70W8AF4Vi4qpMyvSa8Vhsgo9vt1KpU6EMGvM1jj34+DctBW2WIvBIRw0Lcc2N/I7WyU8shcGRewtVLHyiAEC9v8HzK+5E4n9w9EdsfhWhsAMyuEJnXP4pBaL03RKZayPDGxbAzLwoCXgKWusm5jW1wPgMnsgVyBkRIngjN+f9A2NzRjs1mCIUi0TbNC2W3sI6RhhXSA0JwzgIaJPZsb/PATZ0ghVepo/fZiBPDy40FoQOd/VJychLGIerEa569tjDbyrSEDLbA6QA63J/GoXdhtplbLPLbTkbbK7g6WCwVyTXKQ0NeTA01oqHRrW6N8d6/bi57/hhfOrplsrjrmDx0JKo6TVONW9ZX9/qIW0KvoVFFKZ8aXX4Cn1nC4Ef0HsvZQOGQMgNTPZNtw0OMriIfZ61l4BwUsm33qiqfTaHrmyAnKIBn1ZbM00fCoXT0IPVaHDBBu+gfpc97eW2vBYzCoCrsOdB9rH3U6bZyohhE/+wLZJ8CEeVzdUmunp8p9Nn6zfNli5qbIJYN1UoI9GYrQ3sFHBFBCK9gvsNaTniXqFf+SMgRhXIsop4AoyNoOhXTDunPwwMVeABps6RBM041zG6/nMp6na72+WfmNC8H9PP pKMV2Rid q1xfcmAFpAQoBgjcu1Dom2CKjP6t0y2TMAy1M0nIDnRN0nX6MkNgPndWEuzJh6UOQFESk9Ek6Sqx12fg2VLhFGznGYXOZ6v+j/eboBEbnqLGL10qkCDbcD4NKKNeI+jpMBT1raJFG73F39aUSEDofJP0SP0TiWPq73ByOuRrMJOYS+Gw+AUu46XBga48e2pa9dgaGowdwMk9s1azFOVIExXquK1/LAlE/FyP53/Wn8aA8ICDlWKi3Bko7gZOAGFkUr/C38vICYx/+cQUILLkT5OPV+KO75uFJgDAXGJP3Y07dcvR6WlV/wgxfGzN/2ayUT4otJtABecaEAYC/Ckhgkkqg+rB1r79iK3gueyUkYbDu4vVaa/DPYzaU2dN9JC4RYKbn/I19IQWSw722+L1ccoUuPqN6k1Od5rhbpPJtMZhFMvU= 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 203ba7aaf5fc..745055c3dc09 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 Tue Oct 29 00:13: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: 13854297 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 E7C6FD5B852 for ; Tue, 29 Oct 2024 00:24:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 221656B00BF; Mon, 28 Oct 2024 20:24:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A4438D0006; Mon, 28 Oct 2024 20:24:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F155A8D0003; Mon, 28 Oct 2024 20:24:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C8A746B00BF for ; Mon, 28 Oct 2024 20:24:12 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 80087AC0BC for ; Tue, 29 Oct 2024 00:24:12 +0000 (UTC) X-FDA: 82724741106.17.5B96EC6 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf01.hostedemail.com (Postfix) with ESMTP id F0B5240004 for ; Tue, 29 Oct 2024 00:23:51 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=bTdXTTpk; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf01.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=1730161334; a=rsa-sha256; cv=none; b=koKIFGQowIdA6+dL4Vk+vsugXG4vMVfSod0oDOHUlDzw24nEygBOYmd/ZCiajxX75dG3LM A5Mc/K5hzaB/eFB/zkSCohrTNOr7xx/5KBP0Lk1kkg8Aus/iAyapMTj2UA+aWkEIfC6r5R KjlSxMwJAExx8vbvc0zzs8uPSplni8k= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=bTdXTTpk; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf01.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=1730161334; 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=f8gjxek9e09f6K3wtJdNM5s9pyafMNTnPC2fusopxIU=; b=Yz7sQppd+e7iNUkC9L5XlHHcCoT2E1b1gtz1doUYVgqYyNulfHusw76W4WK2gIY9QLaaQg O2f8ZqNrtzl8HjjzO+g43ZPDQKEzbzRRiHn/S3LuCYZMHUSfnf8K54PghjOXCndjYroS0e XFInr4BmKnPOkNu5BbvbiJL6e4jH4NA= 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=f8gjxek9e09f6K3wtJdNM5s9pyafMNTnPC2fusopxIU=; b=bTdXTTpkXCmQP+P7vIFB9/gVW5 q6pgvxDrtE0mWPVomEbGVstuXNZsRkNV9ZEFtTqYfYuGDSRsXA9Pgx0FLw7D770Qi0mSaxnkqeXM+ RLbnLEuYpUUxQe5JQ6Bf99l/dCpjqnCgEl+AS1FOpqj2/+ihN6K1jjf+q8hVMB25f1ni71wDtz4/1 cmiqN7ToZQCDuSjpsQ3xSnSeBUdV+faRG6Jy09C1DdxOLAgUOlC5HLpNxDZB+VUncT0p+MFUgtEmB uN6wWULCJjf+7D03vrK3hGIXYdTC9lg/9yt0Pr278kRwmWREl6D+JAKJBjVa23jE3Ec79yFI/sheN XJAAHk7Q==; 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 1t5a1a-00GIrd-1C; Tue, 29 Oct 2024 01:23:54 +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, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Ma=C3=ADra_C?= =?utf-8?q?anal?= Subject: [PATCH v2 2/4] mm: shmem: control THP support through the kernel command line Date: Mon, 28 Oct 2024 21:13:06 -0300 Message-ID: <20241029002324.1062723-3-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241029002324.1062723-1-mcanal@igalia.com> References: <20241029002324.1062723-1-mcanal@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F0B5240004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: oh9zbdyek9hoea7k1k7goozqszer9uaw X-HE-Tag: 1730161431-105119 X-HE-Meta: U2FsdGVkX1+aMENKUiZ7U8UXDAazYOizjkRsC+SyborqxndI9opueo9pWgrxhAOKCeTBJ88uDjSRl309qu/h9bZOgwCD4I+JbKyFAVHxkY36A+dLLOVJrbYgJUWCV5ByXrtPnq+FDNJ+R2/AZewNRkSN0h/q31X+WpqDI+FMlGZO1t8aF7BOCjj1eYmd/qBmFkGfJO2olrnAbF89XRZFxWfhvhviEiXnvogfp9AY7Xiu6DspkY/WTAy4MaLt8zOMpxFoAzCbSAwvMkFkdPzEIw+Bnyz5KOJmXWEqtYZ2eKdACjRwz6MFGSh1dx1lOUG9Kw0GKp1J3ayZnQQo0tiB/F6W6/H3sNzuS8EVVQ5qYeTSSpy9GFUUDFtsPz6+ngYRzJFbjdE+3L5L7bhKtJ862/q5iC24p+U0PNdf/7gh0dj9gnPlfAyvY8ghUGfP/nDuyuqDffaEvIKDcMH7mCVPkyab8KfelJguKg4Z5Mn/wZnARZcJGsj/xLDWSZR38+IDMUg0eeiYFvop7jqcFqwXkJuOZhofhC9ofo7wgwQ1/vPjNlXSiw8JkgzG6AUIYlXgfWn1iTcna3dx4vTtCHw83lTGfltLkiuqzrFu6XMPbQF7k8AhQ0zVxhxGFCDAnfVmbf+yTBkPufL0SIcDpAJwVYhzNFv2mzkcbNllj48qhShMaSbVSMzp9zpGSiupERgImE2Smf86pGkPLTUtvvFlZmxE3pA/ACYSCoqJ7EYGWCJznqDetK8xxCiBrB5c4AiDU6hnFHZk/igM59Uw19L2L2NsVpAmTbdmZw7otf4188AKChQh04TQJRsbT2GD9IG0Ose+CxE+F3s8LOeAgbtcCPzmqjd21BSJLOtecnD43qKIrrWUO0wjYy3u9xIxT4CflNJ+CWG3GA6ihASDW7Of+Eb0N5+x/ECDVCihoItcFy/DBXFMA9Irrml+nq2mDWalAsMIcPOe/neQ0Yz0RFD p3x5KEd9 7b+3N5oTeXk3mSBuijlJFmP7ZRkSMZAfjB/tU5mB85CPkbvAFiURUkzSc1aa51REfOSpeCuiyKFXpmMZbdpyiI1mxZmSyihz6neGQZuIEfBmBrVtR0H5kj/c8Y4xvOyNNija4soAyc4qO6HurM52ZhO/MXo2KdYTUTwR69WS4Ezpt2oOf1mWJ9UevHkTJoRB0rKu2WCGTHGw3fcYNw6yGkV8FFeL0/0OpFqTYcX3GOhnuSvb4QpnacfmWYqUG1f+Jdz9kbxR02cu5AEY76O3dAY1bUJD/RdFTmtGfsIYLnLQt2aeSzg03J7DiOySzT8ksfkTz91VoTeZ+YkU= 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. By configuring the default hugepage allocation policy for the internal shmem mount, applications that use shmem, such as the DRM GEM objects, can take advantage of mTHP before it's been configured through sysfs. Signed-off-by: Maíra Canal --- .../admin-guide/kernel-parameters.txt | 7 +++ Documentation/admin-guide/mm/transhuge.rst | 6 +++ mm/shmem.c | 53 +++++++++++++++---- 3 files changed, 57 insertions(+), 9 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 745055c3dc09..9b5b02c4d1ab 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 44282a296c33..26c1eb1b4b1d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -582,7 +582,6 @@ static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, } } -#if defined(CONFIG_SYSFS) static int shmem_parse_huge(const char *str) { if (!strcmp(str, "never")) @@ -599,7 +598,6 @@ static int shmem_parse_huge(const char *str) return SHMEM_HUGE_FORCE; return -EINVAL; } -#endif #if defined(CONFIG_SYSFS) || defined(CONFIG_TMPFS) static const char *shmem_format_huge(int huge) @@ -624,6 +622,20 @@ static const char *shmem_format_huge(int huge) } #endif +static int shmem_valid_huge(int huge) +{ + 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 0; +} + static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, struct shrink_control *sc, unsigned long nr_to_free) { @@ -5070,14 +5082,10 @@ 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; + err = shmem_valid_huge(huge); + if (err) + return err; shmem_huge = huge; if (shmem_huge > SHMEM_HUGE_DENY) @@ -5174,6 +5182,33 @@ 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, ret = 0; + + if (!str) + goto out; + + huge = shmem_parse_huge(str); + if (huge == -EINVAL) + goto out; + + ret = shmem_valid_huge(huge); + if (ret) + goto out; + + shmem_huge = huge; + return 1; +out: + pr_warn("transparent_hugepage_shmem= cannot parse, ignored\n"); + return ret; +} +__setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #else /* !CONFIG_SHMEM */ /* From patchwork Tue Oct 29 00:13: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: 13854296 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 9D986D5B851 for ; Tue, 29 Oct 2024 00:24:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AF586B00BE; Mon, 28 Oct 2024 20:24:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 832226B00BF; Mon, 28 Oct 2024 20:24:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65F506B00C0; Mon, 28 Oct 2024 20:24:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 34AB06B00BE for ; Mon, 28 Oct 2024 20:24:11 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CB224140839 for ; Tue, 29 Oct 2024 00:24:10 +0000 (UTC) X-FDA: 82724741904.21.1CF6950 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf13.hostedemail.com (Postfix) with ESMTP id 713F420006 for ; Tue, 29 Oct 2024 00:23:44 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=Sdshq8td; spf=pass (imf13.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=1730161369; a=rsa-sha256; cv=none; b=7dzDDaM43LvH6g/OoCZNM86R4yC2vA5q7YWIfee/kzbPrC9q+f2hYBjz3I1lPMHlsG7L3/ 3hypbDvVa/6EvmxbOG0P4vSopw0X4ouxzi5YNuhkPumqjbKGKlTF/oW2Z5o+MzQqEz2pqA SArlKrZbm1ThA9kZ7uI9+p6VsvuHbgs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=Sdshq8td; spf=pass (imf13.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=1730161369; 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=w+ns6OSoZMKNPdhNYQfwqi4ljcYi8WU+6sPV1i33TG4=; b=LqRiTgUwhhTWE/gFmPNpApWZNCjXq038XF+f1qMET5J1ShwOFXCzUiMaHAF7Z9mUNMRVlj oZ2q2lyxr5UslRgKczMeO/eeZtSG3Hvsub5O2t7CZs5C4oluwIbNi9doEFnVWeT2H7wrD0 n4GecBYpQPUz5O2T3l7RLGONA9UlNsw= 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=w+ns6OSoZMKNPdhNYQfwqi4ljcYi8WU+6sPV1i33TG4=; b=Sdshq8tdeTIIZrwGdLocfz8Z1U /2xLHI03EpXyzG964+QjuqUdm7LDnIh4Fdiefj+fzZ0ATq0IkgA2c9zEpJ3pJlnMgD7k9smvtGXkj hNzBnBZuh21B65Mq9xtip4Ughf7wt4IwyKJ+siF42LigZgZe1s35ifUaMxw+H8QVKh+5hFekWf6pV 9LdZlYmo9CCSvlkAMg8AqIn6xg6TPWB1FxT54SgAP8jMTLU+4xmdR9e6Gs9IAuDAyfdgJtWaa1QbK uP+1i0vmjaqC8pP3eE0NtDIBhZvDEBPSmyiTJav4TEdkcRhY6TL1w/oFvVRNU0g9q/mNQLqWviQ3N PxRkKfNw==; 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 1t5a1f-00GIrd-8G; Tue, 29 Oct 2024 01:23:59 +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, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Ma=C3=ADra_C?= =?utf-8?q?anal?= Subject: [PATCH v2 3/4] mm: generalize the implementation of ``thp_anon=`` Date: Mon, 28 Oct 2024 21:13:07 -0300 Message-ID: <20241029002324.1062723-4-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241029002324.1062723-1-mcanal@igalia.com> References: <20241029002324.1062723-1-mcanal@igalia.com> MIME-Version: 1.0 X-Stat-Signature: dqf617q9igzenmfpgmqzphoh6qeathjf X-Rspamd-Queue-Id: 713F420006 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1730161424-857403 X-HE-Meta: U2FsdGVkX18aMpAkcfShqHimosyKOaSXi5B/lKHXVBwMibMitHOe6zTj0nv7szCZVRK4Dt2+MVol0NwqzqbxTeTNaRb6gJX2c9T6OvZsPqtBmo4AepBVIVOoUE9biaklu27eOCn/CGUhsVUwEM3euQIvZvSW89C3fpSGtmq7PQK9iYSsOY9iA7WV1CUHq2y4qnIeCbDFDlbAFKmkuLi++qCEIFCpz5iI/fT53wJ0hbZplpro57L1mZrSh2Yyue9du7x5TLS6frXBEXX+dNhXk8rtqeGOmxkQDOuNPOScurDiMu30POqw5zIi3f3AbQpntuzrGTkol3tPHwz+96e1j+wvrwa0WfGnq2DrZ5qYUcOk9lkgeD6aFEviOJUjTeAJGkVULhvvLxHIdoSdIqYty2i9P6vo89LjRJrpI0KBjhXsLni1+paWEsHp7lr032nRV7n9khUerFLbM/wA0LQSxZxTbe2k1tDwFjnCMn7j2DrwpOcFN6YZOfUzhpKDO0yO17Xi3deANizqUF29d/wBK/jfQdbvsOmhiKvzjTzpzBcCo7iHFIaZc30psPGJSKHuvHxL0f6hEwGOC0WqznZifY42ATtldEdEw2jcxGhVFHqjsHqi1w9P+2BDds0T0aVvyEOgHr9KK+iJ4f1lK+7d30cX/sSWHY3P3KbqW2efNN8YC7hNPhQxYO/+2/rwAJzpMgc4gYEe+T5B9fDCxMcqapA4Sk5z+sn8ZmOqLmBNaxsBiRtTFagjXn6bdKVr1mDje1A2v3Z25++vpZcV3EhLTYgREgbqcoizlsHxiX6Tg1IpR/XMyBxcumLRveHuXmJfqRwjfugC0fj5tyMsxVZ2TIAk9qszeQL1oj1vjFhOrdw6dw/dArD2HIuQtGr7R38u96Z6WHiy2qyaIDfgKkuzLJJtQW397LJYPveUESwq9XOS9IYOBJs74rz9m1OiP7zJR6R45AHL7B3vM+0N0XO SWXfDvWj Gp62oQMMVFIDurQr7hqXi9SMpaFzwGfTxPlQV6dKQx8GKYBUANKpEoXhUF59HDcuuUmiXcED94nJCdd2ZSkHfXwogm+kAc3KbIGP/vUrWQ2O0JoVd2tCcHKC77INVsGOCenq12vCtNs+IgWEXsvAZV6k1V4N8ksHlrph0qUbnUEPKw3JlVlNGi/tL5vlkMBW7c9yvQu1yV9/d7XvlVOncAh804q7Nt1gnpd1tF0oKsFy2j+oV8rYEn3NMMCFZymMSGUO7MV6MQY3dfOhUwUek/srGwEy9OzHsTe5tsoyO0aFZXQUJCnid5ZmqLTZ7FxDHNJdaPEcu4eNQqlJzQBu2q5X3/aWwh8g1iYceUr/ldp0MoCqrRJ67TFyXMcL4yhFRuV+f 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: Currently, the function ``setup_thp_anon()`` is extremely tied to the policies and bitmaps that currently exist for anon THP. This means that we can't reuse the function if we implement a ``thp_shmem=``. This commit extracts the behavior of the function to a new generic function. The new function is exposed in common headers for future use by mm/shmem.c. Signed-off-by: Maíra Canal --- include/linux/huge_mm.h | 29 +++++++++++ mm/huge_memory.c | 109 ++++++++++++++++++---------------------- 2 files changed, 78 insertions(+), 60 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index b94c2e8ee918..b82e9379f2bf 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -471,6 +471,35 @@ void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address, bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmdp, struct folio *folio); +static inline int get_order_from_str(const char *size_str, + const unsigned long thp_orders) +{ + 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) + goto err; + + return order; +err: + pr_err("invalid size %s in boot parameter\n", size_str); + return -EINVAL; +} + +struct thp_policy_bitmap { + const char *policy; + unsigned long bitmap; +}; + +int parse_huge_orders(char *p, struct thp_policy_bitmap *policies, + const int num_policies, const unsigned long thp_orders); #else /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline bool folio_test_pmd_mappable(struct folio *folio) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 832ca761b4c3..c61f4481cb6a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -958,91 +958,80 @@ 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) +int parse_huge_orders(char *p, struct thp_policy_bitmap *policies, + const int num_policies, const unsigned long thp_orders) { char *token, *range, *policy, *subtoken; - unsigned long always, inherit, madvise; char *start_size, *end_size; - int start, end, nr; - char *p; + int start, end, nr, i; + bool policy_set; - if (!str || strlen(str) + 1 > PAGE_SIZE) - goto err; - strcpy(str_dup, str); - - always = huge_anon_orders_always; - madvise = huge_anon_orders_madvise; - inherit = huge_anon_orders_inherit; - p = str_dup; while ((token = strsep(&p, ";")) != NULL) { range = strsep(&token, ":"); policy = token; if (!policy) - goto err; + return 0; while ((subtoken = strsep(&range, ",")) != NULL) { + policy_set = false; + if (strchr(subtoken, '-')) { 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); + end = get_order_from_str(end_size, thp_orders); } else { - start = end = get_order_from_str(subtoken); + start = end = get_order_from_str(subtoken, thp_orders); } if (start < 0 || end < 0 || start > end) - goto err; + return 0; nr = end - start + 1; - if (!strcmp(policy, "always")) { - bitmap_set(&always, start, nr); - bitmap_clear(&inherit, start, nr); - bitmap_clear(&madvise, start, nr); - } else if (!strcmp(policy, "madvise")) { - bitmap_set(&madvise, start, nr); - bitmap_clear(&inherit, start, nr); - bitmap_clear(&always, start, nr); - } else if (!strcmp(policy, "inherit")) { - bitmap_set(&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); - } else { - pr_err("invalid policy %s in thp_anon boot parameter\n", policy); - goto err; + + for (i = 0; i < num_policies; i++) { + if (!strcmp(policy, policies[i].policy)) { + bitmap_set(&policies[i].bitmap, start, nr); + policy_set = true; + } else + bitmap_clear(&policies[i].bitmap, start, nr); + } + + if (!policy_set && strcmp(policy, "never")) { + pr_err("invalid policy %s in boot parameter\n", policy); + return 0; } } } - huge_anon_orders_always = always; - huge_anon_orders_madvise = madvise; - huge_anon_orders_inherit = inherit; + return 1; +} + +static char str_dup[PAGE_SIZE] __initdata; +static int __init setup_thp_anon(char *str) +{ + struct thp_policy_bitmap policies[] = { + { "always", huge_anon_orders_always }, + { "madvise", huge_anon_orders_madvise }, + { "inherit", huge_anon_orders_inherit }, + }; + char *p; + + if (!str || strlen(str) + 1 > PAGE_SIZE) + goto err; + + strscpy(str_dup, str); + p = str_dup; + + if (!parse_huge_orders(p, policies, ARRAY_SIZE(policies), + THP_ORDERS_ALL_ANON)) + goto err; + + huge_anon_orders_always = policies[0].bitmap; + huge_anon_orders_madvise = policies[1].bitmap; + huge_anon_orders_inherit = policies[2].bitmap; anon_orders_configured = true; return 1; From patchwork Tue Oct 29 00:13: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: 13854298 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 543CFD5B851 for ; Tue, 29 Oct 2024 00:24:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B25F8D0003; Mon, 28 Oct 2024 20:24:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 414276B00C1; Mon, 28 Oct 2024 20:24:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CA0D8D0003; Mon, 28 Oct 2024 20:24:17 -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 E57B56B00C0 for ; Mon, 28 Oct 2024 20:24:16 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A8C6E140890 for ; Tue, 29 Oct 2024 00:24:16 +0000 (UTC) X-FDA: 82724742030.25.CA8CC98 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf30.hostedemail.com (Postfix) with ESMTP id D2EDA80003 for ; Tue, 29 Oct 2024 00:23:29 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=icCQQT2l; 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=1730161400; 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=BwshJwo48RIhJnqvpdLmCKcZc0vOflKYESOeF9s3h5g=; b=C9JOoVld5U4jsXlrxr0qyF+ozGgCqA2hM83RUdRNcHrawcsGmjAbqvaVmSV0sViV0Cv/kC D2u6jb4Pp/SC3/e5s93CNjFz904fqtpuipLxrfpcbQUy1fFWfPQnJDygZuf1YnprEqdenf qLYGPbeA0gacBCl2vED2Pd8p6PMLQFg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=icCQQT2l; 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730161400; a=rsa-sha256; cv=none; b=vHs/CQM3PU4e4uy6nBH7uWFMipS0wt7jWNsM4Be33LuF5uRVwJWmqctGaokwbixB5+JbT1 7xdAn9Q04NPioY4u12lwbqR70YCkMca+U+kVh1QEZ8qNimmnUdP7Gm0VDZep/+BiXmZxLr QgIA8OJvPyWHp5IEyajDu40gTZWItAk= 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=BwshJwo48RIhJnqvpdLmCKcZc0vOflKYESOeF9s3h5g=; b=icCQQT2lxYD/Bkswn+kH5dOcQl 4OyL053b9xdV1IU4hvc3z6E6kEqCdEQKIEOC3InqAVEdZmg0nkJYzr+9gIoHMpwBzRVEPPwROwdcz 1raCGT8RCC7Uh3t7hjq/6slsuJgezXZxSUq/LCx//sXBjGDMmcZ7r1nBGM9G1BoVBC2Hq6ZqUHRYk 31RYRo3CfcM+ElquSuLvP2lxg7i46wfBU+3vacpv/2Rd5XwuCzqZksb1AGiXJZJe93JRyWhLd5r1U /P0X6aHHZdihEbdOoe/XLiNuG6lQRhNlmCNnt3Pwcpm5Max35hEfROmuCh3Doo7ExtT6383OxEDOZ /B+mHGrg==; 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 1t5a1k-00GIrd-8p; Tue, 29 Oct 2024 01:24: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, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Ma=C3=ADra_C?= =?utf-8?q?anal?= Subject: [PATCH v2 4/4] mm: shmem: override mTHP shmem default with a kernel parameter Date: Mon, 28 Oct 2024 21:13:08 -0300 Message-ID: <20241029002324.1062723-5-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241029002324.1062723-1-mcanal@igalia.com> References: <20241029002324.1062723-1-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: i9nff1qbtn66wibjfq3azmui73rfiibz X-Rspamd-Queue-Id: D2EDA80003 X-Rspamd-Server: rspam11 X-HE-Tag: 1730161409-319075 X-HE-Meta: U2FsdGVkX18IXt585UiIc2nw2J742+ilvW/xqdq88eeFd9bO8gKtvCedcamx8BiNz4s8ruHcuj8iHgmgv3f5of0P2jz8ZTSQCTsgh2LSAIB43vb8GJ2NaKt1Oe0V637W7/svVa1Al4v4L8HbseChXsvzEYEZM4Vcvb4g8VXJh7xrAK5BP0MKB0OxSzTtnw2XNMzZs69m1sAa6uJmnXmdm4AXL2zBQ2g0b8IiEFEnXL1wmhqL5dlTa9QAGKHeAB7bVKgmcjAbWwrHBtnwj4FSAKJ3WP2QFhREaukRu0sAJX3ArBFcsqx2Z37ljj0HepbopqzwrKSRPY5ECJ39BAetgEdRESMcgHLwFlvwJmEacMvmeKgQR5FhnYQg7Sz90CNcCRoEmEdrdf23B/ENzRF165CK8H9v7+ay4WXGEUmBtdvRFLg7Jr9XRfeK6X5NRzNT3mWIHkGx8/pTakcra6RNcZosMXL9kXhH3bTaA09Q1lRAgk3P5J1btCAViblvMmil3YeryWtinZ5KwQbsg0wbSSO4LQFwzuQk+/R76NOMMLObwn9UkLT87723FtunDVCMHpzogX6HL/jjE8T/KIeaVyQ/FfOiaW7Ze1ns+sNg0Thhe8+K322BAZaxVZOx6QW1BgbJwAvK3ka52j/yO0M8EEPoM28l8HAfZ/Vuc3zpcicKjYx7OEjifw6tcN/1NJ35orj398/PbQrxeUbChGP5aKBzqFA2wa2gq2hJdGcqfFpUdRaKY8Ghc64vo8K5941LdtWBtSRS5D460KKAU4OQkwdUEQMtWdt+GlYsbJ7eQGRe513NyYxGNKMlX3Xmlc8nGsS5rO8+3F3jIdk29TdADFpgWmBjYtzwrGRwHWQTmnsGJ9A1JRWJNE7xRsmR9HwXL570V7DvqxtniG2mIM1iN2SZZLe3DKoH3zhWS+cuHjj/x25ctn6I+5MyoRbxybeVBVNAE/7BWRZvGALRjz8 MPufr3mQ r48kLdVFHUWhMBRL2AcRbyBuf3SZ4/Y3EMEzH3a+8CajwaL3AIewIa7y9vbWYPPymAK+6rzjzlmag41QNw7lXMUbVOGl4JSHHDxAJnFXjiDYk2aCVtnBKTuBp2TdPU7daSxDQzhcVPnHFEz4MXHQeQs31DHSYYAbMlagEqaxmww9iHKt2V41aN36XW3CtocHrzt1YF5aDVUlxP+Gp/IxyuhuuyMNjlo4G6lfvqKUOROKbL0sunoIJvLXexI4qtTw3fh3Q2boCTGixGl+X1r4ufNff6peIKfMxd9W8RAE+8r5BNEIift8stq3uDM2cZoheCATYd9bIsi4MP7A= 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 By configuring the default policy of several shmem hugepages, the user can take advantage of mTHP before it's been configured through sysfs. Signed-off-by: Maíra Canal --- .../admin-guide/kernel-parameters.txt | 10 +++++ Documentation/admin-guide/mm/transhuge.rst | 17 +++++++++ mm/shmem.c | 38 ++++++++++++++++++- 3 files changed, 64 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 9b5b02c4d1ab..47e7fc30e22d 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 26c1eb1b4b1d..37951bb863dd 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; @@ -5184,6 +5186,7 @@ struct kobj_attribute thpsize_shmem_enabled_attr = #if defined(CONFIG_TRANSPARENT_HUGEPAGE) + static int __init setup_transparent_hugepage_shmem(char *str) { int huge, ret = 0; @@ -5207,6 +5210,39 @@ 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) +{ + struct thp_policy_bitmap policies[] = { + { "always", huge_shmem_orders_always }, + { "inherit", huge_shmem_orders_inherit }, + { "advise", huge_shmem_orders_madvise }, + { "within_size", huge_shmem_orders_within_size } + }; + char *p; + + if (!str || strlen(str) + 1 > PAGE_SIZE) + goto err; + + strscpy(str_dup, str); + p = str_dup; + + if (!parse_huge_orders(p, policies, ARRAY_SIZE(policies), + THP_ORDERS_ALL_FILE_DEFAULT)) + goto err; + + huge_shmem_orders_always = policies[0].bitmap; + huge_shmem_orders_inherit = policies[1].bitmap; + huge_shmem_orders_madvise = policies[2].bitmap; + huge_shmem_orders_within_size = policies[3].bitmap; + 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 */