Index: /trunk/include/VBox/pgm.h
===================================================================
--- /trunk/include/VBox/pgm.h	(revision 26684)
+++ /trunk/include/VBox/pgm.h	(revision 26685)
@@ -283,4 +283,6 @@
     (    (enmProt) == PGMROMPROT_READ_ROM_WRITE_IGNORE \
       || (enmProt) == PGMROMPROT_READ_ROM_WRITE_RAM )
+
+
 
 VMMDECL(bool)       PGMIsLocked(PVM pVM);
@@ -405,4 +407,15 @@
 
 
+VMMDECL(void) PGMSetLargePageUsage(PVM pVM, bool fUseLargePages);
+
+/**
+ * Query large page usage state
+ *
+ * @returns 0 - disabled, 1 - enabled
+ * @param   pVM         The VM to operate on.
+ */
+#define PGMIsUsingLargePages(pVM) (pVM->fUseLargePages)
+
+
 #ifdef IN_RC
 /** @defgroup grp_pgm_gc  The PGM Guest Context API
Index: /trunk/include/VBox/vm.h
===================================================================
--- /trunk/include/VBox/vm.h	(revision 26684)
+++ /trunk/include/VBox/vm.h	(revision 26685)
@@ -784,4 +784,6 @@
     /** PARAV enabled flag. */
     bool                        fPARAVEnabled;
+    /** Large page enabled flag. */
+    bool                        fUseLargePages;
     /** @} */
 
Index: /trunk/src/VBox/VMM/HWACCM.cpp
===================================================================
--- /trunk/src/VBox/VMM/HWACCM.cpp	(revision 26684)
+++ /trunk/src/VBox/VMM/HWACCM.cpp	(revision 26685)
@@ -1157,4 +1157,9 @@
                     if (pVM->hwaccm.s.vmx.fUnrestrictedGuest)
                         LogRel(("HWACCM: Unrestricted guest execution enabled!\n"));
+
+#ifdef DEBUG_sandervl
+                    /* Use large (2 MB) pages for our EPT PDEs where possible. */
+                    PGMSetLargePageUsage(pVM, true);
+#endif
                 }
                 else
Index: /trunk/src/VBox/VMM/VMMAll/HWACCMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/HWACCMAll.cpp	(revision 26684)
+++ /trunk/src/VBox/VMM/VMMAll/HWACCMAll.cpp	(revision 26685)
@@ -338,3 +338,2 @@
     return !!pVCpu->hwaccm.s.Event.fPending;
 }
-
Index: /trunk/src/VBox/VMM/VMMAll/PGMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/PGMAll.cpp	(revision 26684)
+++ /trunk/src/VBox/VMM/VMMAll/PGMAll.cpp	(revision 26685)
@@ -2108,4 +2108,15 @@
 
 /**
+ * Enable or disable large page usage
+ *
+ * @param   pVM             The VM to operate on.
+ * @param   fUseLargePages  Use/not use large pages
+ */
+VMMDECL(void) PGMSetLargePageUsage(PVM pVM, bool fUseLargePages)
+{
+      pVM->fUseLargePages = fUseLargePages;
+}
+
+/**
  * Acquire the PGM lock.
  *
Index: /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 26684)
+++ /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 26685)
@@ -2937,10 +2937,11 @@
     Assert(!PdeDst.n.u1Present); /* We're only supposed to call SyncPT on PDE!P and conflicts.*/
 
-# if (PGM_SHW_TYPE == PGM_TYPE_EPT) && (HC_ARCH_BITS == 64) && defined(RT_OS_WINDOWS) && defined(DEBUG_sandervl)
+# if (PGM_SHW_TYPE == PGM_TYPE_EPT) && (HC_ARCH_BITS == 64) && defined(RT_OS_WINDOWS)
+    if (PGMIsUsingLargePages(pVM))
     {
         RTHCPHYS HCPhys;
         rc = pgmPhysAllocLargePage(pVM, GCPtrPage & SHW_PDE_PG_MASK, &HCPhys);
         if (RT_SUCCESS(rc))
-        {   
+        {
             PdeDst.u &= X86_PDE_AVL_MASK;
             PdeDst.u |= HCPhys;
Index: /trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp	(revision 26684)
+++ /trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp	(revision 26685)
@@ -368,4 +368,14 @@
     Assert(!PGM_PAGE_IS_MMIO(pPage));
 
+    if (PGMIsUsingLargePages(pVM))
+    {
+        RTHCPHYS HCPhysDummy;
+
+        int rc = pgmPhysAllocLargePage(pVM, GCPhys, &HCPhysDummy);
+        if (rc == VINF_SUCCESS)
+            return rc;
+
+        /* fall back to 4kb pages. */
+    }
 
     /*
@@ -471,4 +481,5 @@
      */
     Assert(PGMIsLocked(pVM));
+    Assert(PGMIsUsingLargePages(pVM));
     Assert((GCPhys & X86_PD_PAE_MASK) == 0);
     AssertPtr(pHCPhys);
@@ -540,4 +551,7 @@
                 }
                 LogFlow(("pgmPhysAllocLargePage failed with %Rrc\n", rc));
+
+                /* If we fail once, it most likely means the host's memory is too fragmented; don't bother trying again. */
+                PGMSetLargePageUsage(pVM, false);
                 return rc;
             }
