forked from HDFGroup/hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathH5AC.c
2587 lines (2211 loc) · 94.5 KB
/
H5AC.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the LICENSE file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5AC.c
*
* Purpose: Functions in this file implement a cache for
* things which exist on disk. All "things" associated
* with a particular HDF file share the same cache; each
* HDF file has it's own cache.
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#include "H5ACmodule.h" /* This source code file is part of the H5AC module */
#define H5C_FRIEND /* Suppress error about including H5Cpkg */
#define H5F_FRIEND /* Suppress error about including H5Fpkg */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5ACpkg.h" /* Metadata cache */
#include "H5Clog.h" /* Cache logging */
#include "H5Cpkg.h" /* Cache */
#include "H5CXprivate.h" /* API Contexts */
#include "H5Eprivate.h" /* Error handling */
#include "H5Fpkg.h" /* Files */
#include "H5FLprivate.h" /* Free Lists */
#include "H5Pprivate.h" /* Property lists */
#include "H5SLprivate.h" /* Skip Lists */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/********************/
/* Local Prototypes */
/********************/
static herr_t H5AC__check_if_write_permitted(const H5F_t *f, bool *write_permitted_ptr);
static herr_t H5AC__ext_config_2_int_config(const H5AC_cache_config_t *ext_conf_ptr,
H5C_auto_size_ctl_t *int_conf_ptr);
#if H5AC_DO_TAGGING_SANITY_CHECKS
static herr_t H5AC__verify_tag(const H5AC_class_t *type);
#endif /* H5AC_DO_TAGGING_SANITY_CHECKS */
/*********************/
/* Package Variables */
/*********************/
/* Package initialization variable */
bool H5_PKG_INIT_VAR = false;
/*****************************/
/* Library Private Variables */
/*****************************/
#ifdef H5_HAVE_PARALLEL
/* Environment variable for collective API sanity checks */
bool H5_coll_api_sanity_check_g = false;
#endif /* H5_HAVE_PARALLEL */
/*******************/
/* Local Variables */
/*******************/
/* Metadata entry class list */
/* Remember to add new type ID to the H5AC_type_t enum in H5ACprivate.h when
* adding a new class.
*/
static const H5AC_class_t *const H5AC_class_s[] = {
H5AC_BT, /* ( 0) B-tree nodes */
H5AC_SNODE, /* ( 1) symbol table nodes */
H5AC_LHEAP_PRFX, /* ( 2) local heap prefix */
H5AC_LHEAP_DBLK, /* ( 3) local heap data block */
H5AC_GHEAP, /* ( 4) global heap */
H5AC_OHDR, /* ( 5) object header */
H5AC_OHDR_CHK, /* ( 6) object header chunk */
H5AC_BT2_HDR, /* ( 7) v2 B-tree header */
H5AC_BT2_INT, /* ( 8) v2 B-tree internal node */
H5AC_BT2_LEAF, /* ( 9) v2 B-tree leaf node */
H5AC_FHEAP_HDR, /* (10) fractal heap header */
H5AC_FHEAP_DBLOCK, /* (11) fractal heap direct block */
H5AC_FHEAP_IBLOCK, /* (12) fractal heap indirect block */
H5AC_FSPACE_HDR, /* (13) free space header */
H5AC_FSPACE_SINFO, /* (14) free space sections */
H5AC_SOHM_TABLE, /* (15) shared object header message master table */
H5AC_SOHM_LIST, /* (16) shared message index stored as a list */
H5AC_EARRAY_HDR, /* (17) extensible array header */
H5AC_EARRAY_IBLOCK, /* (18) extensible array index block */
H5AC_EARRAY_SBLOCK, /* (19) extensible array super block */
H5AC_EARRAY_DBLOCK, /* (20) extensible array data block */
H5AC_EARRAY_DBLK_PAGE, /* (21) extensible array data block page */
H5AC_FARRAY_HDR, /* (22) fixed array header */
H5AC_FARRAY_DBLOCK, /* (23) fixed array data block */
H5AC_FARRAY_DBLK_PAGE, /* (24) fixed array data block page */
H5AC_SUPERBLOCK, /* (25) file superblock */
H5AC_DRVRINFO, /* (26) driver info block (supplements superblock) */
H5AC_EPOCH_MARKER, /* (27) epoch marker - always internal to cache */
H5AC_PROXY_ENTRY, /* (28) cache entry proxy */
H5AC_PREFETCHED_ENTRY /* (29) prefetched entry - always internal to cache */
};
/*-------------------------------------------------------------------------
* Function: H5AC_init
*
* Purpose: Initialize the interface from some other layer.
*
* Return: Success: non-negative
* Failure: negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_init(void)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* FUNC_ENTER() does all the work */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5AC_init() */
/*-------------------------------------------------------------------------
* Function: H5AC__init_package
*
* Purpose: Initialize interface-specific information
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__init_package(void)
{
FUNC_ENTER_PACKAGE_NOERR
#ifdef H5_HAVE_PARALLEL
/* check whether to enable strict collective function calling
* sanity checks using MPI barriers
*/
{
const char *s; /* String for environment variables */
s = getenv("H5_COLL_API_SANITY_CHECK");
if (s && isdigit(*s)) {
long env_val = strtol(s, NULL, 0);
H5_coll_api_sanity_check_g = (0 == env_val) ? false : true;
}
}
#endif /* H5_HAVE_PARALLEL */
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5AC__init_package() */
/*-------------------------------------------------------------------------
* Function: H5AC_term_package
*
* Purpose: Terminate this interface.
*
* Return: Success: Positive if anything was done that might
* affect other interfaces; zero otherwise.
* Failure: Negative.
*
*-------------------------------------------------------------------------
*/
int
H5AC_term_package(void)
{
FUNC_ENTER_NOAPI_NOINIT_NOERR
if (H5_PKG_INIT_VAR)
/* Reset interface initialization flag */
H5_PKG_INIT_VAR = false;
FUNC_LEAVE_NOAPI(0)
} /* end H5AC_term_package() */
/*-------------------------------------------------------------------------
*
* Function: H5AC_cache_image_pending()
*
* Purpose: Debugging function that tests to see if the load of a
* metadata cache image load is pending (i.e. will be executed
* on the next protect or insert)
*
* Returns true if a cache image load is pending, and false
* if not. Throws an assertion failure on error.
*
* Return: true if a cache image load is pending, and false otherwise.
*
*-------------------------------------------------------------------------
*/
bool
H5AC_cache_image_pending(const H5F_t *f)
{
H5C_t *cache_ptr;
bool ret_value = false; /* Return value */
FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Sanity checks */
assert(f);
assert(f->shared);
cache_ptr = f->shared->cache;
ret_value = H5C_cache_image_pending(cache_ptr);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_cache_image_pending() */
/*-------------------------------------------------------------------------
* Function: H5AC_create
*
* Purpose: Initialize the cache just after a file is opened. The
* SIZE_HINT is the number of cache slots desired. If you
* pass an invalid value then H5AC_NSLOTS is used. You can
* turn off caching by using 1 for the SIZE_HINT value.
*
* Return: Success: Number of slots actually used.
*
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_create(const H5F_t *f, H5AC_cache_config_t *config_ptr, H5AC_cache_image_config_t *image_config_ptr)
{
#ifdef H5_HAVE_PARALLEL
char prefix[H5C__PREFIX_LEN] = "";
H5AC_aux_t *aux_ptr = NULL;
#endif /* H5_HAVE_PARALLEL */
struct H5C_cache_image_ctl_t int_ci_config = H5C__DEFAULT_CACHE_IMAGE_CTL;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Check arguments */
assert(f);
assert(NULL == f->shared->cache);
assert(config_ptr != NULL);
assert(image_config_ptr != NULL);
assert(image_config_ptr->version == H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION);
HDcompile_assert(NELMTS(H5AC_class_s) == H5AC_NTYPES);
HDcompile_assert(H5C__MAX_NUM_TYPE_IDS == H5AC_NTYPES);
/* Validate configurations */
if (H5AC_validate_config(config_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad cache configuration");
if (H5AC_validate_cache_image_config(image_config_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad cache image configuration");
#ifdef H5_HAVE_PARALLEL
if (H5F_HAS_FEATURE(f, H5FD_FEAT_HAS_MPI)) {
MPI_Comm mpi_comm;
int mpi_rank;
int mpi_size;
if (MPI_COMM_NULL == (mpi_comm = H5F_mpi_get_comm(f)))
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "can't get MPI communicator");
if ((mpi_rank = H5F_mpi_get_rank(f)) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "can't get mpi rank");
if ((mpi_size = H5F_mpi_get_size(f)) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "can't get mpi size");
if (NULL == (aux_ptr = H5FL_CALLOC(H5AC_aux_t)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "Can't allocate H5AC auxiliary structure");
aux_ptr->mpi_comm = mpi_comm;
aux_ptr->mpi_rank = mpi_rank;
aux_ptr->mpi_size = mpi_size;
aux_ptr->write_permitted = false;
aux_ptr->dirty_bytes_threshold = H5AC__DEFAULT_DIRTY_BYTES_THRESHOLD;
aux_ptr->dirty_bytes = 0;
aux_ptr->metadata_write_strategy = H5AC__DEFAULT_METADATA_WRITE_STRATEGY;
#ifdef H5AC_DEBUG_DIRTY_BYTES_CREATION
aux_ptr->dirty_bytes_propagations = 0;
aux_ptr->unprotect_dirty_bytes = 0;
aux_ptr->unprotect_dirty_bytes_updates = 0;
aux_ptr->insert_dirty_bytes = 0;
aux_ptr->insert_dirty_bytes_updates = 0;
aux_ptr->move_dirty_bytes = 0;
aux_ptr->move_dirty_bytes_updates = 0;
#endif /* H5AC_DEBUG_DIRTY_BYTES_CREATION */
aux_ptr->d_slist_ptr = NULL;
aux_ptr->c_slist_ptr = NULL;
aux_ptr->candidate_slist_ptr = NULL;
aux_ptr->write_done = NULL;
aux_ptr->sync_point_done = NULL;
aux_ptr->p0_image_len = 0;
snprintf(prefix, sizeof(prefix), "%d:", mpi_rank);
if (mpi_rank == 0) {
if (NULL == (aux_ptr->d_slist_ptr = H5SL_create(H5SL_TYPE_HADDR, NULL)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTCREATE, FAIL, "can't create dirtied entry list");
if (NULL == (aux_ptr->c_slist_ptr = H5SL_create(H5SL_TYPE_HADDR, NULL)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTCREATE, FAIL, "can't create cleaned entry list");
} /* end if */
/* construct the candidate skip list for all processes.
* when the distributed strategy is selected as all processes
* will use it in the case of a flush.
*/
if (NULL == (aux_ptr->candidate_slist_ptr = H5SL_create(H5SL_TYPE_HADDR, NULL)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTCREATE, FAIL, "can't create candidate entry list");
if (aux_ptr->mpi_rank == 0)
f->shared->cache = H5C_create(H5AC__DEFAULT_MAX_CACHE_SIZE, H5AC__DEFAULT_MIN_CLEAN_SIZE,
(H5AC_NTYPES - 1), H5AC_class_s, H5AC__check_if_write_permitted,
true, H5AC__log_flushed_entry, (void *)aux_ptr);
else
f->shared->cache =
H5C_create(H5AC__DEFAULT_MAX_CACHE_SIZE, H5AC__DEFAULT_MIN_CLEAN_SIZE, (H5AC_NTYPES - 1),
H5AC_class_s, H5AC__check_if_write_permitted, true, NULL, (void *)aux_ptr);
} /* end if */
else {
#endif /* H5_HAVE_PARALLEL */
/* The default max cache size and min clean size will frequently be
* overwritten shortly by the subsequent set resize config call.
* -- JRM
*/
f->shared->cache =
H5C_create(H5AC__DEFAULT_MAX_CACHE_SIZE, H5AC__DEFAULT_MIN_CLEAN_SIZE, (H5AC_NTYPES - 1),
H5AC_class_s, H5AC__check_if_write_permitted, true, NULL, NULL);
#ifdef H5_HAVE_PARALLEL
} /* end else */
#endif /* H5_HAVE_PARALLEL */
if (NULL == f->shared->cache)
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed");
#ifdef H5_HAVE_PARALLEL
if (aux_ptr != NULL)
if (H5C_set_prefix(f->shared->cache, prefix) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "H5C_set_prefix() failed");
#endif /* H5_HAVE_PARALLEL */
/* Turn on metadata cache logging, if being used
* This will be JSON until we create a special API call. Trace output
* is generated when logging is controlled by the struct.
*/
if (H5F_USE_MDC_LOGGING(f))
if (H5C_log_set_up(f->shared->cache, H5F_MDC_LOG_LOCATION(f), H5C_LOG_STYLE_JSON,
H5F_START_MDC_LOG_ON_ACCESS(f)) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "mdc logging setup failed");
/* Set the cache parameters */
if (H5AC_set_cache_auto_resize_config(f->shared->cache, config_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "auto resize configuration failed");
/* Don't need to get the current H5C image config here since the
* cache has just been created, and thus f->shared->cache->image_ctl
* must still set to its initial value (H5C__DEFAULT_CACHE_IMAGE_CTL).
* Note that this not true as soon as control returns to the application
* program, as some test code modifies f->shared->cache->image_ctl.
*/
int_ci_config.version = image_config_ptr->version;
int_ci_config.generate_image = image_config_ptr->generate_image;
int_ci_config.save_resize_status = image_config_ptr->save_resize_status;
int_ci_config.entry_ageout = image_config_ptr->entry_ageout;
if (H5C_set_cache_image_config(f, f->shared->cache, &int_ci_config) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "auto resize configuration failed");
done:
/* If currently logging, generate a message */
if (f->shared->cache->log_info->logging)
if (H5C_log_write_create_cache_msg(f->shared->cache, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
#ifdef H5_HAVE_PARALLEL
/* if there is a failure, try to tidy up the auxiliary structure */
if (ret_value < 0) {
if (aux_ptr != NULL) {
if (aux_ptr->d_slist_ptr != NULL)
H5SL_close(aux_ptr->d_slist_ptr);
if (aux_ptr->c_slist_ptr != NULL)
H5SL_close(aux_ptr->c_slist_ptr);
if (aux_ptr->candidate_slist_ptr != NULL)
H5SL_close(aux_ptr->candidate_slist_ptr);
aux_ptr = H5FL_FREE(H5AC_aux_t, aux_ptr);
} /* end if */
} /* end if */
#endif /* H5_HAVE_PARALLEL */
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_create() */
/*-------------------------------------------------------------------------
* Function: H5AC_dest
*
* Purpose: Flushes all data to disk and destroys the cache.
* This function fails if any object are protected since the
* resulting file might not be consistent.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_dest(H5F_t *f)
{
bool log_enabled; /* true if logging was set up */
bool curr_logging; /* true if currently logging */
#ifdef H5_HAVE_PARALLEL
H5AC_aux_t *aux_ptr = NULL;
#endif /* H5_HAVE_PARALLEL */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
assert(f);
assert(f->shared);
assert(f->shared->cache);
#if H5AC_DUMP_STATS_ON_CLOSE
/* Dump debugging info */
H5AC_stats(f);
#endif /* H5AC_DUMP_STATS_ON_CLOSE */
/* Check if log messages are being emitted */
if (H5C_get_logging_status(f->shared->cache, &log_enabled, &curr_logging) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to get logging status");
/* Tear down logging */
if (log_enabled) {
if (curr_logging)
if (H5C_log_write_destroy_cache_msg(f->shared->cache) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
if (H5C_log_tear_down(f->shared->cache) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "metadata cache logging tear-down failed");
} /* end if */
#ifdef H5_HAVE_PARALLEL
/* destroying the cache, so clear all collective entries */
if (H5C_clear_coll_entries(f->shared->cache, false) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "can't clear collective entries");
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(f->shared->cache);
if (aux_ptr) {
/* If the file was opened R/W, attempt to flush all entries
* from rank 0 & Bcast clean list to other ranks.
*
* Must not flush in the R/O case, as this will trigger the
* free space manager settle routines.
*
* Must also enable the skip list before the call to
* H5AC__flush_entries() and disable it afterwards, as the
* skip list will be disabled after the previous flush.
*
* Note that H5C_dest() does skip list setup and take down as well.
* Unfortunately, we can't do the setup and take down just once,
* as H5C_dest() is called directly in the test code.
*
* Fortunately, the cache should be clean or close to it at this
* point, so the overhead should be minimal.
*/
if (H5F_ACC_RDWR & H5F_INTENT(f)) {
/* enable and load the skip list */
if (H5C_set_slist_enabled(f->shared->cache, true, true) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "can't enable skip list");
if (H5AC__flush_entries(f) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush");
/* disable the skip list -- should be empty */
if (H5C_set_slist_enabled(f->shared->cache, false, false) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "can't disable skip list");
} /* end if */
} /* end if */
#endif /* H5_HAVE_PARALLEL */
/* Destroy the cache */
if (H5C_dest(f) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "can't destroy cache");
f->shared->cache = NULL;
#ifdef H5_HAVE_PARALLEL
if (aux_ptr != NULL) {
if (aux_ptr->d_slist_ptr != NULL) {
assert(H5SL_count(aux_ptr->d_slist_ptr) == 0);
H5SL_close(aux_ptr->d_slist_ptr);
} /* end if */
if (aux_ptr->c_slist_ptr != NULL) {
assert(H5SL_count(aux_ptr->c_slist_ptr) == 0);
H5SL_close(aux_ptr->c_slist_ptr);
} /* end if */
if (aux_ptr->candidate_slist_ptr != NULL) {
assert(H5SL_count(aux_ptr->candidate_slist_ptr) == 0);
H5SL_close(aux_ptr->candidate_slist_ptr);
} /* end if */
aux_ptr = H5FL_FREE(H5AC_aux_t, aux_ptr);
} /* end if */
#endif /* H5_HAVE_PARALLEL */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_dest() */
/*-------------------------------------------------------------------------
* Function: H5AC_evict
*
* Purpose: Evict all entries except the pinned entries
* in the cache.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_evict(H5F_t *f)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
assert(f);
assert(f->shared);
assert(f->shared->cache);
/* Evict all entries in the cache except the pinned superblock entry */
if (H5C_evict(f) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "can't evict cache");
done:
/* If currently logging, generate a message */
if (f->shared->cache->log_info->logging)
if (H5C_log_write_evict_cache_msg(f->shared->cache, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_evict() */
/*-------------------------------------------------------------------------
* Function: H5AC_expunge_entry
*
* Purpose: Expunge the target entry from the cache without writing it
* to disk even if it is dirty. The entry must not be either
* pinned or protected.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_expunge_entry(H5F_t *f, const H5AC_class_t *type, haddr_t addr, unsigned flags)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity checks */
assert(f);
assert(f->shared);
assert(f->shared->cache);
assert(type);
assert(type->serialize);
assert(H5_addr_defined(addr));
if (H5C_expunge_entry(f, type, addr, flags) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTEXPUNGE, FAIL, "H5C_expunge_entry() failed");
done:
/* If currently logging, generate a message */
if (f->shared->cache->log_info->logging)
if (H5C_log_write_expunge_entry_msg(f->shared->cache, addr, type->id, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_expunge_entry() */
/*-------------------------------------------------------------------------
* Function: H5AC_flush
*
* Purpose: Flush (and possibly destroy) the metadata cache associated
* with the specified file.
*
* If the cache contains protected entries, the function will
* fail, as protected entries cannot be flushed. However
* all unprotected entries should be flushed before the
* function returns failure.
*
* Return: Non-negative on success/Negative on failure if there was a
* request to flush all items and something was protected.
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_flush(H5F_t *f)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity checks */
assert(f);
assert(f->shared);
assert(f->shared->cache);
#ifdef H5_HAVE_PARALLEL
/* flushing the cache, so clear all collective entries */
if (H5C_clear_coll_entries(f->shared->cache, false) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTGET, FAIL, "H5C_clear_coll_entries() failed");
/* Attempt to flush all entries from rank 0 & Bcast clean list to other ranks */
if (H5AC__flush_entries(f) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush");
#endif /* H5_HAVE_PARALLEL */
/* Flush the cache */
/* (Again, in parallel - writes out the superblock) */
if (H5C_flush_cache(f, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush cache");
done:
/* If currently logging, generate a message */
if (f->shared->cache->log_info->logging)
if (H5C_log_write_flush_cache_msg(f->shared->cache, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_flush() */
/*-------------------------------------------------------------------------
* Function: H5AC_get_entry_status
*
* Purpose: Given a file address, determine whether the metadata
* cache contains an entry at that location. If it does,
* also determine whether the entry is dirty, protected,
* pinned, etc. and return that information to the caller
* in *status.
*
* If the specified entry doesn't exist, set *status_ptr
* to zero.
*
* On error, the value of *status is undefined.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_get_entry_status(const H5F_t *f, haddr_t addr, unsigned *status)
{
bool in_cache; /* Entry @ addr is in the cache */
bool is_dirty; /* Entry @ addr is in the cache and dirty */
bool is_protected; /* Entry @ addr is in the cache and protected */
bool is_pinned; /* Entry @ addr is in the cache and pinned */
bool is_corked;
bool is_flush_dep_child; /* Entry @ addr is in the cache and is a flush dependency child */
bool is_flush_dep_parent; /* Entry @ addr is in the cache and is a flush dependency parent */
bool image_is_up_to_date; /* Entry @ addr is in the cache and has an up to date image */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
if ((f == NULL) || (!H5_addr_defined(addr)) || (status == NULL))
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad param(s) on entry");
if (H5C_get_entry_status(f, addr, NULL, &in_cache, &is_dirty, &is_protected, &is_pinned, &is_corked,
&is_flush_dep_parent, &is_flush_dep_child, &image_is_up_to_date) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_get_entry_status() failed");
if (in_cache) {
*status |= H5AC_ES__IN_CACHE;
if (is_dirty)
*status |= H5AC_ES__IS_DIRTY;
if (is_protected)
*status |= H5AC_ES__IS_PROTECTED;
if (is_pinned)
*status |= H5AC_ES__IS_PINNED;
if (is_corked)
*status |= H5AC_ES__IS_CORKED;
if (is_flush_dep_parent)
*status |= H5AC_ES__IS_FLUSH_DEP_PARENT;
if (is_flush_dep_child)
*status |= H5AC_ES__IS_FLUSH_DEP_CHILD;
if (image_is_up_to_date)
*status |= H5AC_ES__IMAGE_IS_UP_TO_DATE;
} /* end if */
else
*status = 0;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_get_entry_status() */
/*-------------------------------------------------------------------------
* Function: H5AC_insert_entry
*
* Purpose: Adds the specified thing to the cache. The thing need not
* exist on disk yet, but it must have an address and disk
* space reserved.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_insert_entry(H5F_t *f, const H5AC_class_t *type, haddr_t addr, void *thing, unsigned int flags)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity checks */
assert(f);
assert(f->shared);
assert(f->shared->cache);
assert(type);
assert(type->serialize);
assert(H5_addr_defined(addr));
assert(thing);
/* Check for invalid access request */
if (0 == (H5F_INTENT(f) & H5F_ACC_RDWR))
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "no write intent on file");
#if H5AC_DO_TAGGING_SANITY_CHECKS
if (!H5C_get_ignore_tags(f->shared->cache) && H5AC__verify_tag(type) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "Bad tag value");
#endif /* H5AC_DO_TAGGING_SANITY_CHECKS */
/* Insert entry into metadata cache */
if (H5C_insert_entry(f, type, addr, thing, flags) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, FAIL, "H5C_insert_entry() failed");
#ifdef H5_HAVE_PARALLEL
{
H5AC_aux_t *aux_ptr;
if (NULL != (aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(f->shared->cache))) {
/* Log the new entry */
if (H5AC__log_inserted_entry((H5AC_info_t *)thing) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, FAIL, "H5AC__log_inserted_entry() failed");
/* Check if we should try to flush */
if (aux_ptr->dirty_bytes >= aux_ptr->dirty_bytes_threshold)
if (H5AC__run_sync_point(f, H5AC_SYNC_POINT_OP__FLUSH_TO_MIN_CLEAN) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't run sync point");
} /* end if */
}
#endif /* H5_HAVE_PARALLEL */
done:
/* If currently logging, generate a message */
if (f->shared->cache->log_info->logging)
if (H5C_log_write_insert_entry_msg(f->shared->cache, addr, type->id, flags,
((H5C_cache_entry_t *)thing)->size, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_insert_entry() */
/*-------------------------------------------------------------------------
* Function: H5AC_load_cache_image_on_next_protect
*
* Purpose: Load the cache image block at the specified location,
* decode it, and insert its contents into the metadata
* cache.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_load_cache_image_on_next_protect(H5F_t *f, haddr_t addr, hsize_t len, bool rw)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity checks */
assert(f);
assert(f->shared);
assert(f->shared->cache);
if (H5C_load_cache_image_on_next_protect(f, addr, len, rw) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTLOAD, FAIL, "call to H5C_load_cache_image_on_next_protect failed");
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_load_cache_image_on_next_protect() */
/*-------------------------------------------------------------------------
* Function: H5AC_mark_entry_dirty
*
* Purpose: Mark a pinned or protected entry as dirty. The target
* entry MUST be either pinned, protected, or both.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_mark_entry_dirty(void *thing)
{
H5AC_info_t *entry_ptr = NULL; /* Pointer to the cache entry */
H5C_t *cache_ptr = NULL; /* Pointer to the entry's associated metadata cache */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
assert(thing);
/* Set up entry & cache pointers */
entry_ptr = (H5AC_info_t *)thing;
cache_ptr = entry_ptr->cache_ptr;
#ifdef H5_HAVE_PARALLEL
{
H5AC_aux_t *aux_ptr;
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
if ((!entry_ptr->is_dirty) && (!entry_ptr->is_protected) && (entry_ptr->is_pinned) &&
(NULL != aux_ptr))
if (H5AC__log_dirtied_entry(entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKDIRTY, FAIL, "can't log dirtied entry");
}
#endif /* H5_HAVE_PARALLEL */
if (H5C_mark_entry_dirty(thing) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKDIRTY, FAIL, "can't mark pinned or protected entry dirty");
done:
/* If currently logging, generate a message */
if (cache_ptr != NULL && cache_ptr->log_info != NULL)
if (cache_ptr->log_info->logging)
if (H5C_log_write_mark_entry_dirty_msg(cache_ptr, entry_ptr, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_mark_entry_dirty() */
/*-------------------------------------------------------------------------
* Function: H5AC_mark_entry_clean
*
* Purpose: Mark a pinned entry as clean. The target
* entry MUST be pinned.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_mark_entry_clean(void *thing)
{
H5AC_info_t *entry_ptr = NULL; /* Pointer to the cache entry */
H5C_t *cache_ptr = NULL; /* Pointer to the entry's associated metadata cache */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
assert(thing);
entry_ptr = (H5AC_info_t *)thing;
cache_ptr = entry_ptr->cache_ptr;
#ifdef H5_HAVE_PARALLEL
{
H5AC_aux_t *aux_ptr;
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
if ((!entry_ptr->is_dirty) && (!entry_ptr->is_protected) && (entry_ptr->is_pinned) &&
(NULL != aux_ptr))
if (H5AC__log_cleaned_entry(entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKCLEAN, FAIL, "can't log cleaned entry");
}
#endif /* H5_HAVE_PARALLEL */
if (H5C_mark_entry_clean(thing) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKCLEAN, FAIL, "can't mark pinned or protected entry clean");
done:
/* If currently logging, generate a message */
if (cache_ptr != NULL && cache_ptr->log_info != NULL)
if (cache_ptr->log_info->logging)
if (H5C_log_write_mark_entry_clean_msg(cache_ptr, entry_ptr, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_mark_entry_clean() */
/*-------------------------------------------------------------------------
* Function: H5AC_mark_entry_unserialized
*
* Purpose: Mark a pinned or protected entry as unserialized. The target
* entry MUST be either pinned, protected, or both.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_mark_entry_unserialized(void *thing)
{
H5AC_info_t *entry_ptr = NULL; /* Pointer to the cache entry */
H5C_t *cache_ptr = NULL; /* Pointer to the entry's associated metadata cache */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
assert(thing);
/* Set up entry & cache pointers */
entry_ptr = (H5AC_info_t *)thing;
cache_ptr = entry_ptr->cache_ptr;
if (H5C_mark_entry_unserialized(thing) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKUNSERIALIZED, FAIL, "can't mark entry unserialized");
done:
/* If currently logging, generate a message */
if (cache_ptr != NULL && cache_ptr->log_info != NULL)
if (cache_ptr->log_info->logging)
if (H5C_log_write_mark_unserialized_entry_msg(cache_ptr, entry_ptr, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_mark_entry_unserialized() */
/*-------------------------------------------------------------------------
* Function: H5AC_mark_entry_serialized
*
* Purpose: Mark a pinned entry as serialized. The target
* entry MUST be pinned.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_mark_entry_serialized(void *thing)
{
H5AC_info_t *entry_ptr = NULL; /* Pointer to the cache entry */
H5C_t *cache_ptr = NULL; /* Pointer to the entry's associated metadata cache */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity check */
assert(thing);
entry_ptr = (H5AC_info_t *)thing;
cache_ptr = entry_ptr->cache_ptr;
if (H5C_mark_entry_serialized(thing) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKSERIALIZED, FAIL, "can't mark entry serialized");
done:
/* If currently logging, generate a message */
if (cache_ptr != NULL && cache_ptr->log_info != NULL)
if (cache_ptr->log_info->logging)
if (H5C_log_write_mark_serialized_entry_msg(cache_ptr, entry_ptr, ret_value) < 0)
HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_mark_entry_serialized() */
/*-------------------------------------------------------------------------
* Function: H5AC_move_entry
*
* Purpose: Use this function to notify the cache that an object's
* file address changed.