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 C474EC7115C for ; Wed, 25 Jun 2025 08:52:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 581C06B00AB; Wed, 25 Jun 2025 04:52:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 531F76B00AC; Wed, 25 Jun 2025 04:52:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4473B6B00B0; Wed, 25 Jun 2025 04:52:14 -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 350396B00AB for ; Wed, 25 Jun 2025 04:52:14 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DD2591D9A02 for ; Wed, 25 Jun 2025 08:52:13 +0000 (UTC) X-FDA: 83593306146.22.A13E089 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf29.hostedemail.com (Postfix) with ESMTP id 979BE120002 for ; Wed, 25 Jun 2025 08:52:10 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=sR2rWfdF; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750841531; a=rsa-sha256; cv=none; b=5DFWTrfDbq6dSVmimwPynT3UnmvydAMbXpDQ7PMNMjQgthuPZfs4iFYpDYUZheFWKknMqa mcq6u2dn+0Og9dV5tqE3qtsl+4xWcrj15Pd8F+1RXnHQ2xL+yru0PuGTFe0HkRKqVTSm7U nW5KR4TriAw66mbycn7u/45JbYHQIOM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=sR2rWfdF; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750841531; 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=Jdk7MOIYN3yseBOY4jjLY6dw7calfP5EQ2cuWW/TLEA=; b=vYNg9uxYaTY//EfQVTVoe85MX2J3Bc3eftLAiqCSvK3yEan3Mk39aqt4BglgSkC8Kyy1U9 GwKUo1iHTNDCrbiPc2pXzjvE3/6UXqkkrmVmV+FcOlA1ROdjMtDY0G4kQ0dhp0NbCurqVb xFvMZMiDttDfA3MtNZVZtYrQxgqI7xI= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1750841527; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=Jdk7MOIYN3yseBOY4jjLY6dw7calfP5EQ2cuWW/TLEA=; b=sR2rWfdFIiYHRrL8m0y6fsB61pkT5sxPwBvddNjje21ykfhQLxTIt8Lv3Wv/iIC6hDYd18D1XLHlCNHh6f2rZu3xPK7WmKZwoafL7YXTERvOtua5oHzLKGDsk/X9YPVCwgUiaapRUl1uBXg+lmseFWoMVYFy730GwmoLLYwSrq8= Received: from 30.74.144.110(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WevRTcD_1750841524 cluster:ay36) by smtp.aliyun-inc.com; Wed, 25 Jun 2025 16:52:06 +0800 Message-ID: Date: Wed, 25 Jun 2025 16:52:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 0/2] fix MADV_COLLAPSE issue if THP settings are disabled To: Lorenzo Stoakes , David Hildenbrand Cc: Hugh Dickins , akpm@linux-foundation.org, ziy@nvidia.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, zokeefe@google.com, shy828301@gmail.com, usamaarif642@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <75c02dbf-4189-958d-515e-fa80bb2187fc@google.com> <008ec97f-3b33-4b47-a112-9cef8c1d7f58@redhat.com> <01d679f2-fd64-472c-b9dc-ebe87268ce82@lucifer.local> <23b8ad10-cd1f-45df-a25c-78d01c8af44f@redhat.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: ss8sxme6upanm5qrqfy53ketx8uw695x X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 979BE120002 X-HE-Tag: 1750841530-891390 X-HE-Meta: U2FsdGVkX190jxzsJR8hYsW8qalKJxcCN/pa33gBA15VaB181pglF5h4WNFYhQo2OFxdkqlfo7Rr6C7cqTCUpMjOUjyVdYCvbDoKjCT+SJW4BS4kzfnDGo6to3edpeKRaVyAYFj7HaLc4wbLa1GIFia8/IxxftalC4Em2znbIDPurPDKyIaqD4hXfAMRQIh0sXtr+Oz2wLcmqDJzo1xv4WOdgY/mZh8CaKJ8F/CKNnXr24tKWYMN7osVxuYn4+Qf6p5z/8V3wNupTJR2mbqtBAsx9dvt2mdaXP4S9qdH7fFZOwtWQuFKf/Kh8V+YMsWd1X+oeN46Gt0n9298BChMF++ES7vjGEBQ8mvSZhvp/bTdzK99l5XlPF4eHkpbmEjBoAb/6XujcfhUn+zfI5NGSs17ARviJ8szUqjYSPspmzKCdJLeqr7fegOphUbA/W2iYcgnYN2PajPAkJvZb76T+g1+a6JcLC0X9/+0JLa2ObSRwm5aE8Yh0h94yIJRJturMKVzgv1+ac+1lyHGI/oV2QDKcb4YneW0lwKrHhzUfUsMAHgFRFyqjuN44IY5qLkBxn/b0qc+ION6qpN6jmSkil64gwmFK6ilyobtCXtXrtUZW8CRwYBY9+KJi+ujHeoixun4NcGvjxG6OEvjgYX82Wlmi623k6JlT738qpCf0sxHkLNMFDWpD4FoB9bsgklT1F+5JV9bDA9YMB4RPBrpkwl1KuYtuwhCeyYGiCoXmyGOz8oWe8AT7eWc/i+B2Y0DKEBVk1F6BRtcQ5LEE+kfR7kFc9K0SACe43QX5hw7xIO8BT/5wKJvpAWR6Ho6EE8rtEqfLOZH/7FukgJpsg110ONC7TgpH0iX4Jz5z011YGHil8fmcVYBf49m9tG89z5/4wN73uAD56DqNT/UdoLp42qPkHBsWHTF2bnSZdflIXHyAXji/DQHzfP+ZnVGs6Dw17IpkxZvAijjw4DRMc7 tcVCUYrC Wxp+25D0hZ1SyVh/9HNQMO+v0PJva2MB5vW9r2hSvR9iwvrx4W6eCD8SjQJZnOq0wz5HFtglfMoSR/IwV9HKjNZ5zM5ht6jIc9UrtKFkh0gh8Q7O64KQUWzuXXSNNq/bjjbjQNyOyGIdBe5chuilOJGFkg+OBGXOFQT2uP0/JThxjhXVbDyMiEc/eN1JnJaOfves/qOauvPw1x3Q1Z1rDJp2yMmAF64eojTfmeTS0HML384KdPpfF5sLp3qkEXU7xljjtXFfyQanc7PkAzU1V5IR28d8cvCjBYFhydYiSA7D9fnTJekEbG7/i+kgrLGFeWtNM5U8l3uR/Xb0gWPi9DZHaFe9TnpihKdXJZ6C1jvDK+UeD6EH1M58AGw== 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/25 16:37, Lorenzo Stoakes wrote: > On Wed, Jun 25, 2025 at 10:24:53AM +0200, David Hildenbrand wrote: >> On 25.06.25 10:12, Lorenzo Stoakes wrote: >>> On Wed, Jun 25, 2025 at 08:55:28AM +0100, Lorenzo Stoakes wrote: >>>> I suppose the least awful way of addressing Baolin's concerns re: mTHP >>>> while simultaneosly keeping existing semantics is: >>>> >>>> 1. Introduce deny to mean what never should have meant. >>> >>> To fix Baolin's issue btw we'd have to add 'deny' to both 'global' settings >>> _and_ each page size setting. >>> >>> Because otherwise we'd end up in a weird case where say: >>> >>> global 'deny' >>> >>> 2 MiB 'never' >>> 64 KiB 'inherit' >>> >>> And err... get 2 MiB THP pages from MADV_COLLAPSE :) >>> >>> Or: >>> >>> global 'deny' >>> >>> 2 MiB 'never' >>> 64 KiB 'always' >>> >>> Or: >>> >>> global 'never' >>> >>> 2 MiB 'never' >>> 64 KiB 'always' >>> >>> Or: >>> >>> global 'never' >>> >>> 2 MiB 'madvise' >>> 64 KiB 'always' >>> >>> All doing the same. Not very clear is it? >>> >>> We have sowed the seeds of something terrible here, truly. >> >> Fully agreed. "Deny" is nasty. Maybe if we really need a way to disable >> "madv_collapse", it should be done differently, not using this toggle here. > > Yeah maybe the best way is to just have another tunable for this? > > /sys/kernel/mm/transparent_hugepage/disable_collapse perhaps? > > What do you think Hugh, Baolin? I think it's not necessary to find a way to disable madvise_collapse. Essentially, it's a conflict between the semantics of madvise_collapse and the '/sys/kernel/mm/transparent_hugepage/enabled' interface. We should reach a consensus on the semantics first: Semantic 1: madv_collapse() should ignore any THP system settings, meaning we need to update the 'never' semantics in '/sys/kernel/mm/transparent_hugepage/enabled', which would only disable page fault and khugepaged, not including madvise_collapse. If we agree on this, then the 'never' for per-sized mTHP would have the same semantics, i.e., when I set 64K mTHP to 'always' and 2M mTHP to 'never', madvise_collapse would still allow the collapse of 2M THP. We should document this clearly in case users still want 64K mTHP from madvise_collapse. Semantic 2: madv_collapse() needs to respect THP system settings, which is what my patch does. Never means never, and we would need to update the documentation of madv_collapse() to make it clearer. >> Regarding MADV_COLLAPSE, I strongly assume that we should not change it to >> collapse smaller mTHPs as part of the khugepaged mTHP work. For now, it will >> simply always collapse to PMD THPs. > > Yeah thinking about it maybe this is the best way. And we can then update > the man page to make this ABUNDANTLY clear (am happy to do this). > > This keeps things simple. Yes, agree. > (One side note on PMD-sized MADV_COLLAPSE - this is basically completely > useless for 64 KB page size arm64 systems where PMD's are 512 MB :) > > Thoughts Baolin? We should not collapse 512MB THP on 64K pagesize kernel. So seems madv_collapse() can not work on 64K pagesize kernel. >> Once we want to support other sizes, likely MADV_COLLAPSE users want to have >> better control over which size to use, at which point it all gets nasty. > > madvise2() this time with extra parameters? ;) > > I sort of wish we had added a flags parameter there. > > But lacking a time machine... :) > >> >> -- >> Cheers, >> >> David / dhildenb >> > > To summarise: > > Drop series: > > * Might degrade performance for very specific users using > never/MADV_COLLAPSE (quite possibly via process_madvise() + a remote > process). > > * Matches 'de jure' interpretation of documentation. > > Keep series: > > * Provides no means whatsoever to have a 'manual only' collapse mode, > though does provide for manual khugepaged THP. > > * MADV_COLLAPSE automatically gets mTHP support based on obeying 'never'. > > * Matches likely 'de facto' understanding system admins have about THP > usage. > > Action items: > > * Either way, I (Lorenzo) will improve documentation. Great. Thanks. > * If we drop the series, provide another means to disable > MADV_COLLAPSE. But not using existing sysfs toggles, something new. We > will document MADV_COLLAPSE as PMD only. > > * If we drop the series, also consider how we might provide mTHP-compatible > MADV_COLLAPSE. Yes. Agree. Will be another mess I guess :) > > * Totally and completely refactor the hell out of the THP implementation > from top-to-bottom (over time this is becoming more and more of a me > thing... as I'm getting ever more frustrated with the implementation ;) Yes.