From patchwork Mon Aug 22 13:04:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 12950638 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 CFB56C28D13 for ; Mon, 22 Aug 2022 13:33:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8F46B0075; Mon, 22 Aug 2022 09:33:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 089146B0078; Mon, 22 Aug 2022 09:33:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E94438D0001; Mon, 22 Aug 2022 09:33:48 -0400 (EDT) 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 D993C6B0075 for ; Mon, 22 Aug 2022 09:33:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B47821412C8 for ; Mon, 22 Aug 2022 13:33:48 +0000 (UTC) X-FDA: 79827321336.30.198D9D1 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by imf04.hostedemail.com (Postfix) with ESMTP id 840B041113 for ; Mon, 22 Aug 2022 13:24:04 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 3BB495FB1D; Mon, 22 Aug 2022 15:04:37 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] mm: pagewalk: move variables to more local scope, tweak loops Date: Mon, 22 Aug 2022 15:04:12 +0200 Message-ID: <8155217.NyiUUSuA9g@devpool047> Organization: emlix GmbH In-Reply-To: <3200642.44csPzL39Z@devpool047> References: <3200642.44csPzL39Z@devpool047> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661174648; a=rsa-sha256; cv=none; b=Hb8CSWvNpKBfOfG1PvbIh9xlU1zVmgirRhDxe+yCWMcr0X7haag9sqgP/xWDeXOAMGGfMT 7cKwZusgQPTJBqHHE10VmrvOFfcITBNTd3BhR6ZCkpuoizI6yybsc50vYgleLyaOMwnMD7 I4ht3AHTaDC8UOCnAFdYtsIrYX9V0SA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661174648; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L1UehnZMiqaXktQM1WRXMn/xqd1kme/gnP9JtMR89OE=; b=1zOe2jik+5NN3SPo6X0hfvSAzJzLOEMAWS8J4T1r2MMZ/71m0RcyG0SZpziAlKWSOUrpJ8 yC8xaOwUtDHOuxOv/cgVtE54RcX+QNwkv+6Gozgsg56OBWjvLtOwmEeyFcZJNyaUngWkyM Up5S4klYw1V7vi02xL+WccRDOG3+pNg= Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of eb@emlix.com designates 136.243.223.33 as permitted sender) smtp.mailfrom=eb@emlix.com; dmarc=none X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 840B041113 X-Stat-Signature: b55ac88yzqnmqcgyxs97whugz5h7to4b X-Rspam-User: X-HE-Tag: 1661174644-921376 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: Move some variables to more local scopes to make it obvious that they don't carry state. Put the end additions into the for loop instructions to make them easier to read. Signed-off-by: Rolf Eike Beer --- mm/pagewalk.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index f816f86588be..d8be8a30b272 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -25,14 +25,12 @@ static int walk_pte_range_inner(pte_t *pte, unsigned long addr, { const struct mm_walk_ops *ops = walk->ops; - for (;;) { + for (;; addr += PAGE_SIZE, pte++) { int err = ops->pte_entry(pte, addr, addr + PAGE_SIZE, walk); if (err) return err; if (addr >= end - PAGE_SIZE) break; - addr += PAGE_SIZE; - pte++; } return 0; } @@ -42,13 +40,14 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, { pte_t *pte; int err; - spinlock_t *ptl; if (walk->no_vma) { pte = pte_offset_map(pmd, addr); err = walk_pte_range_inner(pte, addr, end, walk); pte_unmap(pte); } else { + spinlock_t *ptl; + pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); err = walk_pte_range_inner(pte, addr, end, walk); pte_unmap_unlock(pte, ptl); @@ -71,7 +70,7 @@ static int walk_hugepd_range(hugepd_t *phpd, unsigned long addr, if (addr & (page_size - 1)) return 0; - for (;;) { + for (;; addr += page_size) { pte_t *pte; int err; @@ -84,7 +83,6 @@ static int walk_hugepd_range(hugepd_t *phpd, unsigned long addr, return err; if (addr >= end - page_size) break; - addr += page_size; } return 0; } @@ -307,14 +305,13 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, unsigned long next; unsigned long hmask = huge_page_mask(h); unsigned long sz = huge_page_size(h); - pte_t *pte; const struct mm_walk_ops *ops = walk->ops; - do { + for (; addr < end; addr = next) { int err; + pte_t *pte = huge_pte_offset(walk->mm, addr & hmask, sz); next = hugetlb_entry_end(h, addr, end); - pte = huge_pte_offset(walk->mm, addr & hmask, sz); if (pte) err = ops->hugetlb_entry(pte, hmask, addr, next, walk); @@ -323,7 +320,7 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, if (err) return err; - } while (addr = next, addr != end); + } return 0; } @@ -461,14 +458,13 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, do { int err; + walk.vma = vma; if (!vma) { /* after the last vma */ - walk.vma = NULL; next = end; } else if (start < vma->vm_start) { /* outside vma */ walk.vma = NULL; next = min(end, vma->vm_start); } else { /* inside vma */ - walk.vma = vma; next = min(end, vma->vm_end); vma = vma->vm_next; @@ -595,11 +591,11 @@ int walk_page_mapping(struct address_space *mapping, pgoff_t first_index, }; struct vm_area_struct *vma; pgoff_t vba, vea, cba, cea; - unsigned long start_addr, end_addr; lockdep_assert_held(&mapping->i_mmap_rwsem); vma_interval_tree_foreach(vma, &mapping->i_mmap, first_index, first_index + nr - 1) { + unsigned long start_addr, end_addr; int err; /* Clip to the vma */