From 806453645a83f4b94e7f6a82b416834be864127a Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 20 Jul 2007 06:55:11 +0000 Subject: [PATCH] Two changes to vm_fault_additional_pages(): 1. Rewrite the backward scan. Specifically, reverse the order in which pages are allocated so that upon failure it is never necessary to free pages that were just allocated. Moreover, any allocated pages can be put to use. This makes the backward scan behave just like the forward scan. 2. Eliminate an explicit, unsynchronized check for low memory before calling vm_page_alloc(). It serves no useful purpose. It is, in effect, optimizing the uncommon case at the expense of the common case. Approved by: re (hrs) MFC after: 3 weeks --- sys/vm/vm_fault.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index e09fbfbe8fe1..8b843dc9bddb 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -1254,17 +1254,6 @@ vm_fault_additional_pages(m, rbehind, rahead, marray, reqpage) rbehind = cbehind; } - /* - * try to do any readahead that we might have free pages for. - */ - if ((rahead + rbehind) > - ((cnt.v_free_count + cnt.v_cache_count) - cnt.v_free_reserved)) { - pagedaemon_wakeup(); - marray[0] = m; - *reqpage = 0; - return 1; - } - /* * scan backward for the read behind pages -- in memory */ @@ -1280,21 +1269,24 @@ vm_fault_additional_pages(m, rbehind, rahead, marray, reqpage) rtm->pindex >= startpindex) startpindex = rtm->pindex + 1; - for (i = 0, tpindex = startpindex; tpindex < pindex; i++, tpindex++) { + /* tpindex is unsigned; beware of numeric underflow. */ + for (i = 0, tpindex = pindex - 1; tpindex >= startpindex && + tpindex < pindex; i++, tpindex--) { rtm = vm_page_alloc(object, tpindex, VM_ALLOC_NORMAL); if (rtm == NULL) { - vm_page_lock_queues(); + /* + * Shift the allocated pages to the + * beginning of the array. + */ for (j = 0; j < i; j++) { - vm_page_free(marray[j]); + marray[j] = marray[j + tpindex + 1 - + startpindex]; } - vm_page_unlock_queues(); - marray[0] = m; - *reqpage = 0; - return 1; + break; } - marray[i] = rtm; + marray[tpindex - startpindex] = rtm; } } else { startpindex = 0;