From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49109C61DB2 for ; Mon, 9 Jun 2025 06:36:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D78446B007B; Mon, 9 Jun 2025 02:36:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D28846B0088; Mon, 9 Jun 2025 02:36:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C40836B0089; Mon, 9 Jun 2025 02:36:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A3D3A6B007B for ; Mon, 9 Jun 2025 02:36:13 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1711C1410DE for ; Mon, 9 Jun 2025 06:36:13 +0000 (UTC) X-FDA: 83534902626.29.8A5D26E Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf12.hostedemail.com (Postfix) with ESMTP id 960F140009 for ; Mon, 9 Jun 2025 06:36:08 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mSZlG2+C; spf=pass (imf12.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749450970; 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=NkGvTMFQQCyEpDTkBUCTdfjzDh5e8ly4M3dbCb1Avtk=; b=PXXXEoxBmD6Nm33i2nLFLWS+oWbO2caKNy+Y1tELtZdsKwJtEfVXaFnK+3tNjNhyYOCdZM eRX0FY5ScgQsGgz6xfmyfdQcuPBtYXjxp+RdsLtwxxOvLyEUgtAmSY5tWpwXpmyCxYSGXL oP1Wk68LRn5jgvr2dqvXn5LTGDnpmJU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mSZlG2+C; spf=pass (imf12.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749450970; a=rsa-sha256; cv=none; b=Du5+p/ydhY5f6EniRy28HBQn/DNB9dIcuMIVPutVRE7bn2lkyZkfW3YUtYIRe7gjPs5lCd PXJGiRAyEkA/QGowJON+18vOcUkX26KGJLUr+exPI+XWXdtcGwndHWgWht9YDd1MkTrVic IfYy2bdQooAF99RbkEkD7i+VyK/IFlc= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1749450964; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=NkGvTMFQQCyEpDTkBUCTdfjzDh5e8ly4M3dbCb1Avtk=; b=mSZlG2+Ch94b+6dd/Mp2U7lDCe94GDE+MCinpJlWWGzdkV5gIRlcrpy4TO+MlanaS12CD5JEyoSfYLobYSQQgMYGnikRBY/7gD/Widy6N7W4Y/Nbfu85ijSl/3IsAnxPRgr/gNEcugbpRtPCydEd3vZjdVtmyItCskPX1TeQ27c= Received: from 30.74.144.144(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WdM8f3A_1749450961 cluster:ay36) by smtp.aliyun-inc.com; Mon, 09 Jun 2025 14:36:02 +0800 Message-ID: Date: Mon, 9 Jun 2025 14:36:01 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] mm: huge_memory: disallow hugepages if the system-wide THP sysfs settings are disabled To: Nico Pache Cc: akpm@linux-foundation.org, hughd@google.com, david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, dev.jain@arm.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <8eefb0809c598fadaa4a022634fba5689a4f3257.1749109709.git.baolin.wang@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 960F140009 X-Stat-Signature: 8nf3gbhx1m8cu5ckgxd1x4m7rhqaxtkk X-Rspam-User: X-HE-Tag: 1749450968-478296 X-HE-Meta: U2FsdGVkX18QiSQepo/6p5PuQ8LIF8FNW+CeVpgiI6K2tXf7iIxJIjTjE9uTlKvAR8yT4Z9TBaHn/9g4kLuURWgbyN+TOWkXfNq4nc6X4RejMahz60UfMXkxLpCWDHvhvqJRh+ySYEmHEKwqjbL30fvbbGnRDv20WPDKlcb8z9eVTkBIRp8pnlBspccJ8pQaEGlBg4+XVYQ87VAO6mloXp8z3Z3SxpSedq2+h5diXnDvYsq3sQvT55SaPD5E9jjL+RX1Tty+4dbSJhNH8cLmBA1P9pS/qYsAiW29wNzqCYUdMyFUjFvJpsNMqawZfuZCRpOkJ17S+4sFR0QAX26cMk89alp7ecmdNk1g7fYU0jNT1Lnsrd5FZo9CzK/0vIsA8ls0ogsgzT/99MUihqOEuVVaZ4BnrI0v2SG8vdzVfJ6J6+TVux+l1eWgzRKq7krDValN2CbI6Yr7DDt+nadUfFu/Kfykf+9daChsgg/4rVqXXgEoIsOqJ/hcI6MXe29TNXWS3x/WgWjnoEua63wpOtiYorez+2SJHGmod9CFHz7i6NKwBuv8AVIkUkB5TtFrLCzEnoyV386qs0ZgObmnemTF9Ir0Lxiclln4afjg1JgGZOxwZxpV78YbieOEOWrO/iTP7cSzEBZ5GWywJXE7tZcsbpIkEajilkCh34GfsZLhKoKPEZpEGKEjDueQGcl1bxIrIesUH58GcV6Y8WI08vvAgGs69UT/5cuWZzRBN+xW+gLV1UFIAdky5bDwSPEQoIZ/BWTkI/UgFKU9BU91nkw4U85EVqUD3vnQUjOPm9pNvYjX8rSC1AcyaElXkIaHDH+1NhMWyCJ1NqhUw0Ph8Yc6Jh3OHYwngF+7GP7jf53fhtKGQMmIRqQkMSMxIeN38WBZ6o9sY7HhlrSuxZtPDZt8oKtYQKMxechcTvaQtDgNy6dH6WuAaUXXIdUDovx7B/WfOO63F5aE+yiTM+K rOzEWEab 1PI8ryZ4q8Hj9hcx+D5rJtWhwc4kFMf/DhWkCQ6KpnfVB8CMA18cRHO6wnHiRHjCWDosvf33+4oq3ADdfBJDVsa9yFAe/2NVsnGC8MjG/floqlrw2+2yvg999UFBANwdtj0J0NBBOxkdMCpsJiG8OfpeRsL2y8/cFDIShBI3Adx7oNIRR3M6X0UpKu/P8vsVUo7Xalg3svT4xn7vhJPWcMhV625nm3nBcFoyjdG7HQ+JyzkRcKir9fXV7vuUBLjDLhCBPOuoQ/uodhT3Ew/vxs03Hu9qDG3wcph+/qPFIPxCXFrw7u+Q39c+lXY6/wLGUea/J7x5F3HtFUHkZoTGjPFfmF+YuHXEMzGhASlYQQhbKhyZ6ncxh7tcMg7rcGHFmjeGwtl/5pVJs4UF0ZV8eX4WmiXxlTPtr+49jcF7eTCyAJqM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2025/6/9 02:37, Nico Pache wrote: > On Thu, Jun 5, 2025 at 2:01 AM Baolin Wang > wrote: >> >> The MADV_COLLAPSE will ignore the system-wide Anon THP sysfs settings, which >> means that even though we have disabled the Anon THP configuration, MADV_COLLAPSE >> will still attempt to collapse into a Anon THP. This violates the rule we have >> agreed upon: never means never. >> >> Another rule for madvise, referring to David's suggestion: “allowing for collapsing >> in a VM without VM_HUGEPAGE in the "madvise" mode would be fine". >> >> To address this issue, should check whether the Anon THP configuration is disabled >> in thp_vma_allowable_orders(), even when the TVA_ENFORCE_SYSFS flag is set. >> >> In summary, the current strategy is: >> >> 1. If always & orders == 0, and madvise & orders == 0, and hugepage_global_enabled() == false >> (global THP settings are not enabled), it means mTHP of that orders are prohibited >> from being used, then madvise_collapse() is forbidden for that orders. >> >> 2. If always & orders == 0, and madvise & orders == 0, and hugepage_global_enabled() == true >> (global THP settings are enabled), and inherit & orders == 0, it means mTHP of that >> orders are still prohibited from being used, thus madvise_collapse() is not allowed >> for that orders. >> >> Reviewed-by: Zi Yan >> Signed-off-by: Baolin Wang >> --- >> include/linux/huge_mm.h | 23 +++++++++++++++++++---- >> 1 file changed, 19 insertions(+), 4 deletions(-) >> >> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >> index 2f190c90192d..199ddc9f04a1 100644 >> --- a/include/linux/huge_mm.h >> +++ b/include/linux/huge_mm.h >> @@ -287,20 +287,35 @@ unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma, >> unsigned long orders) >> { >> /* Optimization to check if required orders are enabled early. */ >> - if ((tva_flags & TVA_ENFORCE_SYSFS) && vma_is_anonymous(vma)) { >> - unsigned long mask = READ_ONCE(huge_anon_orders_always); >> + if (vma_is_anonymous(vma)) { >> + unsigned long always = READ_ONCE(huge_anon_orders_always); >> + unsigned long madvise = READ_ONCE(huge_anon_orders_madvise); >> + unsigned long inherit = READ_ONCE(huge_anon_orders_inherit); >> + unsigned long mask = always | madvise; >> + >> + /* >> + * If the system-wide THP/mTHP sysfs settings are disabled, >> + * then we should never allow hugepages. >> + */ >> + if (!(mask & orders) && !(hugepage_global_enabled() && (inherit & orders))) >> + return 0; > Hi Baolin, > > Thanks for making this change so we enforce the 'never' being never > rule. As others have noted, this statement is hard to read-- is there > any improvements we can make to the readability as Lorenzo suggested? Yes, will do in next version. > Either way, I've tested this and the functionality works as intended. > > Tested-by: Nico Pache Thanks for testing.