forked from HDFGroup/hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathH5ACmpio.c
2213 lines (1951 loc) · 82 KB
/
H5ACmpio.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: H5ACmpio.c
*
* Purpose: Functions in this file implement support for parallel
* I/O cache functionality
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#include "H5ACmodule.h" /* This source code file is part of the H5AC module */
#define H5F_FRIEND /*suppress error about including H5Fpkg */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5ACpkg.h" /* Metadata cache */
#include "H5Cprivate.h" /* Cache */
#include "H5CXprivate.h" /* API Contexts */
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free Lists */
#include "H5Fpkg.h" /* Files */
#include "H5MMprivate.h" /* Memory management */
#include "H5SLprivate.h" /* Skip Lists */
#ifdef H5_HAVE_PARALLEL
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/****************************************************************************
*
* structure H5AC_slist_entry_t
*
* The dirty entry list maintained via the d_slist_ptr field of H5AC_aux_t
* and the cleaned entry list maintained via the c_slist_ptr field of
* H5AC_aux_t are just lists of the file offsets of the dirty/cleaned
* entries. Unfortunately, the slist code makes us define a dynamically
* allocated structure to store these offsets in. This structure serves
* that purpose. Its fields are as follows:
*
* addr: file offset of a metadata entry. Entries are added to this
* list (if they aren't there already) when they are marked
* dirty in an unprotect, inserted, or moved. They are
* removed when they appear in a clean entries broadcast.
*
****************************************************************************/
typedef struct H5AC_slist_entry_t {
haddr_t addr;
} H5AC_slist_entry_t;
/* User data for address list building callbacks */
typedef struct H5AC_addr_list_ud_t {
H5AC_aux_t *aux_ptr; /* 'Auxiliary' parallel cache info */
haddr_t *addr_buf_ptr; /* Array to store addresses */
unsigned u; /* Counter for position in array */
} H5AC_addr_list_ud_t;
/********************/
/* Local Prototypes */
/********************/
static herr_t H5AC__broadcast_candidate_list(H5AC_t *cache_ptr, unsigned *num_entries_ptr,
haddr_t **haddr_buf_ptr_ptr);
static herr_t H5AC__broadcast_clean_list(H5AC_t *cache_ptr);
static herr_t H5AC__construct_candidate_list(H5AC_t *cache_ptr, H5AC_aux_t *aux_ptr, int sync_point_op);
static herr_t H5AC__copy_candidate_list_to_buffer(const H5AC_t *cache_ptr, unsigned *num_entries_ptr,
haddr_t **haddr_buf_ptr_ptr);
static herr_t H5AC__propagate_and_apply_candidate_list(H5F_t *f);
static herr_t H5AC__propagate_flushed_and_still_clean_entries_list(H5F_t *f);
static herr_t H5AC__receive_haddr_list(MPI_Comm mpi_comm, unsigned *num_entries_ptr,
haddr_t **haddr_buf_ptr_ptr);
static herr_t H5AC__receive_candidate_list(const H5AC_t *cache_ptr, unsigned *num_entries_ptr,
haddr_t **haddr_buf_ptr_ptr);
static herr_t H5AC__receive_and_apply_clean_list(H5F_t *f);
static herr_t H5AC__tidy_cache_0_lists(H5AC_t *cache_ptr, unsigned num_candidates,
haddr_t *candidates_list_ptr);
static herr_t H5AC__rsp__dist_md_write__flush(H5F_t *f);
static herr_t H5AC__rsp__dist_md_write__flush_to_min_clean(H5F_t *f);
static herr_t H5AC__rsp__p0_only__flush(H5F_t *f);
static herr_t H5AC__rsp__p0_only__flush_to_min_clean(H5F_t *f);
/*********************/
/* Package Variables */
/*********************/
/* Declare a free list to manage the H5AC_aux_t struct */
H5FL_DEFINE(H5AC_aux_t);
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/* Declare a free list to manage the H5AC_slist_entry_t struct */
H5FL_DEFINE_STATIC(H5AC_slist_entry_t);
/*-------------------------------------------------------------------------
* Function: H5AC__set_sync_point_done_callback
*
* Purpose: Set the value of the sync_point_done callback. This
* callback is used by the parallel test code to verify
* that the expected writes and only the expected writes
* take place during a sync point.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__set_sync_point_done_callback(H5C_t *cache_ptr, H5AC_sync_point_done_cb_t sync_point_done)
{
H5AC_aux_t *aux_ptr;
FUNC_ENTER_PACKAGE_NOERR
/* Sanity checks */
assert(cache_ptr);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
aux_ptr->sync_point_done = sync_point_done;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5AC__set_sync_point_done_callback() */
/*-------------------------------------------------------------------------
* Function: H5AC__set_write_done_callback
*
* Purpose: Set the value of the write_done callback. This callback
* is used to improve performance of the parallel test bed
* for the cache.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__set_write_done_callback(H5C_t *cache_ptr, H5AC_write_done_cb_t write_done)
{
H5AC_aux_t *aux_ptr;
FUNC_ENTER_PACKAGE_NOERR
/* Sanity checks */
assert(cache_ptr);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
aux_ptr->write_done = write_done;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5AC__set_write_done_callback() */
/*-------------------------------------------------------------------------
* Function: H5AC_add_candidate()
*
* Purpose: Add the supplied metadata entry address to the candidate
* list. Verify that each entry added does not appear in
* the list prior to its insertion.
*
* This function is intended for used in constructing list
* of entried to be flushed during sync points. It shouldn't
* be called anywhere else.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC_add_candidate(H5AC_t *cache_ptr, haddr_t addr)
{
H5AC_aux_t *aux_ptr;
H5AC_slist_entry_t *slist_entry_ptr = NULL;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity checks */
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
assert(aux_ptr->metadata_write_strategy == H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED);
assert(aux_ptr->candidate_slist_ptr != NULL);
/* Construct an entry for the supplied address, and insert
* it into the candidate slist.
*/
if (NULL == (slist_entry_ptr = H5FL_MALLOC(H5AC_slist_entry_t)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "Can't allocate candidate slist entry");
slist_entry_ptr->addr = addr;
if (H5SL_insert(aux_ptr->candidate_slist_ptr, slist_entry_ptr, &(slist_entry_ptr->addr)) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTINSERT, FAIL, "can't insert entry into dirty entry slist");
done:
/* Clean up on error */
if (ret_value < 0)
if (slist_entry_ptr)
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC_add_candidate() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__broadcast_candidate_list()
*
* Purpose: Broadcast the contents of the process 0 candidate entry
* slist. In passing, also remove all entries from said
* list. As the application of this will be handled by
* the same functions on all processes, construct and
* return a copy of the list in the same format as that
* received by the other processes. Note that if this
* copy is returned in *haddr_buf_ptr_ptr, the caller
* must free it.
*
* This function must only be called by the process with
* MPI_rank 0.
*
* Return SUCCEED on success, and FAIL on failure.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5AC__broadcast_candidate_list(H5AC_t *cache_ptr, unsigned *num_entries_ptr, haddr_t **haddr_buf_ptr_ptr)
{
H5AC_aux_t *aux_ptr = NULL;
haddr_t *haddr_buf_ptr = NULL;
int mpi_result;
unsigned num_entries;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
assert(aux_ptr->mpi_rank == 0);
assert(aux_ptr->metadata_write_strategy == H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED);
assert(aux_ptr->candidate_slist_ptr != NULL);
assert(num_entries_ptr != NULL);
assert(*num_entries_ptr == 0);
assert(haddr_buf_ptr_ptr != NULL);
assert(*haddr_buf_ptr_ptr == NULL);
/* First broadcast the number of entries in the list so that the
* receivers can set up buffers to receive them. If there aren't
* any, we are done.
*/
num_entries = (unsigned)H5SL_count(aux_ptr->candidate_slist_ptr);
if (MPI_SUCCESS != (mpi_result = MPI_Bcast(&num_entries, 1, MPI_UNSIGNED, 0, aux_ptr->mpi_comm)))
HMPI_GOTO_ERROR(FAIL, "MPI_Bcast failed", mpi_result)
if (num_entries > 0) {
size_t buf_size = 0;
unsigned chk_num_entries = 0;
/* convert the candidate list into the format we
* are used to receiving from process 0, and also load it
* into a buffer for transmission.
*/
if (H5AC__copy_candidate_list_to_buffer(cache_ptr, &chk_num_entries, &haddr_buf_ptr) < 0) {
/* Push an error, but still participate in following MPI_Bcast */
HDONE_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't construct candidate buffer.");
}
assert(chk_num_entries == num_entries);
assert(haddr_buf_ptr != NULL);
/* Now broadcast the list of candidate entries */
buf_size = sizeof(haddr_t) * num_entries;
if (MPI_SUCCESS !=
(mpi_result = MPI_Bcast((void *)haddr_buf_ptr, (int)buf_size, MPI_BYTE, 0, aux_ptr->mpi_comm)))
HMPI_GOTO_ERROR(FAIL, "MPI_Bcast failed", mpi_result)
} /* end if */
/* Pass the number of entries and the buffer pointer
* back to the caller. Do this so that we can use the same code
* to apply the candidate list to all the processes.
*/
*num_entries_ptr = num_entries;
*haddr_buf_ptr_ptr = haddr_buf_ptr;
done:
if (ret_value < 0)
if (haddr_buf_ptr)
haddr_buf_ptr = (haddr_t *)H5MM_xfree((void *)haddr_buf_ptr);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC__broadcast_candidate_list() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__broadcast_clean_list_cb()
*
* Purpose: Skip list callback for building array of addresses for
* broadcasting the clean list.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5AC__broadcast_clean_list_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata)
{
H5AC_slist_entry_t *slist_entry_ptr = (H5AC_slist_entry_t *)_item; /* Address of item */
H5AC_addr_list_ud_t *udata = (H5AC_addr_list_ud_t *)_udata; /* Context for callback */
haddr_t addr;
FUNC_ENTER_PACKAGE_NOERR
/* Sanity checks */
assert(slist_entry_ptr);
assert(udata);
/* Store the entry's address in the buffer */
addr = slist_entry_ptr->addr;
udata->addr_buf_ptr[udata->u] = addr;
udata->u++;
/* now release the entry */
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
/* and also remove the matching entry from the dirtied list
* if it exists.
*/
if (NULL !=
(slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(udata->aux_ptr->d_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5AC__broadcast_clean_list_cb() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__broadcast_clean_list()
*
* Purpose: Broadcast the contents of the process 0 cleaned entry
* slist. In passing, also remove all entries from said
* list, and also remove any matching entries from the dirtied
* slist.
*
* This function must only be called by the process with
* MPI_rank 0.
*
* Return SUCCEED on success, and FAIL on failure.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5AC__broadcast_clean_list(H5AC_t *cache_ptr)
{
haddr_t *addr_buf_ptr = NULL;
H5AC_aux_t *aux_ptr;
int mpi_result;
unsigned num_entries = 0;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
assert(aux_ptr->mpi_rank == 0);
assert(aux_ptr->c_slist_ptr != NULL);
/* First broadcast the number of entries in the list so that the
* receives can set up a buffer to receive them. If there aren't
* any, we are done.
*/
num_entries = (unsigned)H5SL_count(aux_ptr->c_slist_ptr);
if (MPI_SUCCESS != (mpi_result = MPI_Bcast(&num_entries, 1, MPI_UNSIGNED, 0, aux_ptr->mpi_comm)))
HMPI_GOTO_ERROR(FAIL, "MPI_Bcast failed", mpi_result)
if (num_entries > 0) {
H5AC_addr_list_ud_t udata;
size_t buf_size;
/* allocate a buffer to store the list of entry base addresses in */
buf_size = sizeof(haddr_t) * num_entries;
if (NULL == (addr_buf_ptr = (haddr_t *)H5MM_malloc(buf_size))) {
/* Push an error, but still participate in following MPI_Bcast */
HDONE_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed for addr buffer");
}
else {
/* Set up user data for callback */
udata.aux_ptr = aux_ptr;
udata.addr_buf_ptr = addr_buf_ptr;
udata.u = 0;
/* Free all the clean list entries, building the address list in the callback */
/* (Callback also removes the matching entries from the dirtied list) */
if (H5SL_free(aux_ptr->c_slist_ptr, H5AC__broadcast_clean_list_cb, &udata) < 0) {
/* Push an error, but still participate in following MPI_Bcast */
HDONE_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "Can't build address list for clean entries");
}
}
/* Now broadcast the list of cleaned entries */
if (MPI_SUCCESS !=
(mpi_result = MPI_Bcast((void *)addr_buf_ptr, (int)buf_size, MPI_BYTE, 0, aux_ptr->mpi_comm)))
HMPI_GOTO_ERROR(FAIL, "MPI_Bcast failed", mpi_result)
} /* end if */
/* if it is defined, call the sync point done callback. Note
* that this callback is defined purely for testing purposes,
* and should be undefined under normal operating circumstances.
*/
if (aux_ptr->sync_point_done)
(aux_ptr->sync_point_done)(num_entries, addr_buf_ptr);
done:
if (addr_buf_ptr)
addr_buf_ptr = (haddr_t *)H5MM_xfree((void *)addr_buf_ptr);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC__broadcast_clean_list() */
/*-------------------------------------------------------------------------
* Function: H5AC__construct_candidate_list()
*
* Purpose: In the parallel case when the metadata_write_strategy is
* H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED, process 0 uses
* this function to construct the list of cache entries to
* be flushed. This list is then propagated to the other
* caches, and then flushed in a distributed fashion.
*
* The sync_point_op parameter is used to determine the extent
* of the flush.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5AC__construct_candidate_list(H5AC_t *cache_ptr, H5AC_aux_t H5_ATTR_NDEBUG_UNUSED *aux_ptr,
int sync_point_op)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(cache_ptr != NULL);
assert(aux_ptr != NULL);
assert(aux_ptr->metadata_write_strategy == H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED);
assert((sync_point_op == H5AC_SYNC_POINT_OP__FLUSH_CACHE) || (aux_ptr->mpi_rank == 0));
assert(aux_ptr->d_slist_ptr != NULL);
assert(aux_ptr->c_slist_ptr != NULL);
assert(H5SL_count(aux_ptr->c_slist_ptr) == 0);
assert(aux_ptr->candidate_slist_ptr != NULL);
assert(H5SL_count(aux_ptr->candidate_slist_ptr) == 0);
assert((sync_point_op == H5AC_SYNC_POINT_OP__FLUSH_TO_MIN_CLEAN) ||
(sync_point_op == H5AC_SYNC_POINT_OP__FLUSH_CACHE));
switch (sync_point_op) {
case H5AC_SYNC_POINT_OP__FLUSH_TO_MIN_CLEAN:
if (H5C_construct_candidate_list__min_clean((H5C_t *)cache_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_construct_candidate_list__min_clean() failed.");
break;
case H5AC_SYNC_POINT_OP__FLUSH_CACHE:
if (H5C_construct_candidate_list__clean_cache((H5C_t *)cache_ptr) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL,
"H5C_construct_candidate_list__clean_cache() failed.");
break;
default:
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "unknown sync point operation.");
break;
} /* end switch */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC__construct_candidate_list() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__copy_candidate_list_to_buffer_cb
*
* Purpose: Skip list callback for building array of addresses for
* broadcasting the candidate list.
*
* Return: Return SUCCEED on success, and FAIL on failure.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5AC__copy_candidate_list_to_buffer_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata)
{
H5AC_slist_entry_t *slist_entry_ptr = (H5AC_slist_entry_t *)_item; /* Address of item */
H5AC_addr_list_ud_t *udata = (H5AC_addr_list_ud_t *)_udata; /* Context for callback */
FUNC_ENTER_PACKAGE_NOERR
/* Sanity checks */
assert(slist_entry_ptr);
assert(udata);
/* Store the entry's address in the buffer */
udata->addr_buf_ptr[udata->u] = slist_entry_ptr->addr;
udata->u++;
/* now release the entry */
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5AC__copy_candidate_list_to_buffer_cb() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__copy_candidate_list_to_buffer
*
* Purpose: Allocate buffer(s) and copy the contents of the candidate
* entry slist into it (them). In passing, remove all
* entries from the candidate slist. Note that the
* candidate slist must not be empty.
*
* If MPI_Offset_buf_ptr_ptr is not NULL, allocate a buffer
* of MPI_Offset, copy the contents of the candidate
* entry list into it with the appropriate conversions,
* and return the base address of the buffer in
* *MPI_Offset_buf_ptr. Note that this is the buffer
* used by process 0 to transmit the list of entries to
* be flushed to all other processes (in this file group).
*
* Similarly, allocate a buffer of haddr_t, load the contents
* of the candidate list into this buffer, and return its
* base address in *haddr_buf_ptr_ptr. Note that this
* latter buffer is constructed unconditionally.
*
* In passing, also remove all entries from the candidate
* entry slist.
*
* Return: Return SUCCEED on success, and FAIL on failure.
*
*-------------------------------------------------------------------------
*/
static herr_t
H5AC__copy_candidate_list_to_buffer(const H5AC_t *cache_ptr, unsigned *num_entries_ptr,
haddr_t **haddr_buf_ptr_ptr)
{
H5AC_aux_t *aux_ptr = NULL;
H5AC_addr_list_ud_t udata;
haddr_t *haddr_buf_ptr = NULL;
size_t buf_size;
unsigned num_entries = 0;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
assert(aux_ptr->metadata_write_strategy == H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED);
assert(aux_ptr->candidate_slist_ptr != NULL);
assert(H5SL_count(aux_ptr->candidate_slist_ptr) > 0);
assert(num_entries_ptr != NULL);
assert(*num_entries_ptr == 0);
assert(haddr_buf_ptr_ptr != NULL);
assert(*haddr_buf_ptr_ptr == NULL);
num_entries = (unsigned)H5SL_count(aux_ptr->candidate_slist_ptr);
/* allocate a buffer(s) to store the list of candidate entry
* base addresses in
*/
buf_size = sizeof(haddr_t) * num_entries;
if (NULL == (haddr_buf_ptr = (haddr_t *)H5MM_malloc(buf_size)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed for haddr buffer");
/* Set up user data for callback */
udata.aux_ptr = aux_ptr;
udata.addr_buf_ptr = haddr_buf_ptr;
udata.u = 0;
/* Free all the candidate list entries, building the address list in the callback */
if (H5SL_free(aux_ptr->candidate_slist_ptr, H5AC__copy_candidate_list_to_buffer_cb, &udata) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "Can't build address list for candidate entries");
/* Pass the number of entries and the buffer pointer
* back to the caller.
*/
*num_entries_ptr = num_entries;
*haddr_buf_ptr_ptr = haddr_buf_ptr;
done:
if (ret_value < 0)
if (haddr_buf_ptr)
haddr_buf_ptr = (haddr_t *)H5MM_xfree((void *)haddr_buf_ptr);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC__copy_candidate_list_to_buffer() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__log_deleted_entry()
*
* Purpose: Log an entry which has been deleted.
*
* Only called for mpi_rank 0. We must make sure that the entry
* doesn't appear in the cleaned or dirty entry lists.
*
* Return SUCCEED on success, and FAIL on failure.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__log_deleted_entry(const H5AC_info_t *entry_ptr)
{
H5AC_t *cache_ptr;
H5AC_aux_t *aux_ptr;
H5AC_slist_entry_t *slist_entry_ptr = NULL;
haddr_t addr;
FUNC_ENTER_PACKAGE_NOERR
/* Sanity checks */
assert(entry_ptr);
addr = entry_ptr->addr;
cache_ptr = entry_ptr->cache_ptr;
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
assert(aux_ptr->mpi_rank == 0);
assert(aux_ptr->d_slist_ptr != NULL);
assert(aux_ptr->c_slist_ptr != NULL);
/* if the entry appears in the dirtied entry slist, remove it. */
if (NULL != (slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(aux_ptr->d_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
/* if the entry appears in the cleaned entry slist, remove it. */
if (NULL != (slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(aux_ptr->c_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5AC__log_deleted_entry() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__log_dirtied_entry()
*
* Purpose: Update the dirty_bytes count for a newly dirtied entry.
*
* If mpi_rank isn't 0, this simply means adding the size
* of the entries to the dirty_bytes count.
*
* If mpi_rank is 0, we must first check to see if the entry
* appears in the dirty entries slist. If it is, do nothing.
* If it isn't, add the size to the dirty_bytes count, add the
* entry to the dirty entries slist, and remove it from the
* cleaned list (if it is present there).
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__log_dirtied_entry(const H5AC_info_t *entry_ptr)
{
H5AC_t *cache_ptr;
H5AC_aux_t *aux_ptr;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(entry_ptr);
assert(entry_ptr->is_dirty == false);
cache_ptr = entry_ptr->cache_ptr;
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
if (aux_ptr->mpi_rank == 0) {
H5AC_slist_entry_t *slist_entry_ptr;
haddr_t addr = entry_ptr->addr;
/* Sanity checks */
assert(aux_ptr->d_slist_ptr != NULL);
assert(aux_ptr->c_slist_ptr != NULL);
if (NULL == H5SL_search(aux_ptr->d_slist_ptr, (void *)(&addr))) {
/* insert the address of the entry in the dirty entry list, and
* add its size to the dirty_bytes count.
*/
if (NULL == (slist_entry_ptr = H5FL_MALLOC(H5AC_slist_entry_t)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "Can't allocate dirty slist entry .");
slist_entry_ptr->addr = addr;
if (H5SL_insert(aux_ptr->d_slist_ptr, slist_entry_ptr, &(slist_entry_ptr->addr)) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTINSERT, FAIL, "can't insert entry into dirty entry slist.");
aux_ptr->dirty_bytes += entry_ptr->size;
#ifdef H5AC_DEBUG_DIRTY_BYTES_CREATION
aux_ptr->unprotect_dirty_bytes += entry_ptr->size;
aux_ptr->unprotect_dirty_bytes_updates += 1;
#endif /* H5AC_DEBUG_DIRTY_BYTES_CREATION */
} /* end if */
/* the entry is dirty. If it exists on the cleaned entries list,
* remove it.
*/
if (NULL !=
(slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(aux_ptr->c_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
} /* end if */
else {
aux_ptr->dirty_bytes += entry_ptr->size;
#ifdef H5AC_DEBUG_DIRTY_BYTES_CREATION
aux_ptr->unprotect_dirty_bytes += entry_ptr->size;
aux_ptr->unprotect_dirty_bytes_updates += 1;
#endif /* H5AC_DEBUG_DIRTY_BYTES_CREATION */
} /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC__log_dirtied_entry() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__log_cleaned_entry()
*
* Purpose: Treat this operation as a 'clear' and remove the entry
* from both the cleaned and dirtied lists if it is present.
* Reduces the dirty_bytes count by the size of the entry.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__log_cleaned_entry(const H5AC_info_t *entry_ptr)
{
H5AC_t *cache_ptr;
H5AC_aux_t *aux_ptr;
FUNC_ENTER_PACKAGE_NOERR
/* Sanity check */
assert(entry_ptr);
assert(entry_ptr->is_dirty == false);
cache_ptr = entry_ptr->cache_ptr;
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
if (aux_ptr->mpi_rank == 0) {
H5AC_slist_entry_t *slist_entry_ptr;
haddr_t addr = entry_ptr->addr;
/* Sanity checks */
assert(aux_ptr->d_slist_ptr != NULL);
assert(aux_ptr->c_slist_ptr != NULL);
/* Remove it from both the cleaned list and the dirtied list. */
if (NULL !=
(slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(aux_ptr->c_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
if (NULL !=
(slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(aux_ptr->d_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
} /* end if */
/* Decrement the dirty byte count */
aux_ptr->dirty_bytes -= entry_ptr->size;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5AC__log_cleaned_entry() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__log_flushed_entry()
*
* Purpose: Update the clean entry slist for the flush of an entry --
* specifically, if the entry has been cleared, remove it
* from both the cleaned and dirtied lists if it is present.
* Otherwise, if the entry was dirty, insert the indicated
* entry address in the clean slist if it isn't there already.
*
* This function is only used in PHDF5, and should only
* be called for the process with mpi rank 0.
*
* Return SUCCEED on success, and FAIL on failure.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__log_flushed_entry(H5C_t *cache_ptr, haddr_t addr, bool was_dirty, unsigned flags)
{
bool cleared;
H5AC_aux_t *aux_ptr;
H5AC_slist_entry_t *slist_entry_ptr = NULL;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity check */
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
assert(aux_ptr->mpi_rank == 0);
assert(aux_ptr->c_slist_ptr != NULL);
/* Set local flags */
cleared = ((flags & H5C__FLUSH_CLEAR_ONLY_FLAG) != 0);
if (cleared) {
/* If the entry has been cleared, must remove it from both the
* cleaned list and the dirtied list.
*/
if (NULL !=
(slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(aux_ptr->c_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
if (NULL !=
(slist_entry_ptr = (H5AC_slist_entry_t *)H5SL_remove(aux_ptr->d_slist_ptr, (void *)(&addr))))
slist_entry_ptr = H5FL_FREE(H5AC_slist_entry_t, slist_entry_ptr);
} /* end if */
else if (was_dirty) {
if (NULL == H5SL_search(aux_ptr->c_slist_ptr, (void *)(&addr))) {
/* insert the address of the entry in the clean entry list. */
if (NULL == (slist_entry_ptr = H5FL_MALLOC(H5AC_slist_entry_t)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "Can't allocate clean slist entry .");
slist_entry_ptr->addr = addr;
if (H5SL_insert(aux_ptr->c_slist_ptr, slist_entry_ptr, &(slist_entry_ptr->addr)) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTINSERT, FAIL, "can't insert entry into clean entry slist.");
} /* end if */
} /* end else-if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC__log_flushed_entry() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__log_inserted_entry()
*
* Purpose: Update the dirty_bytes count for a newly inserted entry.
*
* If mpi_rank isn't 0, this simply means adding the size
* of the entry to the dirty_bytes count.
*
* If mpi_rank is 0, we must also add the entry to the
* dirty entries slist.
*
* Return SUCCEED on success, and FAIL on failure.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__log_inserted_entry(const H5AC_info_t *entry_ptr)
{
H5AC_t *cache_ptr;
H5AC_aux_t *aux_ptr;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(entry_ptr);
cache_ptr = entry_ptr->cache_ptr;
assert(cache_ptr != NULL);
aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
assert(aux_ptr != NULL);
if (aux_ptr->mpi_rank == 0) {
H5AC_slist_entry_t *slist_entry_ptr;
assert(aux_ptr->d_slist_ptr != NULL);
assert(aux_ptr->c_slist_ptr != NULL);
/* Entry to insert should not be in dirty list currently */
if (NULL != H5SL_search(aux_ptr->d_slist_ptr, (const void *)(&entry_ptr->addr)))
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Inserted entry already in dirty slist.");
/* insert the address of the entry in the dirty entry list, and
* add its size to the dirty_bytes count.
*/
if (NULL == (slist_entry_ptr = H5FL_MALLOC(H5AC_slist_entry_t)))
HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "Can't allocate dirty slist entry .");
slist_entry_ptr->addr = entry_ptr->addr;
if (H5SL_insert(aux_ptr->d_slist_ptr, slist_entry_ptr, &(slist_entry_ptr->addr)) < 0)
HGOTO_ERROR(H5E_CACHE, H5E_CANTINSERT, FAIL, "can't insert entry into dirty entry slist.");
/* Entry to insert should not be in clean list either */
if (NULL != H5SL_search(aux_ptr->c_slist_ptr, (const void *)(&entry_ptr->addr)))
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Inserted entry in clean slist.");
} /* end if */
aux_ptr->dirty_bytes += entry_ptr->size;
#ifdef H5AC_DEBUG_DIRTY_BYTES_CREATION
aux_ptr->insert_dirty_bytes += entry_ptr->size;
aux_ptr->insert_dirty_bytes_updates += 1;
#endif /* H5AC_DEBUG_DIRTY_BYTES_CREATION */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5AC__log_inserted_entry() */
/*-------------------------------------------------------------------------
*
* Function: H5AC__log_moved_entry()
*
* Purpose: Update the dirty_bytes count for a moved entry.
*
* WARNING
*
* At present, the way that the move call is used ensures
* that the moved entry is present in all caches by
* moving in a collective operation and immediately after
* unprotecting the target entry.
*
* This function uses this invariant, and will cause arcane
* failures if it is not met. If maintaining this invariant
* becomes impossible, we will have to rework this function
* extensively, and likely include a bit of IPC for
* synchronization. A better option might be to subsume
* move in the unprotect operation.
*
* Given that the target entry is in all caches, the function
* proceeds as follows:
*
* For processes with mpi rank other 0, it simply checks to
* see if the entry was dirty prior to the move, and adds
* the entries size to the dirty bytes count.
*
* In the process with mpi rank 0, the function first checks
* to see if the entry was dirty prior to the move. If it
* was, and if the entry doesn't appear in the dirtied list
* under its old address, it adds the entry's size to the
* dirty bytes count.
*
* The rank 0 process then removes any references to the
* entry under its old address from the clean and dirtied
* lists, and inserts an entry in the dirtied list under the
* new address.
*
* Return SUCCEED on success, and FAIL on failure.
*
* Return: Non-negative on success/Negative on failure.
*
*-------------------------------------------------------------------------
*/
herr_t
H5AC__log_moved_entry(const H5F_t *f, haddr_t old_addr, haddr_t new_addr)
{
H5AC_t *cache_ptr;
H5AC_aux_t *aux_ptr;
bool entry_in_cache;
bool entry_dirty;
size_t entry_size;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity checks */
assert(f);
assert(f->shared);