[prev in list] [next in list] [prev in thread] [next in thread] 

List:       helix-server-cvs
Subject:    [Server-cvs] engine/core shregion.cpp,1.8,1.9
From:       dcollins () helixcommunity ! org
Date:       2010-02-28 16:38:59
Message-ID: 201002281639.o1SGd13h027717 () mailer ! progressive-comp ! com
[Download RAW message or body]

Update of /cvsroot/server/engine/core
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv21387

Modified Files:
	shregion.cpp 
Log Message:
Synopsis
========
Fix PR 258800: Need to set the memory default to more than 256MB on startup

Branches: SERVER_14_0_RN, SERVER_CURRENT_RN (HEAD)
Reviewer: Jamie


Description
===========

This adds a routine to try to pick the size of the shared memory segment
based on how much memory the system has.  This is used only if the user
did *not* specify a -m flag, instead of defaulting to 256MB.

Note that the OS may or may not decide to give us as much as we've
requested.  This size is just where we start requesting, working down
from there.

If the user specified a -m command-line flag, start with that (though
still detect and report the physical RAM anyhow.)

Otherwise, determine the size of physical RAM.  Use the smaller of this
or 2GB, multiplied by 0.8, as our initial request size.  The multiplier
is so that we don't request all memory.  We need to leave some room for
memory-mapped I/O blocks and other things outside the shared region.
The value of the multiplier is a historical best-guess, a rule-of-thumb,
opinions vary about it being 0.75 to 0.8, I think 0.8 is ok for a default.
If people care they can pick what they want and use -m.

One small change I made is that for DEBUG builds it will continue to
default to 256MB (or really, 320MB * 0.8 :-)  I don't know about you,
but debugging 2GB core files is not something I care to do more than
I really have to.  Normally 256MB will suffice for the majority of dev
work with debug builds.  Let me know if this is ok or not.


Files Affected
==============
server/engine/core/shregion.cpp
server/engine/core/pub/shregion.h


Testing Performed
=================

Unit Tests:
- N/A

Integration Tests:
- Ran the server with and without a -m flag on each platform.

Leak Tests:
- N/A

Performance Tests:
- N/A

Platforms Tested: linux-rhel4-i686, win32-i386-vc7, sunos-5.10-sparc-server
Build verified: linux-rhel4-i686, win32-i386-vc7, sunos-5.10-sparc-server


QA Hints
========
* Use -m for functional testing if you weren't already.


Index: shregion.cpp
===================================================================
RCS file: /cvsroot/server/engine/core/shregion.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- shregion.cpp	5 Mar 2007 23:24:05 -0000	1.8
+++ shregion.cpp	28 Feb 2010 16:38:57 -0000	1.9
@@ -40,6 +40,12 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <fcntl.h>
+#ifdef _SOLARIS
+#include <kstat.h>
+#endif
+#ifdef _LINUX
+#include <sys/sysinfo.h>
+#endif
 
 #if !defined _WIN32
 #include <sys/mman.h>
@@ -66,18 +72,19 @@
 void* g_pHeapTop = NULL;
 #endif
 
-#ifdef _FREEBSD
-#define START	1024		// 1 Gig
+#ifdef _DEBUG
+#define START	320 		// 320 MB for debug builds
 #else
-#define START	256
+#define START	2048		// 2 Gigs for release builds
 #endif
+#define START_FACTOR (0.8)
 
 SharedRegion::SharedRegion(INT32 _size)
     : m_region(0)
     , m_size(0)
     , m_second_heap_size(0)
 {
-    UINT32 ulStartSize = g_ulSizemmap ? g_ulSizemmap : START;
+    UINT32 ulStartSize = PickStartSize();
     UINT32 ulSize = ulStartSize;
     double lfBackOffFraction = (double)g_ulBackOffPercentage / 100.0;
     UINT32 ulDecrement = (UINT32)((double)ulSize * lfBackOffFraction);
@@ -312,3 +319,87 @@
     return m_size;
 #endif
 }
+
+// PickStartSize - Determine the size of our initial shared region request.
+//
+// The OS may or may not decide to give us as much as we've requested.
+// This size is just where we start requesting, working down from there.
+//
+// If the user specified a -m command-line flag, start with that (though
+// detect and report the physical RAM anyhow.)
+//
+// Otherwise, determine the size of physical RAM.  Use the smaller of
+// this or the START value (defined above), multiplied by START_FACTOR, as
+// our initial request size.  The multiplier is so that we don't request
+// all memory.  We need to leave some room for memory-mapped I/O blocks
+// and other things outside the shared region.
+//
+UINT32
+SharedRegion::PickStartSize()
+{
+    UINT32 ulDetectedMB = 0;
+
+#if defined(_LINUX)
+    struct sysinfo info;
+    sysinfo(&info);
+    ulDetectedMB = (UINT32)(info.totalram * info.mem_unit / 1024 / 1024);
+#elif defined(_WIN32)
+    MEMORYSTATUSEX memstatus;
+    memstatus.dwLength = sizeof(memstatus);
+    GlobalMemoryStatusEx(&memstatus);
+    ulDetectedMB = (UINT32)(memstatus.ullTotalPhys / 1024 / 1024);
+#elif defined(_SOLARIS)
+    size_t ulFreeMem = 0;
+    size_t ulLotsFree = 0;
+    static kstat_t* pSystemPages = NULL;
+    kstat_named_t* kn = NULL;
+    kstat_ctl_t* kc = kstat_open();
+
+    if (kc)
+    {
+        pSystemPages = kstat_lookup(kc, "unix", 0, "system_pages");
+    }
+    if (pSystemPages && kstat_read(kc, pSystemPages, 0) != -1)
+    {
+        kn = (kstat_named_t*)kstat_data_lookup(pSystemPages, "lotsfree");
+    }
+    if (kn)
+    {
+        ulLotsFree = kn->value.ul;
+        kn = (kstat_named_t*)kstat_data_lookup(pSystemPages, "freemem");
+    }
+    if (kn)
+    {
+        ulFreeMem = kn->value.ul;
+        ulDetectedMB = sysconf(_SC_PAGESIZE) / 1024 * (ulFreeMem - ulLotsFree) / \
1024; +    }
+#endif
+
+    UINT32 ulStartSize = g_ulSizemmap;  // the -m command-line flag value, in MB
+
+    if (!ulStartSize)
+    {
+        if (ulDetectedMB)
+        {
+            ulStartSize = ulDetectedMB;
+        }
+
+        if (ulStartSize > START)
+        {
+            ulStartSize = START;
+        }
+
+        ulStartSize = (UINT32)(START_FACTOR * ulStartSize);
+    }
+
+    if (ulDetectedMB >= 1000)
+    {
+        printf("Detected %0.1f GB RAM (Requesting %ld MB)\n", (float)ulDetectedMB / \
1000.0, ulStartSize); +    }
+    else
+    {
+        printf("Detected %ld MB RAM (Requesting %ld MB)\n", ulDetectedMB, \
ulStartSize); +    }
+
+    return ulStartSize;
+}


_______________________________________________
Server-cvs mailing list
Server-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/server-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic