H5ACprivate.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*-------------------------------------------------------------------------
00017  *
00018  * Created:             H5ACprivate.h
00019  *                      Jul  9 1997
00020  *                      Robb Matzke <matzke@llnl.gov>
00021  *
00022  * Purpose:             Constants and typedefs available to the rest of the
00023  *                      library.
00024  *
00025  * Modifications:       JRM - 6/4/04
00026  *                      Complete re-write for a new caching algorithm
00027  *                      located in H5C.c
00028  *
00029  *-------------------------------------------------------------------------
00030  */
00031 
00032 #ifndef _H5ACprivate_H
00033 #define _H5ACprivate_H
00034 
00035 #include "H5ACpublic.h"         /*public prototypes                     */
00036 
00037 /* Pivate headers needed by this header */
00038 #include "H5private.h"          /* Generic Functions                    */
00039 #include "H5Fprivate.h"         /* File access                          */
00040 #include "H5Cprivate.h"         /* cache                                */
00041 
00042 #ifdef H5_METADATA_TRACE_FILE
00043 #define H5AC__TRACE_FILE_ENABLED        1
00044 #else /* H5_METADATA_TRACE_FILE */
00045 #define H5AC__TRACE_FILE_ENABLED        0
00046 #endif /* H5_METADATA_TRACE_FILE */
00047 
00048 /* Types of metadata objects cached */
00049 typedef enum {
00050     H5AC_BT_ID = 0,     /*B-tree nodes                               */
00051     H5AC_SNODE_ID,      /*symbol table nodes                         */
00052     H5AC_LHEAP_ID,      /*local heap                                 */
00053     H5AC_GHEAP_ID,      /*global heap                                */
00054     H5AC_OHDR_ID,       /*object header                              */
00055     H5AC_BT2_HDR_ID,    /*v2 B-tree header                           */
00056     H5AC_BT2_INT_ID,    /*v2 B-tree internal node                    */
00057     H5AC_BT2_LEAF_ID,   /*v2 B-tree leaf node                        */
00058     H5AC_FHEAP_HDR_ID,  /*fractal heap header                        */
00059     H5AC_FHEAP_DBLOCK_ID, /*fractal heap direct block                */
00060     H5AC_FHEAP_IBLOCK_ID, /*fractal heap indirect block              */
00061     H5AC_FSPACE_HDR_ID, /*free space header                          */
00062     H5AC_FSPACE_SINFO_ID,/*free space sections                       */
00063     H5AC_SOHM_TABLE_ID, /*shared object header message master table  */
00064     H5AC_SOHM_LIST_ID,  /*shared message index stored as a list      */
00065     H5AC_TEST_ID,       /*test entry -- not used for actual files    */
00066     H5AC_NTYPES         /* Number of types, must be last             */
00067 } H5AC_type_t;
00068 
00069 /* H5AC_DUMP_STATS_ON_CLOSE should always be FALSE when
00070  * H5C_COLLECT_CACHE_STATS is FALSE.
00071  *
00072  * When H5C_COLLECT_CACHE_STATS is TRUE, H5AC_DUMP_STATS_ON_CLOSE must
00073  * be FALSE for "make check" to succeed, but may be set to TRUE at other
00074  * times for debugging purposes.
00075  *
00076  * Hence the following, somewhat odd set of #defines.
00077  */
00078 #if H5C_COLLECT_CACHE_STATS
00079 
00080 #define H5AC_DUMP_STATS_ON_CLOSE        0
00081 
00082 #else /* H5C_COLLECT_CACHE_STATS */
00083 
00084 #define H5AC_DUMP_STATS_ON_CLOSE        0
00085 
00086 #endif /* H5C_COLLECT_CACHE_STATS */
00087 
00088 /* Default max metadata cache size and min clean size are give here.
00089  * At present, these are the same as those given in H5Cprivate.h.
00090  */
00091 
00092 #define H5AC__DEFAULT_MAX_CACHE_SIZE    H5C__DEFAULT_MAX_CACHE_SIZE
00093 #define H5AC__DEFAULT_MIN_CLEAN_SIZE    H5C__DEFAULT_MIN_CLEAN_SIZE
00094 
00095 
00096 /*
00097  * Class methods pertaining to caching.  Each type of cached object will
00098  * have a constant variable with permanent life-span that describes how
00099  * to cache the object.  That variable will be of type H5AC_class_t and
00100  * have the following required fields...
00101  *
00102  * LOAD:        Loads an object from disk to memory.  The function
00103  *              should allocate some data structure and return it.
00104  *
00105  * FLUSH:       Writes some data structure back to disk.  It would be
00106  *              wise for the data structure to include dirty flags to
00107  *              indicate whether it really needs to be written.  This
00108  *              function is also responsible for freeing memory allocated
00109  *              by the LOAD method if the DEST argument is non-zero (by
00110  *              calling the DEST method).
00111  *
00112  * DEST:        Just frees memory allocated by the LOAD method.
00113  *
00114  * CLEAR:       Just marks object as non-dirty.
00115  *
00116  * SIZE:        Report the size (on disk) of the specified cache object.
00117  *              Note that the space allocated on disk may not be contiguous.
00118  */
00119 
00120 #define H5AC_CALLBACK__NO_FLAGS_SET             H5C_CALLBACK__NO_FLAGS_SET
00121 #define H5AC_CALLBACK__SIZE_CHANGED_FLAG        H5C_CALLBACK__SIZE_CHANGED_FLAG
00122 #define H5AC_CALLBACK__RENAMED_FLAG             H5C_CALLBACK__RENAMED_FLAG
00123 
00124 typedef H5C_load_func_t         H5AC_load_func_t;
00125 typedef H5C_flush_func_t        H5AC_flush_func_t;
00126 typedef H5C_dest_func_t         H5AC_dest_func_t;
00127 typedef H5C_clear_func_t        H5AC_clear_func_t;
00128 typedef H5C_size_func_t         H5AC_size_func_t;
00129 
00130 typedef H5C_class_t             H5AC_class_t;
00131 
00132 
00133 /* The H5AC_NSLOTS #define is now obsolete, as the metadata cache no longer
00134  * uses slots.  However I am leaving it in for now to avoid modifying the
00135  * interface between the metadata cache and the rest of HDF.  It should
00136  * be removed when we get to dealing with the size_hint parameter in
00137  * H5AC_create().
00138  *                                              JRM - 5/20/04
00139  *
00140  * Old comment on H5AC_NSLOTS follows:
00141  *
00142  * A cache has a certain number of entries.  Objects are mapped into a
00143  * cache entry by hashing the object's file address.  Each file has its
00144  * own cache, an array of slots.
00145  */
00146 #define H5AC_NSLOTS     10330           /* The library "likes" this number... */
00147 
00148 
00149 typedef H5C_cache_entry_t       H5AC_info_t;
00150 
00151 
00152 /*===----------------------------------------------------------------------===
00153  *                             Protect Types
00154  *===----------------------------------------------------------------------===
00155  *
00156  * These are for the wrapper functions to H5AC_protect. They specify what
00157  * type of operation you're planning on doing to the metadata. The
00158  * Flexible Parallel HDF5 locking can then act accordingly.
00159  */
00160 
00161 typedef enum H5AC_protect_t {
00162     H5AC_WRITE,                 /* Protect object for writing                */
00163     H5AC_READ                   /* Protect object for reading                */
00164 } H5AC_protect_t;
00165 
00166 
00167 /* Typedef for metadata cache (defined in H5Cpkg.h) */
00168 typedef H5C_t   H5AC_t;
00169 
00170 /* Metadata specific properties for FAPL */
00171 /* (Only used for parallel I/O) */
00172 #ifdef H5_HAVE_PARALLEL
00173 /* Definitions for "block before metadata write" property */
00174 #define H5AC_BLOCK_BEFORE_META_WRITE_NAME       "H5AC_block_before_meta_write"
00175 #define H5AC_BLOCK_BEFORE_META_WRITE_SIZE       sizeof(unsigned)
00176 #define H5AC_BLOCK_BEFORE_META_WRITE_DEF        0
00177 
00178 /* Definitions for "library internal" property */
00179 #define H5AC_LIBRARY_INTERNAL_NAME       "H5AC_library_internal"
00180 #define H5AC_LIBRARY_INTERNAL_SIZE       sizeof(unsigned)
00181 #define H5AC_LIBRARY_INTERNAL_DEF        0
00182 #endif /* H5_HAVE_PARALLEL */
00183 
00184 /* Dataset transfer property list for flush calls */
00185 /* (Collective set, "block before metadata write" set and "library internal" set) */
00186 /* (Global variable declaration, definition is in H5AC.c) */
00187 extern hid_t H5AC_dxpl_id;
00188 
00189 /* Dataset transfer property list for independent metadata I/O calls */
00190 /* (just "library internal" set - i.e. independent transfer mode) */
00191 /* (Global variable declaration, definition is in H5AC.c) */
00192 extern hid_t H5AC_ind_dxpl_id;
00193 
00194 
00195 /* Default cache configuration. */
00196 
00197 #define H5AC__DEFAULT_CACHE_CONFIG                                            \
00198 {                                                                             \
00199   /* int         version                = */ H5C__CURR_AUTO_SIZE_CTL_VER,     \
00200   /* hbool_t     rpt_fcn_enabled        = */ FALSE,                           \
00201   /* hbool_t     open_trace_file        = */ FALSE,                           \
00202   /* hbool_t     close_trace_file       = */ FALSE,                           \
00203   /* char        trace_file_name[]      = */ "",                              \
00204   /* hbool_t     evictions_enabled      = */ TRUE,                            \
00205   /* hbool_t     set_initial_size       = */ TRUE,                            \
00206   /* size_t      initial_size           = */ ( 2 * 1024 * 1024),              \
00207   /* double      min_clean_fraction     = */ 0.3,                             \
00208   /* size_t      max_size               = */ (16 * 1024 * 1024),              \
00209   /* size_t      min_size               = */ ( 1 * 1024 * 1024),              \
00210   /* long int    epoch_length           = */ 50000,                           \
00211   /* enum H5C_cache_incr_mode incr_mode = */ H5C_incr__threshold,             \
00212   /* double      lower_hr_threshold     = */ 0.9,                             \
00213   /* double      increment              = */ 2.0,                             \
00214   /* hbool_t     apply_max_increment    = */ TRUE,                            \
00215   /* size_t      max_increment          = */ (4 * 1024 * 1024),               \
00216   /* enum H5C_cache_flash_incr_mode       */                                  \
00217   /*                    flash_incr_mode = */ H5C_flash_incr__add_space,       \
00218   /* double      flash_multiple         = */ 1.0,                             \
00219   /* double      flash_threshold        = */ 0.25,                            \
00220   /* enum H5C_cache_decr_mode decr_mode = */ H5C_decr__age_out_with_threshold,\
00221   /* double      upper_hr_threshold     = */ 0.999,                           \
00222   /* double      decrement              = */ 0.9,                             \
00223   /* hbool_t     apply_max_decrement    = */ TRUE,                            \
00224   /* size_t      max_decrement          = */ (1 * 1024 * 1024),               \
00225   /* int         epochs_before_eviction = */ 3,                               \
00226   /* hbool_t     apply_empty_reserve    = */ TRUE,                            \
00227   /* double      empty_reserve          = */ 0.1,                             \
00228   /* int         dirty_bytes_threshold  = */ (256 * 1024)                     \
00229 }
00230 
00231 
00232 /*
00233  * Library prototypes.
00234  */
00235 
00236 /* #defines of flags used in the flags parameters in some of the
00237  * following function calls.  Note that they are just copies of
00238  * the equivalent flags from H5Cprivate.h.
00239  */
00240 
00241 #define H5AC__NO_FLAGS_SET                H5C__NO_FLAGS_SET
00242 #define H5AC__SET_FLUSH_MARKER_FLAG       H5C__SET_FLUSH_MARKER_FLAG
00243 #define H5AC__DELETED_FLAG                H5C__DELETED_FLAG
00244 #define H5AC__DIRTIED_FLAG                H5C__DIRTIED_FLAG
00245 #define H5AC__SIZE_CHANGED_FLAG           H5C__SIZE_CHANGED_FLAG
00246 #define H5AC__PIN_ENTRY_FLAG              H5C__PIN_ENTRY_FLAG
00247 #define H5AC__UNPIN_ENTRY_FLAG            H5C__UNPIN_ENTRY_FLAG
00248 #define H5AC__FLUSH_INVALIDATE_FLAG       H5C__FLUSH_INVALIDATE_FLAG
00249 #define H5AC__FLUSH_CLEAR_ONLY_FLAG       H5C__FLUSH_CLEAR_ONLY_FLAG
00250 #define H5AC__FLUSH_MARKED_ENTRIES_FLAG   H5C__FLUSH_MARKED_ENTRIES_FLAG
00251 #define H5AC__FLUSH_IGNORE_PROTECTED_FLAG H5C__FLUSH_IGNORE_PROTECTED_FLAG
00252 #define H5AC__FREE_FILE_SPACE_FLAG        H5C__FREE_FILE_SPACE_FLAG
00253 #define H5AC__TAKE_OWNERSHIP_FLAG         H5C__TAKE_OWNERSHIP_FLAG
00254 
00255 
00256 /* #defines of flags used to report entry status in the
00257  * H5AC_get_entry_status() call.
00258  */
00259 
00260 #define H5AC_ES__IN_CACHE       0x0001
00261 #define H5AC_ES__IS_DIRTY       0x0002
00262 #define H5AC_ES__IS_PROTECTED   0x0004
00263 #define H5AC_ES__IS_PINNED      0x0008
00264 
00265 
00266 /* external function declarations: */
00267 
00268 H5_DLL herr_t H5AC_init(void);
00269 H5_DLL herr_t H5AC_create(const H5F_t *f, H5AC_cache_config_t *config_ptr);
00270 H5_DLL herr_t H5AC_get_entry_status(H5F_t * f, haddr_t addr,
00271                                     unsigned * status_ptr);
00272 H5_DLL herr_t H5AC_set(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type,
00273                        haddr_t addr, void *thing, unsigned int flags);
00274 H5_DLL herr_t H5AC_pin_protected_entry(H5F_t * f, void *  thing);
00275 H5_DLL void * H5AC_protect(H5F_t *f, hid_t dxpl_id, const H5AC_class_t *type,
00276                            haddr_t addr, const void *udata1, void *udata2,
00277                            H5AC_protect_t rw);
00278 H5_DLL herr_t H5AC_resize_pinned_entry(H5F_t * f,
00279                                        void *  thing,
00280                                        size_t  new_size);
00281 H5_DLL herr_t H5AC_unpin_entry(H5F_t * f,
00282                                void *  thing);
00283 H5_DLL herr_t H5AC_unprotect(H5F_t *f, hid_t dxpl_id,
00284                              const H5AC_class_t *type, haddr_t addr,
00285                              void *thing, unsigned flags);
00286 H5_DLL herr_t H5AC_flush(H5F_t *f, hid_t dxpl_id, unsigned flags);
00287 H5_DLL herr_t H5AC_mark_pinned_entry_dirty(H5F_t * f,
00288                                            void *  thing,
00289                                            hbool_t size_changed,
00290                                            size_t  new_size);
00291 H5_DLL herr_t H5AC_mark_pinned_or_protected_entry_dirty(H5F_t * f,
00292                                                         void *  thing);
00293 H5_DLL herr_t H5AC_rename(H5F_t *f, const H5AC_class_t *type,
00294                            haddr_t old_addr, haddr_t new_addr);
00295 
00296 H5_DLL herr_t H5AC_dest(H5F_t *f, hid_t dxpl_id);
00297 
00298 H5_DLL herr_t H5AC_expunge_entry(H5F_t *f, hid_t dxpl_id,
00299                                  const H5AC_class_t *type, haddr_t addr,
00300                                  unsigned flags);
00301 
00302 H5_DLL herr_t H5AC_set_write_done_callback(H5C_t * cache_ptr,
00303                                            void (* write_done)(void));
00304 H5_DLL herr_t H5AC_stats(const H5F_t *f);
00305 
00306 H5_DLL herr_t H5AC_get_cache_auto_resize_config(H5AC_t * cache_ptr,
00307                                                H5AC_cache_config_t *config_ptr);
00308 
00309 H5_DLL herr_t H5AC_get_cache_size(H5AC_t * cache_ptr,
00310                                   size_t * max_size_ptr,
00311                                   size_t * min_clean_size_ptr,
00312                                   size_t * cur_size_ptr,
00313                                   int32_t * cur_num_entries_ptr);
00314 
00315 H5_DLL herr_t H5AC_get_cache_hit_rate(H5AC_t * cache_ptr,
00316                                       double * hit_rate_ptr);
00317 
00318 H5_DLL herr_t H5AC_reset_cache_hit_rate_stats(H5AC_t * cache_ptr);
00319 
00320 H5_DLL herr_t H5AC_set_cache_auto_resize_config(H5AC_t * cache_ptr,
00321                                                H5AC_cache_config_t *config_ptr);
00322 
00323 H5_DLL herr_t H5AC_validate_config(H5AC_cache_config_t * config_ptr);
00324 
00325 H5_DLL herr_t H5AC_close_trace_file( H5AC_t * cache_ptr);
00326 
00327 H5_DLL herr_t H5AC_open_trace_file(H5AC_t * cache_ptr,
00328                                    const char * trace_file_name);
00329 
00330 #endif /* !_H5ACprivate_H */
00331