Changeset: 6f87a4f5853b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6f87a4f5853b
Modified Files:
        gdk/gdk.h
        gdk/gdk_atoms.c
        gdk/gdk_bat.c
        gdk/gdk_heap.c
        gdk/gdk_storage.c
        gdk/gdk_utils.c
Branch: Feb2013
Log Message:

Get rid of difference between heap maxsize and size values.
Since we don't use anonymous virtual memory anymore (MT_vmalloc), we
don't use reserved memory maps anymore, and hence the distinction
between the maxsize (reserved address space) and size (allocate
memory) was lost.  We now make sure they are the same.
maxsize is to be removed in the default branch.


diffs (201 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -617,7 +617,7 @@ typedef enum {
 } storage_t;
 
 typedef struct {
-       size_t maxsize;         /* maximum realloc size (bytes) */
+       size_t maxsize;         /* deprecated: kept equal to size */
        size_t free;            /* index where free area starts. */
        size_t size;            /* size of the heap (bytes) */
        char *base;             /* base pointer in memory. */
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -1182,11 +1182,6 @@ strPut(Heap *h, var_t *dst, const char *
                        GDKerror("strPut: string heaps gets larger than " SZFMT 
"GB.\n", (((size_t) VAR_MAX) << GDK_VARSHIFT) >> 30);
                        return 0;
                }
-               if (h->free + pad + len + extralen < h->maxsize) {
-                       /* if there is reserved space, first use the
-                        * reserved space */
-                       newsize = MIN(newsize, h->maxsize);
-               }
                HEAPDEBUG fprintf(stderr, "#HEAPextend in strPut %s " SZFMT " " 
SZFMT "\n", h->filename, h->size, newsize);
                if (HEAPextend(h, newsize) < 0) {
                        return 0;
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2805,7 +2805,7 @@ BATassertHeadProps(BAT *b)
        p = BUNfirst(b);
        q = BUNlast(b);
 
-       assert(b->H->heap.size <= b->H->heap.maxsize);
+       assert(b->H->heap.size == b->H->heap.maxsize);
        if (b->htype != TYPE_void) {
                assert(b->batCount <= b->batCapacity);
                assert(b->H->heap.size >= b->H->heap.free);
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -252,24 +252,6 @@ decompose_filename(str nme)
  * seek. This is fast, and leads to files-with-holes on Unixes (on
  * Windows, it actually always performs I/O which is not nice).
  */
-static size_t
-HEAPmargin(size_t maxsize)
-{
-       size_t ret;
-#if SIZEOF_VOID_P == 8
-       /* in 64-bits systems, try to enforce in-place realloc, but
-        * provoke the memcpy on 256MB, then 4GB */
-       size_t use = GDKvm_cursize();
-       ret = MIN(GDK_mem_maxsize, MAX(((size_t) 1) << 26, 16 * maxsize));
-       if ((ret + ret) > (GDK_vm_maxsize - MIN(GDK_vm_maxsize, use)))  /* only 
if room */
-#endif
-               ret = ((size_t) (((double) BATMARGIN) * (double) maxsize)) - 1; 
/* do not waste VM on 32-bits */
-       HEAPDEBUG fprintf(stderr, "#HEAPmargin " SZFMT " -> " SZFMT "\n",
-                         maxsize, (1 + (MAX(maxsize, ret) >> 16)) << 16);
-       return (1 + (MAX(maxsize, ret) >> 16)) << 16;   /* round up to 64K */
-}
-
-/* in 64-bits space, use very large margins to accommodate reallocations */
 int
 HEAPalloc(Heap *h, size_t nitems, size_t itemsize)
 {
@@ -302,7 +284,8 @@ HEAPalloc(Heap *h, size_t nitems, size_t
 
        if (h->filename == NULL || (h->size < minsize)) {
                h->storage = STORE_MEM;
-               h->base = (char *) GDKmallocmax(h->size, &h->maxsize, 0);
+               h->base = (char *) GDKmallocmax(h->size, &h->size, 0);
+               h->maxsize = h->size;
                HEAPDEBUG fprintf(stderr, "#HEAPalloc " SZFMT " " SZFMT " " 
PTRFMT "\n", h->size, h->maxsize, PTRFMTCAST h->base);
        }
        if (h->filename && h->base == NULL) {
@@ -312,7 +295,8 @@ HEAPalloc(Heap *h, size_t nitems, size_t
 
                if (stat(nme, &st) != 0) {
                        h->storage = STORE_MMAP;
-                       h->base = HEAPcacheFind(&h->maxsize, of, h->storage);
+                       h->base = HEAPcacheFind(&h->size, of, h->storage);
+                       h->maxsize = h->size;
                        h->filename = of;
                } else {
                        char *ext;
@@ -400,23 +384,16 @@ HEAPextend(Heap *h, size_t size)
                 * of anonymous MMAP in GDKmalloc */
                int must_mmap = can_mmap && (small_cpy || exceeds_swap || 
h->newstorage != STORE_MEM || size >= GDK_mem_bigsize);
 
-               h->size = size;
-
-               if (can_mmap) {
-                       /* in anonymous vm, if have to realloc anyway,
-                        * we reserve some extra space */
-                       h->maxsize = HEAPmargin(MAX(size, h->maxsize));
-               } else {
-                       h->maxsize = size;      /* for normal GDKmalloc, 
maxsize = size */
-               }
+               h->maxsize = h->size = size;
 
                /* try GDKrealloc if the heap size stays within
                 * reasonable limits */
                if (!must_mmap) {
                        void *p = h->base;
                        h->newstorage = h->storage = STORE_MEM;
-                       h->base = GDKreallocmax(h->base, size, &h->maxsize, 0);
-                       HEAPDEBUG fprintf(stderr, "#HEAPextend: extending 
malloced heap " SZFMT " " SZFMT " " PTRFMT " " PTRFMT "\n", size, h->maxsize, 
PTRFMTCAST p, PTRFMTCAST h->base);
+                       h->base = GDKreallocmax(h->base, size, &h->size, 0);
+                       h->maxsize = h->size;
+                       HEAPDEBUG fprintf(stderr, "#HEAPextend: extending 
malloced heap " SZFMT " " SZFMT " " PTRFMT " " PTRFMT "\n", size, h->size, 
PTRFMTCAST p, PTRFMTCAST h->base);
                        if (h->base)
                                return 0;
                }
@@ -444,8 +421,9 @@ HEAPextend(Heap *h, size_t size)
                                if (h->filename == NULL)
                                        goto failed;
                                sprintf(h->filename, "%s.%s", nme, ext);
-                               h->base = HEAPcacheFind(&h->maxsize, 
h->filename, STORE_MMAP);
+                               h->base = HEAPcacheFind(&h->size, h->filename, 
STORE_MMAP);
                                if (h->base) {
+                                       h->maxsize = h->size;
                                        h->newstorage = h->storage = STORE_MMAP;
                                        memcpy(h->base, bak.base, bak.free);
                                        HEAPfree(&bak);
@@ -618,7 +596,7 @@ HEAPfree_(Heap *h, int free_file)
                        HEAPDEBUG fprintf(stderr, "#HEAPfree " SZFMT " " SZFMT 
" " PTRFMT "\n", h->size, h->maxsize, PTRFMTCAST h->base);
                        GDKfree(h->base);
                } else {        /* mapped file, or STORE_PRIV */
-                       int ret = HEAPcacheAdd(h->base, h->maxsize, 
h->filename, h->storage, free_file);
+                       int ret = HEAPcacheAdd(h->base, h->size, h->filename, 
h->storage, free_file);
 
                        if (ret < 0) {
                                GDKsyserror("HEAPfree: %s was not mapped\n", 
h->filename);
@@ -627,7 +605,7 @@ HEAPfree_(Heap *h, int free_file)
                        HEAPDEBUG fprintf(stderr,
                                          "#munmap(base=" PTRFMT ", size=" 
SZFMT ") = %d\n",
                                          PTRFMTCAST(void *)h->base,
-                                         h->maxsize, ret);
+                                         h->size, ret);
                }
        }
        h->base = NULL;
@@ -671,10 +649,8 @@ HEAPload_intern(Heap *h, const char *nme
 
        /* round up mmap heap sizes to REMAP_PAGE_MAXSIZE (usually
         * 512KB) segments */
-       if ((h->storage != STORE_MEM) && (minsize != h->size)) {
-               h->size = minsize;
-               h->maxsize = MAX(minsize, h->maxsize);
-       }
+       if (h->storage != STORE_MEM && minsize != h->size)
+               h->maxsize = h->size = minsize;
 
        /* when a bat is made read-only, we can truncate any unused
         * space at the end of the heap */
@@ -826,7 +802,7 @@ size_t
 HEAPvmsize(Heap *h)
 {
        if (h && h->free)
-               return h->maxsize;
+               return h->size;
        return 0;
 }
 
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -358,12 +358,16 @@ GDKsave(const char *nme, const char *ext
  * Space for the load is directly allocated and the heaps are mapped.
  * Further initialization of the atom heaps require a separate action
  * defined in their implementation.
+ *
+ * size -- how much to read
+ * maxsize -- how much to allocate
  */
 char *
 GDKload(const char *nme, const char *ext, size_t size, size_t maxsize, 
storage_t mode)
 {
        char *ret = NULL;
 
+       assert(size <= maxsize);
        IODEBUG {
                THRprintf(GDKstdout, "#GDKload: name=%s, ext=%s, mode %d\n", 
nme, ext ? ext : "", (int) mode);
        }
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -693,9 +693,8 @@ GDKmallocmax(size_t size, size_t *maxsiz
 void *
 GDKmalloc(size_t size)
 {
-       size_t maxsize = size;
-       void *p = GDKmallocmax(size, &maxsize, 0);
-       ALLOCDEBUG fprintf(stderr, "#GDKmalloc " SZFMT " " SZFMT " " PTRFMT 
"\n", size, maxsize, PTRFMTCAST p);
+       void *p = GDKmallocmax(size, &size, 0);
+       ALLOCDEBUG fprintf(stderr, "#GDKmalloc " SZFMT " " PTRFMT "\n", size, 
PTRFMTCAST p);
 #ifndef NDEBUG
        DEADBEEFCHK if (p)
                memset(p, 0xBD, size);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to