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: