summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorHarshavardhana <fharshav@redhat.com>2012-01-09 17:15:23 -0800
committerVijay Bellur <vijay@gluster.com>2012-01-26 02:32:08 -0800
commitcf57b7b517af68c56fb8d4c229e2988c306384c4 (patch)
treee40af71abed7817b9ed1493c2fbeff0446bdfba6 /libglusterfs
parente8c722ba2832e4d0cae6ba3d043e5f06aaadbacd (diff)
common-utils: Add support for solaris, bsd and mac os/x
get_mem_size() is more standardized now. Change-Id: I8e3dc29df0a64a5eb8eea4fd3965b268cb1a85c2 BUG: 772808 Signed-off-by: Harshavardhana <fharshav@redhat.com> Reviewed-on: http://review.gluster.com/2618 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index ce1e1f45bff..42bfd035569 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -42,6 +42,10 @@
#include <signal.h>
#include <stdlib.h>
+#if defined GF_BSD_HOST_OS || defined GF_DARWIN_HOST_OS
+#include <sys/sysctl.h>
+#endif
+
#include "logging.h"
#include "common-utils.h"
#include "revision.h"
@@ -1874,30 +1878,25 @@ get_mem_size ()
{
uint64_t memsize = -1;
-#ifdef __linux__
- FILE *fp = NULL;
- char line[1028] = {0,};
+#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS
- fp = fopen ("/proc/meminfo", "r");
- if (!fp) {
- gf_log ("common-utils", GF_LOG_DEBUG,
- "Could not open /proc/meminfo");
- return memsize;
- }
+ uint64_t page_size = 0;
+ uint64_t num_pages = 0;
- while (fgets (line, sizeof (line), fp) != 0) {
- if (strncmp (line, "MemTotal:", 9) == 0) {
- sscanf (line, "%*s %"SCNu64" kB", &memsize);
- memsize *= 1024; //convert to bytes
- gf_log ("common-utils", GF_LOG_INFO,
- "Total Mem: %"PRIu64, memsize);
- break;
- }
- }
+ page_size = sysconf (_SC_PAGESIZE);
+ num_pages = sysconf (_SC_PHYS_PAGES);
+
+ memsize = page_size * num_pages;
#endif
- // TODO: Methods for other platforms
- return memsize;
+#if defined GF_BSD_HOST_OS || defined GF_DARWIN_HOST_OS
+
+ size_t len = sizeof(memsize);
+ int name [] = { CTL_HW, HW_PHYSMEM };
+
+ sysctl (name, 2, &memsize, &len, NULL, 0);
+#endif
+ return memsize;
}