From patchwork Mon Dec 16 16:50:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13910080 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 9CBEDE77180 for ; Mon, 16 Dec 2024 16:52:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 311966B00C5; Mon, 16 Dec 2024 11:52:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C2356B00C6; Mon, 16 Dec 2024 11:52:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 162896B00C7; Mon, 16 Dec 2024 11:52:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E961C6B00C5 for ; Mon, 16 Dec 2024 11:52:44 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7071D120D00 for ; Mon, 16 Dec 2024 16:52:44 +0000 (UTC) X-FDA: 82901415366.26.70A02FE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 71D298001C for ; Mon, 16 Dec 2024 16:51:46 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734367948; 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; bh=syZ6BkV2LgDcRliK9yoqySwy+/idtulFsqPrRs6j6ho=; b=eRRE5Hpjxp44BfbfSpEEm5Z/TvFMoH2LrHVwXL09zq1tZCYfeKJsxznQY0FENVk8SlzMMT TUJYRd/l8hnjjdMnFQH/HWBENICEFRg8TBcOqtokHKN1+U8uORECoc+r4e4O5N4fCl7wGb 3PixSPXul6MmUde3r0jGG7mf/dEQxlQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734367948; a=rsa-sha256; cv=none; b=U7rUfCa8GK+Tx4LOesMmQOgWKKu+AcCAHjdxQ8B/KKI/FpRkqxTZVVNEhynJpitg2ribdK axt4WGz+DVIIdpy7EIGJyxWPEFD2p31cxp2mPfdS++p8yl8tABm8KxcyYfzgu9BgLfEby0 G0NLpcNUdlwSeKGhC1LlDyK8ARu75a8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2894116F8; Mon, 16 Dec 2024 08:53:10 -0800 (PST) Received: from K4MQJ0H1H2.arm.com (unknown [10.163.78.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 364F13F528; Mon, 16 Dec 2024 08:52:30 -0800 (PST) From: Dev Jain To: akpm@linux-foundation.org, david@redhat.com, willy@infradead.org, kirill.shutemov@linux.intel.com Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dev Jain Subject: [RFC PATCH 06/12] khugepaged: Generalize __collapse_huge_page_copy_failed() Date: Mon, 16 Dec 2024 22:20:59 +0530 Message-Id: <20241216165105.56185-7-dev.jain@arm.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241216165105.56185-1-dev.jain@arm.com> References: <20241216165105.56185-1-dev.jain@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 71D298001C X-Stat-Signature: 43k3ofcjkcneq7u56jhuygcojhzsbg65 X-Rspam-User: X-HE-Tag: 1734367906-566176 X-HE-Meta: U2FsdGVkX1+1p6CzUMyMiwfMCdiyj6dmyefaxfip/c1SrGzaOOPZctJGm9CnUjTM4VEsZq9sumy0CTBI+2cPnOt2ez6kfGqM+kBlR7ajmdT9UBSzt56rulu0vZ0Wt/YdY32V7Q3KNBJunr/YLoWJ0b3avirT0FdUpzvi4JO8WYGIgQkA8yAfDdunVfBpHezI9CbvINmHQz6dkwtVEl9gki7dqYfcAG9BkGmvdyzEHvMFttp9K9Wor2fCSWXVGarsy4z9f3owx+fvNkcDpx9rUSo49f9IwCF5Bf+hyAhulhpppPMKNhwaHolR1a73HjoFDfhEiwaJ6hUyR2Saj10OrZo4YOHPqjEgwN1YRldwblzQZZbuUFFpFqVB91V7Cu7QUr6rr14xxmKNHDvtzp2w6mj3BrYNrfYk9yvoJdl6qLXTfv2YtrqXWSIG3iUUSUhlfw2+YSYcvesZ6yLGeCLkIE8kJT6T1qgCmGpIoEd4x0Fjyq+7R1FV7tYQO6MeBMAwEUJih39We+REnPtFuTJJENp1uW1eW4cGFZNkM5N05fPsnKSf9k0YohtVvsNQ5yg46A5gogWHGouptNdpvHX6gQ4WcVurZH1waxL1ezr4JmXyUCPbP5/VVujqkUvGoSMjHr7vQ9hAyD7gI8qU3CzH257mEC58l23qSmEIYfnWqPtHHYc7+uy1Q1izS8HJQZR2d/RzLt2oIKMLiwCtHSk88pSAyTsklrz3ktLqgN0PG2g75xB/g0K20IV3rPsHL9A5e8B6syFXBX1IMXSS0kdnDxl4NxaK8ffftbCt8aWs2/cb/v4ygc42aApWAF4wHrI4a0MQGq1UnVYWge934l94lTS35auYUKcpLd+/BtIisplm88l1Z7QDH7iCRoymNWdcrY11pPbYMso/Onipfr4nGO3pH33IJfSS92V3bUyCIr0ZqTSWO9Pp1eD+jzUqdqymdp51gZ6wu/nv1e5PI0l FmFeBT2V yWpw0vsAXqlcSrB9EtQ6DQSjJAGbCuIgeFLE8U3wsmeRw+prapApvYYHjgfqx/Gx8j1rckekkI8KIoHYoGEXnhqeDo2eB69B5lMRsSzVBkspYF6VXMmGdfUWu1NtDidfZE7aEtbXFZrLRNwdYUITMkAFS0VLcB4SYsr/7+6trJYDx+oXYqRzXKJqZtvhPWgGjBgitspP1XqRMQn+JsyQ70CfsGpUjJIfuA47ATFU6ivXjyMzPliwQJUeznRxv64OVwWIIzm8qU69re+xcGGp1ZUQHXvAmHZLtP10QCDVyxWL29XLLN023kIB6Rq8nmUzEuJk2j95YQcc7V5zJ5P7HLeqey524SDsJkti8dWS/JPsgQqzknXQGnYxzmzUVwhu7Dn8os2MfwMh2KtA= 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: Upon failure, we repopulate the PMD in case of PMD-THP collapse. Hence, make this logic specific for PMD case. Signed-off-by: Dev Jain --- mm/khugepaged.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index de044b1f83d4..886c76816963 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -766,7 +766,7 @@ 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, int order) { spinlock_t *pmd_ptl; @@ -776,14 +776,16 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, * pages. Since pages are still isolated and locked here, * acquiring anon_vma_lock_write is unnecessary. */ - pmd_ptl = pmd_lock(vma->vm_mm, pmd); - pmd_populate(vma->vm_mm, pmd, pmd_pgtable(orig_pmd)); - spin_unlock(pmd_ptl); + if (order == HPAGE_PMD_ORDER) { + pmd_ptl = pmd_lock(vma->vm_mm, pmd); + pmd_populate(vma->vm_mm, pmd, pmd_pgtable(orig_pmd)); + spin_unlock(pmd_ptl); + } /* * 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 + (1UL << order), compound_pagelist); } /* @@ -834,7 +836,7 @@ static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, compound_pagelist); else __collapse_huge_page_copy_failed(pte, pmd, orig_pmd, vma, - compound_pagelist); + compound_pagelist, order); return result; }