Skip to content

Commit

Permalink
Initial crack at page buffer tolerance
Browse files Browse the repository at this point in the history
Accepts:
* Opening a non-pb file with fapl pb settings
* Opening a pb file with fapl page size < file pb size

Not working:
* Creating a pb file with a fapl page size < fcp pb size

Includes testing
  • Loading branch information
derobins committed Mar 29, 2024
1 parent 16ba713 commit 1ae8f48
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 13 deletions.
27 changes: 20 additions & 7 deletions src/H5Fint.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,12 +2017,12 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
/* Temporary: fail file create when page buffering feature is enabled for parallel */
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "page buffering is disabled for parallel");
#endif /* H5_HAVE_PARALLEL */
/* Query for other page buffer cache properties */
if (H5P_get(a_plist, H5F_ACS_PAGE_BUFFER_MIN_META_PERC_NAME, &page_buf_min_meta_perc) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't get minimum metadata fraction of page buffer");
if (H5P_get(a_plist, H5F_ACS_PAGE_BUFFER_MIN_RAW_PERC_NAME, &page_buf_min_raw_perc) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't get minimum raw data fraction of page buffer");
} /* end if */
}
/* Query for other page buffer cache properties (might be needed later) */
if (H5P_get(a_plist, H5F_ACS_PAGE_BUFFER_MIN_META_PERC_NAME, &page_buf_min_meta_perc) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't get minimum metadata fraction of page buffer");
if (H5P_get(a_plist, H5F_ACS_PAGE_BUFFER_MIN_RAW_PERC_NAME, &page_buf_min_raw_perc) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't get minimum raw data fraction of page buffer");

/* Get the evict on close setting */
if (H5P_get(a_plist, H5F_ACS_EVICT_ON_CLOSE_FLAG_NAME, &evict_on_close) < 0)
Expand Down Expand Up @@ -2073,7 +2073,20 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
if (H5F__super_read(file, a_plist, true) < 0)
HGOTO_ERROR(H5E_FILE, H5E_READERROR, NULL, "unable to read superblock");

/* Create the page buffer before initializing the superblock */
/* Tolerate opening files when H5Pset_page_buffer_size() was used to set
* fapl parameters but the file doesn't use page buffering.
*/
if (shared->fs_strategy != H5F_FSPACE_STRATEGY_PAGE)
page_buf_size = 0;

/* Tolerate opening files when H5Pset_page_buffer_size() was used to set
* fapl parameters but the desired page buffer size is smaller than a
* single page.
*/
if (shared->fs_page_size > page_buf_size)
page_buf_size = 0;

/* Create the page buffer *after* reading the superblock */
if (page_buf_size)
if (H5PB_create(shared, page_buf_size, page_buf_min_meta_perc, page_buf_min_raw_perc) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to create page buffer");
Expand Down
15 changes: 11 additions & 4 deletions src/H5Ppublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -5745,10 +5745,17 @@ H5_DLL herr_t H5Pset_mdc_image_config(hid_t plist_id, H5AC_cache_image_config_t
* file close, the page buffer is flushed writing all the pages to the
* file.
*
* If a non-zero page buffer size is set, and the file space strategy
* is not set to paged or the page size for the file space strategy is
* larger than the page buffer size, the subsequent call to H5Fcreate()
* or H5Fopen() using the \p plist_id will fail.
* \note Before HDF5 1.14.4, if a non-zero page buffer size were set, and
* the file space strategy was not set to paged or the page size for
* the file space strategy was larger than the page buffer size,
* the subsequent call to H5Fcreate() or H5Fopen() using the
* \p plist_id would fail. As of HDF5 1.14.4, this function is now
* considered advisory, and unusable settings are ignored. This
* allows setting a page buffer size without having to open a file
* to get the page buffer characteristics.
*
* \note The H5Fcreate() call will still fail when the fapl page size
* is smaller than the fcpl page size.
*
* The function also allows setting the minimum percentage of pages for
* metadata and raw data to prevent a certain type of data to evict hot
Expand Down
93 changes: 91 additions & 2 deletions test/page_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,94 @@ test_min_threshold(hid_t orig_fapl, const char *driver_name)

} /* test_min_threshold */

/*-------------------------------------------------------------------------
* Function: test_pb_fapl_tolerance_at_open()
*
* Purpose: Tests if the library tolerates setting fapl page buffer
* values via H5Pset_page_buffer_size() when opening a file
* that does not use page buffering.
*
* Return: 0 if test is successful
* 1 if test fails
*
*-------------------------------------------------------------------------
*/
static unsigned
test_pb_fapl_tolerance_at_open(void)
{
const char *filename = "pb_fapl_tolerance.h5";
hid_t fapl = H5I_INVALID_HID;
hid_t fcpl = H5I_INVALID_HID;
hid_t fid = H5I_INVALID_HID;

TESTING("if opening non-page-buffered files works w/ H5Pset_page_buffer_size()");

/* Create a file WITHOUT page buffering */
if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
if (H5Fclose(fid) < 0)
TEST_ERROR;

/* Set up page buffering values on a fapl */
if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
TEST_ERROR;
if (H5Pset_page_buffer_size(fapl, 512, 0, 0) < 0)
TEST_ERROR;

/* Attempt to open non-page-buf file w/ page buf fapl */
if ((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
if (H5Fclose(fid) < 0)
TEST_ERROR;

/* Set up a fcpl with a page size that is larger than the fapl size */
if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
TEST_ERROR;
if (H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, false, 1) < 0)
TEST_ERROR;
if (H5Pset_file_space_page_size(fcpl, 4096) < 0)
TEST_ERROR;

/* Create a file that uses page buffering while using a fapl with
* a page buf size that is too small
*/
if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0)
TEST_ERROR;
if (H5Fclose(fid) < 0)
TEST_ERROR;

/* Attempt to open page-buf file w/ fapl page buf size that is too small */
if ((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
if (H5Fclose(fid) < 0)
TEST_ERROR;

/* Shut down */
if (H5Pclose(fcpl) < 0)
TEST_ERROR;
if (H5Pclose(fapl) < 0)
TEST_ERROR;

HDremove(filename);

PASSED();

return 0;

error:

H5E_BEGIN_TRY
{
H5Pclose(fapl);
H5Pclose(fcpl);
H5Fclose(fid);
}
H5E_END_TRY

return 1;

} /* test_pb_fapl_tolerance_at_open */

/*-------------------------------------------------------------------------
* Function: test_stats_collection()
*
Expand Down Expand Up @@ -2083,12 +2171,12 @@ main(void)
SKIPPED();
puts("Skip page buffering test because paged aggregation is disabled for multi/split drivers");
exit(EXIT_SUCCESS);
} /* end if */
}

if ((fapl = h5_fileaccess()) < 0) {
nerrors++;
PUTS_ERROR("Can't get VFD-dependent fapl");
} /* end if */
}

/* Push API context */
if (H5CX_push() < 0)
Expand All @@ -2107,6 +2195,7 @@ main(void)
nerrors += test_lru_processing(fapl, driver_name);
nerrors += test_min_threshold(fapl, driver_name);
nerrors += test_stats_collection(fapl, driver_name);
nerrors += test_pb_fapl_tolerance_at_open();

#endif /* H5_HAVE_PARALLEL */

Expand Down

0 comments on commit 1ae8f48

Please sign in to comment.