From: Rolf Eike Beer <eb@emlix.com>
To: Andrew Morton <akpm@linux-foundation.org>
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 [thread overview]
Message-ID: <8155217.NyiUUSuA9g@devpool047> (raw)
In-Reply-To: <3200642.44csPzL39Z@devpool047>
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 <eb@emlix.com>
---
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 */
--
2.37.2
--
Rolf Eike Beer, emlix GmbH, http://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11
Gothaer Platz 3, 37083 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055
emlix - smart embedded open source
next prev parent reply other threads:[~2022-08-22 13:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 12:59 [PATCH 0/6] Minor improvements for pagewalk code Rolf Eike Beer
2022-08-22 13:00 ` [PATCH 2/6] mm: pagewalk: don't check vma in walk_page_range_novma() Rolf Eike Beer
2022-08-22 13:01 ` [PATCH 3/6] mm: pagewalk: fix documentation of PTE hole handling Rolf Eike Beer
2022-08-22 13:02 ` [PATCH 4/6] mm: pagewalk: add api documentation for walk_page_range_novma() Rolf Eike Beer
2022-08-22 13:03 ` [PATCH 5/6] mm: pagewalk: allow walk_page_range_novma() without mm Rolf Eike Beer
2022-08-22 13:04 ` Rolf Eike Beer [this message]
[not found] ` <2203731.iZASKD2KPV@devpool047>
2022-08-22 20:53 ` [PATCH 1/6] mm: pagewalk: make error checks more obvious Andrew Morton
2022-08-24 11:00 ` [PATCH 7/6] mm: pagewalk: add back missing variable initializations Rolf Eike Beer
2022-08-24 15:08 ` Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8155217.NyiUUSuA9g@devpool047 \
--to=eb@emlix.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox