Update of /cvsroot/monetdb/MonetDB/src/gdk
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11214/src/gdk

Modified Files:
      Tag: MonetDB_1-22
        gdk_posix.mx gdk_utils.mx 
Log Message:
Changed the way we check for and use mallinfo(): If mallinfo() returns
a struct with fields which are too small to hold the information it is
supposed to return (e.g. 32 bits on a 64-bit system), we ignore
mallinfo().  Also, we use our own struct to hold the information, so
that the rest of the software can rely on bot the presence of the
struct and the types of the fields.  

This also results in one interface change: the view_gdk_memory() and
memory() functions in M4 and the memStatistics() function in M5 now
return a BAT with a wrd tail instead of int.


Index: gdk_posix.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_posix.mx,v
retrieving revision 1.153
retrieving revision 1.153.2.1
diff -u -d -r1.153 -r1.153.2.1
--- gdk_posix.mx        11 Jan 2008 10:37:00 -0000      1.153
+++ gdk_posix.mx        12 Feb 2008 09:23:30 -0000      1.153.2.1
@@ -75,7 +75,6 @@
 #undef HAVE_MALLOPT
 #endif
 
-#ifndef HAVE_MALLINFO
 #ifndef M_MXFAST
 #define M_MXFAST       1       /* set size of blocks to be fast */
 #endif
@@ -90,27 +89,22 @@
 #define M_KEEP         4       /* retain contents of block after a free */
                           /* until another allocation */
 #endif
-#ifndef HAVE_STRUCT_MALLINFO
-struct mallinfo {
-       int arena;              /* total space in arena */
-       int ordblks;            /* number of ordinary blocks */
-       int smblks;             /* number of small blocks */
-       int hblks;              /* number of holding blocks */
-       int hblkhd;             /* space in holding block headers */
-       int usmblks;            /* space in small blocks in use */
-       int fsmblks;            /* space in free small blocks */
-       int uordblks;           /* space in ordinary blocks in use */
-       int fordblks;           /* space in free ordinary blocks */
-       int keepcost;           /* cost of enabling keep option */
-};
-#endif
 
-#define mallinfo()             {0}
-#define mallopt(cmd,value)     0
-
-#endif /* ! HAVE_MALLINFO */
+/* our version of struct mallinfo */
+struct Mallinfo {
+       size_t arena;           /* total space in arena */
+       size_t ordblks;         /* number of ordinary blocks */
+       size_t smblks;          /* number of small blocks */
+       size_t hblks;           /* number of holding blocks */
+       size_t hblkhd;          /* space in holding block headers */
+       size_t usmblks;         /* space in small blocks in use */
+       size_t fsmblks;         /* space in free small blocks */
+       size_t uordblks;        /* space in ordinary blocks in use */
+       size_t fordblks;        /* space in free ordinary blocks */
+       size_t keepcost;        /* cost of enabling keep option */
+};
 
-gdk_export struct mallinfo MT_mallinfo(void);
+gdk_export struct Mallinfo MT_mallinfo(void);
 
 @- locking, sleep
 @h
@@ -1122,13 +1116,25 @@
        return ret;
 }
 
-struct mallinfo
+struct Mallinfo
 MT_mallinfo(void)
 {
-       struct mallinfo _ret;
+       struct Mallinfo _ret;
 
-#ifdef HAVE_MALLINFO
-       _ret = mallinfo();
+#ifdef HAVE_USEFUL_MALLINFO
+       struct mallinfo m;
+
+       m = mallinfo();
+       _ret.arena = m.arena;
+       _ret.ordblks = m.ordblks;
+       _ret.smblks = m.smblks;
+       _ret.hblks = m.hblks;
+       _ret.hblkhd = m.hblkhd;
+       _ret.usmblks = m.usmblks;
+       _ret.fsmblks = m.fsmblks;
+       _ret.uordblks = m.uordblks;
+       _ret.fordblks = m.fordblks;
+       _ret.keepcost = m.keepcost;
 #else
        memset(&_ret, 0, sizeof(_ret));
 #endif
@@ -1427,17 +1433,16 @@
 #define _HEAPBADPTR     (-6)
 #endif
 
-struct mallinfo
+struct Mallinfo
 MT_mallinfo(void)
 {
-       struct mallinfo _ret;
+       struct Mallinfo _ret;
        _HEAPINFO hinfo;
        int heapstatus;
 
        hinfo._pentry = NULL;
-       memset(&_ret, 0, sizeof(struct mallinfo));
+       memset(&_ret, 0, sizeof(_ret));
 
-/* 64bit: mallinfo uses ints which won't work on 64 bit platforms */
        while ((heapstatus = _heapwalk(&hinfo)) == _HEAPOK) {
                _ret.arena += hinfo._size;
                if (hinfo._size > MT_SMALLBLOCK) {

Index: gdk_utils.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_utils.mx,v
retrieving revision 1.206.2.1
retrieving revision 1.206.2.2
diff -u -d -r1.206.2.1 -r1.206.2.2
--- gdk_utils.mx        9 Feb 2008 15:38:11 -0000       1.206.2.1
+++ gdk_utils.mx        12 Feb 2008 09:23:31 -0000      1.206.2.2
@@ -511,22 +511,14 @@
 }
 
 volatile int GDK_heapcheck_last = 0;
-int mallinfo_ok = 1;
 
 static INLINE void
 GDKmem_heapcheck(int t)
 {
        /* correct heap estimate with the real thing */
-       if (mallinfo_ok) {
-               struct mallinfo m = MT_mallinfo();
+       struct Mallinfo m = MT_mallinfo();
 
-#if ((SIZEOF_VOID_P==8) && defined(HAVE_SIGNED_MALLINFO))
-               if (m.usmblks < 0 || m.uordblks < 0 || m.hblkhd < 0)
-                       mallinfo_ok = 0;        /* incredible POSIX 
incompetence!! non-64-bit safe mallinfo */
-               else
-#endif
-                       GDK_mallocedbytes_estimate = (size_t) (m.usmblks + 
m.uordblks + m.hblkhd);
-       }
+       GDK_mallocedbytes_estimate = (size_t) (m.usmblks + m.uordblks + 
m.hblkhd);
        GDK_heapcheck_last = t;
 }
 
@@ -624,7 +616,7 @@
 static void
 GDKmemdump(void)
 {
-       struct mallinfo m = MT_mallinfo();
+       struct Mallinfo m = MT_mallinfo();
 
        THRprintf(GDKout, "\n#mallinfo.arena = " SSZFMT "\n", (ssize_t) 
m.arena);
        THRprintf(GDKout, "#mallinfo.ordblks = " SSZFMT "\n", (ssize_t) 
m.ordblks);
@@ -967,7 +959,7 @@
 these redirected blocks.
 @end table
 
-64-bits update: POSIX mallinfo is severely broken, as it uses int-s for memory 
sizes!!
+64-bits update: Some 64-bit implementations (Linux) of mallinfo is severely 
broken, as they use int-s for memory sizes!!
 This causes corruption of mallinfo stats. As we depend on those, we should 
keep the
 malloc arena small. Thus, VM redirection is now quickly applied: for all 
mallocs > 1MB.
 @{


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to