win-pvdrivers

changeset 867:fc034d9ccf1b

Don't balloon down if Windows says low memory
author James Harper <james.harper@bendigoit.com.au>
date Tue Mar 01 10:42:00 2011 +1100 (2011-03-01)
parents c3e9661e4f7e
children 9096c1757947
files xenpci/xenpci_fdo.c
line diff
     1.1 --- a/xenpci/xenpci_fdo.c	Mon Feb 28 10:04:55 2011 +1100
     1.2 +++ b/xenpci/xenpci_fdo.c	Tue Mar 01 10:42:00 2011 +1100
     1.3 @@ -241,12 +241,29 @@ XenPci_BalloonThreadProc(PVOID StartCont
     1.4    ULONG ret;
     1.5    int pfn_count;
     1.6    int timeout_ms = 1000;
     1.7 +  DECLARE_CONST_UNICODE_STRING(low_mem_name, L"\\KernelObjects\\LowMemoryCondition");
     1.8 +  //DECLARE_CONST_UNICODE_STRING(high_commit_name, L"\\KernelObjects\\HighCommitCondition");
     1.9 +  //DECLARE_CONST_UNICODE_STRING(max_commit_name, L"\\KernelObjects\\MaximumCommitCondition");
    1.10 +  PKEVENT low_mem_event;
    1.11 +  //PKEVENT high_commit_event;
    1.12 +  //PKEVENT max_commit_event;
    1.13 +  HANDLE low_mem_handle;
    1.14 +  //HANDLE high_commit_handle;
    1.15 +  //HANDLE max_commit_handle;
    1.16    
    1.17    FUNCTION_ENTER();
    1.18    
    1.19    head = balloon_mdl_head;
    1.20    balloon_mdl_head = NULL;
    1.21  
    1.22 +  low_mem_event = IoCreateNotificationEvent((PUNICODE_STRING)&low_mem_name, &low_mem_handle);
    1.23 +  //high_commit_event = IoCreateNotificationEvent((PUNICODE_STRING)&high_commit_name, &high_commit_handle);
    1.24 +  //max_commit_event = IoCreateNotificationEvent((PUNICODE_STRING)&max_commit_name, &max_commit_handle);
    1.25 +
    1.26 +  KdPrint((__DRIVER_NAME "     low_mem_event = %p, state = %d\n", low_mem_event, low_mem_event?KeReadStateEvent(low_mem_event):(ULONG)-1));
    1.27 +  //KdPrint((__DRIVER_NAME "     high_commit_event = %p, state = %d\n", high_commit_event, high_commit_event?KeReadStateEvent(high_commit_event):(ULONG)-1));
    1.28 +  //KdPrint((__DRIVER_NAME "     max_commit_event = %p, state = %d\n", max_commit_event, max_commit_event?KeReadStateEvent(max_commit_event):(ULONG)-1));
    1.29 +  
    1.30    for(;;)
    1.31    {
    1.32      /* back off exponentially if we have adjustments to make, or wait for event if we don't */
    1.33 @@ -329,6 +346,16 @@ XenPci_BalloonThreadProc(PVOID StartCont
    1.34          alloc_low.QuadPart = 0;
    1.35          alloc_high.QuadPart = 0xFFFFFFFFFFFFFFFFULL;
    1.36          alloc_skip.QuadPart = 0;
    1.37 +
    1.38 +        if (low_mem_event && KeReadStateEvent(low_mem_event))
    1.39 +        {
    1.40 +          KdPrint((__DRIVER_NAME "     Low memory condition exists. Waiting.\n"));
    1.41 +          //KdPrint((__DRIVER_NAME "     low_mem_event = %p, state = %d\n", low_mem_event, low_mem_event?KeReadStateEvent(low_mem_event):(ULONG)-1));
    1.42 +          //KdPrint((__DRIVER_NAME "     high_commit_event = %p, state = %d\n", high_commit_event, high_commit_event?KeReadStateEvent(high_commit_event):(ULONG)-1));
    1.43 +          //KdPrint((__DRIVER_NAME "     max_commit_event = %p, state = %d\n", max_commit_event, max_commit_event?KeReadStateEvent(max_commit_event):(ULONG)-1));
    1.44 +          break;
    1.45 +        }
    1.46 +
    1.47          #if (NTDDI_VERSION >= NTDDI_WS03SP1)
    1.48          /* our contract says that we must zero pages before returning to xen, so we can't use MM_DONT_ZERO_ALLOCATION */
    1.49          mdl = MmAllocatePagesForMdlEx(alloc_low, alloc_high, alloc_skip, BALLOON_UNITS, MmCached, 0);
    1.50 @@ -381,6 +408,7 @@ XenPci_BalloonThreadProc(PVOID StartCont
    1.51          }
    1.52        }
    1.53      }
    1.54 +    KdPrint((__DRIVER_NAME "     Memory = %d, Balloon Target = %d\n", xpdd->current_memory, new_target));
    1.55    }
    1.56    //FUNCTION_EXIT();
    1.57  }