From 0c1f21a28ec44f527237be9f810284de265c8522 Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Fri, 10 Sep 2010 11:35:30 +0200 Subject: [PATCH] qmemman: when a AppVM is low on memory, allow small adjustments A small AppVM (say, with 100MB total) can go below prefmem, and still not be assigned memory, because of the MIN_TOTAL_MEMORY_TRANSFER threshold. So, if AppVM is below prefmem, allow for smaller mem-sets. --- common/meminfo-writer.c | 12 +++++++----- dom0/qmemman/qmemman.py | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/common/meminfo-writer.c b/common/meminfo-writer.c index d97c68df..2f6f2174 100644 --- a/common/meminfo-writer.c +++ b/common/meminfo-writer.c @@ -17,7 +17,8 @@ char *parse(char *buf) static char outbuf[4096]; int val; int len; - int MemTotal=0, MemFree=0, Buffers=0, Cached=0, SwapTotal=0, SwapFree=0; + int MemTotal = 0, MemFree = 0, Buffers = 0, Cached = 0, SwapTotal = + 0, SwapFree = 0; unsigned long long key; long used_mem, used_mem_diff; int nitems = 0; @@ -54,10 +55,12 @@ char *parse(char *buf) return NULL; used_mem_diff = used_mem - prev_used_mem; - prev_used_mem = used_mem; if (used_mem_diff < 0) used_mem_diff = -used_mem_diff; - if (used_mem_diff > used_mem_change_threshold) { + if (used_mem_diff > used_mem_change_threshold + || (used_mem > prev_used_mem && used_mem * 13 / 10 > MemTotal + && used_mem_diff > used_mem_change_threshold/2)) { + prev_used_mem = used_mem; sprintf(outbuf, "MemTotal: %d kB\nMemFree: %d kB\nBuffers: %d kB\nCached: %d kB\n" "SwapTotal: %d kB\nSwapFree: %d kB\n", MemTotal, @@ -82,8 +85,7 @@ void send_to_qmemman(struct xs_handle *xs, char *data) } } -int -main(int argc, char **argv) +int main(int argc, char **argv) { char buf[4096]; int n; diff --git a/dom0/qmemman/qmemman.py b/dom0/qmemman/qmemman.py index eb9b4328..cbfc0543 100755 --- a/dom0/qmemman/qmemman.py +++ b/dom0/qmemman/qmemman.py @@ -101,10 +101,16 @@ class SystemState: def is_balance_req_significant(self, memset_reqs): total_memory_transfer = 0 MIN_TOTAL_MEMORY_TRANSFER = 150*1024*1024 + MIN_MEM_CHANGE_WHEN_UNDER_PREF = 15*1024*1024 for rq in memset_reqs: dom, mem = rq - memory_change = mem - self.domdict[dom].last_target + last_target = self.domdict[dom].last_target + memory_change = mem - last_target total_memory_transfer += abs(memory_change) + pref = qmemman_algo.prefmem(self.domdict[dom]) + if last_target > 0 and last_target < pref and memory_change > MIN_MEM_CHANGE_WHEN_UNDER_PREF: + print 'dom', dom, 'is below pref, allowing balance' + return True return total_memory_transfer > MIN_TOTAL_MEMORY_TRANSFER def print_stats(self, xenfree, memset_reqs):