From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9669175BF for ; Sun, 12 Jan 2025 14:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736691140; cv=none; b=hdBK94gxvJz7HKxIa72zKMWwH6Gvb8sy8ygwsaR7TnsAxOV6gwl30BpBdZBDP7BmlWyw42B8Q/q/uquL5ZUTzJBjsABGOJUAQvxV1MExQQiZe9Y8PsROgqBJHgRIY8F1Tjpo8VLSPVmoA6sH8ER2QuSP1ZNUMx7Mf6b+7cHyCl0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736691140; c=relaxed/simple; bh=70DtnBMqYWN9JfWuReyCaW5yr87pEM87THWdjdizSYA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=belSCIp0Sfnpql3TcQsSbPxLYfssFkQWav9AHc1Ys52XVqosVOLfYQAXIT9BzNZpvYWVAt4sA8bI5iXwGOB8bx5f5MVHVDqQ+Oyyg4jenyWi7bWMMS7Evgr3f+z36d/w0Vn5GitcF+xXV6jQXAT6qMbY4ASCH9sqVX0va+pObIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 C3E23106F; Sun, 12 Jan 2025 06:12:39 -0800 (PST) Received: from [10.163.85.40] (unknown [10.163.85.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 644CE3F59E; Sun, 12 Jan 2025 06:11:59 -0800 (PST) Message-ID: <2aed36e5-740e-45bc-ae29-cfc11be780cf@arm.com> Date: Sun, 12 Jan 2025 19:41:56 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 00/11] khugepaged: mTHP support To: Nico Pache Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, 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 References: <20250108233128.14484-1-npache@redhat.com> <3e3252c2-65fc-45aa-99a1-ed66c31aba12@arm.com> <4ab296ec-5dd2-4d1f-a823-29396cade93e@arm.com> Content-Language: en-US From: Dev Jain In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/01/25 3:31 am, Nico Pache wrote: > On Thu, Jan 9, 2025 at 9:56 PM Dev Jain wrote: >> >> >> >> On 10/01/25 7:57 am, Nico Pache wrote: >>> On Wed, Jan 8, 2025 at 11:22 PM Dev Jain wrote: >>>> >>>> >>>> On 09/01/25 5:01 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 fully 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 is mapped to a 0-100 range to >>>>> determine how full a mTHP order needs to be before collapsing it. >>>>> >>>>> Some design choices to note: >>>>> - bitmap structures are allocated dynamically because on some arch's >>>>> (like PowerPC) the value of MTHP_BITMAP_SIZE cannot be computed at >>>>> compile time leading to warnings. >>>>> - The recursion is masked through a stack structure. >>>>> - A MTHP_MIN_ORDER was added to compress the bitmap, and ensure it was >>>>> 64bit on x86. This provides some optimization on the bitmap operations. >>>>> if other arches/configs that have larger than 512 PTEs per PMD want to >>>>> compress their bitmap further we can change this value per arch. >>>>> >>>>> Patch 1-2: Some refactoring to combine madvise_collapse and khugepaged >>>>> Patch 3: A minor "fix"/optimization >>>>> Patch 4: Refactor/rename hpage_collapse >>>>> Patch 5-7: Generalize khugepaged functions for arbitrary orders >>>>> Patch 8-11: The mTHP patches >>>>> >>>>> This series acts as an alternative to Dev Jain's approach [1]. The two >>>>> series differ in a few ways: >>>>> - My approach uses a bitmap to store the state of the linear scan_pmd to >>>>> then determine potential mTHP batches. Devs incorporates his directly >>>>> into the scan, and will try each available order. >>>>> - Dev is attempting to optimize the locking, while my approach keeps the >>>>> locking changes to a minimum. I believe his changes are not safe for >>>>> uffd. >>>>> - Dev's changes only work for khugepaged not madvise_collapse (although >>>>> i think that was by choice and it could easily support madvise) >>>>> - Dev scales all khugepaged sysfs tunables by order, while im removing >>>>> the restriction of max_ptes_none and converting it to a scale to >>>>> determine a (m)THP threshold. >>>>> - Dev turns on khugepaged if any order is available while mine still >>>>> only runs if PMDs are enabled. I like Dev's approach and will most >>>>> likely do the same in my PATCH posting. >>>>> - mTHPs need their ref count updated to 1<>>>> >>>>> Patch 11 was inspired by one of Dev's changes. >>>>> >>>>> [1] https://lore.kernel.org/lkml/20241216165105.56185-1-dev.jain@arm.com/ >>>>> >>>>> Nico Pache (11): >>>>> introduce khugepaged_collapse_single_pmd to collapse a single pmd >>>>> khugepaged: refactor madvise_collapse and khugepaged_scan_mm_slot >>>>> khugepaged: Don't allocate khugepaged mm_slot early >>>>> 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: remove max_ptes_none restriction on the pmd scan >>>>> khugepaged: skip collapsing mTHP to smaller orders >>>>> >>>>> include/linux/khugepaged.h | 4 +- >>>>> mm/huge_memory.c | 3 +- >>>>> mm/khugepaged.c | 436 +++++++++++++++++++++++++------------ >>>>> 3 files changed, 306 insertions(+), 137 deletions(-) >>>> >>>> Before I take a proper look at your series, can you please include any testing >>>> you may have done? >>> >>> I Built these changes for the following arches: x86_64, arm64, >>> arm64-64k, ppc64le, s390x >>> >>> x86 testing: >>> - Selftests mm >>> - some stress-ng tests >>> - compile kernel >>> - I did some tests with my defer [1] set on top. This pushes all the >>> work to khugepaged, which removes the noise of all the PF allocations. >>> >>> I recently got an ARM64 machine and did some simple sanity tests (on >>> both 4k and 64k) like selftests, stress-ng, and playing around with >>> the tunables, etc. >>> >>> I will also be running all the builds through our CI, and perf testing >>> environments before posting. >>> >>> [1] https://lore.kernel.org/lkml/20240729222727.64319-1-npache@redhat.com/ >>> >>>> >>> >> I tested your series with the program I was using and it is not working; >> can you please confirm it. > > Yes, this is expected because you are not fully filling any 32K chunk > (MIN_MTHP_ORDER) so no bit is ever set. That is weird, because if this is the case, then PMD-collapse should have also failed, but that succeeded. Do you have some userspace program I can test with?