From patchwork Mon May 6 15:51:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bang Li X-Patchwork-Id: 13655674 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 0BD15C25B4F for ; Mon, 6 May 2024 15:52:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DC916B009A; Mon, 6 May 2024 11:52:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 264D06B009B; Mon, 6 May 2024 11:52:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08F026B009C; Mon, 6 May 2024 11:52:19 -0400 (EDT) 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 DAAFD6B009A for ; Mon, 6 May 2024 11:52:18 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5F8C6A164B for ; Mon, 6 May 2024 15:52:18 +0000 (UTC) X-FDA: 82088412756.29.E7D9CBA Received: from out0-209.mail.aliyun.com (out0-209.mail.aliyun.com [140.205.0.209]) by imf29.hostedemail.com (Postfix) with ESMTP id 59ABC12000C for ; Mon, 6 May 2024 15:52:15 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=antgroup.com header.s=default header.b=MJ9JpeGQ; spf=pass (imf29.hostedemail.com: domain of libang.li@antgroup.com designates 140.205.0.209 as permitted sender) smtp.mailfrom=libang.li@antgroup.com; dmarc=pass (policy=quarantine) header.from=antgroup.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715010736; 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=ymFvshx88TI9/EMP30aaqBdjrnITBbXYS6oOftHtOBQ=; b=a4IqdN6SKg9pJu7iXkPmmptbjeOJTEnmhXcHnr0X9AihZD9uE5yaJprkcS/npODxxgcFM5 yOJMdMqQTeJPsWCzhwR5sT3/tHvZ+6n/N+gkwSD5Vl0Ofo6NGJwg7098lIYHVNzRyCJwEA eqbBUlgwOglYpFFG+FLLQKsPy9RvhMo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715010736; a=rsa-sha256; cv=none; b=BavUb6u5Y0UiLVWrthRGwjwZ72+jPKlQVTU781gCLq+OS1bT5YBsvVBfSTHIbSJ9yuPiQH raCQVTWC9d4niOq/X5wAjj1kSnNg0A4ZXLWxDcaji7/ld3jzWWUPdYg82nncXSGWUCfvuI uyBLpWkDdZWDCk+zHkRjJUla1ieqYJA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=antgroup.com header.s=default header.b=MJ9JpeGQ; spf=pass (imf29.hostedemail.com: domain of libang.li@antgroup.com designates 140.205.0.209 as permitted sender) smtp.mailfrom=libang.li@antgroup.com; dmarc=pass (policy=quarantine) header.from=antgroup.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1715010732; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ymFvshx88TI9/EMP30aaqBdjrnITBbXYS6oOftHtOBQ=; b=MJ9JpeGQL1WuHbhx6kehn4UM7BwvjbskZc3LoYDnUohCrbpgNkDvzrm3P9Po5u+agT3bbPe4nYjQ3hhPSVy/pSFb5CdRnnH+WsL84AnapTR3mc2AqfGBf2WYsil7wXVEiR8yJDiR7xKrJ1EwYLnnWLDdE5RlaGXGMsamYUDE7lg= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047198;MF=libang.li@antgroup.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---.XTf7qIH_1715010729; Received: from localhost(mailfrom:libang.li@antgroup.com fp:SMTPD_---.XTf7qIH_1715010729) by smtp.aliyun-inc.com; Mon, 06 May 2024 23:52:10 +0800 From: "Bang Li" To: akpm@linux-foundation.org, chenhuacai@kernel.org, tsbogend@alpha.franken.de, paul.walmsley@sifive.com, palmer@dabbelt.com, chris@zankel.net, jcmvbkbc@gmail.com Cc: , , , , , , , , "Bang Li" Subject: [PATCH v2 5/5] mm: Add update_mmu_tlb_range() Date: Mon, 06 May 2024 23:51:20 +0800 Message-Id: <20240506155120.83105-6-libang.li@antgroup.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240506155120.83105-1-libang.li@antgroup.com> References: <20240506155120.83105-1-libang.li@antgroup.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: py38hjdksx3scec3xjbkfae5p9454ein X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 59ABC12000C X-HE-Tag: 1715010735-39860 X-HE-Meta: U2FsdGVkX18srtGNdn4SL/N6mUPq8nwtoN/5OY+ZC9SsWqumg0srI6KLxF8rHEGo/61UuG6i4z7iA3rZ1wwMl5eLVujMQeG2j/fnZbiWb9VsIuZavxfksB/uxFUCjeUOzGAxDhcvF1tByL1aaioe/pQ+UzHSKAvpV0W2R3nZWffq3VImRNwR5ShTUh5cSUgjtbFCJwmfQ5YO4f9h44T4wa0Q2XTOhxw+2lKD/YAPu65za+oGWWeT25isAV/gr9Vr0R8iU66NW/8dLA4oyvfiUTT2X7Zuly8xXGV4MgNptPzqMlF8sv8RCxiI7CDJFDJEO1EUfhd8ZNxPQwdgoyOMj7LUggnX9vqCFxWIMLN2K2BNlEYd0lsVF+YJZ1V+a4nOF1IJS9Ge+/yH9FDiXTmHLYcE4gTpTJgNwmAECrhUhj7TNA6IKUWXiXI0gZeLkbyqqqwuHSG8mIhnOgHUdJEiwNieoYDZoU+JUZSmE7crrYjdMybNYfb4dHTJ5lae89j+0E4ex3sGaK0CVi2plkfLaAeZvOmoWUYki0/MVJBZfUNCTWXqZz4+Sr5LefUZSOljmve4yxlaTjk9fFNm02w/Pa+3zZvNTRnbDggjL7VDv+DTaukUNnaSWtfakTcNVybAioElnZ2KjgGJVEXect8LcPFf3YVBCMYgJfNM1zisLtk4F2QR+0ux/ooKZvw6Jq/yzsnduI0LdzArNFWdPsRXMwbGG8cmlqrijj74xmwixqIN2MbKWlnF9UyEDKPhuhF4h2lswnZ/8U4Q1c75Dbb8rw6qpYFNs3K5LXTtM3En36UL/DJs2SO5h8lS9/q7yTJrrx2NoNAbpllmVV1E6Pa/qNI4PCYJX0uqMmiUtcsaUmEHuirs35TChmUoc1pj3HtOarcRGz/MEI7h3wgQMeERdVSooLkTcIlYGxKcck17CcsZodhgWyonydtNH8Dn9ywt1wyBHosJmNnPHvBqT3S zO39K16N 9V54yvURld4AVPr+LvQUMy1iFzrEQLYjgNq/gAiU46eNQzHez5e6S5zbR+ipv9w5P9MUzwpmfuhRmVpeuDjNfYZEnBjGfAXjARuD5FaA997YOsA9Ihbi7dlaTaMrnDQMZcrEMsnrqSVgRzHMTZikACXfyDBJRoqGBiKXmAndZZqtxZa8dYtN6jh8HJOVWxrVL/cUHEN7OcVR0tfEJWLIblI8fqzPwHXqSyzXtQjBBrrwMJjctKla6fX82wnbF4GgJG6ywzuUNezt7InsR8GVX8nd+6Rd0JTPF7xJ+rroz8Bi0RBRaQ/BuFYbAOe4YQBBcD4MYFUWVfRfel+Q= 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: After the commit 19eaf44954df ("mm: thp: support allocation of anonymous multi-size THP"), it may need to batch update tlb of an address range through the update_mmu_tlb function. We can simplify this operation by adding the update_mmu_tlb_range function, which may also reduce the execution of some unnecessary code in some architectures. Signed-off-by: Bang Li --- include/linux/pgtable.h | 8 ++++++++ mm/memory.c | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 18019f037bae..869bfe6054f1 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -737,6 +737,14 @@ static inline void update_mmu_tlb(struct vm_area_struct *vma, #define __HAVE_ARCH_UPDATE_MMU_TLB #endif +#ifndef __HAVE_ARCH_UPDATE_MMU_TLB_RANGE +static inline void update_mmu_tlb_range(struct vm_area_struct *vma, + unsigned long address, pte_t *ptep, unsigned int nr) +{ +} +#define __HAVE_ARCH_UPDATE_MMU_TLB_RANGE +#endif + /* * Some architectures may be able to avoid expensive synchronization * primitives when modifications are made to PTE's which are already diff --git a/mm/memory.c b/mm/memory.c index eea6e4984eae..2d53e29cf76e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4421,7 +4421,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) vm_fault_t ret = 0; int nr_pages = 1; pte_t entry; - int i; /* File mapping without ->vm_ops ? */ if (vma->vm_flags & VM_SHARED) @@ -4491,8 +4490,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) update_mmu_tlb(vma, addr, vmf->pte); goto release; } else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) { - for (i = 0; i < nr_pages; i++) - update_mmu_tlb(vma, addr + PAGE_SIZE * i, vmf->pte + i); + update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages); goto release; }