From patchwork Mon Sep 16 11:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13805278 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 4812CC3ABB2 for ; Mon, 16 Sep 2024 11:08:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C11E16B0082; Mon, 16 Sep 2024 07:08:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDEF26B0092; Mon, 16 Sep 2024 07:08:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A63806B0093; Mon, 16 Sep 2024 07:08:12 -0400 (EDT) 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 878626B0082 for ; Mon, 16 Sep 2024 07:08:12 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4BC6F140341 for ; Mon, 16 Sep 2024 11:08:12 +0000 (UTC) X-FDA: 82570327224.20.45FE79A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id B92F94000E for ; Mon, 16 Sep 2024 11:08:10 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.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=1726484835; 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=im3FXfedJUXneslzBR2T8Ij2ESATVXDs3oyBPAS+3Jg=; b=OZARborWyMuyCQ7qB5kmVLsbRN489AjIpHHBKL2JHEuGfXY7TNLqknxMRZDazsqc79siSQ nRlWYcH8qWqApxKTU00B0aqTNscaGc2FTx7e3jUBScbGd5gtL4O0CLW9V7MBvQbnoTZD6O 89Hf2wBEXMKSP1hGHUBLuRTywpyM9Ts= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726484835; a=rsa-sha256; cv=none; b=ke9Y8VeN/I63KhWdjryAts/DUWz7EkFUZqCa2Ntc7z/CRUKFXwzMu2rq/nh3U8jg43kgy+ NWMOwgBydTySdC/y0HmftH10CVTVBunSF22Oi+LpNADGPJH5BfPT76ScuC+DfyNHfhXfwv e04vabWuRGvtfixBXJqJ8YzZlSNy/+g= 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 6AAE812FC; Mon, 16 Sep 2024 04:08:39 -0700 (PDT) Received: from e116581.blr.arm.com (e116581.arm.com [10.162.42.11]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DF6683F64C; Mon, 16 Sep 2024 04:08:04 -0700 (PDT) From: Dev Jain To: akpm@linux-foundation.org, david@redhat.com, willy@infradead.org Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, baohua@kernel.org, hughd@google.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, baolin.wang@linux.alibaba.com, gshan@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Dev Jain Subject: [PATCH v2 1/2] mm: Make pte_range_none() return number of empty PTEs Date: Mon, 16 Sep 2024 16:37:53 +0530 Message-Id: <20240916110754.1236200-2-dev.jain@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916110754.1236200-1-dev.jain@arm.com> References: <20240916110754.1236200-1-dev.jain@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: B92F94000E X-Stat-Signature: j5ts4819is5ibhgk9gyh1oiuonw5afs9 X-HE-Tag: 1726484890-860980 X-HE-Meta: U2FsdGVkX19yRSw06dX/Nve3IWbXAPv5p0ndnhiMzQKP9UjOqGLuIYLS7SLIytIpM7gMDB4nWaZZpclq5Jh740zHQHU0AgjZhlnCE4YkTfgr2Ot4q9WQ8uh4qanQMH9RVlA4kAvH5aZJPZoMc30DxuCNKRYAa7OIGfvmx8dFFf6xKakM8VLt3hP3rzE9eR+ccARoNZ25Z6D3a5DoDF1eEMF3ce3CiZ5BycvpftzXsOt90GW0R01SWbtwQ+IsUy6T+V0pS+4n+iE6rf/YJTyiPkdLEK5VfRbz8qLKetXGSAwOg1CRvKN07hNBDuEQoNgFds7X5l0XmnGAEmrVvKqpEf5kOxZ2bdQD/vROijBke6WNZwavofPKLh+TAO71tBDZMZcyJmtmCimgRC5g7lvMOY7iuiyXJvu8B88mqibfht0EEien0K28OAKTIW+vhta9zjUdr2Z1yW7kV9pNCUZC8DT6ULlA0hiK1oOoEqEqi8nIR39iEcntg5IkIPUvy+JADy3TuSJHjcyq3NCf3mLswoohGnLX+dnCJN1jLcDCuq8GQYx9OSa7Xm1Qiq0tQgMh2MNcFwuxze8fxygnkoh0XcKFbhMx9yryO1TDuPUWpO0+xHBEK1H+wT5YTH4w62GMaoPQ4Tyt2lsiep1JG9XLqsDfS6VrvaaRb4qI+CRDveSmsFYs9zrMsDPTC0nMU52zgLi/ExHXbUo0NpW01RhRiI9bK/Ur2h9wFKNp6Jk+kXzzbaiQmwrw15OXqFTUaRWh5XwzsbCPZ/8Nac4Q8C0L0kO2mcbBchswBdDoy2ciOr67kTyjfIwCMb4Zvm62M85I+EJDail7PjIBcVSTgb8OHc1zbT3q3x+h1v3uQLPTSqRTLp+pfc+Rz7rzk23Ttjxojlw4dK2nZa++jD7nHN2yAie63lwMxfMmmWYopG7H34psnxcCu3wS4Qs62gIiDDPLhY1vxHO+wiCPvgqYvmw Wl7UqHZn cSee1mxze47bLuQhTBoIjTgbqzKYNTRHmTF+a7Pf8DJlI/oc46yYRmlD9e6+k2dMZE4Zh9LklTTajhqtOGQx+Ec/JruHSfK2ucQHVnlaHJ9GZnj1iiBqTVbgG2R10EEcjv/djn+NA1sWRebw6DvtO2SRkDTlhOF0jBu56C69coYfVqm3WYRh1KTe7iZWTxiBXt3m2ow2BJpCuLmw= 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: In preparation for the second patch, make pte_range_none() return the number of contiguous empty PTEs. Signed-off-by: Dev Jain Reviewed-by: Baolin Wang --- mm/memory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 6469ac99f2f7..8bb1236de93c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4617,16 +4617,16 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) return ret; } -static bool pte_range_none(pte_t *pte, int nr_pages) +static int pte_range_none(pte_t *pte, int nr_pages) { int i; for (i = 0; i < nr_pages; i++) { if (!pte_none(ptep_get_lockless(pte + i))) - return false; + return i; } - return true; + return nr_pages; } static struct folio *alloc_anon_folio(struct vm_fault *vmf) @@ -4671,7 +4671,7 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf) order = highest_order(orders); while (orders) { addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << order); - if (pte_range_none(pte + pte_index(addr), 1 << order)) + if (pte_range_none(pte + pte_index(addr), 1 << order) == 1 << order) break; order = next_order(&orders, order); } @@ -4787,7 +4787,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) if (nr_pages == 1 && vmf_pte_changed(vmf)) { update_mmu_tlb(vma, addr, vmf->pte); goto release; - } else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) { + } else if (nr_pages > 1 && pte_range_none(vmf->pte, nr_pages) != nr_pages) { update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages); goto release; } @@ -5121,7 +5121,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf) update_mmu_tlb(vma, addr, vmf->pte); ret = VM_FAULT_NOPAGE; goto unlock; - } else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) { + } else if (nr_pages > 1 && pte_range_none(vmf->pte, nr_pages) != nr_pages) { update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages); ret = VM_FAULT_NOPAGE; goto unlock;