From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 12/15] ptwalk: clear_page_range
Date: Wed, 9 Mar 2005 22:14:07 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.61.0503092213310.6070@goblin.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0503092201070.6070@goblin.wat.veritas.com>
Convert clear_page_range pagetable walkers to loops using p?d_addr_end.
These are exceptional in that some out-of-tree memory layouts might pass
end 0, so the macros need to handle that (though previous code did not).
The naming here was out of step: now we usually pass pmd_t *pmd down to
action_on_pte_range, not action_on_pmd_range, etc: made like the others.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
mm/memory.c | 98 ++++++++++++++++++++++++++++--------------------------------
1 files changed, 46 insertions(+), 52 deletions(-)
--- ptwalk11/mm/memory.c 2005-03-09 01:38:54.000000000 +0000
+++ ptwalk12/mm/memory.c 2005-03-09 01:39:06.000000000 +0000
@@ -110,15 +110,14 @@ void pmd_clear_bad(pmd_t *pmd)
* Note: this doesn't free the actual pages themselves. That
* has been handled earlier when unmapping all the memory regions.
*/
-static inline void clear_pmd_range(struct mmu_gather *tlb, pmd_t *pmd, unsigned long start, unsigned long end)
+static inline void clear_pte_range(struct mmu_gather *tlb, pmd_t *pmd,
+ unsigned long addr, unsigned long end)
{
- struct page *page;
-
if (pmd_none_or_clear_bad(pmd))
return;
- if (!((start | end) & ~PMD_MASK)) {
- /* Only clear full, aligned ranges */
- page = pmd_page(*pmd);
+ if (!((addr | end) & ~PMD_MASK)) {
+ /* Only free fully aligned ranges */
+ struct page *page = pmd_page(*pmd);
pmd_clear(pmd);
dec_page_state(nr_page_table_pages);
tlb->mm->nr_ptes--;
@@ -126,77 +125,72 @@ static inline void clear_pmd_range(struc
}
}
-static inline void clear_pud_range(struct mmu_gather *tlb, pud_t *pud, unsigned long start, unsigned long end)
+static inline void clear_pmd_range(struct mmu_gather *tlb, pud_t *pud,
+ unsigned long addr, unsigned long end)
{
- unsigned long addr = start, next;
- pmd_t *pmd, *__pmd;
+ pmd_t *pmd;
+ unsigned long next;
+ pmd_t *empty_pmd = NULL;
if (pud_none_or_clear_bad(pud))
return;
- pmd = __pmd = pmd_offset(pud, start);
+ pmd = pmd_offset(pud, addr);
+
+ /* Only free fully aligned ranges */
+ if (!((addr | end) & ~PUD_MASK))
+ empty_pmd = pmd;
do {
- next = (addr + PMD_SIZE) & PMD_MASK;
- if (next > end || next <= addr)
- next = end;
-
- clear_pmd_range(tlb, pmd, addr, next);
- pmd++;
- addr = next;
- } while (addr && (addr < end));
+ next = pmd_addr_end(addr, end);
+ clear_pte_range(tlb, pmd, addr, next);
+ } while (pmd++, addr = next, addr != end);
- if (!((start | end) & ~PUD_MASK)) {
- /* Only clear full, aligned ranges */
+ if (empty_pmd) {
pud_clear(pud);
- pmd_free_tlb(tlb, __pmd);
+ pmd_free_tlb(tlb, empty_pmd);
}
}
-
-static inline void clear_pgd_range(struct mmu_gather *tlb, pgd_t *pgd, unsigned long start, unsigned long end)
+static inline void clear_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
+ unsigned long addr, unsigned long end)
{
- unsigned long addr = start, next;
- pud_t *pud, *__pud;
+ pud_t *pud;
+ unsigned long next;
+ pud_t *empty_pud = NULL;
if (pgd_none_or_clear_bad(pgd))
return;
- pud = __pud = pud_offset(pgd, start);
+ pud = pud_offset(pgd, addr);
+
+ /* Only free fully aligned ranges */
+ if (!((addr | end) & ~PGDIR_MASK))
+ empty_pud = pud;
do {
- next = (addr + PUD_SIZE) & PUD_MASK;
- if (next > end || next <= addr)
- next = end;
-
- clear_pud_range(tlb, pud, addr, next);
- pud++;
- addr = next;
- } while (addr && (addr < end));
+ next = pud_addr_end(addr, end);
+ clear_pmd_range(tlb, pud, addr, next);
+ } while (pud++, addr = next, addr != end);
- if (!((start | end) & ~PGDIR_MASK)) {
- /* Only clear full, aligned ranges */
+ if (empty_pud) {
pgd_clear(pgd);
- pud_free_tlb(tlb, __pud);
+ pud_free_tlb(tlb, empty_pud);
}
}
/*
* This function clears user-level page tables of a process.
- *
+ * Unlike other pagetable walks, some memory layouts might give end 0.
* Must be called with pagetable lock held.
*/
-void clear_page_range(struct mmu_gather *tlb, unsigned long start, unsigned long end)
+void clear_page_range(struct mmu_gather *tlb,
+ unsigned long addr, unsigned long end)
{
- unsigned long addr = start, next;
- pgd_t * pgd = pgd_offset(tlb->mm, start);
- unsigned long i;
-
- for (i = pgd_index(start); i <= pgd_index(end-1); i++) {
- next = (addr + PGDIR_SIZE) & PGDIR_MASK;
- if (next > end || next <= addr)
- next = end;
-
- clear_pgd_range(tlb, pgd, addr, next);
- pgd++;
- addr = next;
- }
+ pgd_t *pgd;
+ unsigned long next;
+
+ pgd = pgd_offset(tlb->mm, addr);
+ do {
+ next = pgd_addr_end(addr, end);
+ clear_pud_range(tlb, pgd, addr, next);
+ } while (pgd++, addr = next, addr != end);
}
pte_t fastcall * pte_alloc_map(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
next prev parent reply other threads:[~2005-03-09 22:57 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-09 22:05 [PATCH 0/15] ptwalk: pagetable walker cleanup Hugh Dickins
2005-03-09 22:06 ` [PATCH 1/15] ptwalk: p?d_none_or_clear_bad Hugh Dickins
2005-03-09 22:07 ` [PATCH 2/15] ptwalk: change_protection Hugh Dickins
2005-03-09 22:08 ` [PATCH 3/15] ptwalk: sync_page_range Hugh Dickins
2005-03-09 22:08 ` [PATCH 4/15] ptwalk: unuse_mm Hugh Dickins
2005-03-09 22:09 ` [PATCH 5/15] ptwalk: map and unmap_vm_area Hugh Dickins
2005-03-09 22:10 ` [PATCH 6/15] ptwalk: ioremap_page_range Hugh Dickins
2005-03-09 22:10 ` [PATCH 7/15] ptwalk: remap_pfn_range Hugh Dickins
2005-03-09 22:11 ` [PATCH 8/15] ptwalk: zeromap_page_range Hugh Dickins
2005-03-09 22:12 ` [PATCH 9/15] ptwalk: unmap_page_range Hugh Dickins
2005-03-09 22:12 ` [PATCH 10/15] ptwalk: copy_page_range Hugh Dickins
2005-03-09 22:13 ` [PATCH 11/15] ptwalk: copy_pte_range hang Hugh Dickins
2005-03-09 23:25 ` Nick Piggin
2005-03-09 22:14 ` Hugh Dickins [this message]
2005-03-09 22:14 ` [PATCH 13/15] ptwalk: move p?d_none_or_clear_bad Hugh Dickins
2005-03-09 22:15 ` [PATCH 14/15] ptwalk: inline pmd_range and pud_range Hugh Dickins
2005-03-09 22:16 ` [PATCH 15/15] ptwalk: pud and pmd folded Hugh Dickins
2005-03-10 0:39 ` [PATCH 0/15] ptwalk: pagetable walker cleanup Benjamin Herrenschmidt
2005-03-10 1:02 ` David S. Miller
2005-03-10 1:08 ` Benjamin Herrenschmidt
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=Pine.LNX.4.61.0503092213310.6070@goblin.wat.veritas.com \
--to=hugh@veritas.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®