diff --git a/Common/OS.cpp b/Common/OS.cpp
index 2f2e4b9baea711659b4c0e1cb05e8723f556d11d..210c294e24bf0b7623095eb765b1f56a4f5bc2f8 100644
--- a/Common/OS.cpp
+++ b/Common/OS.cpp
@@ -17,6 +17,14 @@
 #include "GmshConfig.h"
 #include "StringUtils.h"
 
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+#endif
+
+#if defined(__linux__)
+#include <sys/sysinfo.h>
+#endif
+
 #if !defined(WIN32) || defined(__CYGWIN__)
 #include <unistd.h>
 #include <sys/time.h>
@@ -262,6 +270,28 @@ double Cpu()
   return s;
 }
 
+double TotalRam()
+{
+  double ram = 0;
+#if defined(__APPLE__)
+  int name[] = {CTL_HW, HW_MEMSIZE};
+  int64_t value;
+  size_t len = sizeof(value);
+  if(sysctl(name, 2, &value, &len, NULL, 0) != -1)
+    ram = value / (1024 * 1024);
+#elif defined (WIN32)
+  MEMORYSTATUSEX status;
+  status.dwLength = sizeof(status);
+  GlobalMemoryStatusEx(&status);
+  ram = status.ullTotalPhys  / ((double)1024 * 1024);
+#elif defined(__linux__)
+  struct sysinfo infos;
+  if(sysinfo(&infos) != -1)
+    ram = infos.totalram * (unsigned long)infos.mem_unit / ((double)1024 * 1024);
+#endif
+  return ram;
+}
+
 long GetMemoryUsage()
 {
   long mem = 0;
diff --git a/Common/OS.h b/Common/OS.h
index ae1e1203997a7200945f4e50bcc3469a1faf46e3..1a0cbb95f66bef62be5a8ee4ab8d636a742840a9 100644
--- a/Common/OS.h
+++ b/Common/OS.h
@@ -15,6 +15,7 @@ double GetTimeInSeconds();
 void SleepInSeconds(double s);
 void CheckResources();
 double Cpu();
+double TotalRam();
 long GetMemoryUsage();
 int GetProcessId();
 std::string GetHostName();