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 07150E77180 for ; Mon, 16 Dec 2024 17:31:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BC8B6B009C; Mon, 16 Dec 2024 12:31:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76B676B009E; Mon, 16 Dec 2024 12:31:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60D196B00A6; Mon, 16 Dec 2024 12:31:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3A7456B009C for ; Mon, 16 Dec 2024 12:31:54 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id AD248A12E0 for ; Mon, 16 Dec 2024 17:31:53 +0000 (UTC) X-FDA: 82901514654.29.1781830 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf12.hostedemail.com (Postfix) with ESMTP id AB93C40026 for ; Mon, 16 Dec 2024 17:31:38 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1734370292; 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=IJwVayrgfC0FjAaH+GARhxkB2GeKKgeq9nyNcaJF9ao=; b=aUrCciQh0R+16bqu2xl/R1NKOkE2ep4glBBv05LWODLbfRYBgyQ+IdF8CeXtg4I/OwzfcI t0hSpGeVYkQJbRBAdFIfIQeicLxhBdY/fnL1pqn8qeLl7QdWWj2MRFaNd05zyzzXKNnlg9 Kv7EX/ugRdtcCBMOqUQ4Pekn2kYrpYU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734370292; a=rsa-sha256; cv=none; b=1QjAq8LKZLNDhp4FAT0d+sGeTvyhzI8D2TrH3CbCEbP5fviKasevONj+B6EW+1gBNjtHgY bMWdJn23odP7b68SE7UeJ8QGgKHSXBa7OFehDn6izKJFjj9ChCqzMLFioujbV7ICqgWTll yWIdf0/WKDhqBJPgQacam7OlxvLHLnM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.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 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 C4DB1106F; Mon, 16 Dec 2024 09:32:18 -0800 (PST) Received: from [10.163.78.212] (unknown [10.163.78.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 033863F528; Mon, 16 Dec 2024 09:31:39 -0800 (PST) Message-ID: <6f7fe967-0864-4b96-8426-cd9d6655d207@arm.com> Date: Mon, 16 Dec 2024 23:01:36 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 00/12] khugepaged: Asynchronous mTHP collapse To: akpm@linux-foundation.org, david@redhat.com, willy@infradead.org, kirill.shutemov@linux.intel.com 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, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nico Pache References: <20241216165105.56185-1-dev.jain@arm.com> Content-Language: en-US From: Dev Jain In-Reply-To: <20241216165105.56185-1-dev.jain@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AB93C40026 X-Stat-Signature: z5j69tx7wyhpfxm6kpenk8d5bdxr6qce X-Rspam-User: X-HE-Tag: 1734370298-481684 X-HE-Meta: U2FsdGVkX18k8XmeEO774kkvcghrTxmlyUHwTcObf+PDFGsjYhNCPhtD6zLhwWrWo6PNuDDe4BwryFWFi/0twVTUCK2DcCTlLudP+5RStd0aQUDjvNkmmWWzfpK6ricNbkjW2JgQi38j3khe/bLaMitU0z2is17CHFgOsRO9ftk0Ja5VCewvj/45B+rvA1OiZ9H33iO5TKdCmB4oRJWg+ajudHnQelN+KYp/pruU+AkESylnPQXAvkCsy7uNv3cdLiMqiZvObWSsKMCTFmHlYA7ZwvAIYwdbX0xBAGyPnJvqW/G6Zq/oZd+Y8BJnafIzcJd70QnRhyrMhDmXyjdcKNwNZHd9N/1cAPAAM4lY2L4sQdcVAwIO+bDNwUD/rGRpGauSOXvlw3SkaO8J3/GUdjo9gSHQY/ivc4osVMqpobogWVHlljIpahh82D57iHTaoQs/KmiL23ELYWITDuOo8CfvL1c9y9wXy3dnunvBMe7ZihSggWZkCpZ8732bBs0w2XnbitOhiriUfzDRwBQ0e4yyrpahLxR215ydYCTjnbYj7Do+L4XJKf8HVULGqfD0VV7rz+4epWsuJQMVaqlZVO+lFB7YVLnsrdOhXhAQezN4hh9lc9XaPuxndIHp+Hw/ysLInIOsjTxiHk/qvnIG3wyJ6AuAJ7VG6uMM8IttMCsdep3PT8yhDFBKePF8HWOTJvk7iehvhwr2+Zp9dFJeF8xu0f1vNzyuY4x8I4MlAW6hn+G8h7vSxF6Z2/IqY06BvycyPJwGhSJQUE1kA+f+d2brqU9r2bpyfDHD7p9SFhzhBr5mUiRyvPcl8ThlTY1fG26Btl9zSfBWAnlR/DYKy/UnU4hFFMQx/ZXcg5lhoJWl6+BzqbtLh3T7e3VYLNuxU/m1COTkjTSiBFsFDGdVCj1vxpfyT8xFmR+GTR92k9j+9pG8e31rLPRB8SvWNcz459FTjaRVF2L5YjmH5mj q+iMoKfh PIrxrw0VheDA7ihRN+1AroGLzzckZspZAw9A72NCDjBCdFWWThz3ZR1Z/8ZhWIhQSEYNVwRNy1cXjZivE6CsMMN0e4ez/PxWPd2uc2GvhhLIJd5T5Lsda6+kDYfpTwvB0PIJxj//cTfazNuGv9tS6Q2MgJj0NAWA/A8cQDQpfUIKkRPBiZ7yVoxnPGCbttbvgjd4T416vtgwdNS9ouW2n0boorlrdfDXwPyY0LwludBErjcW8FlmNNAGGMywPAaFV9RjfazWeOvBxZsCu0eBPB043tLSuEmxtLKehfWYWlbfw6Z0E4HXTmvVAFA== 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: +Nico, apologies, forgot to CC you. On 16/12/24 10:20 pm, Dev Jain wrote: > This patchset extends khugepaged from collapsing only PMD-sized THPs to > collapsing anonymous mTHPs. > > mTHPs were introduced in the kernel to improve memory management by allocating > chunks of larger memory, so as to reduce number of page faults, TLB misses (due > to TLB coalescing), reduce length of LRU lists, etc. However, the mTHP property > is often lost due to CoW, swap-in/out, and when the kernel just cannot find > enough physically contiguous memory to allocate on fault. Henceforth, there is a > need to regain mTHPs in the system asynchronously. This work is an attempt in > this direction, starting with anonymous folios. > > In the fault handler, we select the THP order in a greedy manner; the same has > been used here, along with the same sysfs interface to control the order of > collapse. In contrast to PMD-collapse, we (hopefully) get rid of the mmap_write_lock(). > > --------------------------------------------------------- > Testing > --------------------------------------------------------- > > The set has been build tested on x86_64. > For Aarch64, > 1. mm-selftests: No regressions. > 2. Analyzing with tools/mm/thpmaps on different userspace programs mapping > aligned VMAs of a large size, faulting in basepages/mTHPs (according to sysfs), > and then madvise()'ing the VMA, khugepaged is able to 100% collapse the VMAs. > > This patchset is rebased on mm-unstable (e7e89af21ffcfd1077ca6d2188de6497db1ad84c). > > Some points to be noted: > 1. Some stats like pages_collapsed for khugepaged have not been extended for mTHP. > I'd welcome suggestions on any updation, or addition to the sysfs interface. > 2. Please see patch 9 for lock handling. > > Dev Jain (12): > khugepaged: Rename hpage_collapse_scan_pmd() -> ptes() > khugepaged: Generalize alloc_charge_folio() > khugepaged: Generalize hugepage_vma_revalidate() > khugepaged: Generalize __collapse_huge_page_swapin() > khugepaged: Generalize __collapse_huge_page_isolate() > khugepaged: Generalize __collapse_huge_page_copy_failed() > khugepaged: Scan PTEs order-wise > khugepaged: Abstract PMD-THP collapse > khugepaged: Introduce vma_collapse_anon_folio() > khugepaged: Skip PTE range if a larger mTHP is already mapped > khugepaged: Enable sysfs to control order of collapse > selftests/mm: khugepaged: Enlighten for mTHP collapse > > include/linux/huge_mm.h | 2 + > mm/huge_memory.c | 4 + > mm/khugepaged.c | 445 +++++++++++++++++------- > tools/testing/selftests/mm/khugepaged.c | 5 +- > 4 files changed, 319 insertions(+), 137 deletions(-) >