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 4E478C7115D for ; Mon, 23 Jun 2025 08:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9CB86B00BC; Mon, 23 Jun 2025 04:28:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C252A6B00BD; Mon, 23 Jun 2025 04:28:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AECDB6B00BE; Mon, 23 Jun 2025 04:28:33 -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 94DFA6B00BC for ; Mon, 23 Jun 2025 04:28:33 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 61C17EC89D for ; Mon, 23 Jun 2025 08:28:33 +0000 (UTC) X-FDA: 83585988906.10.3B13296 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf28.hostedemail.com (Postfix) with ESMTP id 67D38C0010 for ; Mon, 23 Jun 2025 08:28:30 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Saj7jdjB; spf=pass (imf28.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 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=1750667311; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=IEf+TlyjGMf/yw5GUS5wgd67IkgEKJjtX3hBskLNRsw=; b=DDDhM8eKn1tVnAWSO+GPccMj8nRniim2Kmiokst2dtxBtGOM6Kilrqbqdv/H2P6VDqOr3i QEKJDExFlUuMj9qWhc9wupWCq0yM4lRkgBliwACX6QdmMVfNqvdWaV9dCKTj0mWycBK8s5 3mTmFSc597GXnbQIuh6kw+9cd/kEOQI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Saj7jdjB; spf=pass (imf28.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 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=1750667311; a=rsa-sha256; cv=none; b=0bDKvWhzyfCmxZxlFsHdZZh6GFrW/XFSC6r26SF1iyfGo1haJ64pLyKzcRE015vs3OSPns WqHPv54Bqvu4sT6Q7dDF0ylaoD463yUiTUCfsIb+sBGtXQerqsWaFMXfAWGva9WKSF8bg0 5kfNgGF+v4yU7DR+RwwLU/4qZzy6cUQ= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750667307; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=IEf+TlyjGMf/yw5GUS5wgd67IkgEKJjtX3hBskLNRsw=; b=Saj7jdjBWBoE510oDM64GRJrEeyCn0o280gFf5yxg7gcKGTchH9AeO/gHYr8Kq2q4e+SvbPiXXzgoq+GVuVOMNPlXP1j1ZwWlUNUIlAaGAAsXGWE3f4rsHCcg6XfcOghd+KpCRLiU+iGFvYut5U52na9qBQa1e1EghwibedQnmM= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WeVy8NT_1750667305 cluster:ay36) by smtp.aliyun-inc.com; Mon, 23 Jun 2025 16:28:26 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@redhat.com Cc: ziy@nvidia.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 0/2] fix MADV_COLLAPSE issue if THP settings are disabled Date: Mon, 23 Jun 2025 16:28:07 +0800 Message-ID: X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: 67D38C0010 X-Stat-Signature: 6c9nigy19tza4tpdixxo13fyod7hs9fx X-HE-Tag: 1750667310-548025 X-HE-Meta: U2FsdGVkX1+6lroWkMJHoNu+c5VQkjFi8Df2awwJ22sdv9XI6Iyg4xEVOU3TiYKzxK3G2UEbel2XnHq7esT162LqZBnY+yn420QzxH8kGTT18LI4y7/ev91kiEcLmo+HyYOaHl60/cYcl0XCoCXaFp6loEYaqqIAd6/T6Qufv9bAnhoMDYxcMn8cOPJa2z7cMDmJazVB9ZvJjehKnXDo5Cp5niE89yvYJQl+7Q70/qnv7HBY7srkNG8PR8v/1AsV5n5XYQgbkNN9VJAi7dqhyA1QBkjzTndfh8nIGzChgwRo32FHLOpbuhz9om45d0MSDLSwFJAhyC7/bXlTdWlqY4ntKkJ0BxIokVy/I0xvzpXohOws6ho3uaQ5KME0MqaE46m0ebhcFEKycQ3rytBtGFeMRviIEURbp9LTVX0YohZkqdx0jn/CpL4i1lyyZ/yitkob+yoMTrAzcJidBz02YNk6WHEfF91jX9Te4EbYghAckQRw2JaznPaj60IOMc3abU8N+pX6iWBVAbiDR9rM0pvV0CZzH4RYH8mB+TP+dbtxXef9fiXZM3nsKeJkO+4yPyBUB4dOWcR5hcCLbiVPVN32siapo0GFDExiLOJYNYspMRCbcBhkViAAypYQ3CjD8gmAZNO+EoKUV7JiSq0hHThcKsSvxjQr1cvvK0Vra8mXxS9L/j6Y2zr/r/b7VLzZuJ0CZFkFNFURLLsd3A5PHMIGQMwTIy/wwGrZ34uZ1CiYIEiFHe9XI49yuTgEiPcfH5sSGBdRrLFUVLheRlti/AJ6yL9+Dnf+2eVVB39KC79ytFLPhNZl4GaiTLcSZlN2HmKTTYJEnxuFyXWOLP+KE6UZYuNZtNzJ5wpXraotWrm95HLOoj1WHuDXQwkfeiF5ivc09jc+rOFXoLJ+e40V7lR2rzAD4hPsQy9UrOiI+qucuV0/HjSlRPvwkroYUbNu3rMWk1oINePR+PNbraT zJA== 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: When invoking thp_vma_allowable_orders(), if the TVA_ENFORCE_SYSFS flag is not specified, we will ignore the THP sysfs settings. Whilst it makes sense for the callers who do not specify this flag, it creates a odd and surprising situation where a sysadmin specifying 'never' for all THP sizes still observing THP pages being allocated and used on the system. And the MADV_COLLAPSE is an example of such a case, that means it will not set TVA_ENFORCE_SYSFS when calling thp_vma_allowable_orders(). As we discussed in the previous thread [1], the MADV_COLLAPSE will ignore the system-wide anon/shmem THP sysfs settings, which means that even though we have disabled the anon/shmem THP configuration, MADV_COLLAPSE will still attempt to collapse into a anon/shmem THP. This violates the rule we have agreed upon: never means never. For example, system administrators who disabled THP everywhere must indeed very much not want THP to be used for whatever reason - having individual programs being able to quietly override this is very surprising and likely to cause headaches for those who desire this not to happen on their systems. This patch set will address the MADV_COLLAPSE issue. Test ==== 1. Tested the mm selftests and found no regressions. 2. With toggling different Anon mTHP settings, the allocation and madvise collapse for anonymous pages work well. 3. With toggling different shmem mTHP settings, the allocation and madvise collapse for shmem work well. 4. Tested the large order allocation for tmpfs, and works as expected. Hi Dev, Nico and Zi, I dropped your reviewed or tested tags for patch 1, since patch 1 was refactored according to Lorenzo's suggestions, please help review it again. Thanks. [1] https://lore.kernel.org/all/1f00fdc3-a3a3-464b-8565-4c1b23d34f8d@linux.alibaba.com/ Changes from v2: - Update the commit message and cover letter, per Lorenzo. Thanks. - Simplify the logic in thp_vma_allowable_orders(), per Lorenzo and David. Thanks. Changes from v1: - Update the commit message, per Zi. - Add Zi's reviewed tag. Thanks. - Update the shmem logic. Baolin Wang (2): mm: huge_memory: disallow hugepages if the system-wide THP sysfs settings are disabled mm: shmem: disallow hugepages if the system-wide shmem THP sysfs settings are disabled include/linux/huge_mm.h | 51 ++++++++++++++++++------- mm/shmem.c | 6 +-- tools/testing/selftests/mm/khugepaged.c | 8 +--- 3 files changed, 43 insertions(+), 22 deletions(-) -- 2.43.5