From d85fbe8a91c49bb1158f80a7931cecc60d21679f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 1 Jun 2012 04:26:50 +0000 Subject: [PATCH] Eliminate code duplication in free_pv_entry() and pmap_remove_pages() by introducing free_pv_chunk(). --- sys/amd64/amd64/pmap.c | 19 ++++++++++--------- sys/i386/i386/pmap.c | 20 ++++++++++---------- sys/i386/xen/pmap.c | 20 ++++++++++---------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index 657b04a9c4ce..79368976b066 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -218,6 +218,7 @@ caddr_t CADDR1 = 0; */ static caddr_t crashdumpmap; +static void free_pv_chunk(struct pv_chunk *pc); static void free_pv_entry(pmap_t pmap, pv_entry_t pv); static pv_entry_t get_pv_entry(pmap_t pmap, boolean_t try); static void pmap_pv_demote_pde(pmap_t pmap, vm_offset_t va, vm_paddr_t pa); @@ -2174,7 +2175,6 @@ pmap_pv_reclaim(pmap_t locked_pmap) static void free_pv_entry(pmap_t pmap, pv_entry_t pv) { - vm_page_t m; struct pv_chunk *pc; int idx, field, bit; @@ -2198,6 +2198,14 @@ free_pv_entry(pmap_t pmap, pv_entry_t pv) return; } TAILQ_REMOVE(&pmap->pm_pvchunk, pc, pc_list); + free_pv_chunk(pc); +} + +static void +free_pv_chunk(struct pv_chunk *pc) +{ + vm_page_t m; + TAILQ_REMOVE(&pv_chunks, pc, pc_lru); PV_STAT(pv_entry_spare -= _NPCPV); PV_STAT(pc_chunk_count--); @@ -4211,15 +4219,8 @@ pmap_remove_pages(pmap_t pmap) } } if (allfree) { - PV_STAT(pv_entry_spare -= _NPCPV); - PV_STAT(pc_chunk_count--); - PV_STAT(pc_chunk_frees++); TAILQ_REMOVE(&pmap->pm_pvchunk, pc, pc_list); - TAILQ_REMOVE(&pv_chunks, pc, pc_lru); - m = PHYS_TO_VM_PAGE(DMAP_TO_PHYS((vm_offset_t)pc)); - dump_drop_page(m->phys_addr); - vm_page_unwire(m, 0); - vm_page_free(m); + free_pv_chunk(pc); } } pmap_invalidate_all(pmap); diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c index a94564d25765..a81b492c1a3d 100644 --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -286,6 +286,7 @@ SYSCTL_INT(_debug, OID_AUTO, PMAP1unchanged, CTLFLAG_RD, "Number of times pmap_pte_quick didn't change PMAP1"); static struct mtx PMAP2mutex; +static void free_pv_chunk(struct pv_chunk *pc); static void free_pv_entry(pmap_t pmap, pv_entry_t pv); static pv_entry_t get_pv_entry(pmap_t pmap, boolean_t try); static void pmap_pv_demote_pde(pmap_t pmap, vm_offset_t va, vm_paddr_t pa); @@ -2343,7 +2344,6 @@ pmap_pv_reclaim(pmap_t locked_pmap) static void free_pv_entry(pmap_t pmap, pv_entry_t pv) { - vm_page_t m; struct pv_chunk *pc; int idx, field, bit; @@ -2364,6 +2364,14 @@ free_pv_entry(pmap_t pmap, pv_entry_t pv) TAILQ_INSERT_HEAD(&pmap->pm_pvchunk, pc, pc_list); return; } + free_pv_chunk(pc); +} + +static void +free_pv_chunk(struct pv_chunk *pc) +{ + vm_page_t m; + TAILQ_REMOVE(&pv_chunks, pc, pc_lru); PV_STAT(pv_entry_spare -= _NPCPV); PV_STAT(pc_chunk_count--); @@ -4445,16 +4453,8 @@ pmap_remove_pages(pmap_t pmap) } } if (allfree) { - PV_STAT(pv_entry_spare -= _NPCPV); - PV_STAT(pc_chunk_count--); - PV_STAT(pc_chunk_frees++); TAILQ_REMOVE(&pmap->pm_pvchunk, pc, pc_list); - TAILQ_REMOVE(&pv_chunks, pc, pc_lru); - m = PHYS_TO_VM_PAGE(pmap_kextract((vm_offset_t)pc)); - pmap_qremove((vm_offset_t)pc, 1); - vm_page_unwire(m, 0); - vm_page_free(m); - pmap_ptelist_free(&pv_vafree, (vm_offset_t)pc); + free_pv_chunk(pc); } } sched_unpin(); diff --git a/sys/i386/xen/pmap.c b/sys/i386/xen/pmap.c index 5f3985ab49a8..b5a0f2d3583c 100644 --- a/sys/i386/xen/pmap.c +++ b/sys/i386/xen/pmap.c @@ -277,6 +277,7 @@ SYSCTL_INT(_debug, OID_AUTO, PMAP1unchanged, CTLFLAG_RD, "Number of times pmap_pte_quick didn't change PMAP1"); static struct mtx PMAP2mutex; +static void free_pv_chunk(struct pv_chunk *pc); static void free_pv_entry(pmap_t pmap, pv_entry_t pv); static pv_entry_t get_pv_entry(pmap_t pmap, boolean_t try); static void pmap_pvh_free(struct md_page *pvh, pmap_t pmap, vm_offset_t va); @@ -2094,7 +2095,6 @@ pmap_pv_reclaim(pmap_t locked_pmap) static void free_pv_entry(pmap_t pmap, pv_entry_t pv) { - vm_page_t m; struct pv_chunk *pc; int idx, field, bit; @@ -2115,6 +2115,14 @@ free_pv_entry(pmap_t pmap, pv_entry_t pv) TAILQ_INSERT_HEAD(&pmap->pm_pvchunk, pc, pc_list); return; } + free_pv_chunk(pc); +} + +static void +free_pv_chunk(struct pv_chunk *pc) +{ + vm_page_t m; + TAILQ_REMOVE(&pv_chunks, pc, pc_lru); PV_STAT(pv_entry_spare -= _NPCPV); PV_STAT(pc_chunk_count--); @@ -3591,16 +3599,8 @@ pmap_remove_pages(pmap_t pmap) } PT_UPDATES_FLUSH(); if (allfree) { - PV_STAT(pv_entry_spare -= _NPCPV); - PV_STAT(pc_chunk_count--); - PV_STAT(pc_chunk_frees++); TAILQ_REMOVE(&pmap->pm_pvchunk, pc, pc_list); - TAILQ_REMOVE(&pv_chunks, pc, pc_lru); - m = PHYS_TO_VM_PAGE(pmap_kextract((vm_offset_t)pc)); - pmap_qremove((vm_offset_t)pc, 1); - vm_page_unwire(m, 0); - vm_page_free(m); - pmap_ptelist_free(&pv_vafree, (vm_offset_t)pc); + free_pv_chunk(pc); } } PT_UPDATES_FLUSH();