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 2DCC6C3ABB2 for ; Wed, 28 May 2025 12:39:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A96156B008C; Wed, 28 May 2025 08:39:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6DA96B0092; Wed, 28 May 2025 08:39:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AAC46B0093; Wed, 28 May 2025 08:39:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7A1A86B008C for ; Wed, 28 May 2025 08:39:24 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E70E5E88F3 for ; Wed, 28 May 2025 12:39:23 +0000 (UTC) X-FDA: 83492272206.28.9E0E1EC Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf14.hostedemail.com (Postfix) with ESMTP id 02773100009 for ; Wed, 28 May 2025 12:39:20 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RrUKv3sP; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 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=1748435962; 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=aVWN/MKmTQqqGKE7GEueaj4Por9dh45wCyBCzff0Izg=; b=ONU9EOLAqWdWZdo8MlOjardoWW3akbDXs7D7INMiI0drXwLM5Nl5BL0RckemaF6N7EiLJf jB2Zxz6hfRqjU+inGcN/Ie0or4gQytV2ofuQ4U3NitP8Bav+F0fBDi8wmj0yih4ZLN2ONy L1HwTL8c6GlbGnQ3ECJcTUsGY6Dswr8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RrUKv3sP; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1748435962; a=rsa-sha256; cv=none; b=dWVy4yzsstEWlmFr3RZDA5lII+wdw79HNyKkOGN2NeON3bN0L8vcds0j2vnnMVbWmVyRDS TEZIYqUo//VIck52CZbsID101lgB5EzhiCrOdILl28nDm3D0jZLRwz0tPqVMQBhqNW0TIP PKKkVaWaB69sDlKlImCdNJ91Ohuc3bg= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1748435955; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=aVWN/MKmTQqqGKE7GEueaj4Por9dh45wCyBCzff0Izg=; b=RrUKv3sPJyauFDM31QWxUjoJpODD8I+NMmCiQ6tq0QBGrxPUG9eunWq/cGUkGKvFuGsybRnzBSGfXoS5jncocIdD13sji2XyA4mae1ZxS3MLqrZysbG6MHxuT6u1NmCRnkHW031jZBcBb66EK5/vnFnhVQWTv10N9LIvFO0YbG4= Received: from 30.15.230.171(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WcDSnsn_1748435951 cluster:ay36) by smtp.aliyun-inc.com; Wed, 28 May 2025 20:39:12 +0800 Message-ID: Date: Wed, 28 May 2025 20:39:10 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 00/12] khugepaged: mTHP support To: Nico Pache , linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: 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, zokeefe@google.com, hannes@cmpxchg.org, rientjes@google.com, mhocko@suse.com, rdunlap@infradead.org References: <20250515032226.128900-1-npache@redhat.com> From: Baolin Wang In-Reply-To: <20250515032226.128900-1-npache@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 02773100009 X-Stat-Signature: 7xofkixiera3gh9sun7edc71kn9q9zdf X-Rspam-User: X-HE-Tag: 1748435960-425057 X-HE-Meta: U2FsdGVkX19zlfWkCUK5bundV/JFCQpHB5mH64i+6UwWf6TaJ5hXVVT+MVcG4RtCuGvHb9f7XG5eIgzD9a6Key08mSsg8znuCoFeXGMgul96Lo313786+IVuuxpIuopJJ1vE+jJB4Gn+Dj3Xn2RkTxSeR287jmcjj7PavrKdzPE/E4NN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P9WE5x3ASP8I4EJTwrgznLNRDYdBLP1NFdCToguGSpMyJgVP9/8scnvgCEglh0gGM1qNZhvOsEUFJagUo17wNTfuM1I6vEloPGRPl6rK/s/gMlcA/VFoQGqn39kF96i8HobetHwGRDn/ONOIppeMcvZopSkwg== 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/15 11:22, Nico Pache wrote: > The following series provides khugepaged and madvise collapse with the > capability to collapse anonymous memory regions to mTHPs. > > To achieve this we generalize the khugepaged functions to no longer depend > on PMD_ORDER. Then during the PMD scan, we keep track of chunks of pages > (defined by KHUGEPAGED_MTHP_MIN_ORDER) that are utilized. This info is > tracked using a bitmap. After the PMD scan is done, we do binary recursion > on the bitmap to find the optimal mTHP sizes for the PMD range. The > restriction on max_ptes_none is removed during the scan, to make sure we > account for the whole PMD range. When no mTHP size is enabled, the legacy > behavior of khugepaged is maintained. max_ptes_none will be scaled by the > attempted collapse order to determine how full a THP must be to be > eligible. If a mTHP collapse is attempted, but contains swapped out, or > shared pages, we dont perform the collapse. > > With the default max_ptes_none=511, the code should keep its most of its > original behavior. To exercise mTHP collapse we need to set > max_ptes_none<=255. With max_ptes_none > HPAGE_PMD_NR/2 you will > experience collapse "creep" and constantly promote mTHPs to the next > available size. This is due the fact that it will introduce at least 2x > the number of pages, and on a future scan will satisfy that condition once > again. > > Patch 1: Refactor/rename hpage_collapse > Patch 2: Some refactoring to combine madvise_collapse and khugepaged > Patch 3-5: Generalize khugepaged functions for arbitrary orders > Patch 6-9: The mTHP patches > Patch 10-11: Tracing/stats > Patch 12: Documentation When I tested 64K mTHP collapse and disabled PMD-sized THP, I found that khugepaged couldn't scan and collapse 64K mTHP. I send out two fix patches[1], and with these patches applied, 64K mTHP collapse works well. I hope my two patches can be folded into your next version series if you think there are no issues. Thanks. [1] https://lore.kernel.org/all/ac9ed6d71b439611f9c94b3506a8ce975d4636e9.1748435162.git.baolin.wang@linux.alibaba.com/