summaryrefslogtreecommitdiffstats
path: root/src/H5HFiblock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5HFiblock.c')
-rw-r--r--src/H5HFiblock.c1172
1 files changed, 716 insertions, 456 deletions
diff --git a/src/H5HFiblock.c b/src/H5HFiblock.c
index 1ecaa9a..fd7b520 100644
--- a/src/H5HFiblock.c
+++ b/src/H5HFiblock.c
@@ -58,15 +58,17 @@
/********************/
/* Indirect block routines */
-static herr_t H5HF_man_iblock_inc_loc(H5HF_indirect_t *iblock);
-static herr_t H5HF_man_iblock_skip_blocks(H5HF_t *hdr,
+static herr_t H5HF_man_iblock_skip_blocks(H5HF_hdr_t *hdr,
H5HF_indirect_t *iblock, haddr_t iblock_addr,
unsigned start_entry, unsigned nentries);
-static herr_t H5HF_man_iblock_skip_ranges(H5HF_t *hdr,
+static herr_t H5HF_man_iblock_skip_ranges(H5HF_hdr_t *hdr,
H5HF_indirect_t *iblock, haddr_t iblock_addr,
unsigned start_entry, unsigned nentries);
-static herr_t H5HF_man_iblock_create(H5HF_t *fh, hid_t dxpl_id,
+static herr_t H5HF_man_iblock_double_root(H5HF_hdr_t *hdr, hid_t dxpl_id,
+ size_t min_dblock_size);
+static herr_t H5HF_man_iblock_create(H5HF_hdr_t *hdr, hid_t dxpl_id,
hsize_t block_off, unsigned nrows, unsigned max_rows, haddr_t *addr_p);
+static herr_t H5HF_man_iblock_build_sections(H5HF_indirect_t *iblock);
/*********************/
/* Package Variables */
@@ -91,71 +93,6 @@ H5FL_SEQ_DEFINE(H5HF_indirect_ent_t);
/*-------------------------------------------------------------------------
- * Function: H5HF_man_iblock_inc_loc
- *
- * Purpose: Increment location of next direct block in indirect block
- *
- * Return: SUCCEED/FAIL
- *
- * Programmer: Quincey Koziol
- * koziol@ncsa.uiuc.edu
- * Mar 14 2006
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-H5HF_man_iblock_inc_loc(H5HF_indirect_t *iblock)
-{
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI_NOINIT(H5HF_man_iblock_inc_loc)
-
- /*
- * Check arguments.
- */
- HDassert(iblock);
-
- /* Increment block entry */
- iblock->next_entry++;
-
- /* Increment column */
- iblock->next_col++;
-
- /* Check for walking off end of column */
- if(iblock->next_col == iblock->shared->man_dtable.cparam.width) {
- /* Reset column */
- iblock->next_col = 0;
-
- /* Increment row & block size */
- iblock->next_row++;
- if(iblock->next_row > 1)
- iblock->next_size *= 2;
-
- /* Check for filling up indirect block */
- if(iblock->next_row == iblock->max_rows) {
- /* Check for "full" heap */
- if(iblock->parent == NULL)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't advance fractal heap block location")
-
- /* Increment location for parent indirect block */
- if(H5HF_man_iblock_inc_loc(iblock->parent) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't advance fractal heap block location")
- } /* end if */
- } /* end if */
-
-#ifdef QAK
-HDfprintf(stderr, "%s: iblock->next_row = %u\n", FUNC, iblock->next_row);
-HDfprintf(stderr, "%s: iblock->next_col = %u\n", FUNC, iblock->next_col);
-HDfprintf(stderr, "%s: iblock->next_entry = %u\n", FUNC, iblock->next_entry);
-HDfprintf(stderr, "%s: iblock->next_size = %Zu\n", FUNC, iblock->next_size);
-#endif /* QAK */
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5HF_man_iblock_inc_loc() */
-
-
-/*-------------------------------------------------------------------------
* Function: H5HF_iblock_incr
*
* Purpose: Increment reference count on shared indirect block
@@ -171,19 +108,23 @@ done:
herr_t
H5HF_iblock_incr(H5HF_indirect_t *iblock)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HF_iblock_incr)
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5HF_iblock_incr)
/* Sanity check */
HDassert(iblock);
-/* XXX: When "un-evictable" feature is finished, mark the block as
- * unevictable on the first block to share it. - QAK
- */
+ /* Mark block as un-evictable when a child block is depending on it */
+ if(iblock->rc == 0)
+ if(H5AC_pin_protected_entry(iblock->hdr->f, iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPIN, FAIL, "unable to pin fractal heap indirect block")
/* Increment reference count on shared indirect block */
iblock->rc++;
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_iblock_incr() */
@@ -203,7 +144,9 @@ H5HF_iblock_incr(H5HF_indirect_t *iblock)
herr_t
H5HF_iblock_decr(H5HF_indirect_t *iblock)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HF_iblock_decr)
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5HF_iblock_decr)
/* Sanity check */
HDassert(iblock);
@@ -211,14 +154,13 @@ H5HF_iblock_decr(H5HF_indirect_t *iblock)
/* Decrement reference count on shared indirect block */
iblock->rc--;
-/* XXX: When "un-evictable" feature is finished, mark the block as
- * evictable when the ref. count drops to zero. - QAK
- */
-/* XXX: Take this call out after "un-evictable" flag is working */
- H5HF_cache_iblock_dest_real(iblock);
-
+ /* Mark block as evictable again when no child blocks depend on it */
+ if(iblock->rc == 0)
+ if(H5AC_unpin_entry(iblock->hdr->f, iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPIN, FAIL, "unable to unpin fractal heap indirect block")
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_iblock_decr() */
@@ -236,10 +178,8 @@ H5HF_iblock_decr(H5HF_indirect_t *iblock)
*-------------------------------------------------------------------------
*/
herr_t
-H5HF_iblock_dirty(hid_t dxpl_id, H5HF_indirect_t *iblock)
+H5HF_iblock_dirty(H5HF_indirect_t *iblock)
{
- H5HF_indirect_t *tmp_iblock; /* Temporary pointer to indirect block */
- hbool_t is_protected; /* Whether the indirect block is protected */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5HF_iblock_dirty)
@@ -250,28 +190,23 @@ HDfprintf(stderr, "%s: Marking indirect block as dirty\n", FUNC);
/* Sanity check */
HDassert(iblock);
-/* XXX: When "un-evictable" feature is finished, just mark the block as dirty
- * in the cache, instead of this protect -> unprotect kludge - QAK
- */
- /* Protect the indirect block */
- is_protected = iblock->cache_info.is_protected;
- if(!is_protected) {
-#ifdef QAK
-HDfprintf(stderr, "%s: iblock->addr = %a\n", FUNC, iblock->addr);
-#endif /* QAK */
- if(NULL == (tmp_iblock = H5AC_protect(iblock->shared->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock->addr, &iblock->nrows, iblock->shared, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
- HDassert(iblock == tmp_iblock);
- } /* end if */
+/* XXX: Need to mark a protected block as dirty eventually also... */
+{
+ unsigned entry_status; /* Indirect block entry status */
- /* Set the dirty flags for the indirect block */
- iblock->dirty = TRUE;
+ if(H5AC_get_entry_status(iblock->hdr->f, iblock->addr, &entry_status) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTMARKDIRTY, FAIL, "unable to query fractal heap indirect block status")
+ HDassert(entry_status & H5AC_ES__IN_CACHE);
- /* Release the indirect block (marked as dirty) */
- if(!is_protected) {
- if(H5AC_unprotect(iblock->shared->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock->addr, tmp_iblock, H5AC__DIRTIED_FLAG) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
+ if(!(entry_status & H5AC_ES__IS_PROTECTED)) {
+ /* Mark indirect block as dirty in cache */
+ if(H5AC_mark_pinned_entry_dirty(iblock->hdr->f, iblock, FALSE, 0) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTMARKDIRTY, FAIL, "unable to mark fractal heap indirect block as dirty")
} /* end if */
+}
+
+ /* Set the dirty flag for the indirect block */
+ iblock->dirty = TRUE;
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -292,7 +227,7 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5HF_man_iblock_skip_blocks(H5HF_t *hdr, H5HF_indirect_t *iblock,
+H5HF_man_iblock_skip_blocks(H5HF_hdr_t *hdr, H5HF_indirect_t *iblock,
haddr_t iblock_addr, unsigned start_entry, unsigned nentries)
{
H5HF_free_section_t *sec_node; /* Pointer to free list section for range */
@@ -322,8 +257,7 @@ HDfprintf(stderr, "%s: start_entry = %u, nentries = %u\n", FUNC, start_entry, ne
sect_off = iblock->block_off;
for(u = 0; u < curr_row; u++)
sect_off += hdr->man_dtable.row_block_size[u] * hdr->man_dtable.cparam.width;
- for(u = 0; u < curr_col; u++)
- sect_off += hdr->man_dtable.row_block_size[curr_row];
+ sect_off += hdr->man_dtable.row_block_size[curr_row] * curr_col;
#ifdef QAK
HDfprintf(stderr, "%s: sect_off = %Zu\n", FUNC, sect_off);
#endif /* QAK */
@@ -350,8 +284,9 @@ HDfprintf(stderr, "%s: row_entries = %u, hdr->man_dtable.row_dblock_free[%u] = %
sec_node->sect_addr = sect_off;
sec_node->sect_size = hdr->man_dtable.row_dblock_free[curr_row];
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.iblock = iblock;
+ if(H5HF_iblock_incr(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block")
sec_node->u.range.row = curr_row;
sec_node->u.range.col = curr_col;
sec_node->u.range.num_entries = row_entries;
@@ -364,23 +299,17 @@ HDfprintf(stderr, "%s: row_entries = %u, hdr->man_dtable.row_dblock_free[%u] = %
sect_off += row_entries * hdr->man_dtable.row_block_size[curr_row];
curr_row++;
curr_col = 0; /* (first partial row aligns this) */
+
+ /* Increment index variable */
u += row_entries;
} /* end for */
-
- /* Re-compute row information for next empty block */
-#ifdef QAK
-HDfprintf(stderr, "%s: u = %u\n", FUNC, u);
-#endif /* QAK */
- curr_row = u / hdr->man_dtable.cparam.width;
#ifdef QAK
-HDfprintf(stderr, "%s: curr_row = %u\n", FUNC, curr_row);
+HDfprintf(stderr, "%s: sect_off = %Zu\n", FUNC, sect_off);
#endif /* QAK */
- /* Set indirect block's "next entry" information */
- iblock->next_col = 0;
- iblock->next_row = curr_row;
- iblock->next_size = hdr->man_dtable.row_block_size[curr_row];
- iblock->next_entry = u;
+ /* Advance the allocated heap size/new block iterator */
+ if(H5HF_hdr_inc_alloc(hdr, sect_off, nentries) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't increase allocated heap size")
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -401,7 +330,7 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5HF_man_iblock_skip_ranges(H5HF_t *hdr, H5HF_indirect_t *iblock,
+H5HF_man_iblock_skip_ranges(H5HF_hdr_t *hdr, H5HF_indirect_t *iblock,
haddr_t iblock_addr, unsigned start_entry, unsigned nentries)
{
H5HF_free_section_t *sec_node; /* Pointer to free list section for range */
@@ -428,19 +357,21 @@ HDfprintf(stderr, "%s: start_entry = %u, nentries = %u\n", FUNC, start_entry, ne
/* Compute starting column & row */
curr_row = start_entry / hdr->man_dtable.cparam.width;
curr_col = start_entry % hdr->man_dtable.cparam.width;
+#ifdef QAK
+HDfprintf(stderr, "%s: curr_col = %u, curr_row = %u\n", FUNC, curr_col, curr_row);
+#endif /* QAK */
/* Initialize information for rows skipped over */
sect_off = iblock->block_off;
for(u = 0; u < curr_row; u++)
sect_off += hdr->man_dtable.row_block_size[u] * hdr->man_dtable.cparam.width;
- for(u = 0; u < curr_col; u++)
- sect_off += hdr->man_dtable.row_block_size[curr_row];
+ sect_off += hdr->man_dtable.row_block_size[curr_row] * curr_col;
#ifdef QAK
HDfprintf(stderr, "%s: sect_off = %Zu\n", FUNC, sect_off);
#endif /* QAK */
/* Loop over the blocks to skip */
- for(u = start_entry; u < (start_entry + nentries); /* u is advanced in inner loop */) {
+ for(u = start_entry; u < (start_entry + nentries); /* u is advanced in loop */) {
unsigned row_entries; /* Number of entries in a particular row */
unsigned num_rows; /* Number of rows in indirect blocks referenced */
@@ -481,8 +412,9 @@ HDfprintf(stderr, "%s: sec_node->sect_addr = %a\n", FUNC, sec_node->sect_addr);
#endif /* QAK */
sec_node->sect_size = hdr->man_dtable.row_dblock_free[w];
sec_node->type = H5HF_SECT_INDIRECT;
- sec_node->u.indirect.iblock_addr = iblock_addr;
- sec_node->u.indirect.iblock_nrows = iblock->nrows;
+ sec_node->u.indirect.iblock = iblock;
+ if(H5HF_iblock_incr(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block")
sec_node->u.indirect.row = curr_row;
sec_node->u.indirect.col = curr_col;
sec_node->u.indirect.num_entries = row_entries;
@@ -501,27 +433,179 @@ HDfprintf(stderr, "%s: acc_row_dblock_free_space = %Zu\n", FUNC, acc_row_dblock_
sect_off += row_entries * hdr->man_dtable.row_block_size[curr_row];
curr_row++;
curr_col = 0; /* (first partial row aligns this) */
+
+ /* Advance outer loop index */
u += row_entries;
} /* end for */
- /* Re-compute row information for next empty block */
+ /* Advance the allocated heap size/new block iterator */
+ if(H5HF_hdr_inc_alloc(hdr, sect_off, nentries) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't increase allocated heap size")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5HF_man_iblock_skip_ranges() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5HF_man_iblock_double_root
+ *
+ * Purpose: Double size of root indirect block
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Apr 17 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5HF_man_iblock_double_root(H5HF_hdr_t *hdr, hid_t dxpl_id, size_t min_dblock_size)
+{
+ H5HF_indirect_t *iblock; /* Pointer to root indirect block */
+ haddr_t new_addr; /* New address of indirect block */
+ hsize_t acc_dblock_free; /* Accumulated free space in direct blocks */
+ hsize_t next_size; /* The previous value of the "next size" for the new block iterator */
+ unsigned next_row; /* The next row to allocate block in */
+ unsigned next_entry; /* The previous value of the "next entry" for the new block iterator */
+ unsigned new_next_entry; /* The new value of the "next entry" for the new block iterator */
+ unsigned min_nrows = 0; /* Min. # of direct rows */
+ unsigned old_nrows; /* Old # of rows */
+ unsigned new_nrows; /* New # of rows */
+ hbool_t skip_direct_rows = FALSE; /* Whether we are skipping direct rows */
+ size_t u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5HF_man_iblock_double_root)
+
#ifdef QAK
-HDfprintf(stderr, "%s: u = %u\n", FUNC, u);
+HDfprintf(stderr, "%s: Extending root indirect block\n", FUNC);
#endif /* QAK */
- curr_row = u / hdr->man_dtable.cparam.width;
+
+ /* Get "new block" iterator information */
+ if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL, &next_entry, &iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "unable to retrieve current block iterator location")
+ next_size = hdr->man_dtable.row_block_size[next_row];
+
+ /* Make certain the iterator is at the root indirect block */
+ HDassert(iblock->parent == NULL);
+
+ /* Keep this for later */
+ old_nrows = iblock->nrows;
+
+ /* Check for skipping over direct block rows */
+ if(iblock->nrows < hdr->man_dtable.max_direct_rows && min_dblock_size > next_size) {
+ /* Sanity check */
+ HDassert(min_dblock_size > hdr->man_dtable.cparam.start_block_size);
+
+ /* Set flag */
+ skip_direct_rows = TRUE;
+
+ /* Make certain we allocate at least the required row for the block requested */
+ min_nrows = 1 + H5HF_dtable_size_to_row(&hdr->man_dtable, min_dblock_size);
+
+ /* Set the information for the next block, of the appropriate size */
+ new_next_entry = (min_nrows - 1) * hdr->man_dtable.cparam.width;
+ } /* end if */
+
+ /* Compute new # of rows in indirect block */
+ new_nrows = MAX(min_nrows, MIN(2 * iblock->nrows, iblock->max_rows));
#ifdef QAK
-HDfprintf(stderr, "%s: curr_row = %u\n", FUNC, curr_row);
+HDfprintf(stderr, "%s: min_nrows = %u, new_nrows = %u\n", FUNC, min_nrows, new_nrows);
+HDfprintf(stderr, "%s: iblock->nrows = %u\n", FUNC, iblock->nrows);
+HDfprintf(stderr, "%s: old_next_entry = %u, iblock->next_entry = %u\n", FUNC, old_next_entry, iblock->next_entry);
#endif /* QAK */
- /* Set indirect block's "next entry" information */
- iblock->next_col = 0;
- iblock->next_row = curr_row;
- iblock->next_size = hdr->man_dtable.row_block_size[curr_row];
- iblock->next_entry = u;
+/* Currently, the old block data is "thrown away" after the space is reallocated,
+* so avoid data copy in H5MF_realloc() call by just free'ing the space and
+* allocating new space.
+*
+* This also keeps the file smaller, by freeing the space and then
+* allocating new space, instead of vice versa (in H5MF_realloc).
+*
+* QAK - 3/14/2006
+*/
+ /* Free previous indirect block disk space */
+ if(H5MF_xfree(hdr->f, H5FD_MEM_FHEAP_IBLOCK, dxpl_id, iblock->addr, (hsize_t)iblock->size)<0)
+ HGOTO_ERROR(H5E_STORAGE, H5E_CANTFREE, FAIL, "unable to free fractal heap indirect block")
+
+ /* Compute size of buffer needed for new indirect block */
+ iblock->nrows = new_nrows;
+ iblock->size = H5HF_MAN_INDIRECT_SIZE(hdr, iblock);
+
+ /* Allocate space for the new indirect block on disk */
+ if(HADDR_UNDEF == (new_addr = H5MF_alloc(hdr->f, H5FD_MEM_FHEAP_IBLOCK, dxpl_id, (hsize_t)iblock->size)))
+ HGOTO_ERROR(H5E_STORAGE, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap indirect block")
+#ifdef QAK
+HDfprintf(stderr, "%s: new_addr = %a\n", FUNC, new_addr);
+#endif /* QAK */
+
+ /* Re-allocate direct block entry table */
+ if(NULL == (iblock->ents = H5FL_SEQ_REALLOC(H5HF_indirect_ent_t, iblock->ents, (iblock->nrows * hdr->man_dtable.cparam.width))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for direct entries")
+
+ /* Check for skipping over rows and add free section for skipped rows */
+ if(skip_direct_rows) {
+ /* Add skipped blocks to heap's free space */
+ if(H5HF_man_iblock_skip_blocks(hdr, iblock, new_addr,
+ next_entry, (new_next_entry - next_entry)) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't add skipped blocks to heap's free space")
+ } /* end if */
+
+ /* Initialize new direct block entries in rows added */
+ acc_dblock_free = 0;
+ for(u = (old_nrows * hdr->man_dtable.cparam.width); u < (iblock->nrows * hdr->man_dtable.cparam.width); u++) {
+ unsigned row = u / hdr->man_dtable.cparam.width; /* Row for current entry */
+
+ iblock->ents[u].addr = HADDR_UNDEF;
+ iblock->ents[u].free_space = hdr->man_dtable.row_dblock_free[row];
+ iblock->child_free_space += iblock->ents[u].free_space;
+ acc_dblock_free += iblock->ents[u].free_space;
+ } /* end for */
+
+ /* Mark indirect block as dirty */
+ if(H5HF_iblock_dirty(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
+
+ /* Move object in cache */
+ if(H5AC_rename(hdr->f, H5AC_FHEAP_IBLOCK, iblock->addr, new_addr) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTSPLIT, FAIL, "unable to move fractal heap root indirect block")
+
+ /* Update other shared header info */
+ hdr->man_dtable.curr_root_rows = new_nrows;
+ hdr->man_dtable.table_addr = new_addr;
+
+ /* Extend heap to cover new root indirect block */
+#ifdef QAK
+HDfprintf(stderr, "%s: hdr->man_dtable.row_block_off[new_nrows - 1] = %Hu\n", FUNC, hdr->man_dtable.row_block_off[new_nrows - 1]);
+HDfprintf(stderr, "%s: hdr->man_dtable.row_block_off[new_nrows] = %Hu\n", FUNC, hdr->man_dtable.row_block_off[new_nrows]);
+HDfprintf(stderr, "%s: acc_dblock_free = %Hu\n", FUNC, acc_dblock_free);
+#endif /* QAK */
+ if(H5HF_hdr_extend_heap(hdr, 2 * hdr->man_dtable.row_block_off[new_nrows - 1], acc_dblock_free) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, FAIL, "can't increase space to cover root direct block")
+
+ /* Mark heap header as modified */
+ if(H5HF_hdr_dirty(hdr) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark header as dirty")
+
+ /* Lock root indirect block (again) */
+ if(NULL == (iblock = H5HF_man_iblock_protect(hdr, dxpl_id, new_addr, hdr->man_dtable.curr_root_rows, NULL, 0, H5AC_WRITE)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
+ iblock->addr = new_addr;
+
+ /* Update the indirect block pointer in iterator */
+ /* (pins the indirect block after it's in the new location) */
+ if(H5HF_man_iter_update_iblock(&hdr->next_block, iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTMODIFY, FAIL, "unable to update indirect block for block iterator")
+
+ /* Release the indirect block (marked as dirty) */
+ if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock->addr, iblock, H5AC__DIRTIED_FLAG) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5HF_man_iblock_skip_ranges() */
+} /* end H5HF_man_iblock_double_root() */
/*-------------------------------------------------------------------------
@@ -540,8 +624,8 @@ done:
*-------------------------------------------------------------------------
*/
H5HF_indirect_t *
-H5HF_man_iblock_place_dblock(H5HF_t *hdr, hid_t dxpl_id, size_t min_dblock_size,
- haddr_t *addr_p, size_t *entry_p, size_t *dblock_size)
+H5HF_man_iblock_place_dblock(H5HF_hdr_t *hdr, hid_t dxpl_id, size_t min_dblock_size,
+ size_t *entry_p, size_t *dblock_size)
{
H5HF_indirect_t *iblock; /* Pointer to indirect block */
haddr_t iblock_addr; /* Indirect block's address */
@@ -557,7 +641,6 @@ HDfprintf(stderr, "%s: min_dblock_size = %Zu\n", FUNC, min_dblock_size);
*/
HDassert(hdr);
HDassert(min_dblock_size > 0);
- HDassert(addr_p);
/* Check for creating first indirect block */
if(hdr->man_dtable.curr_root_rows == 0) {
@@ -600,7 +683,7 @@ HDfprintf(stderr, "%s: iblock_addr = %a\n", FUNC, iblock_addr);
/* Move current direct block (used as root) into new indirect block */
/* Lock new indirect block */
- if(NULL == (iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, &nrows, hdr, H5AC_WRITE)))
+ if(NULL == (iblock = H5HF_man_iblock_protect(hdr, dxpl_id, iblock_addr, nrows, NULL, 0, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
/* Check if there's already a direct block as root) */
@@ -610,7 +693,7 @@ HDfprintf(stderr, "%s: have_direct_block = %u\n", FUNC, (unsigned)have_direct_bl
#endif /* QAK */
if(have_direct_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)))
+ if(NULL == (dblock = H5HF_man_dblock_protect(hdr, dxpl_id, hdr->man_dtable.table_addr, hdr->man_dtable.cparam.start_block_size, iblock, 0, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap direct block")
/* Point indirect block at direct block to add */
@@ -621,8 +704,6 @@ HDfprintf(stderr, "%s: have_direct_block = %u\n", FUNC, (unsigned)have_direct_bl
/* 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")
@@ -630,26 +711,29 @@ HDfprintf(stderr, "%s: have_direct_block = %u\n", FUNC, (unsigned)have_direct_bl
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 */
+ /* Set up iterator at correct location */
+ if(H5HF_man_iter_start_entry(hdr, &hdr->next_block, iblock, have_direct_block) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't initialize block iterator")
+
/* Check for skipping over direct blocks, in order to get to large enough block */
- if(min_dblock_size > iblock->next_size) {
+ if(min_dblock_size > hdr->man_dtable.cparam.start_block_size) {
/* Add skipped blocks to heap's free space */
if(H5HF_man_iblock_skip_blocks(hdr, iblock, iblock_addr,
have_direct_block, ((nrows - 1) * hdr->man_dtable.cparam.width) - have_direct_block) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, NULL, "can't add skipped blocks to heap's free space")
- HDassert(iblock->next_size == min_dblock_size);
} /* end if */
/* Mark indirect block as modified */
- if(H5HF_iblock_dirty(dxpl_id, iblock) < 0)
+ if(H5HF_iblock_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, NULL, "can't mark indirect block as dirty")
+ /* Unprotect root indirect block (it's pinned by the iterator though) */
+ if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock->addr, iblock, H5AC__DIRTIED_FLAG) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap indirect block")
+ iblock = NULL;
+
/* Point heap header at new indirect block */
hdr->man_dtable.curr_root_rows = nrows;
hdr->man_dtable.table_addr = iblock_addr;
@@ -668,341 +752,289 @@ HDfprintf(stderr, "%s: have_direct_block = %u\n", FUNC, (unsigned)have_direct_bl
HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, NULL, "can't increase space to cover root direct block")
/* Mark heap header as modified */
- hdr->dirty = TRUE;
+ if(H5HF_hdr_dirty(hdr) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, NULL, "can't mark header as dirty")
} /* end if */
else {
+ hbool_t walked_up, walked_down; /* Condition variables for finding direct block location */
+ unsigned next_row; /* Iterator's next block row */
+ unsigned next_entry; /* Iterator's next block entry */
+ unsigned min_dblock_row; /* Minimum row for direct block size request */
+
#ifdef QAK
HDfprintf(stderr, "%s: searching root indirect block\n", FUNC);
#endif /* QAK */
-
- /* Lock root indirect block */
- iblock_addr = hdr->man_dtable.table_addr;
- if(NULL == (iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, &hdr->man_dtable.curr_root_rows, hdr, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
-
+ /* Compute min. row for direct block requested */
+ min_dblock_row = H5HF_dtable_size_to_row(&hdr->man_dtable, min_dblock_size);
#ifdef QAK
-HDfprintf(stderr, "%s: iblock->next_row = %u, iblock->nrows = %u\n", FUNC, iblock->next_row, iblock->nrows);
-HDfprintf(stderr, "%s: iblock->next_size = %Zu\n", FUNC, iblock->next_size);
+HDfprintf(stderr, "%s: min_dblock_size = %Zu, min_dblock_row = %u\n", FUNC, min_dblock_size, min_dblock_row);
#endif /* QAK */
- /* Check if we need a block past current allocation */
- /* (i.e. extend the root indirect block) */
- if(iblock->next_row == iblock->nrows ||
- /* Don't try to extend the root indirect block if the requested
- * direct block is too large, but the
- * next direct block is in a child indirect block.
- */
- (iblock->nrows < hdr->man_dtable.max_direct_rows &&
- min_dblock_size > iblock->next_size)) {
- haddr_t new_addr; /* New address of indirect block */
- hsize_t acc_dblock_free; /* Accumulated free space in direct blocks */
- unsigned old_next_entry; /* The previous value of the "next entry" for the indirect block */
- unsigned min_nrows = 0; /* Min. # of direct rows */
- unsigned old_nrows; /* Old # of rows */
- unsigned new_nrows; /* New # of rows */
- size_t u; /* Local index variable */
+ /* Initialize block iterator, if necessary */
+ if(!H5HF_man_iter_ready(&hdr->next_block)) {
#ifdef QAK
-HDfprintf(stderr, "%s: Extending root indirect block\n", FUNC);
+HDfprintf(stderr, "%s: hdr->man_alloc_size = %Hu\n", FUNC, hdr->man_alloc_size);
#endif /* QAK */
+ /* Start iterator with offset of allocated space */
+ if(H5HF_man_iter_start_offset(hdr, dxpl_id, &hdr->next_block, hdr->man_alloc_size) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "unable to set block iterator location")
+ } /* end if */
- /* Keep this for later */
- old_next_entry = iblock->next_entry;
- old_nrows = iblock->nrows;
-
- /* Check for skipping over rows */
- if(iblock->nrows < hdr->man_dtable.max_direct_rows && min_dblock_size > iblock->next_size) {
- /* Sanity check */
- HDassert(min_dblock_size > hdr->man_dtable.cparam.start_block_size);
-
- /* Make certain we allocate at least the required row for the block requested */
- min_nrows = 2 + (H5V_log2_of2(min_dblock_size) - H5V_log2_of2(hdr->man_dtable.cparam.start_block_size));
-
- /* Set the information for the next block, of the appropriate size */
- iblock->next_entry = (min_nrows - 1) * hdr->man_dtable.cparam.width;
- } /* end if */
- /* Check for special case of second row, which has blocks the same size as first row */
- else if(iblock->next_row == 1)
- iblock->next_size = hdr->man_dtable.cparam.start_block_size;
+ /* Get information about current iterator location */
+ if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL,
+ &next_entry, &iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, NULL, "unable to retrieve current block iterator location")
- /* Compute new # of rows in indirect block */
- new_nrows = MAX(min_nrows, MIN(2 * iblock->nrows, iblock->max_rows));
#ifdef QAK
-HDfprintf(stderr, "%s: min_nrows = %u, new_nrows = %u\n", FUNC, min_nrows, new_nrows);
+HDfprintf(stderr, "%s: Check 1.0\n", FUNC);
+HDfprintf(stderr, "%s: iblock = %p\n", FUNC, iblock);
HDfprintf(stderr, "%s: iblock->nrows = %u\n", FUNC, iblock->nrows);
-HDfprintf(stderr, "%s: old_next_entry = %u, iblock->next_entry = %u\n", FUNC, old_next_entry, iblock->next_entry);
+HDfprintf(stderr, "%s: next_row = %u\n", FUNC, next_row);
+HDfprintf(stderr, "%s: next_entry = %u\n", FUNC, next_entry);
#endif /* QAK */
-
-/* Currently, the old block data is "thrown away" after the space is reallocated,
-* so avoid data copy in H5MF_realloc() call by just free'ing the space and
-* allocating new space.
-*
-* This also keeps the file smaller, by freeing the space and then
-* allocating new space, instead of vice versa (in H5MF_realloc).
-*
-* QAK - 3/14/2006
-*/
- /* Free previous indirect block disk space */
- if(H5MF_xfree(hdr->f, H5FD_MEM_FHEAP_IBLOCK, dxpl_id, iblock_addr, (hsize_t)iblock->size)<0)
- HGOTO_ERROR(H5E_STORAGE, H5E_CANTFREE, NULL, "unable to free fractal heap indirect block")
-
- /* Compute size of buffer needed for new indirect block */
- iblock->nrows = new_nrows;
- iblock->size = H5HF_MAN_INDIRECT_SIZE(hdr, iblock);
-
- /* Allocate space for the new indirect block on disk */
- if(HADDR_UNDEF == (new_addr = H5MF_alloc(hdr->f, H5FD_MEM_FHEAP_IBLOCK, dxpl_id, (hsize_t)iblock->size)))
- HGOTO_ERROR(H5E_STORAGE, H5E_NOSPACE, NULL, "file allocation failed for fractal heap indirect block")
+ /* Check for skipping over blocks in the current block */
+ if(min_dblock_row > next_row) {
+ unsigned min_entry; /* Min entry for direct block requested */
+ unsigned skip_entries; /* Number of entries to skip in the current block */
+
+ /* Compute the number of entries to skip in the current block */
+ min_entry = min_dblock_row * hdr->man_dtable.cparam.width;
+ if(min_dblock_row >= iblock->nrows)
+ skip_entries = (iblock->nrows * hdr->man_dtable.cparam.width) - next_entry;
+ else
+ skip_entries = min_entry - next_entry;
#ifdef QAK
-HDfprintf(stderr, "%s: new_addr = %a\n", FUNC, new_addr);
+HDfprintf(stderr, "%s: min_entry = %u, skip_entries = %u\n", FUNC, min_entry, skip_entries);
#endif /* QAK */
- /* Re-allocate direct block entry table */
- if(NULL == (iblock->ents = H5FL_SEQ_REALLOC(H5HF_indirect_ent_t, iblock->ents, (iblock->nrows * hdr->man_dtable.cparam.width))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for direct entries")
-
- /* Check for skipping over rows and add free section for skipped rows */
- if(iblock->nrows < hdr->man_dtable.max_direct_rows && min_dblock_size > iblock->next_size) {
- /* Add skipped blocks to heap's free space */
- if(H5HF_man_iblock_skip_blocks(hdr, iblock, new_addr,
- old_next_entry, (iblock->next_entry - old_next_entry)) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, NULL, "can't add skipped blocks to heap's free space")
- HDassert(iblock->next_size == min_dblock_size);
- } /* end if */
-
- /* Initialize new direct block entries in rows added */
- acc_dblock_free = 0;
- for(u = (old_nrows * hdr->man_dtable.cparam.width); u < (iblock->nrows * hdr->man_dtable.cparam.width); u++) {
- unsigned row = u / hdr->man_dtable.cparam.width; /* Row for current entry */
-
- iblock->ents[u].addr = HADDR_UNDEF;
- iblock->ents[u].free_space = hdr->man_dtable.row_dblock_free[row];
- iblock->child_free_space += iblock->ents[u].free_space;
- acc_dblock_free += iblock->ents[u].free_space;
- } /* end for */
-
- /* Mark indirect block as dirty */
- if(H5HF_iblock_dirty(dxpl_id, iblock) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, NULL, "can't mark indirect block as dirty")
-
- /* Release the indirect block (marked as dirty) */
- if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, iblock, H5AC__DIRTIED_FLAG) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap indirect block")
- iblock = NULL;
-
- /* Move object in cache */
- if(H5AC_rename(hdr->f, H5AC_FHEAP_IBLOCK, iblock_addr, new_addr) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTSPLIT, NULL, "unable to move fractal heap root indirect block")
-
- /* Update other shared header info */
- hdr->man_dtable.curr_root_rows = new_nrows;
- hdr->man_dtable.table_addr = iblock_addr = new_addr;
+ /* Add skipped direct blocks to heap's free space */
+ if(H5HF_man_iblock_skip_blocks(hdr, iblock, iblock->addr, next_entry, skip_entries) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, NULL, "can't add skipped blocks to heap's free space")
- /* Extend heap to cover new root indirect block */
+ /* Get information about new iterator location */
+ if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL,
+ &next_entry, &iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, NULL, "unable to retrieve current block iterator location")
+ } /* end if */
#ifdef QAK
-HDfprintf(stderr, "%s: hdr->man_dtable.row_block_off[new_nrows - 1] = %Hu\n", FUNC, hdr->man_dtable.row_block_off[new_nrows - 1]);
-HDfprintf(stderr, "%s: hdr->man_dtable.row_block_off[new_nrows] = %Hu\n", FUNC, hdr->man_dtable.row_block_off[new_nrows]);
-HDfprintf(stderr, "%s: acc_dblock_free = %Hu\n", FUNC, acc_dblock_free);
+HDfprintf(stderr, "%s: Check 2.0\n", FUNC);
+HDfprintf(stderr, "%s: iblock = %p\n", FUNC, iblock);
+HDfprintf(stderr, "%s: iblock->nrows = %u\n", FUNC, iblock->nrows);
+HDfprintf(stderr, "%s: next_row = %u\n", FUNC, next_row);
+HDfprintf(stderr, "%s: next_entry = %u\n", FUNC, next_entry);
#endif /* QAK */
- if(H5HF_hdr_extend_heap(hdr, 2 * hdr->man_dtable.row_block_off[new_nrows - 1], acc_dblock_free) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, NULL, "can't increase space to cover root direct block")
-
- /* Mark heap header as modified */
- hdr->dirty = TRUE;
- /* Lock root indirect block (again) */
- if(NULL == (iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, &hdr->man_dtable.curr_root_rows, hdr, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
- iblock->addr = iblock_addr;
- } /* end if */
+ do {
+ /* Reset conditions for leaving loop */
+ walked_up = walked_down = FALSE;
+ /* Check for walking off end of indirect block */
+ /* (walk up iterator) */
+ while(next_row >= iblock->nrows) {
#ifdef QAK
-HDfprintf(stderr, "%s: Check 1.0\n", FUNC);
-HDfprintf(stderr, "%s: iblock->next_row = %u\n", FUNC, iblock->next_row);
-HDfprintf(stderr, "%s: iblock->next_col = %u\n", FUNC, iblock->next_col);
-HDfprintf(stderr, "%s: iblock->next_size = %Zu\n", FUNC, iblock->next_size);
-HDfprintf(stderr, "%s: iblock->next_entry = %u\n", FUNC, iblock->next_entry);
+HDfprintf(stderr, "%s: Off the end of a block\n", FUNC);
#endif /* QAK */
- /* Check for full direct block entries in current indirect block */
- while(iblock->next_row >= hdr->man_dtable.max_direct_rows) {
- haddr_t new_iblock_addr; /* New indirect block's address */
- H5HF_indirect_t *new_iblock; /* Pointer to new indirect block */
- unsigned hdr_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for indirect block */
- unsigned nrows; /* Number of rows in new indirect block */
-
- /* Compute # of rows in child indirect block */
- nrows = (H5V_log2_of2((uint32_t)iblock->next_size) - hdr->man_dtable.first_row_bits) + 1;
+ /* Check for needing to expand root indirect block */
+ if(iblock->parent == NULL) {
#ifdef QAK
-HDfprintf(stderr, "%s: Check 2.0\n", FUNC);
-HDfprintf(stderr, "%s: iblock->next_size = %Hu, nrows = %u\n", FUNC, iblock->next_size, nrows);
-HDfprintf(stderr, "%s: iblock->next_entry = %u\n", FUNC, iblock->next_entry);
-HDfprintf(stderr, "%s: iblock->next_row = %u\n", FUNC, iblock->next_row);
-HDfprintf(stderr, "%s: iblock->max_rows = %u\n", FUNC, iblock->max_rows);
+HDfprintf(stderr, "%s: Doubling root block\n", FUNC);
+#endif /* QAK */
+ if(H5HF_man_iblock_double_root(hdr, dxpl_id, min_dblock_size) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, NULL, "unable to double root indirect block")
+ } /* end if */
+ else {
+#ifdef QAK
+HDfprintf(stderr, "%s: Walking up a level\n", FUNC);
#endif /* QAK */
+ /* Move iterator up one level */
+ if(H5HF_man_iter_up(&hdr->next_block) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTNEXT, NULL, "unable to advance current block iterator location")
- /* Check for skipping over indirect block rows */
- if(hdr->man_dtable.row_block_size[nrows - 1] < min_dblock_size) {
- unsigned child_rows_needed; /* Number of rows needed to hold direct block */
+ /* Increment location of next block at this level */
+ if(H5HF_man_iter_next(hdr, &hdr->next_block, 1) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't advance fractal heap block location")
+ } /* end else */
+
+ /* Get information about new iterator location */
+ if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL,
+ &next_entry, &iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, NULL, "unable to retrieve current block iterator location")
- /* Compute # of rows needed in child indirect block */
- child_rows_needed = (H5V_log2_of2(min_dblock_size) - H5V_log2_of2(hdr->man_dtable.cparam.start_block_size)) + 2;
- HDassert(child_rows_needed > nrows);
+ /* Indicate that we walked up */
+ walked_up = TRUE;
+ } /* end if */
#ifdef QAK
-HDfprintf(stderr, "%s: child_rows_needed = %u\n", FUNC, child_rows_needed);
+HDfprintf(stderr, "%s: Check 3.0\n", FUNC);
+HDfprintf(stderr, "%s: iblock = %p\n", FUNC, iblock);
+HDfprintf(stderr, "%s: iblock->nrows = %u\n", FUNC, iblock->nrows);
+HDfprintf(stderr, "%s: next_row = %u\n", FUNC, next_row);
+HDfprintf(stderr, "%s: next_entry = %u\n", FUNC, next_entry);
#endif /* QAK */
- /* Add skipped indirect ranges to heap's free space */
- if(H5HF_man_iblock_skip_ranges(hdr, iblock, iblock->addr, iblock->next_entry, (child_rows_needed - nrows) * hdr->man_dtable.cparam.width) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, NULL, "can't add skipped blocks to heap's free space")
+ /* Check for walking into child indirect block */
+ /* (walk down iterator) */
+ if(next_row >= hdr->man_dtable.max_direct_rows) {
+ hsize_t next_size; /* Size of next direct block to create */
+ unsigned child_nrows; /* Number of rows in new indirect block */
- /* Update the number of rows in requested child indirect block */
- nrows = child_rows_needed;
#ifdef QAK
-HDfprintf(stderr, "%s: (new) nrows = %u\n", FUNC, nrows);
+HDfprintf(stderr, "%s: Walking down into child indirect block\n", FUNC);
#endif /* QAK */
- } /* end if */
#ifdef QAK
-HDfprintf(stderr, "%s: iblock->next_size = %Hu, nrows = %u\n", FUNC, iblock->next_size, nrows);
-HDfprintf(stderr, "%s: iblock->next_entry = %u\n", FUNC, iblock->next_entry);
-HDfprintf(stderr, "%s: iblock->next_row = %u\n", FUNC, iblock->next_row);
-HDfprintf(stderr, "%s: iblock->max_rows = %u\n", FUNC, iblock->max_rows);
+HDfprintf(stderr, "%s: Check 3.1\n", FUNC);
+HDfprintf(stderr, "%s: iblock = %p\n", FUNC, iblock);
+HDfprintf(stderr, "%s: iblock->nrows = %u\n", FUNC, iblock->nrows);
+HDfprintf(stderr, "%s: next_row = %u\n", FUNC, next_row);
+HDfprintf(stderr, "%s: next_entry = %u\n", FUNC, next_entry);
#endif /* QAK */
+ HDassert(!H5F_addr_defined(iblock->ents[next_entry].addr));
- /* Check for walking off indirect block rows */
- if(iblock->next_row >= iblock->max_rows) {
+ /* Compute # of rows in next child indirect block to use */
+ next_size = hdr->man_dtable.row_block_size[next_row];
+ child_nrows = (H5V_log2_gen(next_size) - hdr->man_dtable.first_row_bits) + 1;
#ifdef QAK
-HDfprintf(stderr, "%s: iblock->parent->nrows = %u\n", FUNC, iblock->parent->nrows);
-HDfprintf(stderr, "%s: iblock->parent->next_entry = %u\n", FUNC, iblock->parent->next_entry);
-HDfprintf(stderr, "%s: iblock->parent->next_size = %Hu\n", FUNC, iblock->parent->next_size);
-HDfprintf(stderr, "%s: iblock->parent->next_row = %u\n", FUNC, iblock->parent->next_row);
-HDfprintf(stderr, "%s: iblock->parent->next_col = %u\n", FUNC, iblock->parent->next_col);
+HDfprintf(stderr, "%s: child_nrows = %u\n", FUNC, child_nrows);
#endif /* QAK */
- /* Locate parent indirect block */
- new_iblock_addr = iblock->parent->addr;
- nrows = iblock->parent->nrows;
- /* Lock parent indirect block */
- if(NULL == (new_iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, new_iblock_addr, &nrows, hdr, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
+ /* Check for skipping over indirect blocks */
+ /* (that don't have direct blocks large enough to hold direct block size requested) */
+ if(hdr->man_dtable.row_block_size[child_nrows - 1] < min_dblock_size) {
+ unsigned child_rows_needed; /* Number of rows needed to hold direct block */
+ unsigned child_entry; /* Entry of child indirect block */
- /* Advance location in parent lock */
- if(H5HF_man_iblock_inc_loc(new_iblock) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't advance fractal heap block location")
- } /* end if */
- else {
- /* Check for allocating new indirect block */
- if(!H5F_addr_defined(iblock->ents[iblock->next_entry].addr)) {
+#ifdef QAK
+HDfprintf(stderr, "%s: Skipping indirect block row that is too small\n", FUNC);
+#endif /* QAK */
+ /* Compute # of rows needed in child indirect block */
+ child_rows_needed = (H5V_log2_of2(min_dblock_size) - H5V_log2_of2(hdr->man_dtable.cparam.start_block_size)) + 2;
+ HDassert(child_rows_needed > child_nrows);
+ child_entry = (next_row + (child_rows_needed - child_nrows)) * hdr->man_dtable.cparam.width;
+#ifdef QAK
+HDfprintf(stderr, "%s: child_rows_needed = %u\n", FUNC, child_rows_needed);
+HDfprintf(stderr, "%s: child_entry = %u\n", FUNC, child_entry);
+#endif /* QAK */
+
+ /* Add skipped indirect ranges to heap's free space */
+ if(H5HF_man_iblock_skip_ranges(hdr, iblock, iblock->addr, next_entry, (child_entry - next_entry)) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, NULL, "can't add skipped blocks to heap's free space")
+ } /* end if */
+ else {
+ H5HF_indirect_t *new_iblock; /* Pointer to new indirect block */
hsize_t new_iblock_off; /* Direct block offset in heap address space */
+ haddr_t new_iblock_addr; /* New indirect block's address */
+
#ifdef QAK
- HDfprintf(stderr, "%s: Allocating new indirect block\n", FUNC);
+HDfprintf(stderr, "%s: Allocating new child 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);
+ new_iblock_off += hdr->man_dtable.row_block_off[next_entry / hdr->man_dtable.cparam.width];
+ new_iblock_off += hdr->man_dtable.row_block_size[next_entry / hdr->man_dtable.cparam.width] * (next_entry % hdr->man_dtable.cparam.width);
/* Allocate new indirect block */
- if(H5HF_man_iblock_create(hdr, dxpl_id, new_iblock_off, nrows, nrows, &new_iblock_addr) < 0)
+ if(H5HF_man_iblock_create(hdr, dxpl_id, new_iblock_off, child_nrows, child_nrows, &new_iblock_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "can't allocate fractal heap indirect block")
/* Lock new indirect block */
- if(NULL == (new_iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, new_iblock_addr, &nrows, hdr, H5AC_WRITE)))
+ if(NULL == (new_iblock = H5HF_man_iblock_protect(hdr, dxpl_id, new_iblock_addr, child_nrows, iblock, next_entry, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
/* Set parent information */
HDassert(new_iblock->parent == NULL);
new_iblock->parent = iblock;
- new_iblock->par_entry = iblock->next_entry;
- new_iblock->par_nrows = iblock->nrows;
- new_iblock->par_addr = iblock->addr;
+ new_iblock->par_entry = next_entry;
if(H5HF_iblock_incr(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't increment reference count on shared indirect block")
/* Point current indirect block at new indirect block */
- iblock->ents[iblock->next_entry].addr = new_iblock_addr;
+ iblock->ents[next_entry].addr = new_iblock_addr;
+
+ /* Move iterator down one level */
+ if(H5HF_man_iter_down(&hdr->next_block, new_iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTNEXT, NULL, "unable to advance current block iterator location")
+
+ /* Get information about new iterator location */
+ if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL,
+ &next_entry, NULL) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, NULL, "unable to retrieve current block iterator location")
+ next_size = hdr->man_dtable.row_block_size[next_row];
#ifdef QAK
- HDfprintf(stderr, "%s: new_iblock->next_row = %u\n", FUNC, new_iblock->next_row);
- HDfprintf(stderr, "%s: new_iblock->next_col = %u\n", FUNC, new_iblock->next_col);
- HDfprintf(stderr, "%s: new_iblock->next_size = %Zu\n", FUNC, new_iblock->next_size);
- HDfprintf(stderr, "%s: new_iblock->next_entry = %u\n", FUNC, new_iblock->next_entry);
+HDfprintf(stderr, "%s: next_row = %u\n", FUNC, next_row);
+HDfprintf(stderr, "%s: next_entry = %u\n", FUNC, next_entry);
#endif /* QAK */
/* Check for skipping over rows and add free section for skipped rows */
- if(min_dblock_size > new_iblock->next_size) {
+ if(min_dblock_size > next_size) {
unsigned new_entry; /* Entry of direct block which is large enough */
/* Compute entry for direct block size requested */
- new_entry = hdr->man_dtable.cparam.width *
- (1 + (H5V_log2_of2(min_dblock_size) - H5V_log2_of2(hdr->man_dtable.cparam.start_block_size)));
+ new_entry = hdr->man_dtable.cparam.width * min_dblock_row;
#ifdef QAK
- HDfprintf(stderr, "%s: new_entry = %u\n", FUNC, new_entry);
+HDfprintf(stderr, "%s: Skipping rows in new child indirect block - new_entry = %u\n", FUNC, new_entry);
#endif /* QAK */
/* Add skipped blocks to heap's free space */
if(H5HF_man_iblock_skip_blocks(hdr, new_iblock, new_iblock->addr, 0, new_entry) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, NULL, "can't add skipped blocks to heap's free space")
- HDassert(new_iblock->next_size == min_dblock_size);
} /* end if */
- /* Mark current indirect block as modified */
- if(H5HF_iblock_dirty(dxpl_id, iblock) < 0)
+ /* Mark new indirect block as modified */
+ if(H5HF_iblock_dirty(new_iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, NULL, "can't mark indirect block as dirty")
- /* Set dirty flag for the current indirect block */
- hdr_flags |= H5AC__DIRTIED_FLAG;
- } /* end if */
- else {
-#ifdef QAK
- HDfprintf(stderr, "%s: Descending existing indirect block\n", FUNC);
-#endif /* QAK */
- /* Locate child indirect block */
- new_iblock_addr = iblock->ents[iblock->next_entry].addr;
+ /* Mark current indirect block as modified */
+ if(H5HF_iblock_dirty(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, NULL, "can't mark indirect block as dirty")
- /* Lock new indirect block */
- if(NULL == (new_iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, new_iblock_addr, &nrows, hdr, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
- } /* end else */
- } /* end else */
-#ifdef QAK
-HDfprintf(stderr, "%s: new_iblock->next_row = %u\n", FUNC, new_iblock->next_row);
-HDfprintf(stderr, "%s: new_iblock->next_col = %u\n", FUNC, new_iblock->next_col);
-HDfprintf(stderr, "%s: new_iblock->next_size = %Zu\n", FUNC, new_iblock->next_size);
-HDfprintf(stderr, "%s: new_iblock->next_entry = %u\n", FUNC, new_iblock->next_entry);
-#endif /* QAK */
+ /* Unprotect child indirect block */
+ if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, new_iblock->addr, new_iblock, H5AC__DIRTIED_FLAG) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap indirect block")
+ } /* end else */
- /* Release the current indirect block (possibly marked as dirty) */
- if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, iblock, hdr_flags) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, NULL, "unable to release fractal heap indirect block")
+ /* Get information about new iterator location */
+ if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL,
+ &next_entry, &iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, NULL, "unable to retrieve current block iterator location")
- /* Switch variables to use new indirect block */
- iblock = new_iblock;
- iblock_addr = new_iblock_addr;
-#ifdef QAK
-HDfprintf(stderr, "%s: new_iblock_addr = %a\n", FUNC, new_iblock_addr);
-#endif /* QAK */
- } /* end while */
+ /* Indicate that we walked down */
+ walked_down = TRUE;
+ } /* end while */
+ } while(walked_down || walked_up);
} /* end else */
+ /* Get information about iterator location */
+{
+ unsigned next_row; /* Iterator's next block row */
+ unsigned next_entry; /* Iterator's next block entry */
+ size_t next_size; /* Size of next direct block to create */
+
+ if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL,
+ &next_entry, &iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, NULL, "unable to retrieve current block iterator location")
+ HDassert(next_row < iblock->nrows);
+ next_size = hdr->man_dtable.row_block_size[next_row];
+
/* Check for skipping over blocks */
- if(min_dblock_size > iblock->next_size) {
-HDfprintf(stderr, "%s: Skipping direct block sizes not supported, iblock->next_size = %Zu\n", FUNC, iblock->next_size);
+ if(min_dblock_size > next_size) {
+HDfprintf(stderr, "%s: Skipping direct block sizes not supported, min_dblock_size = %Zu, next_size = %Zu\n", FUNC, min_dblock_size, next_size);
HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, NULL, "skipping direct block sizes not supported yet")
} /* end if */
- /* Set address of indirect block that's the immediate parent of new direct block */
- *addr_p = iblock_addr;
-
/* Set entry for new direct block to use */
- *entry_p = iblock->next_entry;
+ *entry_p = next_entry;
/* Set size of direct block to create */
- *dblock_size = iblock->next_size;
+ *dblock_size = next_size;
+#ifdef OLD_WAY
/* Increment location of next block from this indirect block */
- if(H5HF_man_iblock_inc_loc(iblock) < 0)
+ if(H5HF_man_iter_next(hdr, &hdr->next_block, 1) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't advance fractal heap block location")
+#endif /* OLD_WAY */
/* Set return value */
ret_value = iblock;
+}
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -1026,16 +1058,13 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5HF_man_iblock_alloc_range(H5HF_t *hdr, hid_t dxpl_id,
- H5HF_free_section_t **sec_node, size_t obj_size)
+H5HF_man_iblock_alloc_range(H5HF_hdr_t *hdr, hid_t dxpl_id,
+ H5HF_free_section_t **sec_node)
{
H5HF_indirect_t *iblock; /* Pointer to indirect block */
- haddr_t iblock_addr; /* Indirect block's address */
haddr_t dblock_addr; /* Direct block's address */
- unsigned iblock_nrows; /* Indirect block's number of rows */
H5HF_free_section_t *dblock_sec_node = NULL; /* Pointer to direct block's section node */
H5HF_free_section_t *old_sec_node = *sec_node; /* Pointer to old section node */
- size_t full_obj_size; /* Size of object including metadata */
unsigned cur_entry; /* Current entry in indirect block */
herr_t ret_value = SUCCEED; /* Return value */
@@ -1046,7 +1075,6 @@ H5HF_man_iblock_alloc_range(H5HF_t *hdr, hid_t dxpl_id,
*/
HDassert(hdr);
HDassert(sec_node && *sec_node);
- HDassert(obj_size > 0);
/* Compute info about range */
cur_entry = (old_sec_node->u.range.row * hdr->man_dtable.cparam.width) + old_sec_node->u.range.col;
@@ -1057,20 +1085,9 @@ HDfprintf(stderr, "%s: Can't handle range sections over indirect blocks yet\n",
HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "'range' free space sections over indirect blocks not supported yet")
} /* end if */
- /* Get information about indirect block covering section */
- /* (Allow for root indirect block being resized) */
- iblock_addr = old_sec_node->u.range.iblock_addr;
- if(H5F_addr_eq(iblock_addr, hdr->man_dtable.table_addr))
- iblock_nrows = hdr->man_dtable.curr_root_rows;
- else
- iblock_nrows = old_sec_node->u.range.iblock_nrows;
-
/* Get a pointer to the indirect block covering the range */
- if(NULL == (iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, &iblock_nrows, hdr, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
-
- /* Compute size of object, with metadata overhead */
- full_obj_size = obj_size + H5HF_MAN_ABS_DIRECT_OBJ_PREFIX_LEN(hdr);
+ iblock = old_sec_node->u.range.iblock;
+ HDassert(iblock);
#ifdef QAK
HDfprintf(stderr, "%s: cur_entry = %u\n", FUNC, cur_entry);
@@ -1087,9 +1104,19 @@ HDfprintf(stderr, "%s: old_sec_node->sect_addr = %a\n", FUNC, old_sec_node->sect
/* Hook direct block up to indirect block */
iblock->ents[cur_entry].addr = dblock_addr;
+ /* Mark indirect block as dirty */
+ if(H5HF_iblock_dirty(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
+
/* Check for only single block covered in range section */
- if(old_sec_node->u.range.num_entries == 1)
+ if(old_sec_node->u.range.num_entries == 1) {
+ /* Drop reference count on indirect block that free section is in */
+ if(H5HF_iblock_decr(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block")
+
+ /* Free section structure */
H5FL_FREE(H5HF_free_section_t, old_sec_node);
+ } /* end if */
else {
/* Adjust section information */
old_sec_node->sect_addr += hdr->man_dtable.row_block_size[old_sec_node->u.range.row];
@@ -1103,10 +1130,6 @@ HDfprintf(stderr, "%s: old_sec_node->sect_addr = %a\n", FUNC, old_sec_node->sect
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add indirect block free space to global list")
} /* end else */
- /* Release the indirect block (marked as dirty) */
- if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, iblock, H5AC__DIRTIED_FLAG) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
-
/* Point 'sec_node' at new direct block section node */
*sec_node = dblock_sec_node;
@@ -1133,16 +1156,13 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5HF_man_iblock_alloc_indirect(H5HF_t *hdr, hid_t dxpl_id,
- H5HF_free_section_t **sec_node, size_t obj_size)
+H5HF_man_iblock_alloc_indirect(H5HF_hdr_t *hdr, hid_t dxpl_id,
+ H5HF_free_section_t **sec_node)
{
H5HF_indirect_t *iblock; /* Pointer to indirect block */
H5HF_indirect_t *child_iblock; /* Pointer to child indirect block */
- unsigned iblock_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for parent indirect block */
- haddr_t iblock_addr; /* Indirect block's address */
haddr_t child_iblock_addr; /* Address of child indirect block */
haddr_t dblock_addr; /* New direct block's address */
- unsigned iblock_nrows; /* Indirect block's number of rows */
H5HF_free_section_t *dblock_sec_node = NULL; /* Pointer to direct block's section node */
H5HF_free_section_t *range_sec_node = NULL; /* Pointer to new range section node */
H5HF_free_section_t *old_sec_node = *sec_node; /* Pointer to old indirect section node */
@@ -1157,22 +1177,12 @@ H5HF_man_iblock_alloc_indirect(H5HF_t *hdr, hid_t dxpl_id,
*/
HDassert(hdr);
HDassert(sec_node && *sec_node);
- HDassert(obj_size > 0);
/* Compute info about range */
curr_entry = (old_sec_node->u.indirect.row * hdr->man_dtable.cparam.width) + old_sec_node->u.indirect.col;
- /* Get information about indirect block covering section */
- /* (Allow for root indirect block being resized) */
- iblock_addr = old_sec_node->u.indirect.iblock_addr;
- if(H5F_addr_eq(iblock_addr, hdr->man_dtable.table_addr))
- iblock_nrows = hdr->man_dtable.curr_root_rows;
- else
- iblock_nrows = old_sec_node->u.indirect.iblock_nrows;
-
- /* Get a pointer to the indirect block covering the range */
- if(NULL == (iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, &iblock_nrows, hdr, H5AC_WRITE)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
+ /* Get a pointer to the indirect block covering the section */
+ iblock = old_sec_node->u.indirect.iblock;
#ifdef QAK
HDfprintf(stderr, "%s: curr_entry = %u\n", FUNC, curr_entry);
@@ -1186,7 +1196,7 @@ HDfprintf(stderr, "%s: old_sec_node->u.indirect.num_entries = %u\n", FUNC, old_s
if(H5F_addr_defined(iblock->ents[curr_entry].addr)) {
/* Look up existing child indirect block */
child_iblock_addr = iblock->ents[curr_entry].addr;
- if(NULL == (child_iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, child_iblock_addr, &old_sec_node->u.indirect.indir_nrows, hdr, H5AC_WRITE)))
+ if(NULL == (child_iblock = H5HF_man_iblock_protect(hdr, dxpl_id, child_iblock_addr, old_sec_node->u.indirect.indir_nrows, iblock, curr_entry, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
} /* end if */
else {
@@ -1207,15 +1217,13 @@ HDfprintf(stderr, "%s: new_iblock_off = %Hu\n", FUNC, new_iblock_off);
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't allocate fractal heap indirect block")
/* Lock new child indirect block */
- if(NULL == (child_iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, child_iblock_addr, &old_sec_node->u.indirect.indir_nrows, hdr, H5AC_WRITE)))
+ if(NULL == (child_iblock = H5HF_man_iblock_protect(hdr, dxpl_id, child_iblock_addr, old_sec_node->u.indirect.indir_nrows, iblock, curr_entry, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
/* Set parent information */
HDassert(child_iblock->parent == NULL);
child_iblock->parent = iblock;
child_iblock->par_entry = curr_entry;
- child_iblock->par_nrows = iblock->nrows;
- child_iblock->par_addr = iblock->addr;
if(H5HF_iblock_incr(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block")
#ifdef QAK
@@ -1227,11 +1235,8 @@ HDfprintf(stderr, "%s: child_iblock->child_free_space = %Hu\n", FUNC, child_iblo
HDassert(iblock->ents[curr_entry].free_space == child_iblock->child_free_space);
/* Mark parent indirect block as modified */
- if(H5HF_iblock_dirty(dxpl_id, iblock) < 0)
+ if(H5HF_iblock_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
-
- /* Set dirty flag for the parent indirect block */
- iblock_flags |= H5AC__DIRTIED_FLAG;
} /* end else */
/* Compute entry for new direct block in child indirect block */
@@ -1249,6 +1254,10 @@ HDfprintf(stderr, "%s: old_sec_node->sect_addr = %a\n", FUNC, old_sec_node->sect
/* Hook direct block up to child indirect block */
child_iblock->ents[dblock_entry].addr = dblock_addr;
+ /* Mark child indirect block as modified */
+ if(H5HF_iblock_dirty(child_iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
+
/* Create "range" section for other direct blocks in row of child indirect block */
@@ -1261,8 +1270,9 @@ HDfprintf(stderr, "%s: old_sec_node->sect_addr = %a\n", FUNC, old_sec_node->sect
+ hdr->man_dtable.row_block_size[old_sec_node->u.indirect.indir_row];
range_sec_node->sect_size = old_sec_node->sect_size;
range_sec_node->type = H5HF_SECT_RANGE;
- range_sec_node->u.range.iblock_addr = child_iblock_addr;
- range_sec_node->u.range.iblock_nrows = child_iblock->nrows;
+ range_sec_node->u.range.iblock = child_iblock;
+ if(H5HF_iblock_incr(child_iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block")
range_sec_node->u.range.row = old_sec_node->u.indirect.indir_row;
range_sec_node->u.range.col = 1;
range_sec_node->u.range.num_entries = hdr->man_dtable.cparam.width - 1;
@@ -1275,8 +1285,14 @@ HDfprintf(stderr, "%s: old_sec_node->sect_addr = %a\n", FUNC, old_sec_node->sect
/* Reduce "indirect" section */
/* Check for only single block covered in range section */
- if(old_sec_node->u.indirect.num_entries == 1)
+ if(old_sec_node->u.indirect.num_entries == 1) {
+ /* Drop reference count on indirect block that free section is in */
+ if(H5HF_iblock_decr(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block")
+
+ /* Free section structure */
H5FL_FREE(H5HF_free_section_t, old_sec_node);
+ } /* end if */
else {
/* Adjust section information */
old_sec_node->sect_addr += hdr->man_dtable.row_block_size[old_sec_node->u.indirect.row];
@@ -1294,10 +1310,6 @@ HDfprintf(stderr, "%s: old_sec_node->sect_addr = %a\n", FUNC, old_sec_node->sect
if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, child_iblock_addr, child_iblock, H5AC__DIRTIED_FLAG) < 0)
HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
- /* Release the parent indirect block (possibly dirty) */
- if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, iblock, iblock_flags) < 0)
- HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
-
/* Point 'sec_node' at new direct block section node */
*sec_node = dblock_sec_node;
@@ -1307,6 +1319,117 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5HF_man_iblock_alloc_opaque
+ *
+ * Purpose: Break up an opaque section into component sections
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Apr 25 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5HF_man_iblock_alloc_opaque(H5HF_hdr_t *hdr, hid_t dxpl_id,
+ H5HF_free_section_t **sec_node)
+{
+ H5HF_indirect_t *iblock; /* Pointer to indirect block */
+ H5HF_free_section_t *old_sec_node = *sec_node; /* Pointer to old section node */
+ haddr_t child_addr; /* Child block's address */
+ unsigned entry; /* Entry of child block for section */
+ unsigned row; /* Row of child block for section */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5HF_man_iblock_alloc_opaque)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(hdr);
+ HDassert(sec_node && *sec_node);
+
+ /* Get a pointer to the indirect block covering the section */
+ iblock = old_sec_node->u.opaque.iblock;
+ HDassert(iblock);
+
+ /* Compute info about child block */
+ entry = old_sec_node->u.opaque.entry;
+ row = entry / hdr->man_dtable.cparam.width;
+ child_addr = iblock->ents[entry].addr;
+
+ /* Check if this section's child block is direct or indirect */
+ if(row < hdr->man_dtable.max_direct_rows) {
+ H5HF_direct_t *child_dblock; /* Direct child block */
+ size_t dblock_size; /* Direct block's size */
+
+ /* Compute direct block info */
+ dblock_size = hdr->man_dtable.row_block_size[row];
+
+ /* Check whether direct block exists yet */
+ if(H5F_addr_defined(child_addr)) {
+ /* Lock child direct block */
+ /* (also parses it's free space sections) */
+ if(NULL == (child_dblock = H5HF_man_dblock_protect(hdr, dxpl_id, child_addr, dblock_size, iblock, entry, H5AC_WRITE)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap direct block")
+
+ /* Unlock child direct block */
+ if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_DBLOCK, child_addr, child_dblock, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap direct block")
+ } /* end if */
+ else {
+ haddr_t dblock_addr; /* Address of direct block created */
+
+ /* Create direct block of appropriate size */
+ if(H5HF_man_dblock_create(dxpl_id, hdr, iblock, entry, dblock_size, (hsize_t)old_sec_node->sect_addr, &dblock_addr, NULL) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't allocate fractal heap direct block")
+
+ /* Hook direct block up to indirect block */
+ iblock->ents[entry].addr = dblock_addr;
+
+ /* Mark indirect block as dirty */
+ if(H5HF_iblock_dirty(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
+ } /* end else */
+ } /* end if */
+ else {
+ H5HF_indirect_t *child_iblock; /* Indirect child block */
+ size_t iblock_nrows; /* Indirect block's size */
+
+ /* Compute indirect block info */
+ iblock_nrows = (H5V_log2_gen(hdr->man_dtable.row_block_size[row]) - hdr->man_dtable.first_row_bits) + 1;
+
+ /* Check whether direct block exists yet */
+ if(H5F_addr_defined(child_addr)) {
+ /* Lock child indirect block */
+ /* (also parses it's free space sections) */
+ if(NULL == (child_iblock = H5HF_man_iblock_protect(hdr, dxpl_id, child_addr, iblock_nrows, iblock, entry, H5AC_WRITE)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
+
+ /* Release the child indirect block */
+ if(H5AC_unprotect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, child_addr, child_iblock, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
+ } /* end if */
+ else {
+HDfprintf(stderr, "%s: Creating indirect block from opaque section not supported\n", FUNC);
+HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, FAIL, "Creating indirect block from opaque section not supported yet")
+ } /* end else */
+ } /* end else */
+
+ /* Drop reference count on indirect block that free section is in */
+ if(H5HF_iblock_decr(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block")
+
+ /* Free section structure */
+ H5FL_FREE(H5HF_free_section_t, old_sec_node);
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5HF_man_iblock_alloc_opaque() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5HF_man_iblock_create
*
* Purpose: Allocate & initialize a managed indirect block
@@ -1320,7 +1443,7 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5HF_man_iblock_create(H5HF_t *hdr, hid_t dxpl_id,
+H5HF_man_iblock_create(H5HF_hdr_t *hdr, hid_t dxpl_id,
hsize_t block_off, unsigned nrows, unsigned max_rows, haddr_t *addr_p)
{
H5HF_indirect_t *iblock = NULL; /* Pointer to indirect block */
@@ -1347,7 +1470,7 @@ H5HF_man_iblock_create(H5HF_t *hdr, hid_t dxpl_id,
HDmemset(&iblock->cache_info, 0, sizeof(H5AC_info_t));
/* Share common heap information */
- iblock->shared = hdr;
+ iblock->hdr = hdr;
if(H5HF_hdr_incr(hdr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared heap header")
@@ -1358,17 +1481,11 @@ HDfprintf(stderr, "%s: nrows = %u, max_nrows = %u\n", FUNC, nrows, max_nrows);
iblock->rc = 0;
iblock->parent = NULL; /* Temporary, except for root indirect block */
iblock->par_entry = 0;
- iblock->par_nrows = 0;
- iblock->par_addr = HADDR_UNDEF;
iblock->block_off = block_off;
iblock->nrows = nrows;
iblock->max_rows = max_rows;
- iblock->next_col = 0;
- iblock->next_row = 0;
- iblock->next_entry = 0;
- iblock->next_size = hdr->man_dtable.cparam.start_block_size;
iblock->dirty = TRUE;
- iblock->evicted = FALSE;
+ iblock->fl_gen = hdr->fl_gen; /* New blocks have their free list generation set up correctly */
/* Compute size of buffer needed for indirect block */
iblock->size = H5HF_MAN_INDIRECT_SIZE(hdr, iblock);
@@ -1408,3 +1525,146 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_man_iblock_create() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5HF_man_iblock_build_sections
+ *
+ * Purpose: Build free space sections for child blocks of an indirect block
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Apr 25 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5HF_man_iblock_build_sections(H5HF_indirect_t *iblock)
+{
+ H5HF_free_section_t *sec_node; /* Pointer to free list section for block */
+ H5HF_hdr_t *hdr; /* Heap header info */
+ haddr_t curr_off; /* Offset of child block in heap */
+ unsigned row, col; /* Current row & column being operated on */
+ unsigned entry; /* Currenty entry being worked on */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5HF_man_iblock_build_sections)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(iblock);
+
+ /* Get the heap header pointer (for convenience) */
+ hdr = iblock->hdr;
+
+ /* Set starting offset in heap */
+ curr_off = iblock->block_off;
+
+ /* Create a free space section for each child block of indirect block */
+ entry = 0;
+#ifdef QAK
+HDfprintf(stderr, "%s: hdr->man_alloc_size = %Hu\n", FUNC, hdr->man_alloc_size);
+#endif /* QAK */
+ for(row = 0; row < iblock->nrows; row++) {
+ for(col = 0; col < hdr->man_dtable.cparam.width; col++) {
+#ifdef QAK
+HDfprintf(stderr, "%s: curr_off = %a\n", FUNC, curr_off);
+#endif /* QAK */
+ /* Only create free space sections for blocks within the allocated size of the heap */
+ if(curr_off >= hdr->man_alloc_size)
+ break;
+
+ /* Allocate section node */
+ if(NULL == (sec_node = H5FL_MALLOC(H5HF_free_section_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for direct block free list section")
+
+ /* Set section's information */
+ sec_node->sect_addr = curr_off;
+ sec_node->sect_size = iblock->ents[entry].free_space;
+ sec_node->type = H5HF_SECT_OPAQUE;
+ sec_node->u.opaque.iblock = iblock;
+ sec_node->u.opaque.entry = entry;
+
+ /* Increment reference count on indirect block */
+ if(H5HF_iblock_incr(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block")
+
+ /* Add section to free list */
+ if(H5HF_flist_add(hdr->flist, sec_node, &sec_node->sect_size, &sec_node->sect_addr) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add free space section to global list")
+
+ /* Advance state */
+ curr_off += hdr->man_dtable.row_block_size[row];
+ entry++;
+ } /* end for */
+ } /* end for */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5HF_man_iblock_build_sections() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5HF_man_iblock_protect
+ *
+ * Purpose: Convenience wrapper around H5AC_protect on a indirect block
+ * (Use H5AC_unprotect to unprotect it for now)
+ *
+ * Return: Pointer to indirect block on success, NULL on failure
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Apr 17 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+H5HF_indirect_t *
+H5HF_man_iblock_protect(H5HF_hdr_t *hdr, hid_t dxpl_id, haddr_t iblock_addr,
+ unsigned iblock_nrows, H5HF_indirect_t *par_iblock, unsigned par_entry,
+ H5AC_protect_t rw)
+{
+ H5HF_parent_t par_info; /* Parent info for loading block */
+ H5HF_indirect_t *iblock; /* Indirect block from cache */
+ H5HF_indirect_t *ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5HF_man_iblock_protect)
+#ifdef QAK
+HDfprintf(stderr, "%s: iblock_addr = %a, iblock_nrows = %u\n", FUNC, iblock_addr, iblock_nrows);
+#endif /* QAK */
+
+ /*
+ * Check arguments.
+ */
+ HDassert(hdr);
+ HDassert(H5F_addr_defined(iblock_addr));
+ HDassert(iblock_nrows > 0);
+
+ /* Set up parent info */
+ par_info.hdr = hdr;
+ par_info.iblock = par_iblock;
+ par_info.entry = par_entry;
+
+ /* Protect the indirect block */
+ if(NULL == (iblock = H5AC_protect(hdr->f, dxpl_id, H5AC_FHEAP_IBLOCK, iblock_addr, &iblock_nrows, &par_info, rw)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
+
+ /* Regenerate the free list information for this block, if necessary */
+ /* (Only create free list information if write access is requested) */
+ if(rw == H5AC_WRITE && hdr->fl_gen != iblock->fl_gen) {
+ /* Build the free list sections for the block */
+ if(H5HF_man_iblock_build_sections(iblock) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, NULL, "can't build free space sections for block")
+
+ /* Mark the block's free list generation as up to date now */
+ iblock->fl_gen = hdr->fl_gen;
+ } /* end if */
+
+ /* Set the return value */
+ ret_value = iblock;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5HF_man_iblock_protect() */
+