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 6A999C369CB for ; Tue, 29 Apr 2025 07:16:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B80AB6B000A; Tue, 29 Apr 2025 03:16:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2CD36B000D; Tue, 29 Apr 2025 03:16:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A02566B000A; Tue, 29 Apr 2025 03:16:23 -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 81E9B6B000A for ; Tue, 29 Apr 2025 03:16:23 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 383E6160E49 for ; Tue, 29 Apr 2025 07:16:23 +0000 (UTC) X-FDA: 83386223046.27.B49B7FA 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 5C0A7A0002 for ; Tue, 29 Apr 2025 07:16:19 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RIlmJnvu; 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=1745910981; a=rsa-sha256; cv=none; b=xwGYrLF8NI4VOh5ommWCgeg1Askj5YPhGNKDfKbjSloA4m7msxP/zoQe/PBKFk+9BarEkE 2TSVJ7M1C5hCFfL/FVvxMZF7UssT/vF/ZCJ71/5/ad315OBj5wnr4lmntIhbYvf1/Bx2Xe oGtUJ/7hOFKK2MCzP9F5N+eAoHz+e68= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RIlmJnvu; 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=1745910981; 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=V7fNVsPJQwk08b50EHm4veDfd70FS94pJvf8TbPo+hE=; b=WGgucBsWlpBH5eB7gaMuzEWKImrRRgfduW7+k5Lb7Tz5jY1wgFQFhPy7ocyUwt7uoq1WE/ 5umIqe3wd56cjPVEW2HtpwWWgVuZt4MtrLE+bgDNXJrzTQCJ9Cmp2R7xl1aFlGwYitoUsj ng8gRhLJgZOnRSL6J+juMIavzK1Z9pU= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1745910972; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=V7fNVsPJQwk08b50EHm4veDfd70FS94pJvf8TbPo+hE=; b=RIlmJnvuNVS/EWwv86PPU8tIWipo+Dj1xzZ1qzqVOIZrmc0VKik2GUXWk8nC2nA+iz7GtvGzCc6jkgsodF3sud7m8kTYjzjE29WaJGELIClpaxQNdOUyaMnNDxHRcayBeO0WTq1dIhkXVEjs0ZjiN3bCQsYQpitux7pKhqvaQb0= Received: from 30.74.146.169(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WYcmdSq_1745910969 cluster:ay36) by smtp.aliyun-inc.com; Tue, 29 Apr 2025 15:16:10 +0800 Message-ID: Date: Tue, 29 Apr 2025 15:16:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 06/12] khugepaged: introduce khugepaged_scan_bitmap for mTHP support To: Nico Pache Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, akpm@linux-foundation.org, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, david@redhat.com, baohua@kernel.org, ryan.roberts@arm.com, willy@infradead.org, peterx@redhat.com, ziy@nvidia.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, dev.jain@arm.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: <20250417000238.74567-1-npache@redhat.com> <20250417000238.74567-7-npache@redhat.com> <5de38fe3-4a73-443b-87d1-0c836ffdbe30@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: 5C0A7A0002 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: efm3sr3bh6wdxn7a3h1zkft6q55aqeyt X-HE-Tag: 1745910979-399507 X-HE-Meta: U2FsdGVkX19/bcQoX/v0qbYODJZfZDqUzwYi800JZM5WpU6KEYnMeL5wIGzPh/BeVfqqjD3Dn56n+LImjzCLk0PpzG0hup/kDDyu1ty/F0Yr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21mIuoOLDIw8Gu7EZVZhTUpnzTT5BuaDiT4IjFDashSLUrl7bSNP3RkClcLCNcxdcO+KYj7uG6QcizjX/zR2LdIu8re/7PIa9H53EY6n/xYWFhawgtOdyFAlONbrsGQowii0/X1sTr5KmSWp+HkJ1ZV1jTJuBMfJCBXVek61gACPlKeuRrz+osSyNXt5/ydDJDF4xzTioIow2Q8S1OyfTvpGr6LCyWhkYoxnpqIG6bFrIGj7SU4b4WFDmOzlB+8XFEOIOnzz3bq2Ig== 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/4/28 22:47, Nico Pache wrote: > On Sat, Apr 26, 2025 at 8:52 PM Baolin Wang > wrote: >> >> >> >> On 2025/4/17 08:02, Nico Pache wrote: >>> khugepaged scans 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 PMD. >>> >>> 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 >>> --- >>> include/linux/khugepaged.h | 4 ++ >>> mm/khugepaged.c | 94 ++++++++++++++++++++++++++++++++++---- >>> 2 files changed, 89 insertions(+), 9 deletions(-) >>> >>> diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h >>> index 1f46046080f5..18fe6eb5051d 100644 >>> --- a/include/linux/khugepaged.h >>> +++ b/include/linux/khugepaged.h >>> @@ -1,6 +1,10 @@ >>> /* SPDX-License-Identifier: GPL-2.0 */ >>> #ifndef _LINUX_KHUGEPAGED_H >>> #define _LINUX_KHUGEPAGED_H >>> +#define KHUGEPAGED_MIN_MTHP_ORDER 2 >> >> Why is the minimum mTHP order set to 2? IMO, the file large folios can >> support order 1, so we don't expect to collapse exec file small folios >> to order 1 if possible? > I should have been more specific in the patch notes, but this affects > anonymous only. I'll go over my commit messages and make sure this is > reflected in the next version. OK. I am looking into how to support shmem mTHP collapse based on your patch series. >> (PS: I need more time to understand your logic in this patch, and any >> additional explanation would be helpful:) ) > > We are currently scanning ptes in a PMD. The core principle/reasoning > behind the bitmap is to keep the PMD scan while saving its state. We > then use this bitmap to determine which chunks of the PMD are active > and are the best candidates for mTHP collapse. We start at the PMD > level, and recursively break down the bitmap to find the appropriate > sizes for the bitmap. > > looking at a simplified example: we scan a PMD and get the following > bitmap, 1111101101101011 (in this case MIN_MTHP_ORDER= 5, so each bit > == 32 ptes, in the actual set each bit == 4 ptes). > We would first attempt a PMD collapse, while checking the number of > bits set vs the max_ptes_none tunable. If those conditions arent > triggered, we will try the next enabled mTHP order, for each half of > the bitmap. > > ie) order 8 attempt on 11111011 and order 8 attempt on 01101011. > > If a collapse succeeds we dont keep recursing on that portion of the > bitmap. If not, we continue attempting lower orders. > > Hopefully that helps you understand my logic here! Let me know if you > need more clarification. Thanks for your explanation. That's pretty much how I understand it.:) I'll give a test for your new version. > > I gave a presentation on this that might help too: > https://docs.google.com/presentation/d/1w9NYLuC2kRcMAwhcashU1LWTfmI5TIZRaTWuZq-CHEg/edit?usp=sharing&resourcekey=0-nBAGld8cP1kW26XE6i0Bpg Unfortunately, this link requires access permission.