summaryrefslogtreecommitdiffstats
path: root/src/H5HL.c
diff options
context:
space:
mode:
authorJames Laird <jlaird@hdfgroup.org>2004-07-14 19:32:51 (GMT)
committerJames Laird <jlaird@hdfgroup.org>2004-07-14 19:32:51 (GMT)
commitd89d73048a57c8dd1bffb3596c633c77d45d5ea6 (patch)
tree25733c713399bb23e8e54ac8f86170dd0a814796 /src/H5HL.c
parentf0fe9b0114591c13051ccc92a2fca81b1ec3ca95 (diff)
downloadhdf5-d89d73048a57c8dd1bffb3596c633c77d45d5ea6.zip
hdf5-d89d73048a57c8dd1bffb3596c633c77d45d5ea6.tar.gz
hdf5-d89d73048a57c8dd1bffb3596c633c77d45d5ea6.tar.bz2
[svn-r8876]
Purpose: Bug Fix Description: If an HDF5 file grows larger than its address space, it dies and is unable to write any data. This is more likely to happen since users are able to change the number of bytes used to store addresses in the file. Solution: HDF5 now throws an error instead of dying. In addition, it "reserves" address space for the local heap and for object headers (which do not allocate space immediately). This ensures that after the error occurs, there is enough address space left to flush the entire file to disk, so no data is lost. A more complete explanation is at /doc/html/TechNotes/ReservedFileSpace.html Platforms tested: sleipnir, copper (parallel), verbena, arabica, Windows (Visual Studio 7) Misc. update:
Diffstat (limited to 'src/H5HL.c')
-rw-r--r--src/H5HL.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/H5HL.c b/src/H5HL.c
index 2ca4c08..40350ce 100644
--- a/src/H5HL.c
+++ b/src/H5HL.c
@@ -71,6 +71,7 @@ typedef struct H5HL_t {
haddr_t addr; /*address of data */
size_t disk_alloc; /*data bytes allocated on disk */
size_t mem_alloc; /*data bytes allocated in mem */
+ size_t disk_resrv; /*data bytes "reserved" on disk */
uint8_t *chunk; /*the chunk, including header */
H5HL_free_t *freelist; /*the free list */
} H5HL_t;
@@ -175,6 +176,7 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
heap->addr = *addr_p + (hsize_t)sizeof_hdr;
heap->disk_alloc = size_hint;
heap->mem_alloc = size_hint;
+ heap->disk_resrv = 0;
if (NULL==(heap->chunk = H5FL_BLK_CALLOC(heap_chunk,(sizeof_hdr + size_hint))))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
@@ -370,6 +372,13 @@ H5HL_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5HL_t *heap)
sizeof_hdr= H5HL_SIZEOF_HDR(f);
/*
+ * Since the file is being flushed to disk, release the file space reserved
+ * for it.
+ */
+ H5MF_free_reserved(f, heap->disk_resrv);
+ heap->disk_resrv = 0;
+
+ /*
* Check to see if we can reduce the size of the heap in memory by
* eliminating free blocks at the tail of the buffer before flushing the
* buffer out.
@@ -772,6 +781,7 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t buf_size, const void *
size_t offset = 0;
size_t need_size, old_size, need_more;
hbool_t found;
+ size_t disk_resrv; /* Amount of additional space to reserve in file */
size_t sizeof_hdr; /* Cache H5HL header size for file */
size_t ret_value; /* Return value */
@@ -880,6 +890,18 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t buf_size, const void *
}
}
+ /* Reserve space in file to hold the increased heap size */
+ if( heap->disk_resrv == heap->mem_alloc)
+ disk_resrv = need_more;
+ else
+ disk_resrv = heap->mem_alloc + need_more - heap->disk_resrv;
+
+ if( H5MF_reserve(f, disk_resrv) < 0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, (size_t) (-1), "unable to reserve space for heap");
+
+ /* Update heap's record of how much space it has reserved */
+ heap->disk_resrv += disk_resrv;
+
#ifdef H5HL_DEBUG
if (H5DEBUG(HL)) {
fprintf(H5DEBUG(HL),