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 AA428C54E65 for ; Thu, 22 May 2025 09:39:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C31C6B0083; Thu, 22 May 2025 05:39:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 499556B0085; Thu, 22 May 2025 05:39:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D60F6B008C; Thu, 22 May 2025 05:39:36 -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 1F6386B0083 for ; Thu, 22 May 2025 05:39:36 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C21A4E6EE3 for ; Thu, 22 May 2025 09:39:35 +0000 (UTC) X-FDA: 83470046310.03.2B3482B Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf13.hostedemail.com (Postfix) with ESMTP id BC0A120002 for ; Thu, 22 May 2025 09:39:32 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=bq3wTmzV; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 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=1747906773; 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=eq52ZTiE586FJQkx6x0iygDvQMrob1T/ZEeu27iZI3Q=; b=E+VEHKxTd0Ke5oSjplV06gmrxwCfpULIQwbZgGTgk9ZAXslxD9TXg3933ZCo9v+iLqHPsn b/u0XuDHKCRCg87WJeTAOwwJBfjD8WG1Rmb8qrhzKmCgmTQpYKwEVsjyFtWf+PZg2+oSBZ ohqwVZuBRjvA6LGWrMO2peEJU6+5Pmg= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=bq3wTmzV; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 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=1747906773; a=rsa-sha256; cv=none; b=FAakJGBYFrEIZJBw4t/jOopOSyKqwq6TBC0LI11ksm77hqwJUKG6lilelszmiFxCJsnQdH TsuTESmI5GOVvxGKR8JojHUSP/fjSlCNKT+6QLJjk3VW3hNheDWKt9oYSpNQRYORTa4qxN gYz2A/+jZaDxFvEIy8zkB55uU+RZQiI= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1747906769; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=eq52ZTiE586FJQkx6x0iygDvQMrob1T/ZEeu27iZI3Q=; b=bq3wTmzVtpye/ntt9i2iHS05NE/SCVYufNsLu/5mZFsu3J+241/UP29t+gnDSz/EkOAJbKc8MwT0+W9v2q4eX3qhUwosxntTnxLhZkkLNgv1Fb4esh0+pk/9aXcRqYMppQEMXABiqrywylon/bjI07UzG3zqaaUrPIoQa/NVqME= Received: from 30.74.113.135(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WbVRfy2_1747906766 cluster:ay36) by smtp.aliyun-inc.com; Thu, 22 May 2025 17:39:27 +0800 Message-ID: <1f00fdc3-a3a3-464b-8565-4c1b23d34f8d@linux.alibaba.com> Date: Thu, 22 May 2025 17:39:26 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 06/12] khugepaged: introduce khugepaged_scan_bitmap for mTHP support To: Nico Pache , David Rientjes , zokeefe@google.com Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, david@redhat.com, ziy@nvidia.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, dev.jain@arm.com, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, baohua@kernel.org, willy@infradead.org, peterx@redhat.com, wangkefeng.wang@huawei.com, usamaarif642@gmail.com, sunnanyong@huawei.com, vishal.moola@gmail.com, thomas.hellstrom@linux.intel.com, yang@os.amperecomputing.com, kirill.shutemov@linux.intel.com, aarcange@redhat.com, raquini@redhat.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, tiwai@suse.de, will@kernel.org, dave.hansen@linux.intel.com, jack@suse.cz, cl@gentwo.org, jglisse@google.com, surenb@google.com, hannes@cmpxchg.org, mhocko@suse.com, rdunlap@infradead.org References: <20250515032226.128900-1-npache@redhat.com> <20250515032226.128900-7-npache@redhat.com> <9c54397f-3cbf-4fa2-bf69-ba89613d355f@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: BC0A120002 X-Stat-Signature: s8y8wc8g1sdqhwh6jbiadku5dwdfguzf X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1747906772-680904 X-HE-Meta: U2FsdGVkX1/m2eWx3XMuO8a3D1sqadnM+aclCoAhhu+B6h5mtLPmPtoca+KGG4JVp2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sPMZ4m3FZMcTTb1QC5gd8AAm9nMrsqoUQFkwWuFjqZksioILtsBybXAZmHxmBnbaHOFKA6vzy1dcYcyh1duqIeuGpr18v5CSnsPh8oEBxsv2ly2Y7eca371OSacZ2BaldAtlWB7FtQ6oDrXD/3hRb9Srjm7cQSfKwH3O1VuHv2SZgfkBu37zuQymqV0tFiRlCnX4b/C5nd5wsyifVgPfLeKkUQlcLetOaf0Kn5JzYaeJmsa22Wn1kBMup1CUiyiSt6zQmoSO3cxmWbmrNCLKO8EsONce+k7qJvHgxhfTD2P7cGgviKFnR/vyNOb5u8l/tyPDX+VA0iYKEHoBYgxkeH0JdkfeO70Ixg== 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/5/21 18:23, Nico Pache wrote: > On Tue, May 20, 2025 at 4:09 AM Baolin Wang > wrote: >> >> Sorry for late reply. >> >> On 2025/5/17 14:47, Nico Pache wrote: >>> On Thu, May 15, 2025 at 9:20 PM Baolin Wang >>> wrote: >>>> >>>> >>>> >>>> On 2025/5/15 11:22, Nico Pache wrote: >>>>> khugepaged scans anons PMD ranges for potential collapse to a hugepage. >>>>> To add mTHP support we use this scan to instead record chunks of utilized >>>>> sections of the PMD. >>>>> >>>>> khugepaged_scan_bitmap uses a stack struct to recursively scan a bitmap >>>>> that represents chunks of utilized regions. We can then determine what >>>>> mTHP size fits best and in the following patch, we set this bitmap while >>>>> scanning the anon PMD. A minimum collapse order of 2 is used as this is >>>>> the lowest order supported by anon memory. >>>>> >>>>> max_ptes_none is used as a scale to determine how "full" an order must >>>>> be before being considered for collapse. >>>>> >>>>> When attempting to collapse an order that has its order set to "always" >>>>> lets always collapse to that order in a greedy manner without >>>>> considering the number of bits set. >>>>> >>>>> Signed-off-by: Nico Pache >>>> >>>> Sigh. You still haven't addressed or explained the issues I previously >>>> raised [1], so I don't know how to review this patch again... >>> Can you still reproduce this issue? >> >> Yes, I can still reproduce this issue with today's (5/20) mm-new branch. >> >> I've disabled PMD-sized THP in my system: >> [root]# cat /sys/kernel/mm/transparent_hugepage/enabled >> always madvise [never] >> [root]# cat /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled >> always inherit madvise [never] >> >> And I tried calling madvise() with MADV_COLLAPSE for anonymous memory, >> and I can still see it collapsing to a PMD-sized THP. > Hi Baolin ! Thank you for your reply and willingness to test again :) > > I didn't realize we were talking about madvise collapse-- this makes > sense now. I also figured out why I could "reproduce" it before. My > script was always enabling the THP settings in two places, and I only > commented out one to test this. But this time I was doing more manual > testing. > > The original design of madvise_collapse ignores the sysfs and > collapses even if you have an order disabled. I believe this behavior > is wrong, but by design. I spent some time playing around with madvise > collapses with and w/o my changes. This is not a new thing, I > reproduced the issue in 6.11 (Fedora 41), and I think its been > possible since the inception of madvise collapse 3 years ago. I > noticed a similar behavior on one of my RFC since it was "breaking" > selftests, and the fix was to reincorporate this broken sysfs > behavior. OK. Thanks for the explanation. > 7d8faaf15545 ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse") > "This call is independent of the system-wide THP sysfs settings, but > will fail for memory marked VM_NOHUGEPAGE." > > The second condition holds true (and fails for VM_NOHUGEPAGE), but I > dont know if we actually want madvise_collapse to be independent of > the system-wide. This design principle surprised me a bit, and I failed to find the reason in the commit log. I agree that "never should mean never," and we should respect the THP/mTHP sysfs setting. Additionally, for the 'shmem_enabled' sysfs interface controlled for shmem/tmpfs, THP collapse can still be prohibited through the 'deny' configuration. The rules here are somewhat confusing. > So I'll ask the authors > +David Rientjes +zokeefe@google.com > Was this brought up as a concern when this feature was first > introduced, was there any pushback, what was the outcome of the > discussion if so? > I can easily fix this and it would further simplify the code (by > removing the is_khugepaged and friends). As David H. has brought up in > other discussions around similar topics, never should mean never, is > this the only exception we should allow? I don't think we need this exception, unless there is some solid reason.