[haiku-commits] r37168 - haiku/trunk/src/system/kernel

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 18 Jun 2010 23:01:28 +0200 (CEST)

Author: bonefish
Date: 2010-06-18 23:01:27 +0200 (Fri, 18 Jun 2010)
New Revision: 37168
Changeset: http://dev.haiku-os.org/changeset/37168/haiku

Modified:
   haiku/trunk/src/system/kernel/low_resource_manager.cpp
Log:
* Changed the address space note, warning, critical limits to fixed values. The
  value for note remains the same, the others are significantly higher, now.
* compute_state(): Log low resource state changes.
* "low_resource" command: Also print the current resource values.


Modified: haiku/trunk/src/system/kernel/low_resource_manager.cpp
===================================================================
--- haiku/trunk/src/system/kernel/low_resource_manager.cpp      2010-06-18 
20:57:05 UTC (rev 37167)
+++ haiku/trunk/src/system/kernel/low_resource_manager.cpp      2010-06-18 
21:01:27 UTC (rev 37168)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008, Ingo Weinhold, ingo_weinhold@xxxxxxx
+ * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@xxxxxxx
  * Copyright 2005-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
@@ -58,7 +58,12 @@
 static off_t sWarnMemoryLimit;
 static off_t sCriticalMemoryLimit;
 
+// address space limits
+static const off_t kMinNoteSpaceLimit          = 128 * 1024 * 1024;
+static const off_t kMinWarnSpaceLimit          = 64 * 1024 * 1024;
+static const off_t kMinCriticalSpaceLimit      = 32 * 1024 * 1024;
 
+
 static int32 sLowPagesState = B_NO_LOW_RESOURCE;
 static int32 sLowMemoryState = B_NO_LOW_RESOURCE;
 static int32 sLowSemaphoresState = B_NO_LOW_RESOURCE;
@@ -74,6 +79,23 @@
 static ConditionVariable sLowResourceWaiterCondition;
 
 
+static const char*
+state_to_string(uint32 state)
+{
+       switch (state) {
+               case B_LOW_RESOURCE_CRITICAL:
+                       return "critical";
+               case B_LOW_RESOURCE_WARNING:
+                       return "warning";
+               case B_LOW_RESOURCE_NOTE:
+                       return "note";
+
+               default:
+                       return "normal";
+       }
+}
+
+
 static int32
 low_resource_state_no_update(uint32 resources)
 {
@@ -136,6 +158,7 @@
        // free pages state
        uint32 freePages = vm_page_num_free_pages();
 
+       int32 oldState = sLowPagesState;
        if (freePages < kCriticalPagesLimit) {
                sLowPagesState = B_LOW_RESOURCE_CRITICAL;
        } else if (freePages < kWarnPagesLimit) {
@@ -147,9 +170,15 @@
                sLowResources &= ~B_KERNEL_RESOURCE_PAGES;
        }
 
+       if (sLowPagesState != oldState) {
+               dprintf("low resource pages: %s -> %s\n", 
state_to_string(oldState),
+                       state_to_string(sLowPagesState));
+       }
+
        // free memory state
        off_t freeMemory = vm_available_not_needed_memory();
 
+       oldState = sLowMemoryState;
        if (freeMemory < sCriticalMemoryLimit) {
                sLowMemoryState = B_LOW_RESOURCE_CRITICAL;
        } else if (freeMemory < sWarnMemoryLimit) {
@@ -161,10 +190,16 @@
                sLowResources &= ~B_KERNEL_RESOURCE_MEMORY;
        }
 
+       if (sLowMemoryState != oldState) {
+               dprintf("low resource memory: %s -> %s\n", 
state_to_string(oldState),
+                       state_to_string(sLowMemoryState));
+       }
+
        // free semaphores state
        uint32 maxSems = sem_max_sems();
        uint32 freeSems = maxSems - sem_used_sems();
 
+       oldState = sLowSemaphoresState;
        if (freeSems < maxSems >> 16) {
                sLowSemaphoresState = B_LOW_RESOURCE_CRITICAL;
        } else if (freeSems < maxSems >> 8) {
@@ -176,21 +211,31 @@
                sLowResources &= ~B_KERNEL_RESOURCE_SEMAPHORES;
        }
 
+       if (sLowSemaphoresState != oldState) {
+               dprintf("low resource semaphores: %s -> %s\n",
+                       state_to_string(oldState), 
state_to_string(sLowSemaphoresState));
+       }
+
        // free kernel address space state
        // TODO: this should take fragmentation into account
-       size_t maxSpace = KERNEL_SIZE;
        size_t freeSpace = vm_kernel_address_space_left();
 
-       if (freeSpace < maxSpace >> 16) {
+       oldState = sLowSpaceState;
+       if (freeSpace < kMinCriticalSpaceLimit) {
                sLowSpaceState = B_LOW_RESOURCE_CRITICAL;
-       } else if (freeSpace < maxSpace >> 8) {
+       } else if (freeSpace < kMinWarnSpaceLimit) {
                sLowSpaceState = B_LOW_RESOURCE_WARNING;
-       } else if (freeSpace < maxSpace >> 4) {
+       } else if (freeSpace < kMinNoteSpaceLimit) {
                sLowSpaceState = B_LOW_RESOURCE_NOTE;
        } else {
                sLowSpaceState = B_NO_LOW_RESOURCE;
                sLowResources &= ~B_KERNEL_RESOURCE_ADDRESS_SPACE;
        }
+
+       if (sLowSpaceState != oldState) {
+               dprintf("low resource address space: %s -> %s\n",
+                       state_to_string(oldState), 
state_to_string(sLowSpaceState));
+       }
 }
 
 
@@ -231,23 +276,6 @@
 }
 
 
-static const char*
-state_to_string(uint32 state)
-{
-       switch (state) {
-               case B_LOW_RESOURCE_CRITICAL:
-                       return "critical";
-               case B_LOW_RESOURCE_WARNING:
-                       return "warning";
-               case B_LOW_RESOURCE_NOTE:
-                       return "note";
-
-               default:
-                       return "normal";
-       }
-}
-
-
 static int
 dump_handlers(int argc, char** argv)
 {
@@ -256,10 +284,14 @@
                (sLowResources & B_KERNEL_RESOURCE_MEMORY) != 0 ? 'm' : '-',
                (sLowResources & B_KERNEL_RESOURCE_SEMAPHORES) != 0 ? 's' : '-',
                (sLowResources & B_KERNEL_RESOURCE_ADDRESS_SPACE) != 0 ? 'a' : 
'-');
-       kprintf("  pages:  %s\n", state_to_string(sLowPagesState));
-       kprintf("  memory: %s\n", state_to_string(sLowMemoryState));
-       kprintf("  sems:   %s\n", state_to_string(sLowSemaphoresState));
-       kprintf("  aspace: %s\n\n", state_to_string(sLowSpaceState));
+       kprintf("  pages:  %s (%" B_PRIu64 ")\n", 
state_to_string(sLowPagesState),
+               (uint64)vm_page_num_free_pages());
+       kprintf("  memory: %s (%" B_PRIdOFF ")\n", 
state_to_string(sLowMemoryState),
+               vm_available_not_needed_memory_debug());
+       kprintf("  sems:   %s (%" B_PRIu32 ")\n",
+               state_to_string(sLowSemaphoresState), sem_max_sems() - 
sem_used_sems());
+       kprintf("  aspace: %s (%" B_PRIuSIZE ")\n\n",
+               state_to_string(sLowSpaceState), 
vm_kernel_address_space_left());
 
        HandlerList::Iterator iterator = sLowResourceHandlers.GetIterator();
        kprintf("function    data         resources  prio  function-name\n");


Other related posts:

  • » [haiku-commits] r37168 - haiku/trunk/src/system/kernel - ingo_weinhold