From 5d339e3d47f09bd166ff9c05d077e22eb0edb40f Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 3 Nov 2001 01:08:55 +0000 Subject: [PATCH] Implement i386/i386/pmap.c 1.292 for alpha, ia64 (avoid free page exhaustion / kernel panic for certain madvise() scenarios) --- sys/alpha/alpha/pmap.c | 18 +++++++++++++++++- sys/ia64/ia64/pmap.c | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/sys/alpha/alpha/pmap.c b/sys/alpha/alpha/pmap.c index c03d3dd43140..21dfef1c14e6 100644 --- a/sys/alpha/alpha/pmap.c +++ b/sys/alpha/alpha/pmap.c @@ -2466,7 +2466,7 @@ pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, psize = alpha_btop(size); if ((object->type != OBJT_VNODE) || - (limit && (psize > MAX_INIT_PT) && + ((limit & MAP_PREFAULT_PARTIAL) && (psize > MAX_INIT_PT) && (object->resident_page_count > MAX_INIT_PT))) { return; } @@ -2494,6 +2494,14 @@ pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, if (tmpidx >= psize) { continue; } + /* + * don't allow an madvise to blow away our really + * free pages allocating pv entries. + */ + if ((limit & MAP_PREFAULT_MADVISE) && + cnt.v_free_count < cnt.v_free_reserved) { + break; + } if (((p->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) && (p->flags & (PG_BUSY | PG_FICTITIOUS)) == 0) { if ((p->queue - p->pc) == PQ_CACHE) @@ -2511,6 +2519,14 @@ pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, * else lookup the pages one-by-one. */ for (tmpidx = 0; tmpidx < psize; tmpidx += 1) { + /* + * don't allow an madvise to blow away our really + * free pages allocating pv entries. + */ + if ((limit & MAP_PREFAULT_MADVISE) && + cnt.v_free_count < cnt.v_free_reserved) { + break; + } p = vm_page_lookup(object, tmpidx + pindex); if (p && ((p->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) && diff --git a/sys/ia64/ia64/pmap.c b/sys/ia64/ia64/pmap.c index 901cd19a5307..8e046778287d 100644 --- a/sys/ia64/ia64/pmap.c +++ b/sys/ia64/ia64/pmap.c @@ -1743,7 +1743,7 @@ pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, psize = ia64_btop(size); if ((object->type != OBJT_VNODE) || - (limit && (psize > MAX_INIT_PT) && + ((limit & MAP_PREFAULT_PARTIAL) && (psize > MAX_INIT_PT) && (object->resident_page_count > MAX_INIT_PT))) { pmap_install(oldpmap); return; @@ -1771,6 +1771,14 @@ pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, if (tmpidx >= psize) { continue; } + /* + * don't allow an madvise to blow away our really + * free pages allocating pv entries. + */ + if ((limit & MAP_PREFAULT_MADVISE) && + cnt.v_free_count < cnt.v_free_reserved) { + break; + } if (((p->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) && (p->flags & (PG_BUSY | PG_FICTITIOUS)) == 0) { if ((p->queue - p->pc) == PQ_CACHE) @@ -1788,6 +1796,14 @@ pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, * else lookup the pages one-by-one. */ for (tmpidx = 0; tmpidx < psize; tmpidx += 1) { + /* + * don't allow an madvise to blow away our really + * free pages allocating pv entries. + */ + if ((limit & MAP_PREFAULT_MADVISE) && + cnt.v_free_count < cnt.v_free_reserved) { + break; + } p = vm_page_lookup(object, tmpidx + pindex); if (p && ((p->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) &&