diff options
Diffstat (limited to 'src/H5Fistore.c')
-rw-r--r-- | src/H5Fistore.c | 121 |
1 files changed, 111 insertions, 10 deletions
diff --git a/src/H5Fistore.c b/src/H5Fistore.c index 31506e6..c4728ad 100644 --- a/src/H5Fistore.c +++ b/src/H5Fistore.c @@ -33,6 +33,7 @@ #include <H5Dprivate.h> #include <H5Eprivate.h> #include <H5Fprivate.h> +#include <H5FLprivate.h> /*Free Lists */ #include <H5Iprivate.h> #include <H5MFprivate.h> #include <H5MMprivate.h> @@ -186,6 +187,103 @@ H5B_class_t H5B_ISTORE[1] = {{ } +/* Declare a free list to manage the chunk information */ +H5FL_BLK_DEFINE_STATIC(istore_chunk); + +/* Declare a free list to manage H5F_rdcc_ent_t objects */ +H5FL_DEFINE_STATIC(H5F_rdcc_ent_t); + + +/*------------------------------------------------------------------------- + * Function: H5F_istore_chunk_alloc + * + * Purpose: Allocates memory for a chunk of a dataset. This routine is used + * instead of malloc because the chunks can be kept on a free list so + * they don't thrash malloc/free as much. + * + * Return: Success: valid pointer to the chunk + * + * Failure: NULL + * + * Programmer: Quincey Koziol + * Tuesday, March 21, 2000 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5F_istore_chunk_alloc(size_t chunk_size) +{ + void *ret_value; /* Pointer to the chunk to return to the user */ + + FUNC_ENTER(H5F_istore_chunk_alloc, NULL); + + ret_value=H5FL_BLK_ALLOC(istore_chunk,chunk_size,0); + + FUNC_LEAVE(ret_value); +} /* end H5F_istore_chunk_alloc() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_istore_chunk_free + * + * Purpose: Releases memory for a chunk of a dataset. This routine is used + * instead of free because the chunks can be kept on a free list so + * they don't thrash malloc/free as much. + * + * Return: Success: NULL + * + * Failure: never fails + * + * Programmer: Quincey Koziol + * Tuesday, March 21, 2000 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5F_istore_chunk_free(void *chunk) +{ + FUNC_ENTER(H5F_istore_chunk_free, NULL); + + H5FL_BLK_FREE(istore_chunk,chunk); + + FUNC_LEAVE(NULL); +} /* end H5F_istore_chunk_free() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_istore_chunk_realloc + * + * Purpose: Resizes a chunk in chunking memory allocation system. This + * does things the straightforward, simple way, not actually using + * realloc. + * + * Return: Success: NULL + * + * Failure: never fails + * + * Programmer: Quincey Koziol + * Tuesday, March 21, 2000 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void * +H5F_istore_chunk_realloc(void *chunk, size_t new_size) +{ + void *ret_value=NULL; /* Return value */ + + FUNC_ENTER(H5F_istore_chunk_realloc, NULL); + + ret_value=H5FL_BLK_REALLOC(istore_chunk,chunk,new_size); + + FUNC_LEAVE(ret_value); +} /* end H5F_istore_chunk_realloc() */ + /*------------------------------------------------------------------------- * Function: H5F_istore_sizeof_rkey @@ -871,7 +969,7 @@ H5F_istore_flush_entry(H5F_t *f, H5F_rdcc_ent_t *ent, hbool_t reset) * for later. */ alloc = ent->chunk_size; - if (NULL==(buf = H5MM_malloc(alloc))) { + if (NULL==(buf = H5F_istore_chunk_alloc(alloc))) { HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for pipeline"); } @@ -920,14 +1018,15 @@ H5F_istore_flush_entry(H5F_t *f, H5F_rdcc_ent_t *ent, hbool_t reset) ent->layout = H5O_free(H5O_LAYOUT, ent->layout); ent->pline = H5O_free(H5O_PLINE, ent->pline); if (buf==ent->chunk) buf = NULL; - ent->chunk = H5MM_xfree(ent->chunk); + if(ent->chunk!=NULL) + ent->chunk = H5F_istore_chunk_free(ent->chunk); } ret_value = SUCCEED; done: /* Free the temp buffer only if it's different than the entry chunk */ - if (buf!=ent->chunk) H5MM_xfree(buf); + if (buf!=ent->chunk) H5F_istore_chunk_free(buf); /* * If we reached the point of no return then we have no choice but to @@ -938,7 +1037,8 @@ H5F_istore_flush_entry(H5F_t *f, H5F_rdcc_ent_t *ent, hbool_t reset) if (ret_value<0 && point_of_no_return) { ent->layout = H5O_free(H5O_LAYOUT, ent->layout); ent->pline = H5O_free(H5O_PLINE, ent->pline); - ent->chunk = H5MM_xfree(ent->chunk); + if(ent->chunk) + ent->chunk = H5F_istore_chunk_free(ent->chunk); } FUNC_LEAVE(ret_value); } @@ -993,7 +1093,7 @@ H5F_istore_preempt (H5F_t *f, H5F_rdcc_ent_t *ent) --rdcc->nused; /* Free */ - H5MM_xfree(ent); + H5FL_FREE(H5F_rdcc_ent_t, ent); FUNC_LEAVE (SUCCEED); } @@ -1291,7 +1391,7 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, chunk_size *= layout->dim[i]; } chunk_alloc = chunk_size; - if (NULL==(chunk=H5MM_malloc (chunk_alloc))) { + if (NULL==(chunk=H5F_istore_chunk_alloc (chunk_alloc))) { HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk"); } @@ -1310,7 +1410,7 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, udata.addr = HADDR_UNDEF; status = H5B_find (f, H5B_ISTORE, layout->addr, &udata); H5E_clear (); - if (NULL==(chunk = H5MM_malloc (chunk_alloc))) { + if (NULL==(chunk = H5F_istore_chunk_alloc (chunk_alloc))) { HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk"); } @@ -1386,7 +1486,7 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, } /* Create a new entry */ - ent = H5MM_malloc(sizeof(H5F_rdcc_ent_t)); + ent = H5FL_ALLOC(H5F_rdcc_ent_t,0); ent->locked = 0; ent->dirty = FALSE; ent->chunk_size = chunk_size; @@ -1471,7 +1571,7 @@ H5F_istore_lock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, ret_value = chunk; done: - if (!ret_value) H5MM_xfree (chunk); + if (!ret_value) H5F_istore_chunk_free (chunk); FUNC_LEAVE (ret_value); } @@ -1552,7 +1652,8 @@ H5F_istore_unlock(H5F_t *f, hid_t dxpl_id, const H5O_layout_t *layout, H5F_istore_flush_entry (f, &x, TRUE); } else { - H5MM_xfree (chunk); + if(chunk) + H5F_istore_chunk_free (chunk); } } else { /* |