summaryrefslogtreecommitdiffstats
path: root/src/H5HL.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5HL.c')
-rw-r--r--src/H5HL.c139
1 files changed, 50 insertions, 89 deletions
diff --git a/src/H5HL.c b/src/H5HL.c
index a69eb16..6be0bbc 100644
--- a/src/H5HL.c
+++ b/src/H5HL.c
@@ -117,10 +117,10 @@ H5FL_BLK_DEFINE(lheap_chunk);
herr_t
H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
{
- H5HL_t *heap = NULL;
- hsize_t total_size; /*total heap size on disk */
+ H5HL_t *heap = NULL; /* Heap created */
+ hsize_t total_size; /* Total heap size on disk */
size_t sizeof_hdr; /* Cache H5HL header size for file */
- herr_t ret_value = SUCCEED;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HL_create, FAIL)
@@ -128,6 +128,7 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
HDassert(f);
HDassert(addr_p);
+ /* Adjust size hint as necessary */
if(size_hint && size_hint < H5HL_SIZEOF_FREE(f))
size_hint = H5HL_SIZEOF_FREE(f);
size_hint = H5HL_ALIGN(size_hint);
@@ -135,23 +136,23 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
/* Cache this for later */
sizeof_hdr = H5HL_SIZEOF_HDR(f);
- /* allocate file version */
+ /* Allocate file version */
total_size = sizeof_hdr + size_hint;
if(HADDR_UNDEF == (*addr_p = H5MF_alloc(f, H5FD_MEM_LHEAP, dxpl_id, total_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate file memory")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "unable to allocate file memory")
/* allocate memory version */
if(NULL == (heap = H5FL_CALLOC(H5HL_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
heap->addr = *addr_p + (hsize_t)sizeof_hdr;
heap->heap_alloc = size_hint;
if(NULL == (heap->chunk = H5FL_BLK_CALLOC(lheap_chunk, (sizeof_hdr + size_hint))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
/* free list */
if(size_hint) {
if(NULL == (heap->freelist = H5FL_MALLOC(H5HL_free_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
heap->freelist->offset = 0;
heap->freelist->size = size_hint;
heap->freelist->prev = heap->freelist->next = NULL;
@@ -159,7 +160,7 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
else
heap->freelist = NULL;
- /* add to cache */
+ /* Add to cache */
if(H5AC_set(f, dxpl_id, H5AC_LHEAP, *addr_p, heap, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "unable to cache heap")
@@ -168,8 +169,8 @@ done:
if(H5F_addr_defined(*addr_p))
H5MF_xfree(f, H5FD_MEM_LHEAP, dxpl_id, *addr_p, total_size);
if(heap)
- if(H5HL_dest(f,heap) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to destroy local heap collection")
+ if(H5HL_dest(f, heap) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to destroy local heap")
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -196,7 +197,7 @@ H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap)
{
size_t new_heap_size = heap->heap_alloc; /* New size of heap */
size_t sizeof_hdr;
- herr_t ret_value = SUCCEED;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HL_minimize_heap_space, FAIL)
@@ -255,8 +256,9 @@ H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap)
/* Truncate the free block */
last_fl->size = H5HL_ALIGN(new_heap_size - last_fl->offset);
new_heap_size = last_fl->offset + last_fl->size;
- assert(last_fl->size >= H5HL_SIZEOF_FREE(f));
- } else {
+ HDassert(last_fl->size >= H5HL_SIZEOF_FREE(f));
+ } /* end if */
+ else {
/*
* Set the size of the memory buffer to the start
* of the free list
@@ -266,12 +268,13 @@ H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap)
/* Eliminate the free block from the list */
last_fl = H5HL_remove_free(heap, last_fl);
} /* end else */
- } else {
+ } /* end if */
+ else {
/* Truncate the free block */
last_fl->size = H5HL_ALIGN(new_heap_size - last_fl->offset);
new_heap_size = last_fl->offset + last_fl->size;
- assert(last_fl->size >= H5HL_SIZEOF_FREE(f));
- assert(last_fl->size == H5HL_ALIGN(last_fl->size));
+ HDassert(last_fl->size >= H5HL_SIZEOF_FREE(f));
+ HDassert(last_fl->size == H5HL_ALIGN(last_fl->size));
} /* end else */
} /* end if */
} /* end if */
@@ -289,9 +292,8 @@ H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap)
HDassert(new_heap_size < heap->heap_alloc);
/* Resize the memory buffer */
- heap->chunk = H5FL_BLK_REALLOC(lheap_chunk, heap->chunk, (sizeof_hdr + new_heap_size));
- if(!heap->chunk)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ if(NULL == (heap->chunk = H5FL_BLK_REALLOC(lheap_chunk, heap->chunk, (sizeof_hdr + new_heap_size))))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
/* Release old space on disk */
/* (Should be safe to free old heap space first, since it's shrinking -QAK) */
@@ -302,7 +304,7 @@ H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap)
/* Allocate new space on disk */
H5_CHECK_OVERFLOW(new_heap_size, size_t, hsize_t);
if(HADDR_UNDEF == (new_addr = H5MF_alloc(f, H5FD_MEM_LHEAP, dxpl_id, (hsize_t)new_heap_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate file space for heap")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTRESIZE, FAIL, "reallocating data block failed")
/* Update heap info*/
heap->addr = new_addr;
@@ -486,7 +488,7 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t buf_size, const void *
size_t sizeof_hdr; /* Cache H5HL header size for file */
size_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5HL_insert, (size_t)(-1))
+ FUNC_ENTER_NOAPI(H5HL_insert, UFAIL)
/* check arguments */
HDassert(f);
@@ -501,7 +503,7 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t buf_size, const void *
* if an error occurs -QAK)
*/
if(H5AC_mark_pinned_or_protected_entry_dirty(f, heap) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTMARKDIRTY, (size_t)(-1), "unable to mark heap as dirty")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTMARKDIRTY, UFAIL, "unable to mark heap as dirty")
/* Cache this for later */
sizeof_hdr = H5HL_SIZEOF_HDR(f);
@@ -566,45 +568,6 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t buf_size, const void *
need_more = need_size;
new_heap_alloc = heap->heap_alloc + need_more;
-#if 0 /* JRM */ /* delete this once we are convinced that the general
- * fix will do the job.
- */
-/*
- * XXX: This is a _total_ hack, a real kludge. :-/ The metadata cache currently
- * responds very poorly when an object is inserted into the cache (or
- * resized) that is larger than the current cache size. It waits through
- * an entire 'epoch' of cache operations to resize the cache larger (getting
- * _very_ poor performance), instead of immediately accommodating the large
- * object by increasing the cache size.
- *
- * So, what we are doing here is to look at the current cache size, check
- * if the new local heap will overwhelm the cache and, if so, resize the
- * cache to be large enough to hold the new local heap block along with
- * leaving room for other objects in the cache.
- *
- * John will be working on a fix inside the cache itself, so this special
- * case code here can be removed when he's finished. - QAK, 2007/12/21
- */
-{
- H5AC_cache_config_t mdc_config;
-
- /* Retrieve the current cache information */
- mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION;
- if(H5AC_get_cache_auto_resize_config(f->shared->cache, &mdc_config) < 0)
- HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, (size_t)-1, "H5AC_get_cache_auto_resize_config() failed.")
-
- /* Check if the current cache will get blown out by adding this heap
- * block and resize it if so.
- */
- if((2 * new_heap_alloc) >= mdc_config.initial_size) {
- mdc_config.set_initial_size = TRUE;
- mdc_config.initial_size = 2 * new_heap_alloc;
-
- if(H5AC_set_cache_auto_resize_config(f->shared->cache, &mdc_config) < 0)
- HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, (size_t)-1, "H5AC_set_cache_auto_resize_config() failed.")
- } /* end if */
-}
-#endif /* JRM */
HDassert(heap->heap_alloc < new_heap_alloc);
H5_CHECK_OVERFLOW(heap->heap_alloc, size_t, hsize_t);
H5_CHECK_OVERFLOW(new_heap_alloc, size_t, hsize_t);
@@ -612,17 +575,17 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t buf_size, const void *
/* Extend current heap if possible */
extended = H5MF_try_extend(f, dxpl_id, H5FD_MEM_LHEAP, heap->addr, (hsize_t)(heap->heap_alloc), (hsize_t)need_more);
if(extended < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, (size_t)(-1), "error trying to extend heap")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, UFAIL, "error trying to extend heap")
/* If we couldn't extend the heap, release old chunk and allocate a new one */
if(extended == FALSE) {
/* Release old space on disk */
if(H5MF_xfree(f, H5FD_MEM_LHEAP, dxpl_id, heap->addr, (hsize_t)heap->heap_alloc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, (size_t)(-1), "unable to free local heap")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, UFAIL, "unable to free local heap")
/* allocate new disk space for the heap */
if((heap->addr = H5MF_alloc(f, H5FD_MEM_LHEAP, dxpl_id, (hsize_t)new_heap_alloc)) == HADDR_UNDEF)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, (size_t)(-1), "unable to allocate file space for heap")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, UFAIL, "unable to allocate file space for heap")
} /* end if */
/* If the last free list in the heap is at the end of the heap, extend it */
@@ -661,7 +624,8 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t buf_size, const void *
HDassert(fl->size == H5HL_ALIGN(fl->size));
fl->prev = NULL;
fl->next = heap->freelist;
- if (heap->freelist) heap->freelist->prev = fl;
+ if(heap->freelist)
+ heap->freelist->prev = fl;
heap->freelist = fl;
#ifdef H5HL_DEBUG
} else if (H5DEBUG(HL) && need_more > need_size) {
@@ -681,18 +645,15 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t buf_size, const void *
}
#endif
heap->heap_alloc = new_heap_alloc;
- heap->chunk = H5FL_BLK_REALLOC(lheap_chunk, heap->chunk, (sizeof_hdr + heap->heap_alloc));
- if(NULL == heap->chunk)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, (size_t)(-1), "memory allocation failed")
+ if(NULL == (heap->chunk = H5FL_BLK_REALLOC(lheap_chunk, heap->chunk, (sizeof_hdr + heap->heap_alloc))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "memory allocation failed")
/* Clear new section so junk doesn't appear in the file */
/* (Avoid clearing section which will be overwritten with newly inserted data) */
HDmemset(heap->chunk + sizeof_hdr + offset + buf_size, 0, (new_heap_alloc - (offset + buf_size)));
} /* end if */
- /*
- * Copy the data into the heap
- */
+ /* Copy the data into the heap */
HDmemcpy(heap->chunk + sizeof_hdr + offset, buf, buf_size);
/* Set return value */
@@ -767,15 +728,15 @@ H5HL_remove(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t offset, size_t size)
if((offset + size) == fl->offset) {
fl->offset = offset;
fl->size += size;
- HDassert(fl->offset==H5HL_ALIGN (fl->offset));
- HDassert(fl->size==H5HL_ALIGN (fl->size));
+ HDassert(fl->offset == H5HL_ALIGN(fl->offset));
+ HDassert(fl->size == H5HL_ALIGN(fl->size));
fl2 = fl->next;
while(fl2) {
if((fl2->offset + fl2->size) == fl->offset) {
fl->offset = fl2->offset;
fl->size += fl2->size;
- HDassert(fl->offset == H5HL_ALIGN (fl->offset));
- HDassert(fl->size == H5HL_ALIGN (fl->size));
+ HDassert(fl->offset == H5HL_ALIGN(fl->offset));
+ HDassert(fl->size == H5HL_ALIGN(fl->size));
fl2 = H5HL_remove_free(heap, fl2);
if(((fl->offset + fl->size) == heap->heap_alloc ) &&
((2 * fl->size) > heap->heap_alloc )) {
@@ -795,28 +756,28 @@ H5HL_remove(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t offset, size_t size)
} else if(fl->offset + fl->size == offset) {
fl->size += size;
fl2 = fl->next;
- HDassert(fl->size==H5HL_ALIGN (fl->size));
+ HDassert(fl->size == H5HL_ALIGN(fl->size));
while(fl2) {
if(fl->offset + fl->size == fl2->offset) {
fl->size += fl2->size;
- HDassert(fl->size==H5HL_ALIGN (fl->size));
+ HDassert(fl->size == H5HL_ALIGN(fl->size));
fl2 = H5HL_remove_free(heap, fl2);
if(((fl->offset + fl->size) == heap->heap_alloc) &&
((2 * fl->size) > heap->heap_alloc)) {
if(H5HL_minimize_heap_space(f, dxpl_id, heap) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "heap size minimization failed")
- }
+ } /* end if */
HGOTO_DONE(SUCCEED);
- }
+ } /* end if */
fl2 = fl2->next;
- }
+ } /* end while */
if(((fl->offset + fl->size) == heap->heap_alloc) &&
((2 * fl->size) > heap->heap_alloc)) {
if(H5HL_minimize_heap_space(f, dxpl_id, heap) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "heap size minimization failed")
- }
+ } /* end if */
HGOTO_DONE(SUCCEED);
- }
+ } /* end if */
fl = fl->next;
} /* end while */
@@ -889,14 +850,14 @@ H5HL_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr)
/* Get heap pointer */
if(NULL == (heap = (H5HL_t *)H5AC_protect(f, dxpl_id, H5AC_LHEAP, addr, NULL, NULL, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap")
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to load heap")
/* Set the cache flags to delete the heap & free its file space */
cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG;
done:
if(heap && H5AC_unprotect(f, dxpl_id, H5AC_LHEAP, addr, heap, cache_flags) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release local heap")
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release local heap")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HL_delete() */
@@ -919,7 +880,7 @@ herr_t
H5HL_get_size(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t *size)
{
H5HL_t *heap = NULL; /* Heap to query */
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HL_get_size, FAIL)
@@ -937,7 +898,7 @@ H5HL_get_size(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t *size)
done:
if(heap && H5AC_unprotect(f, dxpl_id, H5AC_LHEAP, addr, heap, H5AC__NO_FLAGS_SET) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release local heap")
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release local heap")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HL_get_size() */
@@ -961,7 +922,7 @@ H5HL_heapsize(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t *heap_size)
{
H5HL_t *heap = NULL; /* Heap to query */
size_t local_heap_size = 0;
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HL_heapsize, FAIL)
@@ -983,7 +944,7 @@ H5HL_heapsize(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t *heap_size)
done:
if(heap && H5AC_unprotect(f, dxpl_id, H5AC_LHEAP, addr, heap, H5AC__NO_FLAGS_SET) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release local heap")
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release local heap")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HL_heapsize() */