[X2Go-Commits] [x2gobroker] 02/02: Calculate our own MemAvailable value in x2gobroker-agent.pl. Only kernels new than v3.14 offer the MemAvailable: field in /proc/meminfo.

git-admin at x2go.org git-admin at x2go.org
Fri Mar 27 12:11:15 CET 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2gobroker.

commit eaa336c4012348f564de492309efa96eecb1c8bf
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Fri Mar 27 12:11:08 2015 +0100

    Calculate our own MemAvailable value in x2gobroker-agent.pl. Only kernels new than v3.14 offer the MemAvailable: field in /proc/meminfo.
---
 debian/changelog        |    2 ++
 lib/x2gobroker-agent.pl |   43 +++++++++++++++++++++++++++++++++++++++++--
 x2gobroker/agent.py     |    3 +++
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index c7d336d..9d8ae6b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -250,6 +250,8 @@ x2gobroker (0.0.3.0-0x2go1) UNRELEASED; urgency=low
     - agent.py: Make agent query mode LOCAL behave similar to agent query mode
       SSH if things go wrong.
     - agent.py: Set result to None, if SSH connection to broker agent fails.
+    - Calculate our own MemAvailable value in x2gobroker-agent.pl. Only
+      kernels new than v3.14 offer the MemAvailable: field in /proc/meminfo.
   * debian/control:
     + Provide separate bin:package for SSH brokerage: x2gobroker-ssh.
     + Replace LDAP support with session brokerage support in LONG_DESCRIPTION.
diff --git a/lib/x2gobroker-agent.pl b/lib/x2gobroker-agent.pl
index 7996b2f..27709f1 100755
--- a/lib/x2gobroker-agent.pl
+++ b/lib/x2gobroker-agent.pl
@@ -149,16 +149,53 @@ if ( $mode eq 'checkload' ) {
 	}
 
 	# calculate total memory vs. free memory
-        my $memAvail;
+	my $memTotal;
+	my $memFree;
+	my $memAvail;
+	my $pagesActiveFile;
+	my $pagesInactiveFile;
+	my $slabReclaimable;
 	open FILE, "< /proc/meminfo" or die return ("Cannot open /proc/meminfo: $!");
 	foreach(<FILE>) {
+		if ( m/^MemTotal:\s+(\S+)/ ) {
+			$memTotal = $1;
+		}
+		if ( m/^MemFree:\s+(\S+)/ ) {
+			$memFree = $1;
+		}
 		if ( m/^MemAvailable:\s+(\S+)/ ) {
 			$memAvail = $1/1000;
-                        last;
+		}
+		if ( m/^Active\(file\):\s+(\S+)/ ) {
+			$pagesActiveFile = $1;
+		}
+		if ( m/^Inactive\(file\):\s+(\S+)/ ) {
+			$pagesInactiveFile = $1;
+		}
+		if ( m/^SReclaimable:\s+(\S+)/ ) {
+			$slabReclaimable = $1;
 		}
 	}
 	close(FILE);
 
+	my $myMemAvail = 0;
+	if ($myMemAvail == 0) {
+                # taken from Linux kernel code in fs/proc/meminfo.c (since kernel version 3.14)...
+		open FILE, "< /proc/sys/vm/min_free_kbytes" or die return ("Cannot open /proc/sys/vm/min_free_kbytes: $!");
+		my $memLowWatermark = <FILE>;
+		$memLowWatermark =~ s/\n//g;
+		close(FILE);
+		$myMemAvail += $memFree - $memLowWatermark;
+		my $pagecache = $pagesActiveFile + $pagesInactiveFile;
+		$pagecache -= ($pagecache/2, $memLowWatermark) [$pagecache/2 > $memLowWatermark];
+		$myMemAvail += $pagecache;
+		$myMemAvail += $slabReclaimable - ( ($slabReclaimable/2, $memLowWatermark) [$slabReclaimable/2 > $memLowWatermark]);
+		if ($myMemAvail < 0) {
+			$myMemAvail = 0;
+		}
+		$myMemAvail = $myMemAvail / 1000;
+	}
+
 	# check number and type of available CPU cores
 	my $numCPU = 0;
 	my $typeCPU;
@@ -175,6 +212,8 @@ if ( $mode eq 'checkload' ) {
 	print "\n";
 	print sprintf 'memAvail:%1$d', $memAvail;
 	print "\n";
+	print sprintf 'myMemAvail:%1$d', $myMemAvail;
+	print "\n";
 	print sprintf 'numCPU:%1$d', $numCPU;
 	print "\n";
 	print sprintf 'typeCPU:%1$d', $typeCPU;
diff --git a/x2gobroker/agent.py b/x2gobroker/agent.py
index 04591b2..eb6e888 100644
--- a/x2gobroker/agent.py
+++ b/x2gobroker/agent.py
@@ -431,6 +431,9 @@ def checkload(remote_agent=None, logger=None, **kwargs):
             p[key] = float(val)
 
     load_factor = None
+    if p['memAvail'] == 0:
+        p['memAvail'] = p['myMemAvail']
+
     try:
         load_factor = long( ( (p['memAvail']/1000) * p['numCPU'] * p['typeCPU'] * 100 )  / p['loadavgXX'] )
     except KeyError:

--
Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git


More information about the x2go-commits mailing list