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 AF5B9C54756 for ; Wed, 21 May 2025 01:03:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F7D66B0083; Tue, 20 May 2025 21:03:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A80E6B0088; Tue, 20 May 2025 21:03:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BEC06B0089; Tue, 20 May 2025 21:03:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F121F6B0083 for ; Tue, 20 May 2025 21:03:36 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 46D431A1B75 for ; Wed, 21 May 2025 01:03:36 +0000 (UTC) X-FDA: 83465117232.03.1C8347E Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 4656AA000B for ; Wed, 21 May 2025 01:03:32 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=n15OM+Ry; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747789414; a=rsa-sha256; cv=none; b=xjma/pGbudCa3LKsyusqBmD6Zp9l/7gODy/hxo9yBQWFoqEpIGpb/baGfcNSa9DlyJUMkk vOSfw7S0hNdYSwobD0+UOAd9M80outAWRe6m47oZWjXE1w1r8OV4BJ5R1iMNXek1xLBO19 bljq5qD7h81txsvTwEvhSew1eJ1WJTs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=n15OM+Ry; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 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=1747789414; 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=IbxzWj46aDkmP6ud0D2tY3tdDM9QG1secqyWNuptJB0=; b=PWdydyKEr/QnT4dsyS2N+x1Tb6eBIWLYmzftwv4QjbHMYVhpfDaXd85V4/LTVhj0SDVKcn IyanRvkYX3MYRc87x7M6mBqDo29SpN6SV46SSpbGVBHPSm36WH8ttjsJgI9L0xumKSgaaE ooQY44rXiy3yb9k5AENbBJb/6TWiv1A= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1747789409; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=IbxzWj46aDkmP6ud0D2tY3tdDM9QG1secqyWNuptJB0=; b=n15OM+Ryf78KomniRMvzHfTJLZ0D60zifEH48G+wLvfpb7VHGUMWfANRdYAXj1UBp3WP0odxR2njM4pymnxiCNRCDd0+XGEOdoTE+q5MJjGdmr5vUEFkNAEdjxmn9/GycYSU2aZEkND5nMSYog0WSVHMlgIiYnFZpUAVNXdqaJY= Received: from 30.74.144.111(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WbPLCQs_1747789406 cluster:ay36) by smtp.aliyun-inc.com; Wed, 21 May 2025 09:03:27 +0800 Message-ID: <048f7e1c-2ae8-41d9-a46a-964ca6253314@linux.alibaba.com> Date: Wed, 21 May 2025 09:03: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: David Hildenbrand , Nico Pache Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, 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, zokeefe@google.com, hannes@cmpxchg.org, rientjes@google.com, 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> <13f8e557-da9d-4ccf-9372-6acdc865586a@redhat.com> From: Baolin Wang In-Reply-To: <13f8e557-da9d-4ccf-9372-6acdc865586a@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4656AA000B X-Rspam-User: X-Stat-Signature: wgd3obo7m69jt36813rfj9xs44n9fbn7 X-HE-Tag: 1747789412-432867 X-HE-Meta: U2Fsd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=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/20 18:26, David Hildenbrand wrote: > On 20.05.25 12:09, 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] > > Thanks for the easy reproducer, Baolin! It's certainly something that > must be fixed. > >> >> And I tried calling madvise() with MADV_COLLAPSE for anonymous memory, >> and I can still see it collapsing to a PMD-sized THP. > > This almost sounds like it could be converted into an easy selftest. > > Baolin, do you have other ideas for easy selftests? It might be good to > include some in the next version. > > I can think of: enable only a single size, then MADV_COLLAPSE X times > and see if it worked. etc. Yes. And some easy test cases I want to write are: (1) Enable all mTHP size, tuning 'max_ptes_none' parameter to check if the suitable sized mTHP is being collapsed (including MADV_COLLAPSE and khugepaged). (2) Enable only a single size, calling MADV_COLLAPSE madvise() or khugepaged to check if the suitable sized mTHP is being collapsed.