diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-16 18:56:52 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-06-16 18:56:52 (GMT) |
commit | 32336040a288858b1775817ea8c0b5d0bfc23517 (patch) | |
tree | 50f92ab448a0c71acf2d2594cbfc21b65f0a3d59 /src/H5HG.c | |
parent | 2b81894af7cad966189d2b1303d3814f33f1e196 (diff) | |
download | hdf5-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/H5HG.c')
-rw-r--r-- | src/H5HG.c | 62 |
1 files changed, 46 insertions, 16 deletions
@@ -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; |