summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2002-06-06 13:54:26 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2002-06-06 13:54:26 (GMT)
commit754f4780f236297a6a905c83cfd051361d654f8f (patch)
tree645a11b9ff5a2d7bdbba02f8ab1440dee567fdec /src
parent7292287c89df97b6d8bbe062b95b4f469e7fa9ad (diff)
downloadhdf5-754f4780f236297a6a905c83cfd051361d654f8f.zip
hdf5-754f4780f236297a6a905c83cfd051361d654f8f.tar.gz
hdf5-754f4780f236297a6a905c83cfd051361d654f8f.tar.bz2
[svn-r5542] Purpose:
Code cleanup/bug fix Description: Unused space in the file was being "dropped on the floor" when the metadata or "small data" block was moved to a new location in the file and there was unused space in the old block. Solution: Put the space left in the allocation block into the free list of space for the file. This allows it to be [potentially] reused and sometimes allows the file to be smaller. Platforms tested: Solaris 2.7 (arabica) w/FORTRAN and FreeBSD 4.5 (sleipnir) w/C++
Diffstat (limited to 'src')
-rw-r--r--src/H5F.c31
-rw-r--r--src/H5FD.c30
2 files changed, 46 insertions, 15 deletions
diff --git a/src/H5F.c b/src/H5F.c
index 961a8e9..fcf0d84 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -2311,6 +2311,10 @@ H5Fflush(hid_t object_id, H5F_scope_t scope)
* Added boot block & driver info block checksumming, to avoid
* writing them out when they haven't changed.
*
+ * Quincey Koziol, 2002-06-06
+ * Return the remainders of the metadata & "small data" blocks to
+ * the free list of blocks for the file.
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -2360,6 +2364,33 @@ H5F_flush(H5F_t *f, H5F_scope_t scope, hbool_t invalidate,
/* Avoid flushing buffers & caches when alloc_only set */
if(!alloc_only) {
+ /* If we are invalidating everything (which only happens just before
+ * the file closes), release the unused portion of the metadata and
+ * "small data" blocks back to the free lists in the file.
+ */
+ if(invalidate) {
+ if(f->shared->lf->feature_flags&H5FD_FEAT_AGGREGATE_METADATA) {
+ /* Return the unused portion of the metadata block to a free list */
+ if(f->shared->lf->eoma!=0)
+ if(H5FD_free(f->shared->lf,H5FD_MEM_DEFAULT,f->shared->lf->eoma,f->shared->lf->cur_meta_block_size)<0)
+ HRETURN_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "can't free metadata block");
+
+ /* Reset metadata block information, just in case */
+ f->shared->lf->eoma=0;
+ f->shared->lf->cur_meta_block_size=0;
+ } /* end if */
+ if(f->shared->lf->feature_flags&H5FD_FEAT_AGGREGATE_SMALLDATA) {
+ /* Return the unused portion of the "small data" block to a free list */
+ if(f->shared->lf->eosda!=0)
+ if(H5FD_free(f->shared->lf,H5FD_MEM_DRAW,f->shared->lf->eosda,f->shared->lf->cur_sdata_block_size)<0)
+ HRETURN_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "can't free 'small data' block");
+
+ /* Reset "small data" block information, just in case */
+ f->shared->lf->eosda=0;
+ f->shared->lf->cur_sdata_block_size=0;
+ } /* end if */
+ } /* end if */
+
/* flush the data sieve buffer, if we have a dirty one */
if(f->shared->sieve_buf && f->shared->sieve_dirty) {
/* Write dirty data sieve buffer to file */
diff --git a/src/H5FD.c b/src/H5FD.c
index fe43159..129b133 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -1466,12 +1466,12 @@ H5FD_alloc(H5FD_t *file, H5FD_mem_t type, hsize_t size)
file->cur_meta_block_size+=file->def_meta_block_size;
} /* end if */
else {
- /*
- * Instead of just dropping the remainder of the block on the
- * floor and leaving the space in the file unused, we should
- * return this small piece of unused space to the free list
- * management. - QAK
- */
+ /* Return the unused portion of the metadata block to a free list */
+ if(file->eoma!=0)
+ if(H5FD_free(file,H5FD_MEM_DEFAULT,file->eoma,file->cur_meta_block_size)<0)
+ HRETURN_ERROR(H5E_VFL, H5E_CANTFREE, HADDR_UNDEF, "can't free metadata block");
+
+ /* Point the metadata block at the newly allocated block */
file->eoma=new_meta;
file->cur_meta_block_size=file->def_meta_block_size;
} /* end else */
@@ -1535,12 +1535,12 @@ H5FD_alloc(H5FD_t *file, H5FD_mem_t type, hsize_t size)
file->cur_sdata_block_size+=file->def_sdata_block_size;
} /* end if */
else {
- /*
- * Instead of just dropping the remainder of the block on the
- * floor and leaving the space in the file unused, we should
- * return this small piece of unused space to the free list
- * management. - QAK
- */
+ /* Return the unused portion of the "small data" block to a free list */
+ if(file->eosda!=0)
+ if(H5FD_free(file,H5FD_MEM_DRAW,file->eosda,file->cur_sdata_block_size)<0)
+ HRETURN_ERROR(H5E_VFL, H5E_CANTFREE, HADDR_UNDEF, "can't free 'small data' block");
+
+ /* Point the "small data" block at the newly allocated block */
file->eosda=new_data;
file->cur_sdata_block_size=file->def_sdata_block_size;
} /* end else */
@@ -2591,14 +2591,14 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si
/* Check if we should shrink the accumulator buffer */
if(size<(file->accum_buf_size/H5FD_ACCUM_THROTTLE) &&
file->accum_buf_size>H5FD_ACCUM_THRESHOLD) {
- size_t new_size=(file->accum_buf_size/H5FD_ACCUM_THROTTLE); /* New size of accumulator buffer */
+ size_t tmp_size=(file->accum_buf_size/H5FD_ACCUM_THROTTLE); /* New size of accumulator buffer */
/* Shrink the accumulator buffer */
- if ((file->meta_accum=H5FL_BLK_REALLOC(meta_accum,file->meta_accum,new_size))==NULL)
+ if ((file->meta_accum=H5FL_BLK_REALLOC(meta_accum,file->meta_accum,tmp_size))==NULL)
HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer");
/* Note the new buffer size */
- file->accum_buf_size=new_size;
+ file->accum_buf_size=tmp_size;
} /* end if */
} /* end else */