summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-03-28 14:03:46 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-03-28 14:03:46 (GMT)
commit935d75c50d35816e08af71be79ef8ace04f97d04 (patch)
tree2aff56744b8fe1211f0b3a43b9fb11a0f7923eaa /src
parent87050be33e3a5931ef88b4faee557c3bfdb809b4 (diff)
downloadhdf5-935d75c50d35816e08af71be79ef8ace04f97d04.zip
hdf5-935d75c50d35816e08af71be79ef8ace04f97d04.tar.gz
hdf5-935d75c50d35816e08af71be79ef8ace04f97d04.tar.bz2
[svn-r12162] Purpose:
Code checkpoint Description: Check in fractal heap code to add basic support for skipping direct blocks when an object is too large to fit in one. Platforms tested: FreeBSD 4.11 (sleipnir) Linux 2.4 (chicago)
Diffstat (limited to 'src')
-rw-r--r--src/H5HF.c18
-rw-r--r--src/H5HFcache.c7
-rw-r--r--src/H5HFflist.c3
-rw-r--r--src/H5HFint.c253
-rw-r--r--src/H5HFpkg.h16
-rw-r--r--src/H5HFprivate.h2
6 files changed, 206 insertions, 93 deletions
diff --git a/src/H5HF.c b/src/H5HF.c
index 33a1959..7eab53b 100644
--- a/src/H5HF.c
+++ b/src/H5HF.c
@@ -96,7 +96,8 @@ H5FL_DEFINE(H5HF_t);
*-------------------------------------------------------------------------
*/
herr_t
-H5HF_create(H5F_t *f, hid_t dxpl_id, H5HF_create_t *cparam, haddr_t *addr_p)
+H5HF_create(H5F_t *f, hid_t dxpl_id, H5HF_create_t *cparam, haddr_t *addr_p,
+ size_t *id_len_p)
{
H5HF_t *fh = NULL; /* The new fractal heap header information */
herr_t ret_value = SUCCEED; /* Return value */
@@ -109,6 +110,7 @@ H5HF_create(H5F_t *f, hid_t dxpl_id, H5HF_create_t *cparam, haddr_t *addr_p)
HDassert(f);
HDassert(cparam);
HDassert(addr_p);
+ HDassert(id_len_p);
/* Allocate & basic initialization for the shared header */
if(NULL == (fh = H5HF_alloc(f)))
@@ -122,6 +124,12 @@ H5HF_create(H5F_t *f, hid_t dxpl_id, H5HF_create_t *cparam, haddr_t *addr_p)
if(H5HF_init(fh, *addr_p, cparam) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't initialize shared fractal heap header")
+ /* Set the length of heap IDs */
+ *id_len_p = fh->id_len;
+#ifdef QAK
+HDfprintf(stderr, "%s: fh->id_len = %Zu\n", FUNC, fh->id_len);
+#endif /* QAK */
+
/* Cache the new fractal heap header */
if(H5AC_set(f, dxpl_id, H5AC_FHEAP_HDR, *addr_p, fh, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add fractal heap header to cache")
@@ -232,6 +240,7 @@ H5HF_read(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_id,
H5HF_t *fh = NULL; /* The fractal heap header information */
const uint8_t *id = (const uint8_t *)_id; /* Object ID */
hsize_t obj_off; /* Object's offset in heap */
+ size_t obj_len; /* Object's length in heap */
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5HF_read, FAIL)
@@ -250,10 +259,11 @@ H5HF_read(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_id,
if(NULL == (fh = H5AC_protect(f, dxpl_id, H5AC_FHEAP_HDR, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap header")
- /* Decode the offset within the heap */
+ /* Decode the object offset within the heap & it's length */
UINT64DECODE_VAR(id, obj_off, fh->heap_off_size);
+ UINT64DECODE_VAR(id, obj_len, fh->id_len);
#ifdef QAK
-HDfprintf(stderr, "%s: obj_off = %Hu\n", FUNC, obj_off);
+HDfprintf(stderr, "%s: obj_off = %Hu, obj_len = %Zu\n", FUNC, obj_off, obj_len);
#endif /* QAK */
/* Check for standalone object */
@@ -262,7 +272,7 @@ HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "standalone blocks not supported ye
} /* end if */
else {
/* Read object from managed heap blocks */
- if(H5HF_man_read(fh, dxpl_id, obj_off, obj) < 0)
+ if(H5HF_man_read(fh, dxpl_id, obj_off, obj_len, obj) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't read object from fractal heap")
} /* end else */
diff --git a/src/H5HFcache.c b/src/H5HFcache.c
index ab6ea76..d59d164 100644
--- a/src/H5HFcache.c
+++ b/src/H5HFcache.c
@@ -180,9 +180,6 @@ H5HF_dtable_decode(H5F_t *f, const uint8_t **pp, H5HF_dtable_t *dtable)
/* Current # of rows in root indirect block */
UINT16DECODE(*pp, dtable->curr_root_rows);
- /* Next direct block's heap offset */
- H5F_DECODE_LENGTH(f, *pp, dtable->next_dir_block);
-
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5HF_dtable_decode() */
@@ -233,9 +230,6 @@ H5HF_dtable_encode(H5F_t *f, uint8_t **pp, const H5HF_dtable_t *dtable)
/* Current # of rows in root indirect block */
UINT16ENCODE(*pp, dtable->curr_root_rows);
- /* Next direct block's heap offset */
- H5F_ENCODE_LENGTH(f, *pp, dtable->next_dir_block);
-
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5HF_dtable_encode() */
@@ -1166,6 +1160,7 @@ HDfprintf(stderr, "%s: Load indirect block, addr = %a\n", FUNC, addr);
UINT32DECODE_VAR(p, iblock->ents[u].free_space, hdr->man_dtable.max_dir_blk_off_size)
else
UINT64DECODE_VAR(p, iblock->ents[u].free_space, hdr->heap_off_size)
+/* XXX: Add code to indirect block cache load routine to create range sections for skipped blocks */
} /* end for */
/* Sanity check */
diff --git a/src/H5HFflist.c b/src/H5HFflist.c
index 97e30e9..d879a23 100644
--- a/src/H5HFflist.c
+++ b/src/H5HFflist.c
@@ -263,7 +263,8 @@ HDfprintf(stderr, "%s: *size_key = %Zu, *addr_key = %a\n", FUNC, *size_key, *add
} /* end if */
else {
/* Have a single section, put it into the bins */
- if(flist->sec_count == 1) {
+/* XXX: Take out the "&& flist->bins == NULL" when bins converted back into single section */
+ if(flist->sec_count == 1 && flist->bins == NULL) {
HDassert(flist->single.node);
/* Check if we should allocate the bins */
diff --git a/src/H5HFint.c b/src/H5HFint.c
index 3fee747..b73f908 100644
--- a/src/H5HFint.c
+++ b/src/H5HFint.c
@@ -63,11 +63,25 @@
struct H5HF_section_free_node_t {
haddr_t sect_addr; /* Address of free list section in the file */
/* (Not actually used as address, used as unique ID for free list node) */
- haddr_t block_addr; /* Address of direct block for free section */
size_t sect_size; /* Size of free space section */
/* (section size is "object size", without the metadata overhead, since metadata overhead varies from block to block) */
- size_t block_size; /* Size of direct block */
+ /* (for range sections, this is the largest single section within the range) */
+ enum {H5HF_SECT_SINGLE, H5HF_SECT_RANGE} type; /* Type of free space section */
+ union {
+ struct {
+ haddr_t dblock_addr; /* Address of direct block for free section */
+ size_t dblock_size; /* Size of direct block */
/* (Needed to retrieve direct block) */
+ } single;
+ struct {
+ haddr_t iblock_addr; /* Address of indirect block for free section */
+ unsigned iblock_nrows; /* Number of rows in indirect block */
+ /* (Needed to retrieve indirect block) */
+ unsigned entry; /* Starting entry in indirect block */
+ unsigned num_entries; /* Number of entries covered */
+ hsize_t range; /* Size of actual free section */
+ } range;
+ } u;
};
@@ -153,6 +167,7 @@ static herr_t
H5HF_dtable_init(H5HF_dtable_t *dtable)
{
hsize_t tmp_block_size; /* Temporary block size */
+ hsize_t acc_block_off; /* Accumulated block offset */
size_t u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
@@ -175,11 +190,17 @@ H5HF_dtable_init(H5HF_dtable_t *dtable)
/* Build table of block sizes for each row */
if(NULL == (dtable->row_block_size = H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table block size table")
+ if(NULL == (dtable->row_block_off = H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table block offset table")
tmp_block_size = dtable->cparam.start_block_size;
+ acc_block_off = dtable->cparam.start_block_size * dtable->cparam.width;
dtable->row_block_size[0] = dtable->cparam.start_block_size;
+ dtable->row_block_off[0] = 0;
for(u = 1; u < dtable->max_root_rows; u++) {
dtable->row_block_size[u] = tmp_block_size;
+ dtable->row_block_off[u] = acc_block_off;
tmp_block_size *= 2;
+ acc_block_off *= 2;
} /* end for */
done:
@@ -255,6 +276,9 @@ H5HF_dtable_dest(H5HF_dtable_t *dtable)
/* Free the block size lookup table for the doubling table */
H5MM_xfree(dtable->row_block_size);
+ /* Free the block offset lookup table for the doubling table */
+ H5MM_xfree(dtable->row_block_off);
+
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5HF_dtable_dest() */
@@ -340,6 +364,10 @@ H5HF_finish_init(H5HF_t *fh)
if(NULL == (fh->flist = H5HF_flist_create(fh->man_dtable.cparam.max_direct_size, H5HF_dblock_section_node_free_cb)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize free list info")
+ /* Set the size of heap IDs */
+ fh->id_len = fh->heap_off_size + MIN(fh->man_dtable.max_dir_blk_off_size,
+ ((H5V_log2_gen((hsize_t)fh->standalone_size) + 7) / 8));
+
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_finish_init() */
@@ -582,11 +610,12 @@ HDmemset(dblock->blk, 0, dblock->size);
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for direct block free list section")
/* Set section's information */
- sec_node->block_addr = *addr_p;
- sec_node->block_size = block_size;
- sec_node->sect_addr = *addr_p + node->my_offset;
+ sec_node->sect_addr = block_off + node->my_offset;
/* (section size is "object size", without the metadata overhead) */
- sec_node->sect_size = node->size - H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_DBLOCK(hdr, dblock);
+ sec_node->sect_size = node->size - H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr);
+ sec_node->type = H5HF_SECT_SINGLE;
+ sec_node->u.single.dblock_addr = *addr_p;
+ sec_node->u.single.dblock_size = block_size;
/* Add new free space to the global list of space */
if(H5HF_flist_add(hdr->flist, sec_node, &sec_node->sect_size, &sec_node->sect_addr) < 0)
@@ -721,11 +750,12 @@ H5HF_man_dblock_build_freelist(H5HF_direct_t *dblock, haddr_t dblock_addr)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for direct block free list section")
/* Set section's information */
- sec_node->block_addr = dblock_addr;
- sec_node->block_size = dblock->size;
- sec_node->sect_addr = dblock_addr + node->my_offset;
+ sec_node->sect_addr = dblock->block_off + node->my_offset;
/* (section size is "object size", without the metadata overhead) */
- sec_node->sect_size = node->size - H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_DBLOCK(hdr, dblock);
+ sec_node->sect_size = node->size - H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr);
+ sec_node->type = H5HF_SECT_SINGLE;
+ sec_node->u.single.dblock_addr = dblock_addr;
+ sec_node->u.single.dblock_size = dblock->size;
/* Add new free space to the global list of space */
if(H5HF_flist_add(hdr->flist, sec_node, &sec_node->sect_size, &sec_node->sect_addr) < 0)
@@ -763,11 +793,12 @@ H5HF_man_dblock_build_freelist(H5HF_direct_t *dblock, haddr_t dblock_addr)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for direct block free list section")
/* Set section's information */
- sec_node->block_addr = dblock_addr;
- sec_node->block_size = dblock->size;
- sec_node->sect_addr = dblock_addr + node->my_offset;
+ sec_node->sect_addr = dblock->block_off + node->my_offset;
/* (section size is "object size", without the metadata overhead) */
- sec_node->sect_size = node->size - H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_DBLOCK(hdr, dblock);
+ sec_node->sect_size = node->size - H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr);
+ sec_node->type = H5HF_SECT_SINGLE;
+ sec_node->u.single.dblock_addr = dblock_addr;
+ sec_node->u.single.dblock_size = dblock->size;
/* Add new free space to the global list of space */
if(H5HF_flist_add(hdr->flist, sec_node, &sec_node->sect_size, &sec_node->sect_addr) < 0)
@@ -912,32 +943,33 @@ HDfprintf(stderr, "%s: request = %Zu\n", FUNC, request);
if(request < hdr->man_dtable.cparam.start_block_size)
min_dblock_size = hdr->man_dtable.cparam.start_block_size;
else {
- min_dblock_size = 2 * H5V_log2_gen((hsize_t)request);
+ min_dblock_size = 1 << (1 + H5V_log2_gen((hsize_t)request));
HDassert(min_dblock_size <= hdr->man_dtable.cparam.max_direct_size);
} /* end else */
/* Adjust the size of block needed to fulfill request, with overhead */
#ifdef QAK
+HDfprintf(stderr, "%s: Check 1 - min_dblock_size = %Zu\n", FUNC, min_dblock_size);
HDfprintf(stderr, "%s: H5HF_MAN_ABS_DIRECT_OVERHEAD_SIZE = %u\n", FUNC, H5HF_MAN_ABS_DIRECT_OVERHEAD_SIZE(hdr, hdr->man_dtable.cparam.start_block_size));
-HDfprintf(stderr, "%s: H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_SIZE = %u\n", FUNC, H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_SIZE(hdr, hdr->man_dtable.cparam.start_block_size));
+HDfprintf(stderr, "%s: H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN = %u\n", FUNC, H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr));
#endif /* QAK */
if((min_dblock_size - request) < (H5HF_MAN_ABS_DIRECT_OVERHEAD_SIZE(hdr, min_dblock_size)
- + H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_SIZE(hdr, min_dblock_size)))
+ + H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr)))
min_dblock_size *= 2;
#ifdef QAK
-HDfprintf(stderr, "%s: min_dblock_size = %Zu\n", FUNC, min_dblock_size);
+HDfprintf(stderr, "%s: Check 2 - min_dblock_size = %Zu\n", FUNC, min_dblock_size);
#endif /* QAK */
/* Check if this is the first block in the heap */
- if(!H5F_addr_defined(hdr->man_dtable.table_addr)) {
- /* Create new direct block at corrent location*/
+ if(!H5F_addr_defined(hdr->man_dtable.table_addr) &&
+ min_dblock_size == hdr->man_dtable.cparam.start_block_size) {
+ /* Create new direct block at starting offset */
dblock_size = hdr->man_dtable.cparam.start_block_size;
- if(H5HF_man_dblock_create(dxpl_id, hdr, NULL, 0, dblock_size, hdr->man_dtable.next_dir_block, &dblock_addr) < 0)
+ if(H5HF_man_dblock_create(dxpl_id, hdr, NULL, 0, dblock_size, (hsize_t)0, &dblock_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't allocate fractal heap direct block")
#ifdef QAK
HDfprintf(stderr, "%s: dblock_addr = %a\n", FUNC, dblock_addr);
-HDfprintf(stderr, "%s: hdr->man_dtable.next_dir_block = %Hu\n", FUNC, hdr->man_dtable.next_dir_block);
#endif /* QAK */
/* Point root at new direct block */
@@ -949,6 +981,7 @@ HDfprintf(stderr, "%s: hdr->man_dtable.next_dir_block = %Hu\n", FUNC, hdr->man_d
H5HF_indirect_t *iblock; /* Pointer to indirect block to create */
haddr_t iblock_addr; /* Indirect block's address */
size_t dblock_entry; /* Direct entry for new direct block */
+ hsize_t dblock_off; /* Direct block offset in heap address space */
/* Find indirect block with room for block of correct size */
if(NULL == (iblock = H5HF_man_iblock_place_dblock(hdr, dxpl_id, min_dblock_size, &iblock_addr, &dblock_entry, &dblock_size)))
@@ -959,8 +992,13 @@ HDfprintf(stderr, "%s: dblock_entry = %Zu\n", FUNC, dblock_entry);
HDfprintf(stderr, "%s: dblock_size = %Zu\n", FUNC, dblock_size);
#endif /* QAK */
- /* Create new direct block at corrent location*/
- if(H5HF_man_dblock_create(dxpl_id, hdr, iblock, dblock_entry, dblock_size, hdr->man_dtable.next_dir_block, &dblock_addr) < 0)
+ /* Compute the direct block's offset in the heap's address space */
+ dblock_off = iblock->block_off;
+ dblock_off += hdr->man_dtable.row_block_off[dblock_entry / hdr->man_dtable.cparam.width];
+ dblock_off += hdr->man_dtable.row_block_size[dblock_entry / hdr->man_dtable.cparam.width] * (dblock_entry % hdr->man_dtable.cparam.width);
+
+ /* Create new direct block at current location*/
+ if(H5HF_man_dblock_create(dxpl_id, hdr, iblock, dblock_entry, dblock_size, dblock_off, &dblock_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't allocate fractal heap direct block")
#ifdef QAK
@@ -979,10 +1017,6 @@ HDfprintf(stderr, "%s: dblock_addr = %a\n", FUNC, dblock_addr);
HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
} /* end else */
- /* Update shared header */
-/* XXX: This is going to cause problems when we support skipping blocks */
- hdr->man_dtable.next_dir_block += dblock_size;
-
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_man_dblock_new() */
@@ -1082,9 +1116,15 @@ H5HF_man_insert(H5HF_t *hdr, hid_t dxpl_id, H5HF_section_free_node_t *sec_node,
HDassert(obj);
HDassert(id);
+ /* Check for range section */
+ if(sec_node->type == H5HF_SECT_RANGE) {
+HDfprintf(stderr, "%s: Can't handle range sections yet\n", FUNC);
+HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "'range' free space sections not supported yet")
+ } /* end if */
+
/* Lock direct block */
- dblock_addr = sec_node->block_addr;
- if(NULL == (dblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, dblock_addr, &sec_node->block_size, hdr, H5AC_WRITE)))
+ dblock_addr = sec_node->u.single.dblock_addr;
+ if(NULL == (dblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, dblock_addr, &sec_node->u.single.dblock_size, hdr, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to load fractal heap direct block")
/* Insert object into block */
@@ -1100,13 +1140,13 @@ H5HF_man_insert(H5HF_t *hdr, hid_t dxpl_id, H5HF_section_free_node_t *sec_node,
/* Locate "local" free list node for section */
/* XXX: Change to using skip list */
- obj_off = sec_node->sect_addr - sec_node->block_addr;
+ obj_off = sec_node->sect_addr - dblock->block_off;
node = dblock->free_list->first;
while(node->my_offset != obj_off)
node = node->next;
/* Compute full object size, with metadata for object */
- full_obj_size = obj_size + H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_DBLOCK(hdr, dblock);
+ full_obj_size = obj_size + H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr);
/* Sanity checks */
HDassert(dblock->blk_free_space >= full_obj_size);
@@ -1185,9 +1225,6 @@ HDfprintf(stderr, "%s: alloc_obj_size = %Zu\n", FUNC, alloc_obj_size);
/* Point to location for object */
p = dblock->blk + obj_off;
- /* Encode the length */
- UINT64ENCODE_VAR(p, obj_size, dblock->blk_off_size);
-
/* Encode the free fragment size */
*p++ = free_frag_size;
@@ -1206,11 +1243,12 @@ HDfprintf(stderr, "%s: alloc_obj_size = %Zu\n", FUNC, alloc_obj_size);
/* Sanity check */
HDassert((size_t)(p - (dblock->blk + obj_off)) == alloc_obj_size);
- /* Set the heap ID for the new object */
+ /* Set the heap ID for the new object (heap offset & obj length) */
#ifdef QAK
HDfprintf(stderr, "%s: dblock->block_off = %Hu\n", FUNC, dblock->block_off);
#endif /* QAK */
UINT64ENCODE_VAR(id, (dblock->block_off + obj_off), hdr->heap_off_size);
+ UINT64ENCODE_VAR(id, obj_size, hdr->id_len);
} /* end if */
else {
HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "inserting within mapped managed blocks not supported yet")
@@ -1246,12 +1284,11 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5HF_man_read(H5HF_t *hdr, hid_t dxpl_id, hsize_t obj_off, void *obj)
+H5HF_man_read(H5HF_t *hdr, hid_t dxpl_id, hsize_t obj_off, size_t obj_len, void *obj)
{
H5HF_direct_t *dblock; /* Pointer to direct block to query */
size_t blk_off; /* Offset of object in block */
uint8_t *p; /* Temporary pointer to obj info in block */
- size_t obj_size; /* Size of object */
haddr_t dblock_addr; /* Direct block address */
size_t dblock_size; /* Direct block size */
herr_t ret_value = SUCCEED; /* Return value */
@@ -1358,14 +1395,11 @@ HDfprintf(stderr, "%s: entry address = %a\n", FUNC, iblock->ents[entry].addr);
/* Point to location for object */
p = dblock->blk + blk_off;
- /* Decode the length */
- UINT64DECODE_VAR(p, obj_size, dblock->blk_off_size);
-
/* Skip over the free fragment size */
p++;
/* Copy the object's data into the heap */
- HDmemcpy(obj, p, obj_size);
+ HDmemcpy(obj, p, obj_len);
/* Unlock direct block */
if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0)
@@ -1665,8 +1699,17 @@ HDfprintf(stderr, "%s: creating first indirect block\n", FUNC);
/* Check for allocating entire root indirect block initially */
if(hdr->man_dtable.cparam.start_root_rows == 0)
nrows = hdr->man_dtable.max_root_rows;
- else
+ else {
+ unsigned rows_needed; /* Number of rows needed to get to direct block size */
+
nrows = hdr->man_dtable.cparam.start_root_rows;
+ rows_needed = 2 + (H5V_log2_of2(min_dblock_size) - H5V_log2_of2(hdr->man_dtable.cparam.start_block_size));
+ if(nrows < rows_needed)
+ nrows = rows_needed;
+ } /* end else */
+#ifdef QAK
+HDfprintf(stderr, "%s: nrows = %u\n", FUNC, nrows);
+#endif /* QAK */
/* Allocate root indirect block */
if(H5HF_man_iblock_create(hdr, dxpl_id, (hsize_t)0, nrows, hdr->man_dtable.max_root_rows, &iblock_addr) < 0)
@@ -1681,32 +1724,96 @@ HDfprintf(stderr, "%s: iblock_addr = %a\n", FUNC, iblock_addr);
if(NULL == (iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, &nrows, hdr, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
- /* Lock first (root) direct block */
- if(NULL == (dblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, hdr->man_dtable.table_addr, &hdr->man_dtable.cparam.start_block_size, hdr, H5AC_READ)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap direct block")
-
- /* Point indirect block at direct block to add */
- iblock->ents[0].addr = hdr->man_dtable.table_addr;
- iblock->ents[0].free_space = dblock->blk_free_space;
- iblock->child_free_space += dblock->blk_free_space;
-
- /* Make direct block share parent indirect block */
- dblock->parent = iblock;
- dblock->par_entry = 0;
- dblock->par_addr = iblock->addr;
- dblock->par_nrows = iblock->nrows;
- if(H5HF_iblock_incr(iblock) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't increment reference count on shared indirect block")
-
- /* Unlock first (root) direct block */
- if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, hdr->man_dtable.table_addr, dblock, H5AC__NO_FLAGS_SET) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap direct block")
- dblock = NULL;
-
- /* Increment size of next block from this indirect block */
- /* (account for the already existing direct block */
- if(H5HF_man_iblock_inc_loc(iblock) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't advance fractal heap block location")
+ /* Check if there's already a direct block as root) */
+ if(H5F_addr_defined(hdr->man_dtable.table_addr)) {
+ /* Lock first (root) direct block */
+ if(NULL == (dblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, hdr->man_dtable.table_addr, &hdr->man_dtable.cparam.start_block_size, hdr, H5AC_READ)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap direct block")
+
+ /* Point indirect block at direct block to add */
+ iblock->ents[0].addr = hdr->man_dtable.table_addr;
+ iblock->ents[0].free_space = dblock->blk_free_space;
+ iblock->child_free_space += dblock->blk_free_space;
+
+ /* Make direct block share parent indirect block */
+ dblock->parent = iblock;
+ dblock->par_entry = 0;
+ dblock->par_addr = iblock->addr;
+ dblock->par_nrows = iblock->nrows;
+ if(H5HF_iblock_incr(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't increment reference count on shared indirect block")
+
+ /* Unlock first (root) direct block */
+ if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, hdr->man_dtable.table_addr, dblock, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap direct block")
+ dblock = NULL;
+
+ /* Increment size of next block from this indirect block */
+ /* (account for the already existing direct block */
+ if(H5HF_man_iblock_inc_loc(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't advance fractal heap block location")
+ } /* end if */
+ else {
+ H5HF_section_free_node_t *sec_node; /* Pointer to free list section for range */
+ size_t dblock_free_space; /* Size of free space for direct block */
+ hsize_t range; /* Size range skipped over */
+ unsigned cur_entry; /* Current entry */
+ unsigned u, v; /* Local index variables */
+
+ /* Initialize information for rows skipped over */
+ cur_entry = 0;
+ range = 0;
+ for(u = 0; u < (nrows - 1); u++) {
+ /* Compute free space in direct blocks for this row */
+ dblock_free_space = hdr->man_dtable.row_block_size[u] -
+ (H5HF_MAN_ABS_DIRECT_OVERHEAD_SIZE(hdr, hdr->man_dtable.row_block_size[u])
+ + H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr));
+
+ /* Initialize information for this row */
+ for(v = 0; v < hdr->man_dtable.cparam.width; v++) {
+ /* Initialize entry for this row */
+ iblock->ents[cur_entry].addr = HADDR_UNDEF;
+ iblock->ents[cur_entry].free_space = dblock_free_space;
+
+ /* Increment block and heap's free space */
+ iblock->child_free_space += dblock_free_space;
+ hdr->total_man_free += dblock_free_space;
+
+ /* Increment range skipped */
+ range += hdr->man_dtable.row_block_size[u];
+
+ /* Move to next entry */
+ cur_entry++;
+ } /* end for */
+ } /* end for */
+
+ /* Set indirect block's "next entry" information */
+ iblock->next_col = 0;
+ iblock->next_row = u;
+ iblock->next_size = hdr->man_dtable.row_block_size[u];
+ iblock->next_entry = cur_entry;
+ HDassert(iblock->next_size == min_dblock_size);
+
+ /* Create free space section for blocks skipped over */
+
+ /* Create free list section node */
+ if(NULL == (sec_node = H5FL_MALLOC(H5HF_section_free_node_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for direct block free list section")
+
+ /* Set section's information */
+ sec_node->sect_addr = 0; /* Range starts at offset 0 in the heap */
+ sec_node->sect_size = dblock_free_space;
+ sec_node->type = H5HF_SECT_RANGE;
+ sec_node->u.range.iblock_addr = iblock->addr;
+ sec_node->u.range.iblock_nrows = iblock->nrows;
+ sec_node->u.range.entry = 0;
+ sec_node->u.range.num_entries = cur_entry;
+ sec_node->u.range.range = range;
+
+ /* Add new free space to the global list of space */
+ if(H5HF_flist_add(hdr->flist, sec_node, &sec_node->sect_size, &sec_node->sect_addr) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't add indirect block free space to global list")
+ } /* end else */
/* Mark indirect block as modified */
if(H5HF_iblock_dirty(dxpl_id, iblock) < 0)
@@ -1828,11 +1935,17 @@ HDfprintf(stderr, "%s: iblock->next_size = %Hu, nrows = %u\n", FUNC, iblock->nex
/* Check for allocating new indirect block */
if(!H5F_addr_defined(iblock->ents[iblock->next_entry].addr)) {
+ hsize_t new_iblock_off; /* Direct block offset in heap address space */
#ifdef QAK
HDfprintf(stderr, "%s: Allocating new indirect block\n", FUNC);
#endif /* QAK */
+ /* Compute the direct block's offset in the heap's address space */
+ new_iblock_off = iblock->block_off;
+ new_iblock_off += hdr->man_dtable.row_block_off[iblock->next_entry / hdr->man_dtable.cparam.width];
+ new_iblock_off += hdr->man_dtable.row_block_size[iblock->next_entry / hdr->man_dtable.cparam.width] * (iblock->next_entry % hdr->man_dtable.cparam.width);
+
/* Allocate new indirect block */
- if(H5HF_man_iblock_create(hdr, dxpl_id, hdr->man_dtable.next_dir_block, nrows, nrows, &new_iblock_addr) < 0)
+ if(H5HF_man_iblock_create(hdr, dxpl_id, new_iblock_off, nrows, nrows, &new_iblock_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "can't allocate fractal heap indirect block")
/* Lock new indirect block */
diff --git a/src/H5HFpkg.h b/src/H5HFpkg.h
index cede8c9..ab69207 100644
--- a/src/H5HFpkg.h
+++ b/src/H5HFpkg.h
@@ -65,7 +65,6 @@
+ 2 /* Starting # of rows in root indirect block */ \
+ (h)->sizeof_addr /* File address of table managed */ \
+ 2 /* Current # of rows in root indirect block */ \
- + (h)->sizeof_size /* Next direct block's heap offset */ \
)
/* Size of the fractal heap header on disk */
@@ -89,12 +88,7 @@
#define H5HF_MAN_ABS_DIRECT_FREE_NODE_SIZE(d) (2 * (d)->blk_off_size)
/* Size of header for each object in an absolute managed direct block */
-#define H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_SIZE(h, o) ( \
- H5HF_SIZEOF_OFFSET_LEN(o) /* Length of object in block */ \
- + 1 /* Free space fragment length */ \
- )
-#define H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN_DBLOCK(h, d) ( \
- (d)->blk_off_size /* Length of object in block */ \
+#define H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(h) ( \
+ 1 /* Free space fragment length */ \
)
@@ -162,16 +156,15 @@ typedef struct H5HF_dtable_t {
* to direct block (of START_BLOCK_SIZE) instead
* of indirect root block.
*/
-/* XXX: get rid of this global setting */
- hsize_t next_dir_block; /* Offset of next direct managed block */
/* Computed information (not stored) */
unsigned max_root_rows; /* Maximum # of rows in root indirect block */
unsigned max_direct_rows; /* Maximum # of direct rows in any indirect block */
unsigned max_dir_blk_off_size; /* Max. size of offsets in direct blocks */
- unsigned first_row_bits; /* # of bits in address of first row */
+ unsigned first_row_bits; /* # of bits in address of first row */
hsize_t num_id_first_row; /* Number of IDs in first row of table */
hsize_t *row_block_size; /* Block size per row of indirect block */
+ hsize_t *row_block_off; /* Cumulative offset per row of indirect block */
} H5HF_dtable_t;
/* Fractal heap free list info (forward decl - defined in H5HFflist.c) */
@@ -208,6 +201,7 @@ typedef struct H5HF_t {
size_t sizeof_size; /* Size of file sizes */
size_t sizeof_addr; /* Size of file addresses */
H5HF_freelist_t *flist; /* Free list for objects in heap */
+ size_t id_len; /* Size of heap IDs */
/* Doubling table information */
/* (Partially set by user, partially derived/updated internally) */
@@ -374,7 +368,7 @@ H5_DLL herr_t H5HF_man_insert(H5HF_t *fh, hid_t dxpl_id,
H5HF_section_free_node_t *sec_node, size_t obj_size, const void *obj,
void *id);
H5_DLL herr_t H5HF_man_read(H5HF_t *fh, hid_t dxpl_id, hsize_t obj_off,
- void *obj);
+ size_t obj_len, void *obj);
/* Metadata cache callbacks */
H5_DLL herr_t H5HF_cache_hdr_dest(H5F_t *f, H5HF_t *fh);
diff --git a/src/H5HFprivate.h b/src/H5HFprivate.h
index 6296e8c..f97008c 100644
--- a/src/H5HFprivate.h
+++ b/src/H5HFprivate.h
@@ -76,7 +76,7 @@ typedef struct H5HF_create_t {
/* Library-private Function Prototypes */
/***************************************/
H5_DLL herr_t H5HF_create(H5F_t *f, hid_t dxpl_id, H5HF_create_t *cparam,
- haddr_t *addr_p);
+ haddr_t *addr_p, size_t *id_len_p);
H5_DLL herr_t H5HF_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t size,
const void *obj, void *id/*out*/);
H5_DLL herr_t H5HF_read(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *id,