From patchwork Wed Jan 8 23:31:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931710 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 6622BE77199 for ; Wed, 8 Jan 2025 23:33:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C77656B007B; Wed, 8 Jan 2025 18:33:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C265F6B0083; Wed, 8 Jan 2025 18:33:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC7D36B0088; Wed, 8 Jan 2025 18:33:10 -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 8C8426B0083 for ; Wed, 8 Jan 2025 18:33:10 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 026D71C5F33 for ; Wed, 8 Jan 2025 23:33:09 +0000 (UTC) X-FDA: 82985887740.23.A52E3A0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 3DBEE40010 for ; Wed, 8 Jan 2025 23:33:08 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i61sb2MC; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379188; a=rsa-sha256; cv=none; b=M4iNWZwajaa6/O9GezZpw5oVRRxIJX0vgBfS4rnqq9MfVuZ40MGI4g9q/4mGb8ONA3mIZs 5wv9IjR693l23EzRtTuKXDf3Ld0A86uN+hRsY3cxSVW4fvqSSLKDMkFFJxff3Wnm+rP/vI Ur+d0frlLUXGRrsTlbgVI9uYZYX0E0g= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i61sb2MC; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379188; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=x+jqVU9ZBjbAss1pYtlcKhjJs4UO6QLqbD/SlLsG+XQ=; b=T93fGRsBOHs9VpFH9VBV4gQMl9w14JQMiFBuMfNAwIybtCusUih2XnfzIicpvAUZ1M31oU hWV6bLMZe9adEhKLnt0/hGpNOiy9oxuZ3AndmHV7NjzR+nmJPJYnlwMi6PqEjGqvClZ+yx 1nPkxchsIEM733UWSWTSaDY0dOX/m4I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x+jqVU9ZBjbAss1pYtlcKhjJs4UO6QLqbD/SlLsG+XQ=; b=i61sb2MCVRoIZHQlkGc3wo4dVLt74u7fK/JIKdvld1dM8+r8fuTwLZRliJ/WU6DlNI6WI5 ayvk/KvPGI49PfN/umvY4uYIzJ5VZ7ImvYZq3jmdRLYfEQcmkRctkVHeOkpHcsCfhdv+Fc Bw5aqlAoYRV/Byae1qKP+dg3RMFioFI= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-xPwzlNi_O7akFagKf4tyXA-1; Wed, 08 Jan 2025 18:33:05 -0500 X-MC-Unique: xPwzlNi_O7akFagKf4tyXA-1 X-Mimecast-MFC-AGG-ID: xPwzlNi_O7akFagKf4tyXA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1CFC519560B8; Wed, 8 Jan 2025 23:33:01 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 85E1419560B7; Wed, 8 Jan 2025 23:32:52 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 01/11] introduce khugepaged_collapse_single_pmd to collapse a single pmd Date: Wed, 8 Jan 2025 16:31:17 -0700 Message-ID: <20250108233128.14484-2-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3DBEE40010 X-Stat-Signature: oic1f7wpme4u3ygrrdh7jgtgrfcqqipr X-Rspam-User: X-HE-Tag: 1736379188-758451 X-HE-Meta: U2FsdGVkX1+rOvqGx2NdG03EY8YDbI/FJ4EFTx7kiocMDdO8gPUuJ6rfTM8CKfEbGhbRcll6RhtWywqmJDRTMQJdYJ9uvcxZ4bsZa/WsXnpu7VSDQhlM5/y3vdUO8hPw/COHpjR3WDdNlmBBZh5GmmaxPqF/2QWHrMHoA9ViJNnfTbkkLOU2A0Ec7GQuLW5WkTeY4ytNkIloE2i9QSWxQp3Izi3gKNvsxVQhq1TSXl05OFyZw3BqokByjwEHd6Ti6fcy6rq2FuV5HhU+yjeT1nG2YCro/QeEiZsrqQp4xM8sr8KdbkNEUcGEPdME1D01ueR5Kwqa+UCe6wX38sqCsnHo4zV+cV2mu1oZyxMUWpqRFxmzgKUksR1XK+KeGOs28/STCsNvxveeOVy3cUmVEVmRA5j/7y+4C1v3OuEHvg/QSx8gt0RXCU45AMP/YNKHZNncT09Ef/XZ+vza0SVj2dvn2XJWGPe6bbagNQWwYEKZIMq/UdAu703oKbkn7fAKVELyWh4gMUD+ohJZxIuO5aZNVVJ2CrJEa6bXsUlFxEhWy9657YfP183PUNA8ZZ5ImopTPnI84Zgkv1cLmOAw/H47YqUyw482EOF1iqD9lZfUwmv0P2UUcOC36+/QYutr14jK1563JT3fIr/4k+G4o7EhfaFsMFJNNJmLmFmtLvKqk/AtfH+s+LsQ620td+12+wOU3wAuHwTQah+cPtHq4KL9l3yazR9dMpmxhcEpDRmT/Oy0FcJ2G66iCx+Yes9BBCB8VTjr8djiizAKdesor8r8qq/DV82cHf7FdK49CsPosKeJf8c97JI4GcAg/cI7ENPwlP+kuaXyiCAgyxreyQBOrRmvqPMDOBypKV+iHQQ6H7oohs+7ZpJCKtbNGaDFBs0SxbwCOviskg4loW0r56lWbvPUFmyY2bWGYjy/yeCC0Cs3DNQ9UgHSN3E5wtntW7mEZDs5b6hOG8mJ2VG sdc1w8+t vtWxOfNu2CqShSdcBi5onThBmR2VdyCl2y97VdLt0vXqZlTRbFUq51wEN77gPzsFtbnj81JDzkUjtz6pTwoGdzDjjQkluQXJX2zuoXmt0BKqS8V0pwdkPWn28exwrY5QErWwWWzk+KiCK1X1nQdqXUlNSmqUP9oDs2YVstYBIaIDpTwQpaiQ9zJZSrltUgHe0E1lh4l82HlsORcU7iFBTPRvjcPY8b7PPaPqIDkme9GfOTU6na8d2I19jLSCxQMFEFAAjrPeX0xVTROlwlCMK/4B0kzxC//qAWgj5ZGP1CqYW7VEyvii0jfliba26qE8Qwk9M4R+GKU+SDXuKIuivkngVQa9f56nTZerRnKs3JAaezyeea5Q+OZyeqCLnvH7GhkRrbHOeyUAI2Aaa5BxJl8V2F+oLsrROnO7OrabssrmNl/qV4MvGRmpBj0IAhBYXYPIAy+qHNCO5oP5DMYWhERxpD6aMKO1TQYddm7JmcIUJor4= 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: The khugepaged daemon and madvise_collapse have two different implementations that do almost the thing. Create khugepaged_collapse_single_pmd to increase code reuse and create a entry point for future khugepaged changes. Signed-off-by: Nico Pache --- mm/khugepaged.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 653dbb1ff05c..4d932839ff1d 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2348,6 +2348,52 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, } #endif +/* + * Try to collapse a single PMD starting at a PMD aligned addr, and return + * the results. + */ +static int khugepaged_collapse_single_pmd(unsigned long addr, struct mm_struct *mm, + struct vm_area_struct *vma, bool *mmap_locked, + struct collapse_control *cc) +{ + int result = SCAN_FAIL; + unsigned long tva_flags = cc->is_khugepaged ? TVA_ENFORCE_SYSFS : 0; + + if (!*mmap_locked) { + mmap_read_lock(mm); + *mmap_locked = true; + } + + if (thp_vma_allowable_order(vma, vma->vm_flags, + tva_flags, PMD_ORDER)) { + if (IS_ENABLED(CONFIG_SHMEM) && vma->vm_file) { + struct file *file = get_file(vma->vm_file); + pgoff_t pgoff = linear_page_index(vma, addr); + + mmap_read_unlock(mm); + *mmap_locked = false; + result = hpage_collapse_scan_file(mm, addr, file, pgoff, + cc); + fput(file); + if (result == SCAN_PTE_MAPPED_HUGEPAGE) { + mmap_read_lock(mm); + if (hpage_collapse_test_exit_or_disable(mm)) + goto end; + result = collapse_pte_mapped_thp(mm, addr, + !cc->is_khugepaged); + mmap_read_unlock(mm); + } + } else { + result = hpage_collapse_scan_pmd(mm, vma, addr, + mmap_locked, cc); + } + if (result == SCAN_SUCCEED || result == SCAN_PMD_MAPPED) + ++khugepaged_pages_collapsed; + } +end: + return result; +} + static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, struct collapse_control *cc) __releases(&khugepaged_mm_lock) From patchwork Wed Jan 8 23:31:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931712 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 722C5E77188 for ; Wed, 8 Jan 2025 23:33:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06AFA6B0089; Wed, 8 Jan 2025 18:33:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F34B36B008A; Wed, 8 Jan 2025 18:33:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD4F66B008C; Wed, 8 Jan 2025 18:33:20 -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 BEFD06B0089 for ; Wed, 8 Jan 2025 18:33:20 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4489CA15B6 for ; Wed, 8 Jan 2025 23:33:20 +0000 (UTC) X-FDA: 82985888160.04.4E71769 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 818D940013 for ; Wed, 8 Jan 2025 23:33:18 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Xay76jaL; spf=pass (imf01.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379198; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IAvDdT6ZFWIOmFCYflWY6gP5N4T+u2KYNhwxXC129qU=; b=dx4byd1qE4H5+PfwyrmjY6G8PpsDRI7gzXl9AqJdkTKQrzmRmtMNqj2c4c8/hB7eSQrVMu ddAcTPhRkQljtn0hkX9wlhuWm6SnrDIDzFlCxvrGaa16rkTlYal7K5xBgJkIUu9l8inmpA D9Ryshal4t6gz1sgH4It8AsFBs6V3zY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Xay76jaL; spf=pass (imf01.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379198; a=rsa-sha256; cv=none; b=GKhJOgJ9q/LQKg4/3sQVYN4oJ/4Dc0zEuq2BgIzMTT1voHhkiUztfnESBaLrJiMzeeMIQ7 +jsQSHKbdZ4zCDfukSx6T0xXVsPfqVmB3yHEbcv4Ws7fYctkD7ro3336Vw3/BTsJsy15gh SpqC1QiKJAc8AAUSsoy1+zIQl4nw900= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IAvDdT6ZFWIOmFCYflWY6gP5N4T+u2KYNhwxXC129qU=; b=Xay76jaLxpxSXVBU41iW8ia/CUQzrD1ZvKpM3HmJ9VF2032MguysEotPD+1ePpNfhwbaBi b7U9cW5sUcYyeVCSqnXy9AFgmowLSch7LD/4ZZGdq2Y4z1FuyuKE8bWBYP4JMjafHqmueT gE8oENVd8aFKkKbV0adTCdB+Bcx5SdQ= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-3YXL2rIHONerU6TIQLXORA-1; Wed, 08 Jan 2025 18:33:16 -0500 X-MC-Unique: 3YXL2rIHONerU6TIQLXORA-1 X-Mimecast-MFC-AGG-ID: 3YXL2rIHONerU6TIQLXORA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D22C41956083; Wed, 8 Jan 2025 23:33:11 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 796C119560AE; Wed, 8 Jan 2025 23:33:01 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 02/11] khugepaged: refactor madvise_collapse and khugepaged_scan_mm_slot Date: Wed, 8 Jan 2025 16:31:18 -0700 Message-ID: <20250108233128.14484-3-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Queue-Id: 818D940013 X-Stat-Signature: diyoik7ddzq478sr3nsde7gmig78yune X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1736379198-747888 X-HE-Meta: U2FsdGVkX19DVtn+TXFBfWiC2ZeHp2iGsaxZz5RbfbETRrf/MBvO5jPg5/KJENkOc2KY0DP1ggGptnGNTCoBNuY1ARPNWqbCEQA5B2VaSUHgHSNShcyqk93Q/Gl6YxX1NaZ/o+xqZkKbvCpQ0yQoxoKw7vpH4Z9Fb7x4ooI2kq277BQG6zFXnKMJjjffi9p8o8U2gIzW2tEYiuY4L6Yks9Xtz4utfjZRw4fT3ivPz+HxkvT6ZubfLueMedJC1UlLoQggTmZoZk3CHp7bNCuHbEFKAkwvqzB5XQmVkdKMgzr24jRGDdjNGSMOWNxVPBVANnRnSC+koLIqNYOBYADfWZ6uIUXusIj+6+JpG7ywP55S7jC+DG+Ee84h/5I3emncWgtZ7YVvieJt0ODYrJvFN99jcj+weAmyjg5vsgrGZmnFrqhJDUXcHqVVNcAA8wqZ+81ta2fFcqouARL7JRDynBZJWWtDI7dKIKubA7KfFmfqmOKI+wvHsIhdnhcZBKmIUGjJK0eVRlf/HJt04agszK2Lyvb4mlz//uiBxAzY0IYlDNyTZDD2W2z4ibVzgkZvNU1MJxO5M0D2rB0ap9y5MOWPEdI9Q1Qk7z8ajL8Ae8F5yqcJ+Xp4ep1C0bSne/OcMdvg2BTZuzrXhKD7QtWQko70t55xpbX+vZm4kCORtpZ8kcOqBQirrDIrxTiiH6pp0DBFk4QLYl46cFT5NLLmA5EcJjnU+RlsE8GyliYD+czfg3/VBN+Qndf45/lj/fXiBefGNuZlzBJpPHgvocaexpAG4JVUgDU6Xay40Gv3GKmqs8EQFVZevQvfi3+kJ3x+LC4/J7ph7wpVJ89odBfM8vgakxTc4NBXIJi98SBxPucRV5L+gaYFGkUWdeTQHrlBrB4GcCUAfUy3AqfjucnhyVOSAe43M+Khe395d9fMVx+DIiotra4aL0B911Eraw3GbcSskUXSsJW2usnmyCH lamit8xz xsBAKV1cVqmjAg7BlnnDdIUD7LitxzyTqTSqWbRVmGgXVk1xYg/anJn0CbaECPO/4qM2G84+qUDCzBHTaTjV5hIP/DrPH3XutwCTJFv/IPfm77BjghkizmgVQTeMshGe0sdDGrGulaZXJB4zFCqC0Lbcuw7zekiTo1q+ag7/bLWTTzrAQdiE4t8nU36CxUbH+xkOP+SqSoBu6TTfirTgsUxAkzZQ+QmDrprJHUab4vokThRSDbyBhH2a510yXFgJpg/aCCNmzIkXNI/aVxmOufAhcyx6jEbyZOyTXxRoYZOmLKZDkfySxOOxhjhWONVCT7/2L5CHsrOBZOm3qCkmiPIfL+NkSMdMh9WVL0mW7lw11dGiHPFCcLhxIWPqVDzq3EBZkQnv2IAyHATiiOl+yhIGJvc1z5LDfb+bfoQsIELM0qQlCznO1lcloTjnr79SpLdW6 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: Now that we have a khugepaged_collapse_single_pmd, lets use that code in madvise_collapse and khugepaged_scan_mm_slot to create a single entry point. Signed-off-by: Nico Pache --- mm/khugepaged.c | 50 ++++--------------------------------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 4d932839ff1d..ba85a8fcee88 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2468,33 +2468,9 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, VM_BUG_ON(khugepaged_scan.address < hstart || khugepaged_scan.address + HPAGE_PMD_SIZE > hend); - if (IS_ENABLED(CONFIG_SHMEM) && vma->vm_file) { - struct file *file = get_file(vma->vm_file); - pgoff_t pgoff = linear_page_index(vma, - khugepaged_scan.address); - mmap_read_unlock(mm); - mmap_locked = false; - *result = hpage_collapse_scan_file(mm, - khugepaged_scan.address, file, pgoff, cc); - fput(file); - if (*result == SCAN_PTE_MAPPED_HUGEPAGE) { - mmap_read_lock(mm); - if (hpage_collapse_test_exit_or_disable(mm)) - goto breakouterloop; - *result = collapse_pte_mapped_thp(mm, - khugepaged_scan.address, false); - if (*result == SCAN_PMD_MAPPED) - *result = SCAN_SUCCEED; - mmap_read_unlock(mm); - } - } else { - *result = hpage_collapse_scan_pmd(mm, vma, - khugepaged_scan.address, &mmap_locked, cc); - } - - if (*result == SCAN_SUCCEED) - ++khugepaged_pages_collapsed; + *result = khugepaged_collapse_single_pmd(khugepaged_scan.address, + mm, vma, &mmap_locked, cc); /* move to next address */ khugepaged_scan.address += HPAGE_PMD_SIZE; @@ -2814,36 +2790,18 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, mmap_assert_locked(mm); memset(cc->node_load, 0, sizeof(cc->node_load)); nodes_clear(cc->alloc_nmask); - if (IS_ENABLED(CONFIG_SHMEM) && vma->vm_file) { - struct file *file = get_file(vma->vm_file); - pgoff_t pgoff = linear_page_index(vma, addr); - mmap_read_unlock(mm); - mmap_locked = false; - result = hpage_collapse_scan_file(mm, addr, file, pgoff, - cc); - fput(file); - } else { - result = hpage_collapse_scan_pmd(mm, vma, addr, - &mmap_locked, cc); - } + result = khugepaged_collapse_single_pmd(addr, mm, vma, &mmap_locked, cc); + if (!mmap_locked) *prev = NULL; /* Tell caller we dropped mmap_lock */ -handle_result: switch (result) { case SCAN_SUCCEED: case SCAN_PMD_MAPPED: ++thps; break; case SCAN_PTE_MAPPED_HUGEPAGE: - BUG_ON(mmap_locked); - BUG_ON(*prev); - mmap_read_lock(mm); - result = collapse_pte_mapped_thp(mm, addr, true); - mmap_read_unlock(mm); - goto handle_result; - /* Whitelisted set of results where continuing OK */ case SCAN_PMD_NULL: case SCAN_PTE_NON_PRESENT: case SCAN_PTE_UFFD_WP: From patchwork Wed Jan 8 23:31:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931713 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 28870E77188 for ; Wed, 8 Jan 2025 23:33:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3E846B008C; Wed, 8 Jan 2025 18:33:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AEED56B0093; Wed, 8 Jan 2025 18:33:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C1BF6B008C; Wed, 8 Jan 2025 18:33:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7D8B76B008C for ; Wed, 8 Jan 2025 18:33:33 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3B42D160B7D for ; Wed, 8 Jan 2025 23:33:33 +0000 (UTC) X-FDA: 82985888706.28.4C699C8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 8019080009 for ; Wed, 8 Jan 2025 23:33:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dh1HAvXG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379211; a=rsa-sha256; cv=none; b=Mv8JkUl4Iu4F0I0prv2XyB1U/RtcOCh9u7KeISpxq17WbbDYjvxZRmFDbRBj92hSdaOC0k ybwfFUzsRpp0K3zUsdMg2JG/awiFtcCRXN6r5OvuzLh3oYkAp9oeGfpcGLD0PaJAuY087+ K07WTkw7EvXZiNjqWctYTuA1vkq37ts= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dh1HAvXG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379211; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T3A+lzu2HXugNjY9ipPnv1YBHYwcAbMPAnaFgxhpBsc=; b=zCfiQojx5QJIl8RaSb2TBC6kJLNFloiaqLsyjAFffdmeiG8t8IVxI+NwOEw3j958J5cD/Y +zNZBXnrzXqWDmRp7t+eFSDoiS+mo60uL2fiUJLH3KKelzrDD1tOGZxvTiSpIzohLdsjWq gtFNalrPI6Yq/hIOtGPny9bE0XK4XJY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T3A+lzu2HXugNjY9ipPnv1YBHYwcAbMPAnaFgxhpBsc=; b=dh1HAvXGNXwofMdV5utwg//XO2J+KZBAsRcO0BOVM8Wy9LmQ9RIl/aWOV9RvGB6sR6jZAO 35HLlXhaGROP7Y+gRrAwWw18ecg2cOg7x5SpoHpp6MP8khSEZ1GCTh9HrKXbpZL3pRZhky 8ZzI94F2eotZ9hCN3oRsBEILzIWHX5Y= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-lr8fwzThMiy_-N9z-nI7IQ-1; Wed, 08 Jan 2025 18:33:25 -0500 X-MC-Unique: lr8fwzThMiy_-N9z-nI7IQ-1 X-Mimecast-MFC-AGG-ID: lr8fwzThMiy_-N9z-nI7IQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 60E741944B2E; Wed, 8 Jan 2025 23:33:21 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2789F19560B7; Wed, 8 Jan 2025 23:33:11 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 03/11] khugepaged: Don't allocate khugepaged mm_slot early Date: Wed, 8 Jan 2025 16:31:19 -0700 Message-ID: <20250108233128.14484-4-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8019080009 X-Stat-Signature: m49moj73fkk3w1t3gxggqtfy74t3ijoe X-Rspam-User: X-HE-Tag: 1736379211-799581 X-HE-Meta: U2FsdGVkX19SzXje0DGnLLy0Cxd3lrW3TzneXSG41TYh3U4JQxMF19cmPJTDaUYRSVldMfIRRVZN/tJs06/U868g5Iey6ZRJ2QTjdXc7TdRmFaIugBW4HmaXwcPu3RQZBe4xsffz2DZsZD1ownYMyBg/ruEBtREcL4XiCUz9AQ3OJZqUkYG73iaj0D3x+m9T/T+0sAAzWdLXCSu5OzrBH7CQExxgPlAv8IeiuX/5bWZ0x+lkPX7YB4SnRtKV+xc4Md0yhifrXgdkWjOm7VAjZL0gXbVo4dd3HPZyHIHTvN+gqWqpcun+Vw7c+j1Mqi8/0prJC2auJCHrBf2YGP2ZwpbNNiuBxqtyl1RMdj5xWetyuIfa/kIZRdasK5kfUGfssqm1+aDXndp/isqjmOmE3CUcC2rzvvVU7HpsbvPVZ9SGAklS3JQ9gWvwIrM4r6wC0rPT9DQeYhKvZCSsii6Bp1pcmdzRGOWkvc3hg8cBXlWHsONqxnIxrB8+XkRy9SY4B45yPfSTu4+KD2LPeOOGshzAANdQHKu00cY8kvHsq3Y7pu1sfvcqFiYamRPjtN7T3zNPHKDzrbKXodP7flp3MFlg8xnTMkd47qhcKxDAaVX5YRom8sZn4Qp2FtZWD2GL84VZRSyQ7x5I02ZfGG8erYty7Wng2VWtnpOwVNJaRwrx7FOmBi6lff52GQxzj9pg0N6vF4qsUVWPy6SW6HhkXxH3++hAlXP6mTph3/2XTBiBdQXBEBNLppMl7hljkMmFY+Kn3arYHBVrGW+Ou6s6XanzRtV6Jl9Jipcyj0kvXWFvYc7FroeeFR4BLu0FSflC/b4RiQpUJ/fEE2Tbhzitg7Rs0qsyEWd8kdKgJuAMMlOf7jOyfuVew36j2lU7tAh571cALhxM5SlrEQnDLAFglGp2IQ5WoeJ4zA7G1zY2VY6HtgRuRzyxDFRFjVijZ9i7WCUksrIY4aAECc998/Y G4D86Aoe tI1kqIakpxmBK2SXWx1zfakZbkpxTdl4MGkTXXtOp/A5wdONXEhKZ6/AXNcSSTHBAdumIeEmx7QHlDi0CH1cy7YHednS67Bocs1lcfFvMOum3ULSmkZigantShL7KC07CDk+W71Dux4Wq1qltVrnakqH6gaa3yNwrp9z5EYWrbarBK+6gvnfck+29tSoP9Vhg0SqCgojUZ8BxjFZyzH+fIJBCWn1u9TY4hzbBko6XwzNuhYjcdMzfVxNway0SPv7SzpadS+JyD3bU+FUTID/kDCdzwGBzaEGTjvFJ2LKUMrxclYRJOfycAGeVMrsSHR67O2IkyQiFhQftWqBmzcrZDRewaJGkjfFsBW8i6PYtYYhKJFmOevtosHha5cYbRupFhZzD5zHDfkhaqEV1zfT2VsuUChNg9A/LG7V9Ze44g959EOpCLeWx41uvv8565G24AI6I 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: We should only "enter"/allocate the khugepaged mm_slot if we succeed at allocating the PMD sized folio. Move the khugepaged_enter_vma call until after we know the vma_alloc_folio was successful. Signed-off-by: Nico Pache --- mm/huge_memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e53d83b3e5cf..635c65e7ef63 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1323,7 +1323,6 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) ret = vmf_anon_prepare(vmf); if (ret) return ret; - khugepaged_enter_vma(vma, vma->vm_flags); if (!(vmf->flags & FAULT_FLAG_WRITE) && !mm_forbids_zeropage(vma->vm_mm) && @@ -1365,7 +1364,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) } return ret; } - + khugepaged_enter_vma(vma, vma->vm_flags); return __do_huge_pmd_anonymous_page(vmf); } From patchwork Wed Jan 8 23:31:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931714 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 4B417E77188 for ; Wed, 8 Jan 2025 23:33:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B66106B0093; Wed, 8 Jan 2025 18:33:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B15CE6B0095; Wed, 8 Jan 2025 18:33:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B6B96B0096; Wed, 8 Jan 2025 18:33:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7DF5A6B0093 for ; Wed, 8 Jan 2025 18:33:42 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EDEE1A15BE for ; Wed, 8 Jan 2025 23:33:41 +0000 (UTC) X-FDA: 82985889042.08.8E809FB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id E0E911C0007 for ; Wed, 8 Jan 2025 23:33:39 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KxGFuvD3; spf=pass (imf20.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379220; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AcvndsoaXEpPgsEl+w8HgcKpOFH1iO8o+01JlrF6xsM=; b=WLoNskIJMMWAo5DAhH+qHyZPIyzi0D/EOy1JhYkEKJuJnbip0nO30e8clAICEQnnO2Osx0 2MuQi1adtu/AJOZPynk358fIi089NtJaKh4EMT6imFf9pdflxXl1F8f8Ovow0j81mMD1Gt gnO7Zp7cD4LzbkfW2ffeZ/jonLbV1hw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KxGFuvD3; spf=pass (imf20.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379220; a=rsa-sha256; cv=none; b=FXIhzFK6SnmNBWfDigtJ9oszYHLVvwYQ7Y3Cj+j2v9iuNzTiYhLet0rZeZumv8aB6waMHE vKD/zcSAFjwBtkI8qS5OuoFJ2QL8cQlSfMoPq+GMnLP0x7G25GpyUdr0AK3lVpTT4K76p1 8qYi17EF6IaoZ7Pd0WKMm/II6wIhdz4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AcvndsoaXEpPgsEl+w8HgcKpOFH1iO8o+01JlrF6xsM=; b=KxGFuvD3+RMNBXslx384yxY2G90Q4CTjMjI3v0AvGA8T7ouGI4tbr05R7rFfwtzM4P1SH8 apSqjxWIX7+2B+Fe/DxhhooFfe1UdOIFOD14411XfbAQS+b9qLVnsbSFEYuJzmEo7Zr6V3 Z31nKulxsl5yAPtVaP4/MU/FRtkylxs= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-346-Ayib-qL_N4OIqVTG75R-HQ-1; Wed, 08 Jan 2025 18:33:35 -0500 X-MC-Unique: Ayib-qL_N4OIqVTG75R-HQ-1 X-Mimecast-MFC-AGG-ID: Ayib-qL_N4OIqVTG75R-HQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7B34919560BB; Wed, 8 Jan 2025 23:33:30 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BCF7019560AE; Wed, 8 Jan 2025 23:33:21 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 04/11] khugepaged: rename hpage_collapse_* to khugepaged_* Date: Wed, 8 Jan 2025 16:31:20 -0700 Message-ID: <20250108233128.14484-5-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam05 X-Stat-Signature: s886nsuwg3combru1xq6ffoasx9anmu6 X-Rspamd-Queue-Id: E0E911C0007 X-Rspam-User: X-HE-Tag: 1736379219-768495 X-HE-Meta: U2FsdGVkX18MljFeL1NPE2kMAV1k31Fhyqx3JwbVxgipvS4YwFIZ6Tv20OwyQl0OCUuOkRVpPQc2XAsCyaDLSz+5hjykRj7K0oI9DKc7G/rp887H03yy5Isp9aYSjmYhBTc5cU0q8xM8c4ZosC9FysZJT7iNXQUPsd5iED2vLlaW6ILtAX6RWXQfJMCy9KK0HD8tAaXZ2NekoegUMVJs+ZbwgLdH3lKwjPyU3Gu/HD9SKPs6gBot81A32aGNT4uWKUVU5DnkwOfmwe95MeRj2az2Vt3TzWwOEzIvyIybCMgfpDRHnbT92bKzDpqF+vwO5MBK1Hp0X2mJVxP6GBlZS3TtdBlXAw5ihtp8KSOo2H8ep1Nz2gD+bWPTW352V93sm0ZvWOmsM5dYS6rSZDmbncIJQKEJVCP4KRnaFzb8gOE/5ENfX+9CkhaBS2xbyQywa2IoNtD3Gau3kYW4riEeN+5T7qCQetU0XFy92PAX1toI8elmbUgGqgL0RK23r0SConty6on6L9TVqTGPabfcSWAs2Ijap7JWTEe+/rPajSJK7liOP1qwFPIRfcrtIHdJ7YV7jbgPN+nEZZwFkGsVwXB190UzIe6tkTyPh+VXya4UEFGCvBjl1nDU0PIW8YufhSjWc16aM6TStr8w1xyCX0In5wHbtmO9AAGcKdyReHeIGmIAvrgVRV9QdKkofLVxWR6je0ShaoSS1m7RPkHeQID3ZXHpdHs+RT529SkXKD4o8jKBrvw7XMgG5/DWeyJItZ/5u9jyIjAQXpU3dfstDyyKWMFcj1nsHcPDmeBC5+6v5FHOtK58J2+ihBRTFlqFCtZK2udYb75u3RSE9CnAaWk0IMEQDvx7sKjSu3lrsNEeeZqJ5d9DRNcH4NhQAoKE0Ze73mi6uaYnV7ceAKKIOPs6YtHw5H5kwAKBVsy8qzqMQS8I7m96S6MEltkpzrt5Erd/TDkwdLCiGrg5mh+ fveYKkyI i9meKGvP9ZU9xYgTD9wzxjQnOQxnA3U79ke6Dxh0PpYVvSa/+VaDPtO8BA02hya8s5MyvQmHd8XGfzIPP22pb/mL6Rp2RBt0FUVLVZRCHM7TkWGeIyMlMgzxEZ45ggEMyg1Hb4TTWVugJHzICyrbqAvonXVoZBB+C8VLTeid3J/cjqQkObh/cZVkKkUclWxk/p3ctuiEZxk4V8CNAAbsI1enkMYlukfzom2Bq/C5PqxIpZkm+4r5hxVFMpxKmQQqTxbZC6Dde373fA1/78K/gjr9rvDNht2MVkIAnSRZel3pTyDuw/WCzro3i8AqLYb0EP+al+ePqCPEeRno6QVZRZ8xjg1S7Z0+Zena9r68YUV715jo5yfCATLh2qwszkzs61DVdZpRAFAhbmdlh/TJY2PDfb0+VGduBV4ZSwN08ASVAsFJbxwsBOwFzzp01bqUyLIWb 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: functions in khugepaged.c use a mix of hpage_collapse and khugepaged as the function prefix. rename all of them to khugepaged to keep things consistent and slightly shorten the function names. Signed-off-by: Nico Pache --- mm/khugepaged.c | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index ba85a8fcee88..90de49d11a98 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -402,14 +402,14 @@ void __init khugepaged_destroy(void) kmem_cache_destroy(mm_slot_cache); } -static inline int hpage_collapse_test_exit(struct mm_struct *mm) +static inline int khugepaged_test_exit(struct mm_struct *mm) { return atomic_read(&mm->mm_users) == 0; } -static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm) +static inline int khugepaged_test_exit_or_disable(struct mm_struct *mm) { - return hpage_collapse_test_exit(mm) || + return khugepaged_test_exit(mm) || test_bit(MMF_DISABLE_THP, &mm->flags); } @@ -444,7 +444,7 @@ void __khugepaged_enter(struct mm_struct *mm) int wakeup; /* __khugepaged_exit() must not run from under us */ - VM_BUG_ON_MM(hpage_collapse_test_exit(mm), mm); + VM_BUG_ON_MM(khugepaged_test_exit(mm), mm); if (unlikely(test_and_set_bit(MMF_VM_HUGEPAGE, &mm->flags))) return; @@ -503,7 +503,7 @@ void __khugepaged_exit(struct mm_struct *mm) } else if (mm_slot) { /* * This is required to serialize against - * hpage_collapse_test_exit() (which is guaranteed to run + * khugepaged_test_exit() (which is guaranteed to run * under mmap sem read mode). Stop here (after we return all * pagetables will be destroyed) until khugepaged has finished * working on the pagetables under the mmap_lock. @@ -606,7 +606,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, folio = page_folio(page); VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); - /* See hpage_collapse_scan_pmd(). */ + /* See khugepaged_scan_pmd(). */ if (folio_likely_mapped_shared(folio)) { ++shared; if (cc->is_khugepaged && @@ -851,7 +851,7 @@ struct collapse_control khugepaged_collapse_control = { .is_khugepaged = true, }; -static bool hpage_collapse_scan_abort(int nid, struct collapse_control *cc) +static bool khugepaged_scan_abort(int nid, struct collapse_control *cc) { int i; @@ -886,7 +886,7 @@ static inline gfp_t alloc_hugepage_khugepaged_gfpmask(void) } #ifdef CONFIG_NUMA -static int hpage_collapse_find_target_node(struct collapse_control *cc) +static int khugepaged_find_target_node(struct collapse_control *cc) { int nid, target_node = 0, max_value = 0; @@ -905,7 +905,7 @@ static int hpage_collapse_find_target_node(struct collapse_control *cc) return target_node; } #else -static int hpage_collapse_find_target_node(struct collapse_control *cc) +static int khugepaged_find_target_node(struct collapse_control *cc) { return 0; } @@ -925,7 +925,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, struct vm_area_struct *vma; unsigned long tva_flags = cc->is_khugepaged ? TVA_ENFORCE_SYSFS : 0; - if (unlikely(hpage_collapse_test_exit_or_disable(mm))) + if (unlikely(khugepaged_test_exit_or_disable(mm))) return SCAN_ANY_PROCESS; *vmap = vma = find_vma(mm, address); @@ -988,7 +988,7 @@ static int check_pmd_still_valid(struct mm_struct *mm, /* * Bring missing pages in from swap, to complete THP collapse. - * Only done if hpage_collapse_scan_pmd believes it is worthwhile. + * Only done if khugepaged_scan_pmd believes it is worthwhile. * * Called and returns without pte mapped or spinlocks held. * Returns result: if not SCAN_SUCCEED, mmap_lock has been released. @@ -1074,7 +1074,7 @@ static int alloc_charge_folio(struct folio **foliop, struct mm_struct *mm, { gfp_t gfp = (cc->is_khugepaged ? alloc_hugepage_khugepaged_gfpmask() : GFP_TRANSHUGE); - int node = hpage_collapse_find_target_node(cc); + int node = khugepaged_find_target_node(cc); struct folio *folio; folio = __folio_alloc(gfp, HPAGE_PMD_ORDER, node, &cc->alloc_nmask); @@ -1260,7 +1260,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, return result; } -static int hpage_collapse_scan_pmd(struct mm_struct *mm, +static int khugepaged_scan_pmd(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, bool *mmap_locked, struct collapse_control *cc) @@ -1376,7 +1376,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, * hit record. */ node = folio_nid(folio); - if (hpage_collapse_scan_abort(node, cc)) { + if (khugepaged_scan_abort(node, cc)) { result = SCAN_SCAN_ABORT; goto out_unmap; } @@ -1445,7 +1445,7 @@ static void collect_mm_slot(struct khugepaged_mm_slot *mm_slot) lockdep_assert_held(&khugepaged_mm_lock); - if (hpage_collapse_test_exit(mm)) { + if (khugepaged_test_exit(mm)) { /* free mm_slot */ hash_del(&slot->hash); list_del(&slot->mm_node); @@ -1740,7 +1740,7 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) if (find_pmd_or_thp_or_none(mm, addr, &pmd) != SCAN_SUCCEED) continue; - if (hpage_collapse_test_exit(mm)) + if (khugepaged_test_exit(mm)) continue; /* * When a vma is registered with uffd-wp, we cannot recycle @@ -2249,7 +2249,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, return result; } -static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, +static int khugepaged_scan_file(struct mm_struct *mm, unsigned long addr, struct file *file, pgoff_t start, struct collapse_control *cc) { @@ -2294,7 +2294,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, } node = folio_nid(folio); - if (hpage_collapse_scan_abort(node, cc)) { + if (khugepaged_scan_abort(node, cc)) { result = SCAN_SCAN_ABORT; break; } @@ -2340,7 +2340,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, return result; } #else -static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, +static int khugepaged_scan_file(struct mm_struct *mm, unsigned long addr, struct file *file, pgoff_t start, struct collapse_control *cc) { @@ -2372,19 +2372,19 @@ static int khugepaged_collapse_single_pmd(unsigned long addr, struct mm_struct * mmap_read_unlock(mm); *mmap_locked = false; - result = hpage_collapse_scan_file(mm, addr, file, pgoff, + result = khugepaged_scan_file(mm, addr, file, pgoff, cc); fput(file); if (result == SCAN_PTE_MAPPED_HUGEPAGE) { mmap_read_lock(mm); - if (hpage_collapse_test_exit_or_disable(mm)) + if (khugepaged_test_exit_or_disable(mm)) goto end; result = collapse_pte_mapped_thp(mm, addr, !cc->is_khugepaged); mmap_read_unlock(mm); } } else { - result = hpage_collapse_scan_pmd(mm, vma, addr, + result = khugepaged_scan_pmd(mm, vma, addr, mmap_locked, cc); } if (result == SCAN_SUCCEED || result == SCAN_PMD_MAPPED) @@ -2432,7 +2432,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, goto breakouterloop_mmap_lock; progress++; - if (unlikely(hpage_collapse_test_exit_or_disable(mm))) + if (unlikely(khugepaged_test_exit_or_disable(mm))) goto breakouterloop; vma_iter_init(&vmi, mm, khugepaged_scan.address); @@ -2440,7 +2440,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, unsigned long hstart, hend; cond_resched(); - if (unlikely(hpage_collapse_test_exit_or_disable(mm))) { + if (unlikely(khugepaged_test_exit_or_disable(mm))) { progress++; break; } @@ -2462,7 +2462,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, bool mmap_locked = true; cond_resched(); - if (unlikely(hpage_collapse_test_exit_or_disable(mm))) + if (unlikely(khugepaged_test_exit_or_disable(mm))) goto breakouterloop; VM_BUG_ON(khugepaged_scan.address < hstart || @@ -2498,7 +2498,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, * Release the current mm_slot if this mm is about to die, or * if we scanned all vmas of this mm. */ - if (hpage_collapse_test_exit(mm) || !vma) { + if (khugepaged_test_exit(mm) || !vma) { /* * Make sure that if mm_users is reaching zero while * khugepaged runs here, khugepaged_exit will find From patchwork Wed Jan 8 23:31:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931715 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 2E95DE77188 for ; Wed, 8 Jan 2025 23:33:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8DD26B0096; Wed, 8 Jan 2025 18:33:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B3CF86B0098; Wed, 8 Jan 2025 18:33:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DDF46B0099; Wed, 8 Jan 2025 18:33:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 80B976B0096 for ; Wed, 8 Jan 2025 18:33:49 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E6AEC120B3A for ; Wed, 8 Jan 2025 23:33:48 +0000 (UTC) X-FDA: 82985889336.23.4F1D106 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 304D94000F for ; Wed, 8 Jan 2025 23:33:47 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Khc5r2/z"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379227; a=rsa-sha256; cv=none; b=OQMu0r5Zpt+qnQTGhnKvHeLCuxn+OCnex+8DxzGDDpfZwrBHodwX/g9jexQANJHUX4r5n8 CqZUk9VwoRrU+hxq+Fs2Cn8Si+Gxh2XsAD2bTPgd97wtAeGzZ/3/y8hlr5WAt+wcAYBpoL RK7Ic9YrGqJ4C417Ur1EQbQIe2TjZFs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Khc5r2/z"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379227; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LYWZaPy1kd0tcw2Lw/njF3yTpmJS5BgOSyQhXLKd6xQ=; b=DT4Q7xdPkT2suKvS5IITzqbgl1HR/iY6tp9XhTQ/iS/3q+xWPTs7UEGBki8LR+Ub5efcfS 4vO7D0H0vv+OnS4Ho/T/BTGECkwz7f5gMIvTZSToH69AhMPHenbPE4iSeXrD/49LBoAoIR g1jTaZO0QEuT/4xTDiJ6wV/7DfnJNgY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LYWZaPy1kd0tcw2Lw/njF3yTpmJS5BgOSyQhXLKd6xQ=; b=Khc5r2/zXw7o6w7Z2cdbXuY1ggnhvsooA+xh81FhWeVDfWdefsgDZ5uxGyTI9p51OYX4MI P2D7z2TKOvA4B2ZzII+uny8m5gKRS5QAIJyrfvujH9k4cL+nsz+huKSSGt2/qiVWE9CbHX H36MA8mUPMrqkwxa2vhBTOa5OwlOzug= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-425-jTdYKgYgNhSn6U_dgUqwTQ-1; Wed, 08 Jan 2025 18:33:42 -0500 X-MC-Unique: jTdYKgYgNhSn6U_dgUqwTQ-1 X-Mimecast-MFC-AGG-ID: jTdYKgYgNhSn6U_dgUqwTQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 916F619560AF; Wed, 8 Jan 2025 23:33:38 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D82DC19560AE; Wed, 8 Jan 2025 23:33:30 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 05/11] khugepaged: generalize hugepage_vma_revalidate for mTHP support Date: Wed, 8 Jan 2025 16:31:21 -0700 Message-ID: <20250108233128.14484-6-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 304D94000F X-Stat-Signature: z3mbqycr47u5swgpmsp7p3p4eqi9asde X-HE-Tag: 1736379227-570814 X-HE-Meta: U2FsdGVkX19zNxmPaKu5Lqos7KfAk0P9WbPB5bXfieia3zirDwit49xWjgtU4xt5rq2DmORQYshnBobohnYoWu64I1eTtsUbcFDjWj/b/Rqf9YOMxF1IYBKXWcr13zj++j5xvE9RIV/eZ45GtUOcq8H/+Lep7x3H7zhG4QI8/87PxnVdDkXe5zQpBR1BPWihBWzCpmYA0Sn35UQ7XMHjav7/kvJNxLI4oyIJLEVH9H7gf4OE/OLSds/wxfDvFFQc0tBg12lwFq3KCR/9QUB33ESo/aV2UDMj49ZzkaqURsyXOifGW2U6ebdSmWEDnjTnWuxl5PEeQ/xyHGPKhkN1vRUkViaFBSgoOLuSVF+tJ8AB5+db0P18/mD5PK69+Xcew4KeCW+mZEsCsXnZzlmrAu09k3xRv6SlUejdPK5gvM/RcjZLVvPiwLjM7Q79OH4MMQxYU2A/mStBsOSGLInIaFbioxpJEZLbHQVrXbGqCn9Gi+euQwz0vIOlWketBr7FTpYm0hDyCxiaeG2t1x9AerwCjzH9zAgaCaD0Qtdm9Xk9wcXTd+zszJcyEtqlkVehGNzENcH+iqq4an7CWfRxtKu6LFuuxTygShSSMuONYtUQjyyd8AqqwEGoX4rxE9rwafIJ8fCNMYjDguGEl4xgAowGY09jIHJkRyIpVQYVBKraj/3RlKnr+HT08T7gjtAsCmwx0vNkVB4PJyLT3ZyLRE0HSb4M5v+KfYJt4l7Yru4wYTZOJOrG9jn0k1iECoBSknbiMzRmiymCF+xgtI6gOKEE+Vjpux1Swe+QMwW511wH2rutvPutMuHjtO0kY1V2Xt/OlK5GFDi21Vwnd0icDpbvfUCc5D7MA7AxHCjZBv6mjGrcm9cOA0hYpZzrFq97W+e6bdwkfculUppadni+OBxnZpjNj1TtpM9IIqiSA9Vlfk9PrOB0HjIRw9M7ShAUrP/9dkdRRHopa0xSF7C Ge4GuYxR /Ee1aBrsuTB468HmZT9CkeF9rz1XhYT5rnCN3WnbvjN+X8cK8T5gknrRLzA3UbFRGZzYWlRIgRJfyin8HgLX6ZPZt2MgSgPB1ZG0TTdUmGmyKomsU1wpp3EKm30EBx34B8K+IbsdRjjr/oTlYjUdxntkYIWSFZBQkeWeqrePdmObRhzSq1qwHmPlmHFiq0GjHBQA/SxeU60bKqX4qu3hZ6dxdDEiAd5l3hhQP00VNnQruresdAMK4iUwOnCvdYT2Ku1WA7cQ009FTewH2Vj6ESzCp3rJQbbBesokCVIr5Sx9GSYHVzghMtapn5l2XoUS0g5HSzK3J5N1WEHp/DAEnint4ARqFYjA5j3QphfuYDzeIBQsde7JgivBvvN7IutAzGEgLF3vuOfrAwT5HqgznImKtME9cE7wBjtiHpQLlDPDOaTrDg3gKQmEqtVfh9YgbYpcu 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: For khugepaged to support different mTHP orders, we must generalize this function for arbitrary orders. No functional change in this patch. Signed-off-by: Nico Pache --- mm/khugepaged.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 90de49d11a98..e2e6ca9265ab 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -920,7 +920,7 @@ static int khugepaged_find_target_node(struct collapse_control *cc) static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, bool expect_anon, struct vm_area_struct **vmap, - struct collapse_control *cc) + struct collapse_control *cc, int order) { struct vm_area_struct *vma; unsigned long tva_flags = cc->is_khugepaged ? TVA_ENFORCE_SYSFS : 0; @@ -932,9 +932,9 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, if (!vma) return SCAN_VMA_NULL; - if (!thp_vma_suitable_order(vma, address, PMD_ORDER)) + if (!thp_vma_suitable_order(vma, address, order)) return SCAN_ADDRESS_RANGE; - if (!thp_vma_allowable_order(vma, vma->vm_flags, tva_flags, PMD_ORDER)) + if (!thp_vma_allowable_order(vma, vma->vm_flags, tva_flags, order)) return SCAN_VMA_CHECK; /* * Anon VMA expected, the address may be unmapped then @@ -1126,7 +1126,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, goto out_nolock; mmap_read_lock(mm); - result = hugepage_vma_revalidate(mm, address, true, &vma, cc); + result = hugepage_vma_revalidate(mm, address, true, &vma, cc, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) { mmap_read_unlock(mm); goto out_nolock; @@ -1160,7 +1160,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, * mmap_lock. */ mmap_write_lock(mm); - result = hugepage_vma_revalidate(mm, address, true, &vma, cc); + result = hugepage_vma_revalidate(mm, address, true, &vma, cc, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) goto out_up_write; /* check if the pmd is still valid */ @@ -2779,7 +2779,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, mmap_read_lock(mm); mmap_locked = true; result = hugepage_vma_revalidate(mm, addr, false, &vma, - cc); + cc, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) { last_fail = result; goto out_nolock; From patchwork Wed Jan 8 23:31:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931716 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 480E0E77188 for ; Wed, 8 Jan 2025 23:34:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3B306B0099; Wed, 8 Jan 2025 18:34:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEB526B009A; Wed, 8 Jan 2025 18:34:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB2B66B009B; Wed, 8 Jan 2025 18:34:03 -0500 (EST) 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 9CE266B0099 for ; Wed, 8 Jan 2025 18:34:03 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 18FECC154A for ; Wed, 8 Jan 2025 23:34:03 +0000 (UTC) X-FDA: 82985889966.20.B393F73 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 7DF4640003 for ; Wed, 8 Jan 2025 23:34:00 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Df9aCDGQ; spf=pass (imf01.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379241; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S133XG+svDEeb2oKFkZulclk4jILVy1/1EYUYGlZ8FE=; b=ehrcbFaNfVJxqlU/6v+ZaHnvicI6rrM5nz+CcYbTckXW1XzhtCGfYo7jD8+1vR2+7dyRee yWRYZ7d80ycAIyG9SatMwvpvdrlfNMBDm1ePk9ug1Gr8rYGVcbrK7gguM7VIFtlVBigQ7s xUifSKHst34MRohhQrCem6xViLzDe6Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379241; a=rsa-sha256; cv=none; b=tO3FknClCplvv2RsQ+TqjPGM4JFWA3tzPVLmZSN9HxuPzr+/WXkoOZ/2xFH7czqibxCTy0 vnjhRbonx/m6MUhc7x2RPWMCdipnNVwCAH3WFgjuP3c1zS2lp3jHFZ0jAbJd4l7kvcYRuY 2sm5pUOwKn4TaqtNUt3Pe31uVbSrAo8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Df9aCDGQ; spf=pass (imf01.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379239; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S133XG+svDEeb2oKFkZulclk4jILVy1/1EYUYGlZ8FE=; b=Df9aCDGQf1OfDaKnMfs2Bx4nLBSs3xzkedzjODE334xgkEJNrgy1Chkv/P0vKIPGfNE79w smWJ8JprRwEahLBiua/kLnVteUWeDuLxNK++Nuw+o9smLxIk4h8j5ZFpjp9yUSFmxwPRBm xsuSKFah+LxVjD3nkIK15ElVFy1E7tQ= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-1PB79giaOF6GmKQgm3tLVg-1; Wed, 08 Jan 2025 18:33:52 -0500 X-MC-Unique: 1PB79giaOF6GmKQgm3tLVg-1 X-Mimecast-MFC-AGG-ID: 1PB79giaOF6GmKQgm3tLVg Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 376AE19560A1; Wed, 8 Jan 2025 23:33:48 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E4AE419560AE; Wed, 8 Jan 2025 23:33:38 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 06/11] khugepaged: generalize alloc_charge_folio for mTHP support Date: Wed, 8 Jan 2025 16:31:22 -0700 Message-ID: <20250108233128.14484-7-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Queue-Id: 7DF4640003 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: p4mct5jimcs5eo3c8ujz74bu69aeetio X-HE-Tag: 1736379240-400299 X-HE-Meta: U2FsdGVkX1/42iyqdLyxvSEBCHbHy4i90wl2rQBlN/m6PleIm9gja5Yfpg09eKPR9LfAF03/Sh78Dz4jar1ZWBcZ6sSXmotaFWtj6ph+j2BD/Z+iWOQ97m3oOgD2sBY6b7EPSQyq8RnZg105b3ruTtoPI8SeHfZlmb+B9P4hKLH0raeZ5VqoWoZi2WImdZQBmGjGwg2Z4o7tScA+ybz8iwp6YfeJhfV7J79kwVTWWN8p++ItMsTzC+z2/0hnXROJnRZz/x+NXQobs6zFvShZFPmH5x/oFgjNhIuSM061MtdxC1V0Ao5hrjbvxOtDe18Df3wWd9V0SCvoDCW4EKqonGRqyMTGnYXhSepmjHtpm1srMdfcJolvT05Fi760gc0K04go6J4qIrvwMAcQdJSfZOKxQHw7KARbytdBdFr5Nz37WjEiTpRhuuyk6RAYvkitXfG1BZz0D1IW+7k+boisRM0o5GRIGoWk0F8Ks49LvtuLey7zFOBS+wQXBSGkFSWPyUYf8hgvM2r4wes2cI4p8iBmElwlF3r+WetFCJrxJWvIXBEgK49NHnJeTYQKmRj2QfscG566+SwLsPX3mXFFFOGMU+YdhXPD8jIZrTT4dz3D7bpf6XvZAxJB1kGYU9JHiEHaRbd2bjZnNlLSz2osoROFo5oYSEVbOjXnuf4tedrc4KduGIQoP90wA3137RkLUvfOerHUaGPr/9HvnVO4C8t0G9IqgOYSHgGVeXi+DCBRV4BC8KRM0GWF/cb9+lOdUyol8kCYI7dDKoOemSkwHl5NS9afA7B+B9SI9dgWwNi9ia0Z7uU+vG7kWp2m3kRuXcEqHe9MCkKEOryl+Vkbljc5HMz5ZekjO3eatGqB2NLv/9cLfqFPxLjnxgTkTPNhWoqTUkvugtJS09AcCHGANQIZBYCbcElQ+QY80VHyndF/r5rlodqvMBf9Fr0UUiyW5GIUF9garfnyUaqL4sT nJxsmKIN LY+VG9vqJGkWSvmJhutHYf09WA4yN7jIib82PUyfoIIHp6Extbv5Z9QEBpCrc5peC19T2FIf9Qxc9VukUJO63NwnIwmFdQ/pFhJGLMSSimf2CJvkCosR1T1IWTTP+Ijm3ft0yLVXbIsESVPYfftui8ioc3iCl1U0f6CH/RI+1BuJ/h6zzD2kLO/Ng1MNOGZJIopbFESFuBUwu7mU8z0cV+yyWmTNoM7UgUxtP0rmuAGsoH5m4QyxdmHott/Pe6/xC66Lv/piXHV6pJ6ssleqFEGbDV1huNu+ubEskVR624uVNAKUojdgYM3fiA6vYkXWUBwtkTFfvpUsNdNipmoqM5d7YwgXPoiqNIcHc40TBI1mW5Rw6UWqO7XA7iEy23ysdpllTUrzMKAi7Lgu5/SqnCJt+hGtFnDWRE1z647oMxM0l+9qaiNoMsh9hyXrvw69RwFrr 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: alloc_charge_folio allocates the new folio for the khugepaged collapse. Generalize the order of the folio allocations to support future mTHP collapsing. No functional changes in this patch. Signed-off-by: Nico Pache --- mm/khugepaged.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index e2e6ca9265ab..6daf3a943a1a 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1070,14 +1070,14 @@ static int __collapse_huge_page_swapin(struct mm_struct *mm, } static int alloc_charge_folio(struct folio **foliop, struct mm_struct *mm, - struct collapse_control *cc) + struct collapse_control *cc, int order) { gfp_t gfp = (cc->is_khugepaged ? alloc_hugepage_khugepaged_gfpmask() : GFP_TRANSHUGE); int node = khugepaged_find_target_node(cc); struct folio *folio; - folio = __folio_alloc(gfp, HPAGE_PMD_ORDER, node, &cc->alloc_nmask); + folio = __folio_alloc(gfp, order, node, &cc->alloc_nmask); if (!folio) { *foliop = NULL; count_vm_event(THP_COLLAPSE_ALLOC_FAILED); @@ -1121,7 +1121,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, */ mmap_read_unlock(mm); - result = alloc_charge_folio(&folio, mm, cc); + result = alloc_charge_folio(&folio, mm, cc, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) goto out_nolock; @@ -1834,7 +1834,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem); VM_BUG_ON(start & (HPAGE_PMD_NR - 1)); - result = alloc_charge_folio(&new_folio, mm, cc); + result = alloc_charge_folio(&new_folio, mm, cc, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) goto out; From patchwork Wed Jan 8 23:31:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931717 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 64744E7719A for ; Wed, 8 Jan 2025 23:34:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE9B76B009A; Wed, 8 Jan 2025 18:34:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E73486B009B; Wed, 8 Jan 2025 18:34:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9D746B009C; Wed, 8 Jan 2025 18:34:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A812E6B009A for ; Wed, 8 Jan 2025 18:34:04 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 696B7141371 for ; Wed, 8 Jan 2025 23:34:04 +0000 (UTC) X-FDA: 82985890008.20.3F23BE2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id B3168180012 for ; Wed, 8 Jan 2025 23:34:02 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TXVSVi90; spf=pass (imf24.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379242; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NlWBk/L/IkPkjBErBKE0II3MThdDUOorzPsxzF/l62g=; b=VrlTPiUB0ziWBTCTox6YmGE+bDThT1mYO4AGOYh/uDGF4kM2Et3E5iAw8Rbn74k0YyYD+p 9n1g/KZtQq/lx3uWFF4/7DxWi2JYGVWySQ1zuDZg7Ilec0a5/KmATzWPdVUsZoEFtx1pFN FQ44WSh6m1I3zMtfpEN7mLJDU5BNWeQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379242; a=rsa-sha256; cv=none; b=ucumnwYj/SKzi9RdF4YineMZ0fcScUrGe4ctas+VbVCguXpv56nv04VnGZf5duIoYSzJUs euaKWkDZLIH/hyes2xEjc+i5SpilGc0/LtynrEoh8GFYWW+HxDC7FwT7v6xg4naclB7f26 vw5IaCuuz/+JfDkbXdmJwgPiiPvtlcE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TXVSVi90; spf=pass (imf24.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NlWBk/L/IkPkjBErBKE0II3MThdDUOorzPsxzF/l62g=; b=TXVSVi906bcJJn/s7foZhiwPJKYi1GcTtgfXdEDFi3mY4rGv0FhXRrw1gSecyoz7nbBg6p SX0APVpnpMW0gBBsoBoqyFvn0DGtmyvMRZvF5FTvFg0esALWvFQTaQbYjEseFZO30HP6cq lCYEIshxcSMuiImB5KL+qhuCh3oB6dk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-f2Ks21HyPQGtWMlhN9XdfA-1; Wed, 08 Jan 2025 18:34:00 -0500 X-MC-Unique: f2Ks21HyPQGtWMlhN9XdfA-1 X-Mimecast-MFC-AGG-ID: f2Ks21HyPQGtWMlhN9XdfA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCE641956083; Wed, 8 Jan 2025 23:33:56 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 92A9019560AE; Wed, 8 Jan 2025 23:33:48 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 07/11] khugepaged: generalize __collapse_huge_page_* for mTHP support Date: Wed, 8 Jan 2025 16:31:23 -0700 Message-ID: <20250108233128.14484-8-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B3168180012 X-Stat-Signature: r3fa83zkqwnmkc9ca7scyoe6kg7gog6d X-Rspam-User: X-HE-Tag: 1736379242-368473 X-HE-Meta: U2FsdGVkX181mLcM2WDwaA1zkjPGpWy8vZD7S9fpVLf0sN9dYlHmcY++e5elxWJO9UBjygNbclGZDMNIuPQRNnr64A9k9uydBDvr4VdI+hVcd42EVT8t8ZQDzhADn4iJEN49AQVw0Q7i+W1wXD5KZtp9NXEQRSoGOq4gpB21QV4u/FijiXryR7G2pIZwID3ss57acTVCgXrP3kKGxHbz19Rb3tjRkOWObvrBiub0U8hpo2Sgrah1nY7aJ6CZpf4VhunDFKtJf+32GRpHw2K4QqcjBETpz7V16lf5pp0VvDE68ZP5KpVt8V8zN+PpYyWazGppt7P4mha6SDVhjnR3u9azegbUr3CfQeAeqyhhnchWQOijTujwvo8jTfvPPmvusL27vSeD45NRch776Kg4eEuYm7uAcsT1u+z7avrIyVDD/6eQA00gXXtBID7NimLMHLz4GczG0YQ0yYGjHImw8Fdvv+tMdmc19TFqis/etlmvcWJqES9RSYQRxJz54EveU5BHB01UH055ahoAIHg0BmQP+1NS4QiMQpFE0M9hBrsW1adlZwKcNy1HAmor2DivszYJUhNqFopRtO3sAwszqLOmDMOE/1WqCvbnNI/t3CtScbaRaWteDMrI0Zb34cWzZnb7tjm6psqLzPXbr2t9SqYI/Gdg7bJB67stbvvAfpwJI5rlXcA7CiMCCAMFTOF0aqN2HjuzpY8vkl+HaZTGmjjVK3oFkzNq0anyIZULO8xOyXIhzgmEmR7gozSrjaHH3hJGbuT6gQ7W1DVHv98jprCHzw3ZqlVPQWM5SUh/KgGMRd9i6EJSsbYpir0giDUkyp+mS4CXhDQOQvkGveeWR0CCw+2uZV1lKXF7J3D+LU4w5CNUfA1wX5kNSBiz803qLD67CXV2xbi4uFgNWbnswOjiYgej2+0F0u5t2nn4mXCVFSsPj0kThsKwLWOCFIHHnb5EzxIlHL1DvC/NISt 8MhWVrsf ht7IMDBdTgOB5CVetsD8uABQni26ot73UvdGk/RWBgPvTY53KTnJ07q+7V7XAhK5PuTuv5/MYv/hk1tjEpNZvovOPEsH+kCRuxFZuDq8QXOmPn8f1evOUYaYcGfp/VtDMM0A5AZ2KW4AgBv3yobLchHTUSBCV+OPQ5uwEVxaF+DIS2Jm1vEWAIq9Xi/44C+QY8EZg2nws51uui81xjpyYOXaeFbNdp+JNCNbG8Ar4wCn+Jo1OG/mH8apy2JZjl/sHPtRsmHSeaUwSFeWnY8wh/r++7o58QyODaFgUSW/BBj3t7AL1C5ZTCTC/2PbxF5dHwGC5g3DqMpVGRNJDtnkD9e6DtT26MOx5xsNv6cCxubv6uvNABF8drfyGhAY5766usxHpdhklGEKHKZJ+vLZigDuZUe+tRT809LzqH3VPo8RhdEvO/IX5OIStLtT9CQzEoEwo 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: generalize the order of the __collapse_huge_page_* functions to support future mTHP collapse. No functional changes in this patch. Signed-off-by: Nico Pache --- mm/khugepaged.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6daf3a943a1a..9eb161b04ee4 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -565,7 +565,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, unsigned long address, pte_t *pte, struct collapse_control *cc, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, + u8 order) { struct page *page = NULL; struct folio *folio = NULL; @@ -573,7 +574,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0; bool writable = false; - for (_pte = pte; _pte < pte + HPAGE_PMD_NR; + for (_pte = pte; _pte < pte + (1 << order); _pte++, address += PAGE_SIZE) { pte_t pteval = ptep_get(_pte); if (pte_none(pteval) || (pte_present(pteval) && @@ -711,14 +712,15 @@ static void __collapse_huge_page_copy_succeeded(pte_t *pte, struct vm_area_struct *vma, unsigned long address, spinlock_t *ptl, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, + u8 order) { struct folio *src, *tmp; pte_t *_pte; pte_t pteval; - for (_pte = pte; _pte < pte + HPAGE_PMD_NR; - _pte++, address += PAGE_SIZE) { + for (_pte = pte; _pte < pte + (1 << order); + _pte++, address += PAGE_SIZE) { pteval = ptep_get(_pte); if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) { add_mm_counter(vma->vm_mm, MM_ANONPAGES, 1); @@ -764,7 +766,8 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, pmd_t *pmd, pmd_t orig_pmd, struct vm_area_struct *vma, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, + u8 order) { spinlock_t *pmd_ptl; @@ -781,7 +784,7 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, * Release both raw and compound pages isolated * in __collapse_huge_page_isolate. */ - release_pte_pages(pte, pte + HPAGE_PMD_NR, compound_pagelist); + release_pte_pages(pte, pte + (1 << order), compound_pagelist); } /* @@ -802,7 +805,7 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, pmd_t *pmd, pmd_t orig_pmd, struct vm_area_struct *vma, unsigned long address, spinlock_t *ptl, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, u8 order) { unsigned int i; int result = SCAN_SUCCEED; @@ -810,7 +813,7 @@ static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, /* * Copying pages' contents is subject to memory poison at any iteration. */ - for (i = 0; i < HPAGE_PMD_NR; i++) { + for (i = 0; i < (1 << order); i++) { pte_t pteval = ptep_get(pte + i); struct page *page = folio_page(folio, i); unsigned long src_addr = address + i * PAGE_SIZE; @@ -829,10 +832,10 @@ static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, if (likely(result == SCAN_SUCCEED)) __collapse_huge_page_copy_succeeded(pte, vma, address, ptl, - compound_pagelist); + compound_pagelist, order); else __collapse_huge_page_copy_failed(pte, pmd, orig_pmd, vma, - compound_pagelist); + compound_pagelist, order); return result; } @@ -996,11 +999,11 @@ static int check_pmd_still_valid(struct mm_struct *mm, static int __collapse_huge_page_swapin(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long haddr, pmd_t *pmd, - int referenced) + int referenced, u8 order) { int swapped_in = 0; vm_fault_t ret = 0; - unsigned long address, end = haddr + (HPAGE_PMD_NR * PAGE_SIZE); + unsigned long address, end = haddr + ((1 << order) * PAGE_SIZE); int result; pte_t *pte = NULL; spinlock_t *ptl; @@ -1110,7 +1113,6 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, int result = SCAN_FAIL; struct vm_area_struct *vma; struct mmu_notifier_range range; - VM_BUG_ON(address & ~HPAGE_PMD_MASK); /* @@ -1145,7 +1147,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, * that case. Continuing to collapse causes inconsistency. */ result = __collapse_huge_page_swapin(mm, vma, address, pmd, - referenced); + referenced, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) goto out_nolock; } @@ -1192,7 +1194,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, pte = pte_offset_map_lock(mm, &_pmd, address, &pte_ptl); if (pte) { result = __collapse_huge_page_isolate(vma, address, pte, cc, - &compound_pagelist); + &compound_pagelist, HPAGE_PMD_ORDER); spin_unlock(pte_ptl); } else { result = SCAN_PMD_NULL; @@ -1222,7 +1224,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, result = __collapse_huge_page_copy(pte, folio, pmd, _pmd, vma, address, pte_ptl, - &compound_pagelist); + &compound_pagelist, HPAGE_PMD_ORDER); pte_unmap(pte); if (unlikely(result != SCAN_SUCCEED)) goto out_up_write; From patchwork Wed Jan 8 23:31:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931720 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 1B51DE77199 for ; Wed, 8 Jan 2025 23:34:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A55236B009D; Wed, 8 Jan 2025 18:34:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A055E6B009E; Wed, 8 Jan 2025 18:34:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A5C26B009F; Wed, 8 Jan 2025 18:34:18 -0500 (EST) 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 6C8FE6B009D for ; Wed, 8 Jan 2025 18:34:18 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 297F616153F for ; Wed, 8 Jan 2025 23:34:18 +0000 (UTC) X-FDA: 82985890596.19.744DBE3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 3719520009 for ; Wed, 8 Jan 2025 23:34:15 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gUafi8+B; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379256; a=rsa-sha256; cv=none; b=qcmzW1cuP4ht8wU19WkylbF5wyQMuldscrSxT2INxHZxipHKoBCb4cQBYazjEg/nUQocxC HO7xFgNfK09KvYPE0o+CluFX3VgrmGjF7mIy95TFoDZ2l9I3keg/lnz7O1s0+tVot8M9DZ 87oP0QcOi9KdQnJTx5Ix8YnoqeFJLx0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gUafi8+B; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379256; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0aDz9njSBgcFlph30zgTLUgh8iNh2Ug8pSZWMj0+9ks=; b=196LOk/SAeByJvex/iGVxLWizRiFx49MOWMO/5GaQ9JtJEVFwrQPTgyLSAwMQEvHvWaIO0 SGdnKS+0Qcsi1uX64YmfgVAIR5x8yyW4XauIul4yvXUfaiospbLSxWkOnaVpIONI4gvIW+ YH2huquiQuelEurs6RNOdiFD6kmkdrE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0aDz9njSBgcFlph30zgTLUgh8iNh2Ug8pSZWMj0+9ks=; b=gUafi8+B82jjuGIstSsxzhZWVG0RhjE6TYuIV7m8rzG41QoGxyrptQX3NWZt5t6BM4IY5y KcMyejeNLHw3nD0wpAKMUYeuk7K35onhGPVz91LM9fZ1NDxlSqIoh8bDLe5qFypcjTmeDJ WewfSMKfdaZuy0sSdVxa3nqRHKm2tg8= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-IzrUvAYLNmSq9Wj_N5ghYw-1; Wed, 08 Jan 2025 18:34:10 -0500 X-MC-Unique: IzrUvAYLNmSq9Wj_N5ghYw-1 X-Mimecast-MFC-AGG-ID: IzrUvAYLNmSq9Wj_N5ghYw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C0DF19560B1; Wed, 8 Jan 2025 23:34:05 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2718F19560AE; Wed, 8 Jan 2025 23:33:57 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 08/11] khugepaged: introduce khugepaged_scan_bitmap for mTHP support Date: Wed, 8 Jan 2025 16:31:24 -0700 Message-ID: <20250108233128.14484-9-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3719520009 X-Stat-Signature: mudzbxrh7f817qkwtprg9p4tpu44isr8 X-Rspam-User: X-HE-Tag: 1736379255-702926 X-HE-Meta: U2FsdGVkX18I2Whn1ro4mLuE+KFt1O0mR+lTneFmFqZ/ZcJ9q6fMEoy5gwCbAccnTjyHCerx7JfbeAB4N/lrFnulrYwiOZfoT8yiyQNHeg+47dTqZJwzoNE63tQfisBlvCfTPplhX9flVG0KzhyfMTK6E8Yn4Q0j9gilIvszox4/qt0ZbxUmncOLSy1uCB8CzN9OVCIn91d5Lcree7J8B1MRZ3PGg4mbontTYBalOX2Fm5HovgYWS135j9KLvR5lUEVEHJUOhMniOBK2PeJrdwmkAkjMkCuHZxRH8bQigf0Fy6y8ku9QGGaIFdZ5Sw5EXikVwXhpViFwhtWB0kPNNQ3bgGE34m/7uqcatYbl2F4lg+a/QdB4rkYPe/uOc/0jpXvmU4V7QYiMk5OyKHLu1wsl6//ixJo6Okdggk8Qsg+6R5e7RUCTjAn+hr6JFFzxM1V3CF3jhn9v6Yec4n8fHQrMRn5hipsyubB/JAn9cJeGzxkl/ox1DGt42JCqqVYxRPZlfnRyGgFoyOCzpuiZ0Dr5ighcLqq+qlxr5lfylChfcNO7BzvAvtrCk8WeUWrxXrWDCex0IqpQJWgfQzrzIsTvZHHM9SGE0B8bxEyw7Yqq9lg/SDzPt7LvJiG1du7qr7LQahTpy0fO84/t9A012skDdhavpZGrRTi/HFMieK2ijP+Rmn3xv01orth3jlNUBaG6YZbYlXBJsgJXWSKwM20LIUC6VQl3EagDgvoANH2e1WW4wUfgYv3vFo/YnZhL2ktNP1P22HBPHxGTccQppcmfx2zIoZXg87fnbG67qBBUjzy1Nf5ayEMQUFzfgWLBl8EjvyCV++Wbh/5SWsqD3RykzNyMO52t3eCV7Ozvg4IkTkHuR0XP+4jIF5lTwi8Mt8h/DNpMh2KfmQMljscUp4SXnbZt1uWePDLWr5ILRP+7JqyvFO9beK5JuWOLdx7oKwOBbYwzOM3cC7qKOGL NGf7IPyb Uoqb937iSKPOTcsA/Nyb+dbAbNdZJFoAYyMCAO7eUEQE7bBFoBdBhh7Paqhywh44MDZ7//ZkK86apKh6PeudJud9ztOQCyNOZv6M7/vymfIZWQ6pxiR5PonUu5Gwj8jaCUrwHZtda9yhbjWix7Sq3b5O9BGfWaLIrsAGjdP8GhM0n5v7S+nVcCBwsqg6j4FYG3e+LaofxOVIB6qpHMBfYwAQrlXR54ehzyG9lLPjkCeD0v6Z+oAIPRmtKKJeg5Zlff4mOvD7HuMDWrrwsHgd8evx1APhcp57lW/irO48U5+ndan4OQCkpRG9tCvQJyxvaHyIS/5FNHLSmoiCnEaoooRtIwu8xtkEv8ea3g/MaPZyI4J0QYhcrXUcsonn2iq/LoDg/iuP5yh5YW6G55wGku7/aTRnAkjOldhYItB7EZpr2Gp77C5wOVYr+a5ROmnbMdMtl 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: khugepaged scans PMD ranges for potential collapse to a hugepage. To add mTHP support we use this scan to instead record chunks of fully utilized sections of the PMD. create a bitmap to represent a PMD in order MTHP_MIN_ORDER chunks. by default we will set this to order 3. The reasoning is that for 4K 512 PMD size this results in a 64 bit bitmap which has some optimizations. For other arches like ARM64 64K, we can set a larger order if needed. khugepaged_scan_bitmap uses a stack struct to recursively scan a bitmap that represents chunks of fully 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. Signed-off-by: Nico Pache --- include/linux/khugepaged.h | 4 +- mm/khugepaged.c | 129 +++++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 7 deletions(-) diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index 1f46046080f5..31cff8aeec4a 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -1,7 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef _LINUX_KHUGEPAGED_H #define _LINUX_KHUGEPAGED_H - +#define MIN_MTHP_ORDER 3 +#define MIN_MTHP_NR (1<mthp_bitmap_stack[++top] = (struct scan_bit_state) + { HPAGE_PMD_ORDER - MIN_MTHP_ORDER, 0 }; + + while (top >= 0) { + state = cc->mthp_bitmap_stack[top--]; + order = state.order; + offset = state.offset; + num_chunks = 1 << order; + // Skip mTHP orders that are not enabled + if (!(enabled_orders >> (order + MIN_MTHP_ORDER)) & 1) + goto next; + + // copy the relavant section to a new bitmap + bitmap_shift_right(cc->mthp_bitmap_temp, cc->mthp_bitmap, offset, + MTHP_BITMAP_SIZE); + + bits_set = bitmap_weight(cc->mthp_bitmap_temp, num_chunks); + + // Check if the region is "almost full" based on the threshold + max_percent = ((HPAGE_PMD_NR - khugepaged_max_ptes_none - 1) * 100) + / (HPAGE_PMD_NR - 1); + threshold_bits = (max_percent * num_chunks) / 100; + + if (bits_set >= threshold_bits) { + ret = collapse_huge_page(mm, address, referenced, unmapped, cc, + mmap_locked, order + MIN_MTHP_ORDER, offset * MIN_MTHP_NR); + if (ret == SCAN_SUCCEED) + collapsed += (1 << (order + MIN_MTHP_ORDER)); + continue; + } + +next: + if (order > 0) { + next_order = order - 1; + mid_offset = offset + (num_chunks / 2); + cc->mthp_bitmap_stack[++top] = (struct scan_bit_state) + { next_order, mid_offset }; + cc->mthp_bitmap_stack[++top] = (struct scan_bit_state) + { next_order, offset }; + } + } + return collapsed; +} + static int khugepaged_scan_pmd(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, bool *mmap_locked, @@ -1430,7 +1528,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, pte_unmap_unlock(pte, ptl); if (result == SCAN_SUCCEED) { result = collapse_huge_page(mm, address, referenced, - unmapped, cc); + unmapped, cc, mmap_locked, HPAGE_PMD_ORDER, 0); /* collapse_huge_page will return with the mmap_lock released */ *mmap_locked = false; } @@ -2767,6 +2865,21 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, return -ENOMEM; cc->is_khugepaged = false; + cc->mthp_bitmap = kmalloc_array( + BITS_TO_LONGS(MTHP_BITMAP_SIZE), sizeof(unsigned long), GFP_KERNEL); + if (!cc->mthp_bitmap) + return -ENOMEM; + + cc->mthp_bitmap_temp = kmalloc_array( + BITS_TO_LONGS(MTHP_BITMAP_SIZE), sizeof(unsigned long), GFP_KERNEL); + if (!cc->mthp_bitmap_temp) + return -ENOMEM; + + cc->mthp_bitmap_stack = kmalloc_array( + MTHP_BITMAP_SIZE, sizeof(struct scan_bit_state), GFP_KERNEL); + if (!cc->mthp_bitmap_stack) + return -ENOMEM; + mmgrab(mm); lru_add_drain_all(); @@ -2831,8 +2944,12 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, out_nolock: mmap_assert_locked(mm); mmdrop(mm); + kfree(cc->mthp_bitmap); + kfree(cc->mthp_bitmap_temp); + kfree(cc->mthp_bitmap_stack); kfree(cc); + return thps == ((hend - hstart) >> HPAGE_PMD_SHIFT) ? 0 : madvise_collapse_errno(last_fail); } From patchwork Wed Jan 8 23:31:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931721 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 90539E77188 for ; Wed, 8 Jan 2025 23:34:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2189B6B009F; Wed, 8 Jan 2025 18:34:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CABA6B00A0; Wed, 8 Jan 2025 18:34:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 019E26B00A1; Wed, 8 Jan 2025 18:34:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D923F6B009F for ; Wed, 8 Jan 2025 18:34:24 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 665D8161562 for ; Wed, 8 Jan 2025 23:34:24 +0000 (UTC) X-FDA: 82985890848.29.AF83E39 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id B40118000D for ; Wed, 8 Jan 2025 23:34:22 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ND4aWY/w"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379262; a=rsa-sha256; cv=none; b=EZp25gBwp94nPsMd4LENYGZYWvJ6Zizb1SpWEYsSl/iuEnxdP7olXC4vtKF2zl6NO7uwLw 3EUs5yN47y9cLMXcxECbrMCcWLHlWuw6LCzpXUiJIFjXSEPBiydvyP7E2oM2RS9+ATsUZ0 sM2N+SrqMqztPndfz4jv9SGKYoJJoiQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ND4aWY/w"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379262; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=90X6GfV2bcC688lGkgxcg3viPnFdaoWJIxc9fBgBRMY=; b=UlvNMaFM3nr8NWLsovS6eznpkWTHHxZano9tXUbxcukVbgqYBOo3C7jAtXFYDyMq9rAA6U dkZxb/5wlGkBcPb1ZXZv9WlSM7pYFAUzY2n6lZdXbldFollrM6IqiB4j1OtlJN7pr9Y1vH krgIsUdssdC5QAIYGp89Xne1pu9WQ48= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=90X6GfV2bcC688lGkgxcg3viPnFdaoWJIxc9fBgBRMY=; b=ND4aWY/wEkmNKWDmpgg1Y/KAQheuR+jZgVjwfnz6bTcnWr1x7GMm7U3T+s54jJ84V4XKfv 3WiAqm/mBtHsp/PszO38fZ7dKPU63FSLnpyhIK1i0AwJfeqt8iTGM5oZkUi03iFuZStsde +rT/XooRUFYjaa1iTT77Uyfei8Keetk= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-480-6NSDnLaZPwSRWloZEf12ug-1; Wed, 08 Jan 2025 18:34:18 -0500 X-MC-Unique: 6NSDnLaZPwSRWloZEf12ug-1 X-Mimecast-MFC-AGG-ID: 6NSDnLaZPwSRWloZEf12ug Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E318A19560B1; Wed, 8 Jan 2025 23:34:13 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DD72519560AE; Wed, 8 Jan 2025 23:34:05 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 09/11] khugepaged: add mTHP support Date: Wed, 8 Jan 2025 16:31:25 -0700 Message-ID: <20250108233128.14484-10-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Stat-Signature: oe1n7zeahdpmy1h7ce9jaa8n6sx1bbf1 X-Rspam-User: X-Rspamd-Queue-Id: B40118000D X-Rspamd-Server: rspam08 X-HE-Tag: 1736379262-236338 X-HE-Meta: U2FsdGVkX182qhSZ+6RLGmfmXjjAZTwOQKu97LKB7nzOvBy2F53oAstXEpBspidzG1GsbcWwlsaXdxzf1npgfdh+8/K1yKqugfcVr5AIGlcth52qBrLajjFPWl2L5xy4KaAlL+AOiaZFFyGIb0+L0xZcXuYXblDScenC3GL5q8Agonsj52/UCEtMaErv60stYFzlKmz16nlvi3+Yci9Vr8xGZgUcXuA2zB5Qr4rIrtZzg+6JnJHocaQlI4kDaOD6RhVCETB4I9ZKkZlkmDy0a7FNVqDxA+qXVVRg9S50WrnSmFI9n5x81VB4X8R7AGKsGPQO2evFK849ISnPsx4H6BS/Mu/HtKVloIkPZ0GQF8+5EnhzeV9ZD4S8dERAeap6pFUslI5FveFjlkY2xFshtB7qtIbV8nsM0pZgKyfOrQSkwFCoyQ0qh4kHgvmaZRhpCew3tK1Os8KwfVEs2qWjOeBcfjOCAMnkbtXcXjO0kkW2aSpXWeLj3dOS/iyT5O1WuLQnDR/Q4MQ8lYV7j9K926Opl33gjLBf4zI+vysSVdhvCSdwYWO3VBDbA5yUCyoVqNdgrxiGpIAc3Ue3Pqrn6YH/Ns+qhHvwTe3h1ti7i8+vM73DH3iIpwqAZaG/RM3tS85PDQLy4KEkJmDJ8pYYEfeL3LiGmx2lRVj1PqwWA3kNrKtIpRFJ4quBSgbPvbxWBAecoxdPrCH5dba+bdCjBY3GbFWO8QCQDW1ccIgWVSYrqkKqEpp6Evf+npUE/pMcNSiJ25iYtp1pbhiWg1jd/WmNyszorCqEyvTVCk5C5+PqmQBK0Hvj1MCCW9Dp++N5yl78+6EteL6LsuhKJFAXEGo9MdZrQJavEKvH0y3uo1wiA+YevgX5ED/8Vx7LP4vO4klVNMWPKVdnskEUc8xg4VhnllitCxkop4Cl4psawswVQe2EBoiRxEqXLXysncoK5xyBHUTGfmhTWPYHiVg JnHq89iN QyAQaPRHxf1HY2I0KoPG/By7FL9Aug7gIf+uLcxV7e5KXbZi5Omho6dO2rwEZfJKSSH15aFvNv9mos2dTN3lbg5L9TcFtTQdH3ikfZMt70fEiTSLQdVIcyJUsAbiVyUnmWxgEN4kIhRfbRkgrUzqfTmcsJB+QH35GeP3G8Lq7ZnimbujAXp5Ah3sd8TqLhWMBVE3rHNCjs8VcbP0cBrfTn0sjBskmajAhXpgNxqvcXGe7QWFSReaU+GYuc4XekTv3FzwqhVvdj/KLsRi9XrU6TxvuNRJErNVMH4fn6Gi0I9QYbFl1CYUtx0FfYB+Md0uYTtTWh4Ihc3VyEAMaLu7KEGh4YCoACZ8XbC9JFm+vycVsTHdDlLmvKITAA7SSJcGmLfchf5RASqp/0fM= 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: Introduce the ability for khugepaged to collapse to different mTHP sizes. While scanning a PMD range for potential hugepage collapse, track pages in MIN_MTHP_ORDER chunks. Each bit represents a fully utilized region of order MIN_MTHP_ORDER ptes. With this bitmap we can determine which mTHP sizes would be the most efficient to collapse to if the PMD collapse is not suitible. Signed-off-by: Nico Pache --- mm/khugepaged.c | 111 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 34 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index de1dc6ea3c71..4d3c560f20b4 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1139,13 +1139,14 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, { LIST_HEAD(compound_pagelist); pmd_t *pmd, _pmd; - pte_t *pte; + pte_t *pte, mthp_pte; pgtable_t pgtable; struct folio *folio; spinlock_t *pmd_ptl, *pte_ptl; int result = SCAN_FAIL; struct vm_area_struct *vma; struct mmu_notifier_range range; + unsigned long _address = address + offset * PAGE_SIZE; VM_BUG_ON(address & ~HPAGE_PMD_MASK); /* if collapsing mTHPs we may have already released the read_lock, and @@ -1162,12 +1163,13 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, mmap_read_unlock(mm); *mmap_locked = false; - result = alloc_charge_folio(&folio, mm, cc, HPAGE_PMD_ORDER); + result = alloc_charge_folio(&folio, mm, cc, order); if (result != SCAN_SUCCEED) goto out_nolock; mmap_read_lock(mm); - result = hugepage_vma_revalidate(mm, address, true, &vma, cc, HPAGE_PMD_ORDER); + *mmap_locked = true; + result = hugepage_vma_revalidate(mm, address, true, &vma, cc, order); if (result != SCAN_SUCCEED) { mmap_read_unlock(mm); goto out_nolock; @@ -1185,13 +1187,14 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, * released when it fails. So we jump out_nolock directly in * that case. Continuing to collapse causes inconsistency. */ - result = __collapse_huge_page_swapin(mm, vma, address, pmd, - referenced, HPAGE_PMD_ORDER); + result = __collapse_huge_page_swapin(mm, vma, _address, pmd, + referenced, order); if (result != SCAN_SUCCEED) goto out_nolock; } mmap_read_unlock(mm); + *mmap_locked = false; /* * Prevent all access to pagetables with the exception of * gup_fast later handled by the ptep_clear_flush and the VM @@ -1201,7 +1204,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, * mmap_lock. */ mmap_write_lock(mm); - result = hugepage_vma_revalidate(mm, address, true, &vma, cc, HPAGE_PMD_ORDER); + result = hugepage_vma_revalidate(mm, address, true, &vma, cc, order); if (result != SCAN_SUCCEED) goto out_up_write; /* check if the pmd is still valid */ @@ -1212,11 +1215,12 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, vma_start_write(vma); anon_vma_lock_write(vma->anon_vma); - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, address, - address + HPAGE_PMD_SIZE); + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, _address, + _address + (PAGE_SIZE << order)); mmu_notifier_invalidate_range_start(&range); pmd_ptl = pmd_lock(mm, pmd); /* probably unnecessary */ + /* * This removes any huge TLB entry from the CPU so we won't allow * huge and small TLB entries for the same virtual address to @@ -1230,10 +1234,10 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, mmu_notifier_invalidate_range_end(&range); tlb_remove_table_sync_one(); - pte = pte_offset_map_lock(mm, &_pmd, address, &pte_ptl); + pte = pte_offset_map_lock(mm, &_pmd, _address, &pte_ptl); if (pte) { - result = __collapse_huge_page_isolate(vma, address, pte, cc, - &compound_pagelist, HPAGE_PMD_ORDER); + result = __collapse_huge_page_isolate(vma, _address, pte, cc, + &compound_pagelist, order); spin_unlock(pte_ptl); } else { result = SCAN_PMD_NULL; @@ -1262,8 +1266,8 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, anon_vma_unlock_write(vma->anon_vma); result = __collapse_huge_page_copy(pte, folio, pmd, _pmd, - vma, address, pte_ptl, - &compound_pagelist, HPAGE_PMD_ORDER); + vma, _address, pte_ptl, + &compound_pagelist, order); pte_unmap(pte); if (unlikely(result != SCAN_SUCCEED)) goto out_up_write; @@ -1274,20 +1278,37 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, * write. */ __folio_mark_uptodate(folio); - pgtable = pmd_pgtable(_pmd); - - _pmd = mk_huge_pmd(&folio->page, vma->vm_page_prot); - _pmd = maybe_pmd_mkwrite(pmd_mkdirty(_pmd), vma); - - spin_lock(pmd_ptl); - BUG_ON(!pmd_none(*pmd)); - folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE); - folio_add_lru_vma(folio, vma); - pgtable_trans_huge_deposit(mm, pmd, pgtable); - set_pmd_at(mm, address, pmd, _pmd); - update_mmu_cache_pmd(vma, address, pmd); - deferred_split_folio(folio, false); - spin_unlock(pmd_ptl); + if (order == HPAGE_PMD_ORDER) { + pgtable = pmd_pgtable(_pmd); + _pmd = mk_huge_pmd(&folio->page, vma->vm_page_prot); + _pmd = maybe_pmd_mkwrite(pmd_mkdirty(_pmd), vma); + + spin_lock(pmd_ptl); + BUG_ON(!pmd_none(*pmd)); + folio_add_new_anon_rmap(folio, vma, _address, RMAP_EXCLUSIVE); + folio_add_lru_vma(folio, vma); + pgtable_trans_huge_deposit(mm, pmd, pgtable); + set_pmd_at(mm, address, pmd, _pmd); + update_mmu_cache_pmd(vma, address, pmd); + deferred_split_folio(folio, false); + spin_unlock(pmd_ptl); + } else { //mTHP + mthp_pte = mk_pte(&folio->page, vma->vm_page_prot); + mthp_pte = maybe_mkwrite(pte_mkdirty(mthp_pte), vma); + + spin_lock(pmd_ptl); + folio_ref_add(folio, (1 << order) - 1); + folio_add_new_anon_rmap(folio, vma, _address, RMAP_EXCLUSIVE); + folio_add_lru_vma(folio, vma); + spin_lock(pte_ptl); + set_ptes(vma->vm_mm, _address, pte, mthp_pte, (1 << order)); + update_mmu_cache_range(NULL, vma, _address, pte, (1 << order)); + spin_unlock(pte_ptl); + smp_wmb(); /* make pte visible before pmd */ + pmd_populate(mm, pmd, pmd_pgtable(_pmd)); + deferred_split_folio(folio, false); + spin_unlock(pmd_ptl); + } folio = NULL; @@ -1367,21 +1388,26 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, { pmd_t *pmd; pte_t *pte, *_pte; + int i; int result = SCAN_FAIL, referenced = 0; int none_or_zero = 0, shared = 0; struct page *page = NULL; struct folio *folio = NULL; unsigned long _address; + unsigned long enabled_orders; spinlock_t *ptl; int node = NUMA_NO_NODE, unmapped = 0; bool writable = false; - + bool all_valid = true; + unsigned long tva_flags = cc->is_khugepaged ? TVA_ENFORCE_SYSFS : 0; VM_BUG_ON(address & ~HPAGE_PMD_MASK); result = find_pmd_or_thp_or_none(mm, address, &pmd); if (result != SCAN_SUCCEED) goto out; + bitmap_zero(cc->mthp_bitmap, 1 << (HPAGE_PMD_ORDER - MIN_MTHP_ORDER)); + bitmap_zero(cc->mthp_bitmap_temp, 1 << (HPAGE_PMD_ORDER - MIN_MTHP_ORDER)); memset(cc->node_load, 0, sizeof(cc->node_load)); nodes_clear(cc->alloc_nmask); pte = pte_offset_map_lock(mm, pmd, address, &ptl); @@ -1390,8 +1416,12 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, goto out; } - for (_address = address, _pte = pte; _pte < pte + HPAGE_PMD_NR; - _pte++, _address += PAGE_SIZE) { + for (i = 0; i < HPAGE_PMD_NR; i++) { + if (i % MIN_MTHP_NR == 0) + all_valid = true; + + _pte = pte + i; + _address = address + i * PAGE_SIZE; pte_t pteval = ptep_get(_pte); if (is_swap_pte(pteval)) { ++unmapped; @@ -1414,6 +1444,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, } } if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) { + all_valid = false; ++none_or_zero; if (!userfaultfd_armed(vma) && (!cc->is_khugepaged || @@ -1514,7 +1545,15 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm, address))) referenced++; + + /* + * we are reading in MIN_MTHP_NR page chunks. if there are no empty + * pages keep track of it in the bitmap for mTHP collapsing. + */ + if (all_valid && (i + 1) % MIN_MTHP_NR == 0) + bitmap_set(cc->mthp_bitmap, i / MIN_MTHP_NR, 1); } + if (!writable) { result = SCAN_PAGE_RO; } else if (cc->is_khugepaged && @@ -1527,10 +1566,12 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, out_unmap: pte_unmap_unlock(pte, ptl); if (result == SCAN_SUCCEED) { - result = collapse_huge_page(mm, address, referenced, - unmapped, cc, mmap_locked, HPAGE_PMD_ORDER, 0); - /* collapse_huge_page will return with the mmap_lock released */ - *mmap_locked = false; + enabled_orders = thp_vma_allowable_orders(vma, vma->vm_flags, + tva_flags, THP_ORDERS_ALL_ANON); + result = khugepaged_scan_bitmap(mm, address, referenced, unmapped, cc, + mmap_locked, enabled_orders); + if (result > 0) + result = SCAN_SUCCEED; } out: trace_mm_khugepaged_scan_pmd(mm, &folio->page, writable, referenced, @@ -2477,11 +2518,13 @@ static int khugepaged_collapse_single_pmd(unsigned long addr, struct mm_struct * fput(file); if (result == SCAN_PTE_MAPPED_HUGEPAGE) { mmap_read_lock(mm); + *mmap_locked = true; if (khugepaged_test_exit_or_disable(mm)) goto end; result = collapse_pte_mapped_thp(mm, addr, !cc->is_khugepaged); mmap_read_unlock(mm); + *mmap_locked = false; } } else { result = khugepaged_scan_pmd(mm, vma, addr, From patchwork Wed Jan 8 23:31:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931722 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 973F2E77188 for ; Wed, 8 Jan 2025 23:34:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 302C16B00A1; Wed, 8 Jan 2025 18:34:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B22B6B00A2; Wed, 8 Jan 2025 18:34:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17B1E6B00A3; Wed, 8 Jan 2025 18:34:36 -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 ECEAF6B00A1 for ; Wed, 8 Jan 2025 18:34:35 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A9E94457E5 for ; Wed, 8 Jan 2025 23:34:35 +0000 (UTC) X-FDA: 82985891310.13.7489CD1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id EFB4B40008 for ; Wed, 8 Jan 2025 23:34:33 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Lg3kC8q1; spf=pass (imf04.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379274; a=rsa-sha256; cv=none; b=w2tSnDRbasrzC9H4vjbBEO8RkJ+wGnQsqs1R3VUHyJ6VWoXU03ocdsgno04lKCjwPe5Ld9 jJgq8RSUjdIhoml267yEPEh2NDniAOg/2Dwl7dc7nVT6ERo33EDPXscQFk3JjDUdMyYie3 jXqvRiptZdpVm5SJhtHPVx6qY8IDp4Y= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Lg3kC8q1; spf=pass (imf04.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379274; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j5EOVM0v0gflap4pKtAxxmUaALnCNv8cRd9oJSElYf8=; b=5Ph/kJiZK07enXykxL6wTV9aTSYyIsG/JOAK8hV8oPowYjCPT+pTaLyrrmtRGV+PVvEdt2 +3VDEFdEnN64eKPOTuNfnm2Bcs7sJrwLWP00Fc8+bY1dEg7CLCjQ4KiMwe3MI2R/JMTT1a VxT32CpM5ZSjMJrJoE9xojXz315qam0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j5EOVM0v0gflap4pKtAxxmUaALnCNv8cRd9oJSElYf8=; b=Lg3kC8q1v2MBNsj/lUmZi+FTmlFCFExfNt0uKLAyymjo322enanOAC5Fk0gIIikVIqHP7m h2xtTakft42J3pnlkmQeVhzpZXDUrqM5QdCX9Zq4PgsG+wSWW3Goa5/8VnMi0GLn5qcEQB Nsr0rDHy+ZaoDEP4fChEewZmQxLmaF0= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584--pEwM4wDPgm_w6pskDoyhA-1; Wed, 08 Jan 2025 18:34:27 -0500 X-MC-Unique: -pEwM4wDPgm_w6pskDoyhA-1 X-Mimecast-MFC-AGG-ID: -pEwM4wDPgm_w6pskDoyhA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E58CE1979053; Wed, 8 Jan 2025 23:34:22 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4B9B419560AE; Wed, 8 Jan 2025 23:34:14 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 10/11] khugepaged: remove max_ptes_none restriction on the pmd scan Date: Wed, 8 Jan 2025 16:31:26 -0700 Message-ID: <20250108233128.14484-11-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Queue-Id: EFB4B40008 X-Stat-Signature: rg48yuxfaagzd7bst4n7rgw7tdi7jsbp X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736379273-13382 X-HE-Meta: U2FsdGVkX192tMZ9vSU4ZPg6FgLo8CIjqb+uOr1rqR6rp6sIQPNEIh76Y/Zh+jJAyifXYqwpyfb0HjS8Xff2AK/5nRe9hQhNhhuiW1yZ+848/WuZSCW03nZblpAxrNiwcccFL18dcZJRWSxYN/YX4PRUNSn8/9cvA7m7SwjGqild7n8Ryl4Wvv/c3FZcqb0RHffrvmMwicjx3/XjP9QwJqBhBNUpJZGLdy97GMaiSqEVLA7Evmlvbg0AgxCWjw1T5yJpx+3a+knZWOXkIrxbtKXLX+qbWM3nKPI1pYNX1CGt2Y5/nBKOCXAvDiWq9M5IxDlI9QwS8Ibb5XJ8t4pS2FQnFy6rQnhgkxa/IR8oLjsHKb0mkWIGqDJOj6KIdjbQ9LKv2WH9LmySY/yy0Rpc5qpLHKXzoFW2K+TieH7N0HH+2wv1EyQZU0/3D7U336rHL/xEasYxeBneJqSMJs+hqY2kr2u7kS1ukjCz1V14Uby6XrNEEPKXI/jUmQBb2XjgASCCxT1h/NmUzPHAZvimBuB8kUoKUKUXH4O8Th8Gte9umrRUOylz1jbReo7nOcJCwIDKYAz2UItFJzItK+bjY1ecv9p0DGQga4vi/JYa1K5lerkHvBllnTqcBmTB1KJ7gbkaLsSnXZyoWRfMvpxLorEMbd4iwBf3K7WiBacYdhoKfWbPVmUXDkUqtHjdzgG2wdsel4UFYSaqKdJacBxEPyufjlg+DwRI4x0AorS72NPwDCFaRQkr6oA7rroT0GK0ceJB5wJN5ahmJiyVPVv6EXxt77aPV2e1L4ZhyYgBLMzowXbvHojIlV5J5ZlP0DJifbt12OtzbJpfADDRDejNFQHzFpy+Of/9Ea1jIi1nq26uKOwQNY3ivLRP9+S1QV/mHCIoiF8lm5yMxu9rr8yrUN4a7+CCe+JtPhDvE4Mt3s3QDXcstSqQc6iMHcT8ZbA+NyYiApMp0BuFNYLDJY3 wLZ+NImg E6fjS+YJOpjGCAnhOdshz/DqkBR+6fxWAQgcelNq/3PQzeWjAVwW9r5Y8z6ihDmQKJh8O32O9CJuGjCAINJ/hu/Swh4IFQFy1VfanyVkUUUXYfOVfa+0NpBAXEW68CFVz7ICRYCxnEaoOgqJs/rrSfmUDcvEXxeqmSEoewcJjOIy0UMAziSijoFKtVIvaKN6w9fLOoFhlytoyEyS0rTbB0Z1TyO4og1s7NbSmQmYCrqeMehYXUSji32o9k8yC85XsB0FN1z5D1TAaOCL4iIL3eoBLxYIHEgoiyV942/RTF5ZKdCLpBAFbaS/8G7dKhiHD7FkDsQym4S6Ah/CvUvnqsuDdcxKTNDFa8CM02thuuK3juRhrFi5ha0rSfHaT+A2LszCdVDb1RIOCbG6Ej94Ds3lpApuq9U9OhGw9wBYgXT9omND9kk2VEa4NL+cbG/f2VyTe 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: now that we have mTHP support, which uses max_ptes_none to determine how "full" a mTHP size needs to collapse. lets remove the restriction during the scan phase so we dont bailout early and miss potential mTHP candidates. Signed-off-by: Nico Pache --- mm/khugepaged.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 4d3c560f20b4..61a349eb3cf4 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1446,15 +1446,12 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) { all_valid = false; ++none_or_zero; - if (!userfaultfd_armed(vma) && - (!cc->is_khugepaged || - none_or_zero <= khugepaged_max_ptes_none)) { - continue; - } else { + if (userfaultfd_armed(vma)) { result = SCAN_EXCEED_NONE_PTE; count_vm_event(THP_SCAN_EXCEED_NONE_PTE); goto out_unmap; } + continue; } if (pte_uffd_wp(pteval)) { /* From patchwork Wed Jan 8 23:31:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931723 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 0AC66E77199 for ; Wed, 8 Jan 2025 23:34:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D14A6B00A3; Wed, 8 Jan 2025 18:34:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 87F506B00A4; Wed, 8 Jan 2025 18:34:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 720186B00A5; Wed, 8 Jan 2025 18:34:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 51F096B00A3 for ; Wed, 8 Jan 2025 18:34:41 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0F95E1C7458 for ; Wed, 8 Jan 2025 23:34:41 +0000 (UTC) X-FDA: 82985891562.23.2416B89 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 5004B100002 for ; Wed, 8 Jan 2025 23:34:39 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fIg8lGcU; spf=pass (imf05.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379279; a=rsa-sha256; cv=none; b=35jUJJ0K+86pNY2HHKWFA9tOUvvVame2w3c/uncWzDsyKpfOm1YTrrTmp08+t8g+Wy6Hwz UCBQ2NfKkdH9YcfLGm914yPMVRqjKI514/A32Hjf+xh1cdwyUznjrZMiiinbts72UdvOZl KpshdaqSRDvsHo145Vrl+SZjYkI5TUE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fIg8lGcU; spf=pass (imf05.hostedemail.com: domain of npache@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736379279; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Dlo40r5jZ4R+FC4eYe0RwrYQN6FD9g5gDaMstpJqM5E=; b=ve1ksg6fxXWOmwr0nFL3Y9neDCRmYaMf9kTsiVFqDv1Skkv37ZcTqs+syKMtW0HpHdmd9M 987t9BoyIZ10qw4hEcTqwdx79NKH7x9LpnaIKCdtKa7OXhkOF0UzrQ0tgvSNDw4/93wBa7 +r/6o+myxqAdk3kJsTWct7EP1lkLWZI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736379278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dlo40r5jZ4R+FC4eYe0RwrYQN6FD9g5gDaMstpJqM5E=; b=fIg8lGcU3me+W15oWKRz37FArSkznhX68Y0iOgRvdEvlSzkVSNxpcQw+icGMv8gPsbNcK8 RbQDG+PWznmPAJxd8pEjyvx7MwWa8XcHAKRCjfU1dBSyqhirjX2ooaS1wJf6DBzfaoL2Fe pOfIQhqk4tL7EtBbvY9TnR9aCmwN0fE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-370-l4fI3HlEPWGMA1brAjZ3eA-1; Wed, 08 Jan 2025 18:34:35 -0500 X-MC-Unique: l4fI3HlEPWGMA1brAjZ3eA-1 X-Mimecast-MFC-AGG-ID: l4fI3HlEPWGMA1brAjZ3eA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C8D1219560B0; Wed, 8 Jan 2025 23:34:30 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4D5FE19560AE; Wed, 8 Jan 2025 23:34:23 +0000 (UTC) From: Nico Pache To: linux-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, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 11/11] khugepaged: skip collapsing mTHP to smaller orders Date: Wed, 8 Jan 2025 16:31:27 -0700 Message-ID: <20250108233128.14484-12-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Queue-Id: 5004B100002 X-Stat-Signature: cw6chudt7mncjpwbdwkhm5cxr8ztry1r X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736379279-905798 X-HE-Meta: U2FsdGVkX18KrMy6ZQWUUyIp/lbjtI96EB4AOQaCLg1qtPHQJPq4OGFY3qO6wLGmhwXBCeBequapWSP/c3x0r6d13HKGpVyGCQp2XdQg4dNjMb2m10V/rP2gYh1JsP6ftYMCIAgnl40Kp5iFl1OXGA6zOFTHrvUq1nbubO61LF8WQK1B8/nhcEmw5sYK6FtKWdb+dMCQNwav4temhIBoCCx89jpTcdUhJ143Hkr7Jqn102btkz1zG0X7XuSaCOzlzSjxo524YdVQlJgTq/gPHKoC6axNJoaQNSilapZWXzeJBGQDFNUY60r3YIktdF0xjK0M89O0XN5lKXpork2RGlFrGLY1tP+tbjOG4TMhd39cJZvGsSD4o30PiCfO2ixKS6XsTHQxFuFOc1A+Sb79iqeZXm2iuElfKNIhWFCi79dcvyVYZ2jVW80HJK0bGiMUiu4hxRw97xDNnqKE5TaI0DjKJRuh5nMJqGjv2GSzyHLR4ELFUDHX1PIGEbJ1IwVJS33JSEJICKY5WXu+eudF4+Q+B7YDThQekEqYDGQuFZastMFBknlRy2BJUlxkEwPSOmYHV84Cz6v65aMAqAHO5D15D57kcC1NQ7gNiVPVWCmLac1i3A4RdtJ6HHaQDT2BOZDHb9igtLeZG5GIlssiOPhrG0N7+nFX+Gij+P/GMMEjjuKVvMUyD/jLSIRhQBJ7MTW7vznbUiKNlZ1T8BuvFq71A8C34BkYvzV7y23YlVKODa4F/Mfkyx0s8QIJ9Df2URP9+VUhyFa3ni+Ckiq1him52IfrDtCTAEX+Ga3K5JV/enAEDSzWeSm0logjiCssbZctIEa2SEJLVivRi2FGh17ajvi2mUcTCJrFvOYry4lX1UDbBQZoeTV4nwfnf00nhZgXG93wzb3uNW0t712Jli1vc2RDTurj4wQ7euEYg/73pIrR05nf4kK0GKNCLRnDibjXX0IVpEkqJj1t/46 ek81Alko sNzAhPAsMLMw/5yWaQveJ3XUNsbRRo6/FpRmNRbnmcvYBdJmCTAko3YxQt9bwUk8w8MHTnNenVYca8qQe8EUkmdzsBZRAXRmwccQQTDIJtltvnC4xnXyb/qbwvFQXdPHazJad6EprWJjW0C2wLtsFkEvunR/5Itj6pOF1e8eW3cCGqfSUaNWJs3hYcCkQZRfvmJNwXRJgwlzG/5BX8Xx2rku1+a4cR2AIN+3BvPU+xdv0fE1oOEJRvdlnmEYU7S2q1yhoSfdfIntixL5qmiT1isjnF2QxeoG+mNmb2DjtGP7MzD8jr2gZ1TIhvlj4rgVsdW8hjbXetcfoF+WZcsECJ0Ovhnu/e+QyR7ZkGnWoxB+Qn0loIb9NC/I4PW9sCs3Ur5QYZ6dCmK7EP9TH/kJy1BTgtrnJ7qy24QxwjTOFiEM4l3sIGQGrOMZItZP56DM9p1A2DwP0ojj1bf+88QuK+FTPkbFyCEduupvo 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: khugepaged may try to collapse a mTHP to a smaller mTHP, resulting in some pages being unmapped. Skip these cases until we have a way to check if its ok to collapse to a smaller mTHP size (like in the case of a partially mapped folio). This patch is inspired by Dev Jain's work on khugepaged mTHP support [1]. [1] https://lore.kernel.org/lkml/20241216165105.56185-11-dev.jain@arm.com/ Signed-off-by: Nico Pache --- mm/khugepaged.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 61a349eb3cf4..046843a0d632 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -643,6 +643,11 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, folio = page_folio(page); VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); + if (order != HPAGE_PMD_ORDER && folio_order(folio) >= order) { + result = SCAN_PTE_MAPPED_HUGEPAGE; + goto out; + } + /* See khugepaged_scan_pmd(). */ if (folio_likely_mapped_shared(folio)) { ++shared;