Added new function vm_low_memory_state() that returns the current low
memory status. Added new B_NO_LOW_MEMORY constant for the usual case. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15551 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
/* warning levels for low memory handlers */
|
/* warning levels for low memory handlers */
|
||||||
enum {
|
enum {
|
||||||
|
B_NO_LOW_MEMORY = 0,
|
||||||
B_LOW_MEMORY_NOTE,
|
B_LOW_MEMORY_NOTE,
|
||||||
B_LOW_MEMORY_WARNING,
|
B_LOW_MEMORY_WARNING,
|
||||||
B_LOW_MEMORY_CRITICAL,
|
B_LOW_MEMORY_CRITICAL,
|
||||||
@@ -23,6 +24,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
status_t vm_low_memory_init(void);
|
status_t vm_low_memory_init(void);
|
||||||
|
int32 vm_low_memory_state(void);
|
||||||
void vm_low_memory(size_t requirements);
|
void vm_low_memory(size_t requirements);
|
||||||
|
|
||||||
// these calls might get public some day
|
// these calls might get public some day
|
||||||
|
|||||||
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
static const bigtime_t kLowMemoryInterval = 2000000; // 2 secs
|
static const bigtime_t kLowMemoryInterval = 2000000; // 2 secs
|
||||||
|
|
||||||
|
// page limits
|
||||||
static const size_t kNoteLimit = 1024;
|
static const size_t kNoteLimit = 1024;
|
||||||
static const size_t kWarnLimit = 256;
|
static const size_t kWarnLimit = 256;
|
||||||
static const size_t kCriticalLimit = 32;
|
static const size_t kCriticalLimit = 32;
|
||||||
|
|
||||||
|
static int32 sLowMemoryState = B_NO_LOW_MEMORY;
|
||||||
|
|
||||||
|
|
||||||
struct low_memory_handler : public DoublyLinkedListLinkImpl<low_memory_handler> {
|
struct low_memory_handler : public DoublyLinkedListLinkImpl<low_memory_handler> {
|
||||||
low_memory_func function;
|
low_memory_func function;
|
||||||
@@ -48,24 +51,34 @@ call_handlers(int32 level)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int32
|
||||||
|
compute_state(void)
|
||||||
|
{
|
||||||
|
uint32 freePages = vm_page_num_free_pages();
|
||||||
|
if (freePages >= kNoteLimit)
|
||||||
|
return B_NO_LOW_MEMORY;
|
||||||
|
|
||||||
|
// specify low memory level
|
||||||
|
if (freePages < kCriticalLimit)
|
||||||
|
return B_LOW_MEMORY_CRITICAL;
|
||||||
|
else if (freePages < kWarnLimit)
|
||||||
|
return B_LOW_MEMORY_WARNING;
|
||||||
|
|
||||||
|
return B_LOW_MEMORY_NOTE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32
|
static int32
|
||||||
low_memory(void *)
|
low_memory(void *)
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
snooze(kLowMemoryInterval);
|
snooze(kLowMemoryInterval);
|
||||||
|
|
||||||
uint32 freePages = vm_page_num_free_pages();
|
sLowMemoryState = compute_state();
|
||||||
if (freePages >= kNoteLimit)
|
if (sLowMemoryState < B_LOW_MEMORY_NOTE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// specify low memory level
|
call_handlers(sLowMemoryState);
|
||||||
int32 level = B_LOW_MEMORY_NOTE;
|
|
||||||
if (freePages < kCriticalLimit)
|
|
||||||
level = B_LOW_MEMORY_CRITICAL;
|
|
||||||
else if (freePages < kWarnLimit)
|
|
||||||
level = B_LOW_MEMORY_WARNING;
|
|
||||||
|
|
||||||
call_handlers(level);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -80,6 +93,13 @@ vm_low_memory(size_t requirements)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
vm_low_memory_state(void)
|
||||||
|
{
|
||||||
|
return sLowMemoryState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
vm_low_memory_init(void)
|
vm_low_memory_init(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user