You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2014/01/13 22:54:22 UTC

[1/2] git commit: Merged freeMemory() into memory().

Updated Branches:
  refs/heads/master c3c2447d7 -> 6d943bb45


Merged freeMemory() into memory().

Instead of having separate functions to get total and free system
memory, this patch merge the two in memory().
memory() now returns a struct containing both stats.

Review: https://reviews.apache.org/r/16769


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d4c57ceb
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d4c57ceb
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d4c57ceb

Branch: refs/heads/master
Commit: d4c57ceb81cc35ae6f677434e48a6c2d8b445d67
Parents: c3c2447
Author: Niklas Q. Nielsen <ni...@mesosphere.io>
Authored: Mon Jan 13 21:39:25 2014 +0000
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Mon Jan 13 21:39:25 2014 +0000

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         | 59 ++++++++++----------
 1 file changed, 31 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d4c57ceb/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 2c4ddb0..b24804a 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -858,46 +858,47 @@ inline Try<Load> loadavg()
 }
 
 
-// Returns the total size of main memory.
-inline Try<Bytes> memory()
+// Structure returned by memory() containing the total size of main
+// and free memory.
+struct Memory
 {
+  Bytes total;
+  Bytes free;
+};
+
+
+// Returns the total size of main and free memory.
+inline Try<Memory> memory()
+{
+  Memory memory;
+
 #ifdef __linux__
   struct sysinfo info;
   if (sysinfo(&info) != 0) {
     return ErrnoError();
   }
+
 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 23)
-  return Bytes(info.totalram * info.mem_unit);
+  memory.total = Bytes(info.totalram * info.mem_unit);
+  memory.free = Bytes(info.freeram * info.mem_unit);
 # else
-  return Bytes(info.totalram);
+  memory.total = Bytes(info.totalram);
+  memory.free = Bytes(info.freeram);
 # endif
+
+  return memory;
+
 #elif defined __APPLE__
-  const Try<int64_t>& memory =
+  const Try<int64_t>& totalMemory =
     os::sysctl(CTL_HW, HW_MEMSIZE).integer();
 
-  if (memory.isError()) {
-    return Error(memory.error());
+  if (totalMemory.isError()) {
+    return Error(totalMemory.error());
   }
-  return Bytes(memory.get());
-#else
-  return Error("Cannot determine the size of main memory");
-#endif
-}
-
+  memory.total = Bytes(totalMemory.get());
 
-inline Try<Bytes> freeMemory()
-{
-#ifdef __linux__
-  struct sysinfo info;
-  if (sysinfo(&info) != 0) {
-    return ErrnoError();
-  }
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 23)
-  return Bytes(info.freeram * info.mem_unit);
-# else
-  return Bytes(info.freeram);
-# endif
-#elif defined __APPLE__
+  // Size of free memory is available in terms of number of
+  // free pages on Mac OS X.
   const long pageSize = sysconf(_SC_PAGESIZE);
   if (pageSize < 0) {
     return ErrnoError();
@@ -914,10 +915,12 @@ inline Try<Bytes> freeMemory()
       0) != 0) {
     return ErrnoError();
   }
+  memory.free = Bytes(freeCount * pageSize);
+
+  return memory;
 
-  return Bytes(freeCount * pageSize);
 #else
-  return Error("Cannot determine the size of free memory");
+  return Error("Cannot determine the size of total and free memory");
 #endif
 }
 


[2/2] git commit: Updated slave to use new memory struct.

Posted by nn...@apache.org.
Updated slave to use new memory struct.

>From #16769, memory() now returns both total _and_ free system memory.
This patch adjusts for the new return type.

Review: https://reviews.apache.org/r/16771


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6d943bb4
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6d943bb4
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6d943bb4

Branch: refs/heads/master
Commit: 6d943bb45dbff3b2a4acf51e9b5453fb35887704
Parents: d4c57ce
Author: Niklas Q. Nielsen <ni...@mesosphere.io>
Authored: Mon Jan 13 21:40:08 2014 +0000
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Mon Jan 13 21:40:08 2014 +0000

----------------------------------------------------------------------
 src/slave/slave.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6d943bb4/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 396293b..57d58b3 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -147,14 +147,14 @@ void Slave::initialize()
   if (!resources.mem().isSome()) {
     Bytes mem;
 
-    Try<Bytes> mem_ = os::memory();
+    Try<os::Memory> mem_ = os::memory();
     if (!mem_.isSome()) {
       LOG(WARNING) << "Failed to auto-detect the size of main memory: '"
                    << mem_.error()
                    << "' ; defaulting to " << DEFAULT_MEM;
       mem = DEFAULT_MEM;
     } else {
-      mem = mem_.get();
+      mem = mem_.get().total;
 
       // Leave 1 GB free if we have more than 1 GB, otherwise, use all!
       // TODO(benh): Have better default scheme (e.g., % of mem not