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 B810EC021A0 for ; Mon, 17 Feb 2025 06:39:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 324646B00B9; Mon, 17 Feb 2025 01:39:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D4D36B00BA; Mon, 17 Feb 2025 01:39:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19CB9280024; Mon, 17 Feb 2025 01:39:26 -0500 (EST) 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 EA7FA6B00B9 for ; Mon, 17 Feb 2025 01:39:25 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 761561C984C for ; Mon, 17 Feb 2025 06:39:25 +0000 (UTC) X-FDA: 83128485090.20.5F87189 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id 688D4180005 for ; Mon, 17 Feb 2025 06:39:23 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739774363; 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; bh=LEG8GyFmTdjYWJ1HXsZ0ITqSkJ3quS+7nfbUvQBu6Mk=; b=AFrjyKFkqgCPh5n5EYAvDYLiTOVAynD4/uoKDU3KMj4e6rGIfOVrLGWnvpeKvyRGkMfR41 otPA+Y+cKuo1pF0ZaYi4CUsFwRrue953bhmOW6ypj52c7gn8UEpaPayFqjC7GjXPEpDQq7 FXQeRxCdjR0drKiUd4o04P+ECLBP9Dg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739774363; a=rsa-sha256; cv=none; b=cz51hbxSV84p2INYargxY7KXzVJ3ghilZy1ykbnUwI/F7C2HNTHNWGIZ2wYoKiwmY4wZjt Yu0V6bt6/JQoZ0dIBb5NXNs92eGsDXZOOno2zuKFSCMmX9hOB9EwAetl2bnh7Wl9SALaGb PTkT4L9+KMVUdb9jGzLwW9E4smSI1VE= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC90C1063; Sun, 16 Feb 2025 22:39:41 -0800 (PST) Received: from [10.162.41.27] (K4MQJ0H1H2.blr.arm.com [10.162.41.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 73A0A3F59E; Sun, 16 Feb 2025 22:39:09 -0800 (PST) Message-ID: Date: Mon, 17 Feb 2025 12:09:06 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC v2 0/9] khugepaged: mTHP support To: Nico Pache , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, willy@infradead.org, kirill.shutemov@linux.intel.com, david@redhat.com, aarcange@redhat.com, raquini@redhat.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, tiwai@suse.de References: <20250211003028.213461-1-npache@redhat.com> Content-Language: en-US From: Dev Jain In-Reply-To: <20250211003028.213461-1-npache@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 688D4180005 X-Stat-Signature: ggn5qrg7cyc7mtqtg3kybzwnp7zts9o9 X-HE-Tag: 1739774363-72916 X-HE-Meta: U2FsdGVkX1//nwTgXNY/KJDM6TcTNokkokl2u3HijAJG4C73rO85kpxas7fVcAD6Lqi5iMdkhFcHOE1wS58/GSjPSuLrEDUnb97Oixpv9LZ2P0gfBW37IyWMOSDOwWFIekdxYnNAEVlEcx+LlMR7ZNCZ7TjSuRRlwcxD/xLFomMgqAmFYsxnOLsGxwJE0q/Goib9CW/dr29nG5UvDBt4ZuC1AV3bzj+HmVDQjQnE1yfukIz+HVi0cTBTd26S3cuvQYy10cKF+8yBlePHsgMZrOxx4A5oafSBq+RQah2/7EsZnz8jnfElXaas2BMrwTsa2zAJYEgd9NkG+UyxDEqzZsR9bhTVAnaHX8w4AfAyZPBpaL6Js6Vcm+hqR5gWlWHzXcXXSmX9lzybx4FHdV19yanfX+7OLRgrHreidQUWXdOEIFZomBS6oahK/+pwdn5hwiC+4fFTLM96UQPPRNv842PEWUFnEJ8cQkXK2cqSjc4FTIuK3IcIvCYZvn1ggp+ibWonXLu2BlBT29680hcdpgOEfziOAXtAv7lyJP7mvXurTwquZzYvw3hvR645D9xXIAGGAVkG14EwvmZIfNA8A7dhy/TA6nvFk4rO6wRU4mrBULysHRaDyfP+j2A3fJY96HP4rCk+fYz2MXt5FIGAxNKrfGzcn2A14SiIq36qaRweJKllyqJ93yMvnOPuh6ucDR9qCIWRpoPZi7iuNQyS2K1S2JxXGm/FU4rZ4Vn+XnXtSgRrZlNvqUHWXckuV4JGALg2SJLaiE7Z5X831jw7OKXUI0bQ4e8v3yFQBOhWwuxL84UsLM0xmtvI26dc7iT2DaAfNKjnj9xoYn1x5rUIC0TsfEXqXpsnjt8ZaUUbPGlapPX0NbF1jzAWTdRdhnQoiAoQdvH3jmScxOqa7tkxmFDGA5WYBKzXx51EaizwkvyEVcm7ZgxKcoQP/Q1ADMD3N6muUUg4OA/mFVcrg7Q 1hlkldcG gZtJTirev0WMZgg2iCHZnXC1nrnRaCrfPyeHOl59MHfKL+JDNt5pa2+eA4+UVJCY3Oo/DB5/KEmbLHQBW13IyNlIL7N99HpChWag6ubcSqlvDjt/WwVDMFDyJZmXbmWY/dSoHabuBfgDRPJcDkQHQEDMoNid3T70+3PCeD0W2rI+lwMUm1XWOd/bgshADc1hV98acF3clZTo5NupS7np6/ul0eNEE8kbh1yrkrBMBMYYmIZMqNAnZ+tf0j3Tg2OhLisXYg0aOomjCT3uym+NmQMwlESYpJ0UMWFPR 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 11/02/25 6:00 am, Nico Pache wrote: > The following series provides khugepaged and madvise collapse with the > capability to collapse 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 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. 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. How does creep stop when max_ptes_none <= 255? > > Patch 1: Some refactoring to combine madvise_collapse and khugepaged > Patch 2: Refactor/rename hpage_collapse > Patch 3-5: Generalize khugepaged functions for arbitrary orders > Patch 6-9: The mTHP patches > > --------- > Testing > --------- > - Built for x86_64, aarch64, ppc64le, and s390x > - selftests mm > - I created a test script that I used to push khugepaged to its limits while > monitoring a number of stats and tracepoints. The code is available > here[1] (Run in legacy mode for these changes and set mthp sizes to inherit) > The summary from my testings was that there was no significant regression > noticed through this test. In some cases my changes had better collapse > latencies, and was able to scan more pages in the same amount of time/work, > but for the most part the results were consistant. > - redis testing. I tested these changes along with my defer changes > (see followup post for more details). > - some basic testing on 64k page size. > - lots of general use. These changes have been running in my VM for some time. > > Changes since V1 [2]: > - Minor bug fixes discovered during review and testing > - removed dynamic allocations for bitmaps, and made them stack based > - Adjusted bitmap offset from u8 to u16 to support 64k pagesize. > - Updated trace events to include collapsing order info. > - Scaled max_ptes_none by order rather than scaling to a 0-100 scale. > - No longer require a chunk to be fully utilized before setting the bit. Use > the same max_ptes_none scaling principle to achieve this. > - Skip mTHP collapse that requires swapin or shared handling. This helps prevent > some of the "creep" that was discovered in v1. > > [1] - https://gitlab.com/npache/khugepaged_mthp_test > [2] - https://lore.kernel.org/lkml/20250108233128.14484-1-npache@redhat.com/ > > Nico Pache (9): > introduce khugepaged_collapse_single_pmd to unify khugepaged and > madvise_collapse > khugepaged: rename hpage_collapse_* to khugepaged_* > khugepaged: generalize hugepage_vma_revalidate for mTHP support > khugepaged: generalize alloc_charge_folio for mTHP support > khugepaged: generalize __collapse_huge_page_* for mTHP support > khugepaged: introduce khugepaged_scan_bitmap for mTHP support > khugepaged: add mTHP support > khugepaged: improve tracepoints for mTHP orders > khugepaged: skip collapsing mTHP to smaller orders > > include/linux/khugepaged.h | 4 + > include/trace/events/huge_memory.h | 34 ++- > mm/khugepaged.c | 422 +++++++++++++++++++---------- > 3 files changed, 306 insertions(+), 154 deletions(-) >