forked from HDFGroup/hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathH5Centry.c
4191 lines (3583 loc) · 168 KB
/
H5Centry.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: H5Centry.c
*
* Purpose: Routines which operate on cache entries.
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#include "H5Cmodule.h" /* This source code file is part of the H5C module */
#define H5F_FRIEND /* suppress error about including H5Fpkg */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Cpkg.h" /* Cache */
#include "H5CXprivate.h" /* API Contexts */
#include "H5Eprivate.h" /* Error handling */
#include "H5Fpkg.h" /* Files */
#include "H5FLprivate.h" /* Free Lists */
#include "H5MFprivate.h" /* File memory management */
#include "H5MMprivate.h" /* Memory management */
#include "H5SLprivate.h" /* Skip Lists */
/****************/
/* Local Macros */
/****************/
#if H5C_DO_MEMORY_SANITY_CHECKS
#define H5C_IMAGE_EXTRA_SPACE 8
#define H5C_IMAGE_SANITY_VALUE "DeadBeef"
#else /* H5C_DO_MEMORY_SANITY_CHECKS */
#define H5C_IMAGE_EXTRA_SPACE 0
#endif /* H5C_DO_MEMORY_SANITY_CHECKS */
/******************/
/* Local Typedefs */
/******************/
/* Alias for pointer to cache entry, for use when allocating sequences of them */
typedef H5C_cache_entry_t *H5C_cache_entry_ptr_t;
/********************/
/* Local Prototypes */
/********************/
static herr_t H5C__pin_entry_from_client(H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr);
static herr_t H5C__unpin_entry_real(H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr, bool update_rp);
static herr_t H5C__unpin_entry_from_client(H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr, bool update_rp);
static herr_t H5C__generate_image(H5F_t *f, H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr);
static herr_t H5C__verify_len_eoa(H5F_t *f, const H5C_class_t *type, haddr_t addr, size_t *len, bool actual);
static void *H5C__load_entry(H5F_t *f,
#ifdef H5_HAVE_PARALLEL
bool coll_access,
#endif /* H5_HAVE_PARALLEL */
const H5C_class_t *type, haddr_t addr, void *udata);
static herr_t H5C__mark_flush_dep_dirty(H5C_cache_entry_t *entry);
static herr_t H5C__mark_flush_dep_clean(H5C_cache_entry_t *entry);
static herr_t H5C__mark_flush_dep_serialized(H5C_cache_entry_t *entry);
static herr_t H5C__mark_flush_dep_unserialized(H5C_cache_entry_t *entry);
#ifndef NDEBUG
static void H5C__assert_flush_dep_nocycle(const H5C_cache_entry_t *entry,
const H5C_cache_entry_t *base_entry);
#endif
static herr_t H5C__destroy_pf_entry_child_flush_deps(H5C_t *cache_ptr, H5C_cache_entry_t *pf_entry_ptr,
H5C_cache_entry_t **fd_children);
static herr_t H5C__deserialize_prefetched_entry(H5F_t *f, H5C_t *cache_ptr, H5C_cache_entry_t **entry_ptr_ptr,
const H5C_class_t *type, haddr_t addr, void *udata);
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/* Declare a free list to manage arrays of cache entries */
H5FL_SEQ_DEFINE_STATIC(H5C_cache_entry_ptr_t);
/*-------------------------------------------------------------------------
* Function: H5C__pin_entry_from_client()
*
* Purpose: Internal routine to pin a cache entry from a client action.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5C__pin_entry_from_client(H5C_t
#if !H5C_COLLECT_CACHE_STATS
H5_ATTR_UNUSED
#endif
*cache_ptr,
H5C_cache_entry_t *entry_ptr)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(cache_ptr);
assert(entry_ptr);
assert(entry_ptr->is_protected);
/* Check if the entry is already pinned */
if (entry_ptr->is_pinned) {
/* Check if the entry was pinned through an explicit pin from a client */
if (entry_ptr->pinned_from_client)
HGOTO_ERROR(H5E_CACHE, H5E_CANTPIN, FAIL, "entry is already pinned");
} /* end if */
else {
entry_ptr->is_pinned = true;
H5C__UPDATE_STATS_FOR_PIN(cache_ptr, entry_ptr);
} /* end else */
/* Mark that the entry was pinned through an explicit pin from a client */
entry_ptr->pinned_from_client = true;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5C__pin_entry_from_client() */
/*-------------------------------------------------------------------------
* Function: H5C__unpin_entry_real()
*
* Purpose: Internal routine to unpin a cache entry.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5C__unpin_entry_real(H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr, bool update_rp)
{
herr_t ret_value = SUCCEED; /* Return value */
#ifdef H5C_DO_SANITY_CHECKS
FUNC_ENTER_PACKAGE
#else
FUNC_ENTER_PACKAGE_NOERR
#endif
/* Sanity checking */
assert(cache_ptr);
assert(entry_ptr);
assert(entry_ptr->is_pinned);
/* If requested, update the replacement policy if the entry is not protected */
if (update_rp && !entry_ptr->is_protected)
H5C__UPDATE_RP_FOR_UNPIN(cache_ptr, entry_ptr, FAIL);
/* Unpin the entry now */
entry_ptr->is_pinned = false;
/* Update the stats for an unpin operation */
H5C__UPDATE_STATS_FOR_UNPIN(cache_ptr, entry_ptr);
#ifdef H5C_DO_SANITY_CHECKS
done:
#endif
FUNC_LEAVE_NOAPI(ret_value)
} /* H5C__unpin_entry_real() */
/*-------------------------------------------------------------------------
* Function: H5C__unpin_entry_from_client()
*
* Purpose: Internal routine to unpin a cache entry from a client action.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5C__unpin_entry_from_client(H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr, bool update_rp)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checking */
assert(cache_ptr);
assert(entry_ptr);
/* Error checking (should be sanity checks?) */
if (!entry_ptr->is_pinned)
HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPIN, FAIL, "entry isn't pinned");
if (!entry_ptr->pinned_from_client)
HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPIN, FAIL, "entry wasn't pinned by cache client");
/* Check if the entry is not pinned from a flush dependency */
if (!entry_ptr->pinned_from_cache)
if (H5C__unpin_entry_real(cache_ptr, entry_ptr, update_rp) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPIN, FAIL, "can't unpin entry");
/* Mark the entry as explicitly unpinned by the client */
entry_ptr->pinned_from_client = false;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5C__unpin_entry_from_client() */
/*-------------------------------------------------------------------------
* Function: H5C__generate_image
*
* Purpose: Serialize an entry and generate its image.
*
* Note: This may cause the entry to be re-sized and/or moved in
* the cache.
*
* As we will not update the metadata cache's data structures
* until we we finish the write, we must touch up these
* data structures for size and location changes even if we
* are about to delete the entry from the cache (i.e. on a
* flush destroy).
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5C__generate_image(H5F_t *f, H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr)
{
haddr_t new_addr = HADDR_UNDEF;
haddr_t old_addr = HADDR_UNDEF;
size_t new_len = 0;
unsigned serialize_flags = H5C__SERIALIZE_NO_FLAGS_SET;
herr_t ret_value = SUCCEED;
FUNC_ENTER_PACKAGE
/* Sanity check */
assert(f);
assert(cache_ptr);
assert(entry_ptr);
assert(!entry_ptr->image_up_to_date);
assert(entry_ptr->is_dirty);
assert(!entry_ptr->is_protected);
assert(entry_ptr->type);
/* make note of the entry's current address */
old_addr = entry_ptr->addr;
/* Call client's pre-serialize callback, if there's one */
if ((entry_ptr->type->pre_serialize) &&
((entry_ptr->type->pre_serialize)(f, (void *)entry_ptr, entry_ptr->addr, entry_ptr->size, &new_addr,
&new_len, &serialize_flags) < 0))
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to pre-serialize entry");
/* Check for any flags set in the pre-serialize callback */
if (serialize_flags != H5C__SERIALIZE_NO_FLAGS_SET) {
/* Check for unexpected flags from serialize callback */
if (serialize_flags & ~(H5C__SERIALIZE_RESIZED_FLAG | H5C__SERIALIZE_MOVED_FLAG))
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unknown serialize flag(s)");
#ifdef H5_HAVE_PARALLEL
/* In the parallel case, resizes and moves in
* the serialize operation can cause problems.
* If they occur, scream and die.
*
* At present, in the parallel case, the aux_ptr
* will only be set if there is more than one
* process. Thus we can use this to detect
* the parallel case.
*
* This works for now, but if we start using the
* aux_ptr for other purposes, we will have to
* change this test accordingly.
*
* NB: While this test detects entryies that attempt
* to resize or move themselves during a flush
* in the parallel case, it will not detect an
* entry that dirties, resizes, and/or moves
* other entries during its flush.
*/
if (cache_ptr->aux_ptr != NULL)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "resize/move in serialize occurred in parallel case");
#endif
/* If required, resize the buffer and update the entry and the cache
* data structures
*/
if (serialize_flags & H5C__SERIALIZE_RESIZED_FLAG) {
/* Sanity check */
assert(new_len > 0);
/* Allocate a new image buffer */
if (NULL ==
(entry_ptr->image_ptr = H5MM_realloc(entry_ptr->image_ptr, new_len + H5C_IMAGE_EXTRA_SPACE)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL,
"memory allocation failed for on disk image buffer");
#if H5C_DO_MEMORY_SANITY_CHECKS
H5MM_memcpy(((uint8_t *)entry_ptr->image_ptr) + new_len, H5C_IMAGE_SANITY_VALUE,
H5C_IMAGE_EXTRA_SPACE);
#endif /* H5C_DO_MEMORY_SANITY_CHECKS */
/* Update statistics for resizing the entry */
H5C__UPDATE_STATS_FOR_ENTRY_SIZE_CHANGE(cache_ptr, entry_ptr, new_len);
/* Update the hash table for the size change */
H5C__UPDATE_INDEX_FOR_SIZE_CHANGE(cache_ptr, entry_ptr->size, new_len, entry_ptr,
!entry_ptr->is_dirty, FAIL);
/* The entry can't be protected since we are in the process of
* flushing it. Thus we must update the replacement policy data
* structures for the size change. The macro deals with the pinned
* case.
*/
H5C__UPDATE_RP_FOR_SIZE_CHANGE(cache_ptr, entry_ptr, new_len, FAIL);
/* As we haven't updated the cache data structures for
* for the flush or flush destroy yet, the entry should
* be in the slist if the slist is enabled. Since
* H5C__UPDATE_SLIST_FOR_SIZE_CHANGE() is a no-op if the
* slist is enabled, call it un-conditionally.
*/
assert(entry_ptr->is_dirty);
assert((entry_ptr->in_slist) || (!cache_ptr->slist_enabled));
H5C__UPDATE_SLIST_FOR_SIZE_CHANGE(cache_ptr, entry_ptr->size, new_len);
/* Finally, update the entry for its new size */
entry_ptr->size = new_len;
} /* end if */
/* If required, udate the entry and the cache data structures
* for a move
*/
if (serialize_flags & H5C__SERIALIZE_MOVED_FLAG) {
/* Update stats and entries relocated counter */
H5C__UPDATE_STATS_FOR_MOVE(cache_ptr, entry_ptr);
/* We must update cache data structures for the change in address */
if (entry_ptr->addr == old_addr) {
/* Delete the entry from the hash table and the slist */
H5C__DELETE_FROM_INDEX(cache_ptr, entry_ptr, FAIL);
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, false, FAIL);
/* Update the entry for its new address */
entry_ptr->addr = new_addr;
/* And then reinsert in the index and slist */
H5C__INSERT_IN_INDEX(cache_ptr, entry_ptr, FAIL);
H5C__INSERT_ENTRY_IN_SLIST(cache_ptr, entry_ptr, FAIL);
} /* end if */
else /* move is already done for us -- just do sanity checks */
assert(entry_ptr->addr == new_addr);
} /* end if */
} /* end if(serialize_flags != H5C__SERIALIZE_NO_FLAGS_SET) */
/* Serialize object into buffer */
if (entry_ptr->type->serialize(f, entry_ptr->image_ptr, entry_ptr->size, (void *)entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to serialize entry");
#if H5C_DO_MEMORY_SANITY_CHECKS
assert(0 == memcmp(((uint8_t *)entry_ptr->image_ptr) + entry_ptr->size, H5C_IMAGE_SANITY_VALUE,
H5C_IMAGE_EXTRA_SPACE));
#endif /* H5C_DO_MEMORY_SANITY_CHECKS */
entry_ptr->image_up_to_date = true;
/* Propagate the fact that the entry is serialized up the
* flush dependency chain if appropriate. Since the image must
* have been out of date for this function to have been called
* (see assertion on entry), no need to check that -- only check
* for flush dependency parents.
*/
assert(entry_ptr->flush_dep_nunser_children == 0);
if (entry_ptr->flush_dep_nparents > 0)
if (H5C__mark_flush_dep_serialized(entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTNOTIFY, FAIL,
"Can't propagate serialization status to fd parents");
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5C__generate_image */
/*-------------------------------------------------------------------------
* Function: H5C__flush_single_entry
*
* Purpose: Flush or clear (and evict if requested) the cache entry
* with the specified address and type. If the type is NULL,
* any unprotected entry at the specified address will be
* flushed (and possibly evicted).
*
* Attempts to flush a protected entry will result in an
* error.
*
* If the H5C__FLUSH_INVALIDATE_FLAG flag is set, the entry will
* be cleared and not flushed, and the call can't be part of a
* sequence of flushes.
*
* The function does nothing silently if there is no entry
* at the supplied address, or if the entry found has the
* wrong type.
*
* Return: Non-negative on success/Negative on failure or if there was
* an attempt to flush a protected item.
*
*-------------------------------------------------------------------------
*/
herr_t
H5C__flush_single_entry(H5F_t *f, H5C_cache_entry_t *entry_ptr, unsigned flags)
{
H5C_t *cache_ptr; /* Cache for file */
bool destroy; /* external flag */
bool clear_only; /* external flag */
bool free_file_space; /* external flag */
bool take_ownership; /* external flag */
bool del_from_slist_on_destroy; /* external flag */
bool during_flush; /* external flag */
bool write_entry; /* internal flag */
bool destroy_entry; /* internal flag */
bool generate_image; /* internal flag */
bool update_page_buffer; /* internal flag */
bool was_dirty;
bool suppress_image_entry_writes = false;
bool suppress_image_entry_frees = false;
haddr_t entry_addr = HADDR_UNDEF;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
assert(f);
cache_ptr = f->shared->cache;
assert(cache_ptr);
assert(entry_ptr);
assert(entry_ptr->ring != H5C_RING_UNDEFINED);
assert(entry_ptr->type);
/* setup external flags from the flags parameter */
destroy = ((flags & H5C__FLUSH_INVALIDATE_FLAG) != 0);
clear_only = ((flags & H5C__FLUSH_CLEAR_ONLY_FLAG) != 0);
free_file_space = ((flags & H5C__FREE_FILE_SPACE_FLAG) != 0);
take_ownership = ((flags & H5C__TAKE_OWNERSHIP_FLAG) != 0);
del_from_slist_on_destroy = ((flags & H5C__DEL_FROM_SLIST_ON_DESTROY_FLAG) != 0);
during_flush = ((flags & H5C__DURING_FLUSH_FLAG) != 0);
generate_image = ((flags & H5C__GENERATE_IMAGE_FLAG) != 0);
update_page_buffer = ((flags & H5C__UPDATE_PAGE_BUFFER_FLAG) != 0);
/* Set the flag for destroying the entry, based on the 'take ownership'
* and 'destroy' flags
*/
if (take_ownership)
destroy_entry = false;
else
destroy_entry = destroy;
/* we will write the entry to disk if it exists, is dirty, and if the
* clear only flag is not set.
*/
if (entry_ptr->is_dirty && !clear_only)
write_entry = true;
else
write_entry = false;
/* if we have received close warning, and we have been instructed to
* generate a metadata cache image, and we have actually constructed
* the entry images, set suppress_image_entry_frees to true.
*
* Set suppress_image_entry_writes to true if indicated by the
* image_ctl flags.
*/
if (cache_ptr->close_warning_received && cache_ptr->image_ctl.generate_image &&
cache_ptr->num_entries_in_image > 0 && cache_ptr->image_entries != NULL) {
/* Sanity checks */
assert(entry_ptr->image_up_to_date || !(entry_ptr->include_in_image));
assert(entry_ptr->image_ptr || !(entry_ptr->include_in_image));
assert((!clear_only) || !(entry_ptr->include_in_image));
assert((!take_ownership) || !(entry_ptr->include_in_image));
assert((!free_file_space) || !(entry_ptr->include_in_image));
suppress_image_entry_frees = true;
if (cache_ptr->image_ctl.flags & H5C_CI__SUPRESS_ENTRY_WRITES)
suppress_image_entry_writes = true;
} /* end if */
/* run initial sanity checks */
#ifdef H5C_DO_SANITY_CHECKS
if (cache_ptr->slist_enabled) {
if (entry_ptr->in_slist) {
assert(entry_ptr->is_dirty);
if (!entry_ptr->is_dirty)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "entry in slist failed sanity checks");
} /* end if */
}
else /* slist is disabled */
assert(!entry_ptr->in_slist);
#endif /* H5C_DO_SANITY_CHECKS */
if (entry_ptr->is_protected)
/* Attempt to flush a protected entry -- scream and die. */
HGOTO_ERROR(H5E_CACHE, H5E_PROTECT, FAIL, "Attempt to flush a protected entry");
/* Set entry_ptr->flush_in_progress = true
*
* We will set flush_in_progress back to false at the end if the
* entry still exists at that point.
*/
entry_ptr->flush_in_progress = true;
/* Preserve current dirty state for later */
was_dirty = entry_ptr->is_dirty;
/* The entry is dirty, and we are doing a flush, a flush destroy or have
* been requested to generate an image. In those cases, serialize the
* entry.
*/
if (write_entry || generate_image) {
assert(entry_ptr->is_dirty);
if (NULL == entry_ptr->image_ptr) {
if (NULL == (entry_ptr->image_ptr = H5MM_malloc(entry_ptr->size + H5C_IMAGE_EXTRA_SPACE)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL,
"memory allocation failed for on disk image buffer");
#if H5C_DO_MEMORY_SANITY_CHECKS
H5MM_memcpy(((uint8_t *)entry_ptr->image_ptr) + entry_ptr->size, H5C_IMAGE_SANITY_VALUE,
H5C_IMAGE_EXTRA_SPACE);
#endif /* H5C_DO_MEMORY_SANITY_CHECKS */
} /* end if */
if (!entry_ptr->image_up_to_date) {
/* Sanity check */
assert(!entry_ptr->prefetched);
/* Generate the entry's image */
if (H5C__generate_image(f, cache_ptr, entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTGET, FAIL, "can't generate entry's image");
} /* end if ( ! (entry_ptr->image_up_to_date) ) */
} /* end if */
/* Finally, write the image to disk.
*
* Note that if the H5AC__CLASS_SKIP_WRITES flag is set in the
* in the entry's type, we silently skip the write. This
* flag should only be used in test code.
*/
if (write_entry) {
assert(entry_ptr->is_dirty);
#ifdef H5C_DO_SANITY_CHECKS
if (cache_ptr->check_write_permitted && !cache_ptr->write_permitted)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Write when writes are always forbidden!?!?!");
#endif /* H5C_DO_SANITY_CHECKS */
/* Write the image to disk unless the write is suppressed.
*
* This happens if both suppress_image_entry_writes and
* entry_ptr->include_in_image are true, or if the
* H5AC__CLASS_SKIP_WRITES is set in the entry's type. This
* flag should only be used in test code
*/
if ((!suppress_image_entry_writes || !entry_ptr->include_in_image) &&
((entry_ptr->type->flags & H5C__CLASS_SKIP_WRITES) == 0)) {
H5FD_mem_t mem_type = H5FD_MEM_DEFAULT;
#ifdef H5_HAVE_PARALLEL
if (cache_ptr->coll_write_list) {
if (H5SL_insert(cache_ptr->coll_write_list, entry_ptr, &entry_ptr->addr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTINSERT, FAIL, "unable to insert skip list item");
} /* end if */
else {
#endif /* H5_HAVE_PARALLEL */
if (entry_ptr->prefetched) {
assert(entry_ptr->type->id == H5AC_PREFETCHED_ENTRY_ID);
mem_type = cache_ptr->class_table_ptr[entry_ptr->prefetch_type_id]->mem_type;
} /* end if */
else
mem_type = entry_ptr->type->mem_type;
if (H5F_block_write(f, mem_type, entry_ptr->addr, entry_ptr->size, entry_ptr->image_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't write image to file");
#ifdef H5_HAVE_PARALLEL
}
#endif /* H5_HAVE_PARALLEL */
} /* end if */
/* if the entry has a notify callback, notify it that we have
* just flushed the entry.
*/
if (entry_ptr->type->notify &&
(entry_ptr->type->notify)(H5C_NOTIFY_ACTION_AFTER_FLUSH, entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTNOTIFY, FAIL, "can't notify client of entry flush");
} /* if ( write_entry ) */
/* At this point, all pre-serialize and serialize calls have been
* made if it was appropriate to make them. Similarly, the entry
* has been written to disk if desired.
*
* Thus it is now safe to update the cache data structures for the
* flush.
*/
/* start by updating the statistics */
if (clear_only) {
/* only log a clear if the entry was dirty */
if (was_dirty)
H5C__UPDATE_STATS_FOR_CLEAR(cache_ptr, entry_ptr);
}
else if (write_entry) {
assert(was_dirty);
/* only log a flush if we actually wrote to disk */
H5C__UPDATE_STATS_FOR_FLUSH(cache_ptr, entry_ptr);
} /* end else if */
/* Note that the algorithm below is (very) similar to the set of operations
* in H5C_remove_entry() and should be kept in sync with changes
* to that code. - QAK, 2016/11/30
*/
/* Update the cache internal data structures. */
if (destroy) {
/* Sanity checks */
if (take_ownership)
assert(!destroy_entry);
else
assert(destroy_entry);
assert(!entry_ptr->is_pinned);
/* Update stats, while entry is still in the cache */
H5C__UPDATE_STATS_FOR_EVICTION(cache_ptr, entry_ptr, take_ownership);
/* If the entry's type has a 'notify' callback and the entry is about
* to be removed from the cache, send a 'before eviction' notice while
* the entry is still fully integrated in the cache.
*/
if (entry_ptr->type->notify &&
(entry_ptr->type->notify)(H5C_NOTIFY_ACTION_BEFORE_EVICT, entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTNOTIFY, FAIL, "can't notify client about entry to evict");
/* Update the cache internal data structures as appropriate
* for a destroy. Specifically:
*
* 1) Delete it from the index
*
* 2) Delete it from the skip list if requested.
*
* 3) Delete it from the collective read access list.
*
* 4) Update the replacement policy for eviction
*
* 5) Remove it from the tag list for this object
*
* Finally, if the destroy_entry flag is set, discard the
* entry.
*/
H5C__DELETE_FROM_INDEX(cache_ptr, entry_ptr, FAIL);
if (entry_ptr->in_slist && del_from_slist_on_destroy)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, during_flush, FAIL);
#ifdef H5_HAVE_PARALLEL
/* Check for collective read access flag */
if (entry_ptr->coll_access) {
entry_ptr->coll_access = false;
H5C__REMOVE_FROM_COLL_LIST(cache_ptr, entry_ptr, FAIL);
} /* end if */
#endif /* H5_HAVE_PARALLEL */
H5C__UPDATE_RP_FOR_EVICTION(cache_ptr, entry_ptr, FAIL);
/* Remove entry from tag list */
if (H5C__untag_entry(cache_ptr, entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTREMOVE, FAIL, "can't remove entry from tag list");
/* verify that the entry is no longer part of any flush dependencies */
assert(entry_ptr->flush_dep_nparents == 0);
assert(entry_ptr->flush_dep_nchildren == 0);
} /* end if */
else {
assert(clear_only || write_entry);
assert(entry_ptr->is_dirty);
assert((!cache_ptr->slist_enabled) || (entry_ptr->in_slist));
/* We are either doing a flush or a clear.
*
* A clear and a flush are the same from the point of
* view of the replacement policy and the slist.
* Hence no differentiation between them.
*/
H5C__UPDATE_RP_FOR_FLUSH(cache_ptr, entry_ptr, FAIL);
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, during_flush, FAIL);
/* mark the entry as clean and update the index for
* entry clean. Also, call the clear callback
* if defined.
*/
entry_ptr->is_dirty = false;
H5C__UPDATE_INDEX_FOR_ENTRY_CLEAN(cache_ptr, entry_ptr, FAIL);
/* Check for entry changing status and do notifications, etc. */
if (was_dirty) {
/* If the entry's type has a 'notify' callback send a
* 'entry cleaned' notice now that the entry is fully
* integrated into the cache.
*/
if (entry_ptr->type->notify &&
(entry_ptr->type->notify)(H5C_NOTIFY_ACTION_ENTRY_CLEANED, entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTNOTIFY, FAIL,
"can't notify client about entry dirty flag cleared");
/* Propagate the clean flag up the flush dependency chain
* if appropriate
*/
if (entry_ptr->flush_dep_ndirty_children != 0)
assert(entry_ptr->flush_dep_ndirty_children == 0);
if (entry_ptr->flush_dep_nparents > 0)
if (H5C__mark_flush_dep_clean(entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKCLEAN, FAIL, "Can't propagate flush dep clean flag");
} /* end if */
} /* end else */
/* reset the flush_in progress flag */
entry_ptr->flush_in_progress = false;
/* capture the cache entry address for the log_flush call at the
* end before the entry_ptr gets freed
*/
entry_addr = entry_ptr->addr;
/* Internal cache data structures should now be up to date, and
* consistent with the status of the entry.
*
* Now discard the entry if appropriate.
*/
if (destroy) {
/* Sanity check */
assert(0 == entry_ptr->flush_dep_nparents);
/* if both suppress_image_entry_frees and entry_ptr->include_in_image
* are true, simply set entry_ptr->image_ptr to NULL, as we have
* another pointer to the buffer in an instance of H5C_image_entry_t
* in cache_ptr->image_entries.
*
* Otherwise, free the buffer if it exists.
*/
if (suppress_image_entry_frees && entry_ptr->include_in_image)
entry_ptr->image_ptr = NULL;
else if (entry_ptr->image_ptr != NULL)
entry_ptr->image_ptr = H5MM_xfree(entry_ptr->image_ptr);
/* If the entry is not a prefetched entry, verify that the flush
* dependency parents addresses array has been transferred.
*
* If the entry is prefetched, the free_isr routine will dispose of
* the flush dependency parents addresses array if necessary.
*/
if (!entry_ptr->prefetched) {
assert(0 == entry_ptr->fd_parent_count);
assert(NULL == entry_ptr->fd_parent_addrs);
} /* end if */
/* Check whether we should free the space in the file that
* the entry occupies
*/
if (free_file_space) {
hsize_t fsf_size;
/* Sanity checks */
assert(H5_addr_defined(entry_ptr->addr));
assert(!H5F_IS_TMP_ADDR(f, entry_ptr->addr));
#ifndef NDEBUG
{
size_t curr_len;
/* Get the actual image size for the thing again */
entry_ptr->type->image_len((void *)entry_ptr, &curr_len);
assert(curr_len == entry_ptr->size);
}
#endif
/* If the file space free size callback is defined, use
* it to get the size of the block of file space to free.
* Otherwise use entry_ptr->size.
*/
if (entry_ptr->type->fsf_size) {
if ((entry_ptr->type->fsf_size)((void *)entry_ptr, &fsf_size) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "unable to get file space free size");
} /* end if */
else /* no file space free size callback -- use entry size */
fsf_size = entry_ptr->size;
/* Release the space on disk */
if (H5MF_xfree(f, entry_ptr->type->mem_type, entry_ptr->addr, fsf_size) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "unable to free file space for cache entry");
} /* end if ( free_file_space ) */
/* Reset the pointer to the cache the entry is within. -QAK */
entry_ptr->cache_ptr = NULL;
/* increment entries_removed_counter and set
* last_entry_removed_ptr. As we are likely abuut to
* free the entry, recall that last_entry_removed_ptr
* must NEVER be dereferenced.
*
* Recall that these fields are maintained to allow functions
* that perform scans of lists of entries to detect the
* unexpected removal of entries (via expunge, eviction,
* or take ownership at present), so that they can re-start
* their scans if necessary.
*
* Also check if the entry we are watching for removal is being
* removed (usually the 'next' entry for an iteration) and reset
* it to indicate that it was removed.
*/
cache_ptr->entries_removed_counter++;
cache_ptr->last_entry_removed_ptr = entry_ptr;
if (entry_ptr == cache_ptr->entry_watched_for_removal)
cache_ptr->entry_watched_for_removal = NULL;
/* Check for actually destroying the entry in memory */
/* (As opposed to taking ownership of it) */
if (destroy_entry) {
if (entry_ptr->is_dirty) {
/* Reset dirty flag */
entry_ptr->is_dirty = false;
/* If the entry's type has a 'notify' callback send a
* 'entry cleaned' notice now that the entry is fully
* integrated into the cache.
*/
if (entry_ptr->type->notify &&
(entry_ptr->type->notify)(H5C_NOTIFY_ACTION_ENTRY_CLEANED, entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTNOTIFY, FAIL,
"can't notify client about entry dirty flag cleared");
} /* end if */
/* verify that the image has been freed */
assert(entry_ptr->image_ptr == NULL);
if (entry_ptr->type->free_icr((void *)entry_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "free_icr callback failed");
} /* end if */
else {
assert(take_ownership);
} /* end else */
} /* if (destroy) */
/* Check if we have to update the page buffer with cleared entries
* so it doesn't go out of date
*/
if (update_page_buffer) {
/* Sanity check */
assert(!destroy);
assert(entry_ptr->image_ptr);
if (f->shared->page_buf && (f->shared->page_buf->page_size >= entry_ptr->size))
if (H5PB_update_entry(f->shared->page_buf, entry_ptr->addr, entry_ptr->size,
entry_ptr->image_ptr) > 0)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Failed to update PB with metadata cache");
} /* end if */
if (cache_ptr->log_flush)
if ((cache_ptr->log_flush)(cache_ptr, entry_addr, was_dirty, flags) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "log_flush callback failed");
done:
assert((ret_value != SUCCEED) || (destroy_entry) || (!entry_ptr->flush_in_progress));
assert((ret_value != SUCCEED) || (destroy_entry) || (take_ownership) || (!entry_ptr->is_dirty));
FUNC_LEAVE_NOAPI(ret_value)
} /* H5C__flush_single_entry() */
/*-------------------------------------------------------------------------
* Function: H5C__verify_len_eoa
*
* Purpose: Verify that 'len' does not exceed eoa when 'actual' is
* false i.e. 'len" is the initial speculative length from
* get_load_size callback with null image pointer.
* If exceed, adjust 'len' accordingly.
*
* Verify that 'len' should not exceed eoa when 'actual' is
* true i.e. 'len' is the actual length from get_load_size
* callback with non-null image pointer.
* If exceed, return error.
*
* Return: FAIL if error is detected, SUCCEED otherwise.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5C__verify_len_eoa(H5F_t *f, const H5C_class_t *type, haddr_t addr, size_t *len, bool actual)
{
H5FD_mem_t cooked_type; /* Modified type, accounting for switching global heaps */
haddr_t eoa; /* End-of-allocation in the file */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* if type == H5FD_MEM_GHEAP, H5F_block_read() forces
* type to H5FD_MEM_DRAW via its call to H5F__accum_read().
* Thus we do the same for purposes of computing the EOA
* for sanity checks.
*/
cooked_type = (type->mem_type == H5FD_MEM_GHEAP) ? H5FD_MEM_DRAW : type->mem_type;
/* Get the file's end-of-allocation value */
eoa = H5F_get_eoa(f, cooked_type);
if (!H5_addr_defined(eoa))
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "invalid EOA address for file");
/* Check for bad address in general */
if (H5_addr_gt(addr, eoa))
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "address of object past end of allocation");
/* Check if the amount of data to read will be past the EOA */
if (H5_addr_gt((addr + *len), eoa)) {
if (actual)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "actual len exceeds EOA");
else
/* Trim down the length of the metadata */
*len = (size_t)(eoa - addr);
} /* end if */
if (*len <= 0)
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "len not positive after adjustment for EOA");
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5C__verify_len_eoa() */
/*-------------------------------------------------------------------------
* Function: H5C__load_entry
*
* Purpose: Attempt to load the entry at the specified disk address
* and with the specified type into memory. If successful.
* return the in memory address of the entry. Return NULL
* on failure.
*
* Note that this function simply loads the entry into
* core. It does not insert it into the cache.
*
* Return: Non-NULL on success / NULL on failure.
*
*-------------------------------------------------------------------------
*/
void *
H5C__load_entry(H5F_t *f,
#ifdef H5_HAVE_PARALLEL
bool coll_access,
#endif /* H5_HAVE_PARALLEL */
const H5C_class_t *type, haddr_t addr, void *udata)
{
bool dirty = false; /* Flag indicating whether thing was dirtied during deserialize */
uint8_t *image = NULL; /* Buffer for disk image */
void *thing = NULL; /* Pointer to thing loaded */
H5C_cache_entry_t *entry = NULL; /* Alias for thing loaded, as cache entry */
size_t len; /* Size of image in file */
#ifdef H5_HAVE_PARALLEL
int mpi_rank = 0; /* MPI process rank */
MPI_Comm comm = MPI_COMM_NULL; /* File MPI Communicator */
int mpi_code; /* MPI error code */
#endif /* H5_HAVE_PARALLEL */
void *ret_value = NULL; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(f);
assert(f->shared);
assert(f->shared->cache);
assert(type);
assert(H5_addr_defined(addr));
assert(type->get_initial_load_size);
if (type->flags & H5C__CLASS_SPECULATIVE_LOAD_FLAG)
assert(type->get_final_load_size);
else
assert(NULL == type->get_final_load_size);
assert(type->deserialize);