summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-06-16 18:56:52 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-06-16 18:56:52 (GMT)
commit32336040a288858b1775817ea8c0b5d0bfc23517 (patch)
tree50f92ab448a0c71acf2d2594cbfc21b65f0a3d59 /src
parent2b81894af7cad966189d2b1303d3814f33f1e196 (diff)
downloadhdf5-32336040a288858b1775817ea8c0b5d0bfc23517.zip
hdf5-32336040a288858b1775817ea8c0b5d0bfc23517.tar.gz
hdf5-32336040a288858b1775817ea8c0b5d0bfc23517.tar.bz2
[svn-r8696] Purpose:
Code optimizations Description: Eliminate memset() call in H5S_set_extent_simple(). Use malloc() instead of calloc in H5B<mumble>. Change global heap code to track heap objects that are in use in order to allocate new objects more quickly and also to avoid memset() and calloc() calls. Platforms tested: Solaris 2.7 (arabica) FreeBSD 4.10 (sleipnir) w/parallel Too minor to require h5committest
Diffstat (limited to 'src')
-rw-r--r--src/H5B.c2
-rw-r--r--src/H5HG.c62
-rw-r--r--src/H5HGpkg.h4
-rw-r--r--src/H5S.c5
4 files changed, 54 insertions, 19 deletions
diff --git a/src/H5B.c b/src/H5B.c
index dff894d..5f7735b 100644
--- a/src/H5B.c
+++ b/src/H5B.c
@@ -249,7 +249,7 @@ H5B_create(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, void *udata,
bt->left = HADDR_UNDEF;
bt->right = HADDR_UNDEF;
bt->nchildren = 0;
- if (NULL==(bt->page=H5FL_BLK_CALLOC(page,size)) ||
+ if (NULL==(bt->page=H5FL_BLK_MALLOC(page,size)) ||
NULL==(bt->native=H5FL_BLK_MALLOC(native_block,total_native_keysize)) ||
NULL==(bt->child=H5FL_SEQ_MALLOC(haddr_t,(size_t)(2*H5F_KVALUE(f,type)))) ||
NULL==(bt->key=H5FL_SEQ_MALLOC(H5B_key_t,(size_t)(2*H5F_KVALUE(f,type)+1))))
diff --git a/src/H5HG.c b/src/H5HG.c
index 5c7a6a0..01f7a5d 100644
--- a/src/H5HG.c
+++ b/src/H5HG.c
@@ -69,7 +69,8 @@
/*
* Limit global heap collections to the some reasonable size. This is
- * fairly arbitrary...
+ * fairly arbitrary, but needs to be small enough that no more than H5HG_MAXIDX
+ * objects will be allocated from a single heap.
*/
#define H5HG_MAXSIZE 65536
@@ -85,6 +86,11 @@
#define H5HG_MAXLINK 65535
/*
+ * The maximum number of indices allowed in a global heap object.
+ */
+#define H5HG_MAXIDX 65535
+
+/*
* The size of the collection header, always a multiple of the alignment so
* that the stuff that follows the header is aligned.
*/
@@ -202,7 +208,8 @@ H5HG_create (H5F_t *f, hid_t dxpl_id, size_t size)
if (NULL==(heap->chunk = H5FL_BLK_MALLOC (heap_chunk,size)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
heap->nalloc = H5HG_NOBJS (f, size);
- if (NULL==(heap->obj = H5FL_SEQ_CALLOC (H5HG_obj_t,heap->nalloc)))
+ heap->next_idx = 1; /* skip index 0, which is used for the free object */
+ if (NULL==(heap->obj = H5FL_SEQ_MALLOC (H5HG_obj_t,heap->nalloc)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
/* Initialize the header */
@@ -220,18 +227,25 @@ H5HG_create (H5F_t *f, hid_t dxpl_id, size_t size)
* align the pointer, but this might not be the case.
*/
n = H5HG_ALIGN(p-heap->chunk) - (p-heap->chunk);
+#ifdef OLD_WAY
+/* Don't bother zeroing out the rest of the info in the heap -QAK */
HDmemset(p, 0, n);
+#endif /* OLD_WAY */
p += n;
/* The freespace object */
heap->obj[0].size = size - H5HG_SIZEOF_HDR(f);
assert(H5HG_ISALIGNED(heap->obj[0].size));
+ heap->obj[0].nrefs = 0;
heap->obj[0].begin = p;
UINT16ENCODE(p, 0); /*object ID*/
UINT16ENCODE(p, 0); /*reference count*/
UINT32ENCODE(p, 0); /*reserved*/
H5F_ENCODE_LENGTH (f, p, heap->obj[0].size);
+#ifdef OLD_WAY
+/* Don't bother zeroing out the rest of the info in the heap -QAK */
HDmemset (p, 0, (size_t)((heap->chunk+heap->size) - p));
+#endif /* OLD_WAY */
/* Add the heap to the cache */
if (H5AC_set (f, dxpl_id, H5AC_GHEAP, addr, heap)<0)
@@ -287,10 +301,11 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
void UNUSED * udata2)
{
H5HG_heap_t *heap = NULL;
- H5HG_heap_t *ret_value = NULL;
uint8_t *p = NULL;
int i;
size_t nalloc, need;
+ size_t max_idx=0; /* The maximum index seen */
+ H5HG_heap_t *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI(H5HG_load, NULL);
@@ -340,8 +355,11 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
/* Decode each object */
p = heap->chunk + H5HG_SIZEOF_HDR (f);
nalloc = H5HG_NOBJS (f, heap->size);
- if (NULL==(heap->obj = H5FL_SEQ_CALLOC (H5HG_obj_t,nalloc)))
+ if (NULL==(heap->obj = H5FL_SEQ_MALLOC (H5HG_obj_t,nalloc)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ heap->obj[0].size=heap->obj[0].nrefs=0;
+ heap->obj[0].begin=NULL;
+
heap->nalloc = nalloc;
while (p<heap->chunk+heap->size) {
if (p+H5HG_SIZEOF_OBJHDR(f)>heap->chunk+heap->size) {
@@ -371,17 +389,11 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
if (NULL==(new_obj = H5FL_SEQ_REALLOC (H5HG_obj_t, heap->obj, new_alloc)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- /* Reset new objects to zero */
- HDmemset(&new_obj[heap->nalloc],0,sizeof(H5HG_obj_t)*(new_alloc-heap->nalloc));
-
/* Update heap information */
heap->nalloc=new_alloc;
heap->obj=new_obj;
} /* end if */
- /* Check that we haven't double-allocated an index */
- assert (NULL==heap->obj[idx].begin);
-
UINT16DECODE (p, heap->obj[idx].nrefs);
p += 4; /*reserved*/
H5F_DECODE_LENGTH (f, p, heap->obj[idx].size);
@@ -394,6 +406,11 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
*/
if (idx>0) {
need = H5HG_SIZEOF_OBJHDR(f) + H5HG_ALIGN(heap->obj[idx].size);
+
+ /* Check for "gap" in index numbers (caused by deletions) and fill in heap object values */
+ if(idx>(max_idx+1))
+ HDmemset(&heap->obj[max_idx+1],0,sizeof(H5HG_obj_t)*(idx-(max_idx+1)));
+ max_idx=idx;
} else {
need = heap->obj[idx].size;
}
@@ -403,6 +420,12 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
assert(p==heap->chunk+heap->size);
assert(H5HG_ISALIGNED(heap->obj[0].size));
+ /* Set the next index value to use */
+ if(max_idx>0)
+ heap->next_idx=max_idx+1;
+ else
+ heap->next_idx=1;
+
/*
* Add the new heap to the CWFS list, removing some other entry if
* necessary to make room. We remove the right-most entry that has less
@@ -606,9 +629,14 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size)
* Find an ID for the new object. ID zero is reserved for the free space
* object.
*/
- for (idx=1; idx<heap->nalloc; idx++)
- if (NULL==heap->obj[idx].begin)
- break;
+ if(heap->next_idx<H5HG_MAXIDX) {
+ idx=heap->next_idx++;
+ } /* end if */
+ else {
+ for (idx=1; idx<heap->nalloc; idx++)
+ if (NULL==heap->obj[idx].begin)
+ break;
+ } /* end else */
/* Check if we need more room to store heap objects */
if(idx>=heap->nalloc) {
@@ -617,17 +645,16 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size)
/* Determine the new number of objects to index */
new_alloc=MAX(heap->nalloc*2,(idx+1));
+ assert(new_alloc<=(H5HG_MAXIDX+1));
/* Reallocate array of objects */
if (NULL==(new_obj = H5FL_SEQ_REALLOC (H5HG_obj_t, heap->obj, new_alloc)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed");
- /* Reset new objects to zero */
- HDmemset(&new_obj[heap->nalloc],0,sizeof(H5HG_obj_t)*(new_alloc-heap->nalloc));
-
/* Update heap information */
heap->nalloc=new_alloc;
heap->obj=new_obj;
+ assert(heap->nalloc>heap->next_idx);
} /* end if */
/* Initialize the new object */
@@ -871,8 +898,11 @@ H5HG_insert (H5F_t *f, hid_t dxpl_id, size_t size, void *obj, H5HG_t *hobj/*out*
/* Copy data into the heap */
if(size>0) {
HDmemcpy(heap->obj[idx].begin+H5HG_SIZEOF_OBJHDR(f), obj, size);
+#ifdef OLD_WAY
+/* Don't bother zeroing out the rest of the info in the heap -QAK */
HDmemset(heap->obj[idx].begin+H5HG_SIZEOF_OBJHDR(f)+size, 0,
need-(H5HG_SIZEOF_OBJHDR(f)+size));
+#endif /* OLD_WAY */
} /* end if */
heap->cache_info.dirty = TRUE;
diff --git a/src/H5HGpkg.h b/src/H5HGpkg.h
index ee029c4..8eb56e6 100644
--- a/src/H5HGpkg.h
+++ b/src/H5HGpkg.h
@@ -81,6 +81,10 @@ struct H5HG_heap_t {
size_t size; /*total size of collection */
uint8_t *chunk; /*the collection, incl. header */
size_t nalloc; /*numb object slots allocated */
+ size_t next_idx; /* Object index to use next */
+ /* If this value is >65535 then all indices */
+ /* have been used at some time and the */
+ /* correct new index should be searched for */
H5HG_obj_t *obj; /*array of object descriptions */
};
diff --git a/src/H5S.c b/src/H5S.c
index 152d6a0..0de9190 100644
--- a/src/H5S.c
+++ b/src/H5S.c
@@ -1328,6 +1328,7 @@ static herr_t
H5S_set_extent_simple (H5S_t *space, unsigned rank, const hsize_t *dims,
const hsize_t *max)
{
+ unsigned u; /* Local index variable */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_set_extent_simple, FAIL);
@@ -1346,7 +1347,6 @@ H5S_set_extent_simple (H5S_t *space, unsigned rank, const hsize_t *dims,
space->extent.rank = 0; /* set to scalar rank */
} else {
hsize_t nelem; /* Number of elements in extent */
- unsigned u; /* Local index variable */
space->extent.type = H5S_SIMPLE;
@@ -1371,7 +1371,8 @@ H5S_set_extent_simple (H5S_t *space, unsigned rank, const hsize_t *dims,
/* Selection related cleanup */
/* Set offset to zeros */
- HDmemset(space->select.offset,0,sizeof(hssize_t)*rank);
+ for(u=0; u<space->extent.rank; u++)
+ space->select.offset[u]=0;
/* If the selection is 'all', update the number of elements selected */
if(H5S_GET_SELECT_TYPE(space)==H5S_SEL_ALL)