1 /* BLURB lgpl 2 3 Coda File System 4 Release 5 5 6 Copyright (c) 1987-1999 Carnegie Mellon University 7 Additional copyrights listed below 8 9 This code is distributed "AS IS" without warranty of any kind under 10 the terms of the GNU Library General Public Licence Version 2, as 11 shown in the file LICENSE. The technical and financial contributors to 12 Coda are listed in the file CREDITS. 13 14 Additional copyrights 15 none currently 16 17 #*/ 18 19 /* 20 * Public definitions for the Recoverable Dynamic Storage package. 21 */ 22 23 #ifndef _RDS_H_ 24 #define _RDS_H_ 25 26 #include <stdio.h> 27 #include "rvm.h" 28 29 /* Error codes */ 30 31 #define SUCCESS 0 32 #define ERVM_FAILED -1 33 #define EBAD_LIST -2 34 #define EBAD_SEGMENT_HDR -3 35 #define EHEAP_VERSION_SKEW -4 36 #define EHEAP_INIT -5 37 #define EBAD_ARGS -6 38 #define ECORRUPT -7 39 #define EFREED_TWICE -8 40 #define ENO_ROOM -9 41 42 /* Function definitions */ 43 44 extern int rds_zap_heap( 45 char *DevName, 46 rvm_offset_t DevLength, 47 char *startAddr, 48 rvm_length_t staticLength, 49 rvm_length_t heapLength, 50 unsigned long nlists, 51 unsigned long chunkSize, 52 int *err 53 ); 54 55 extern int rds_init_heap( 56 char *base, 57 rvm_length_t length, 58 unsigned long chunkSize, 59 unsigned long nlists, 60 rvm_tid_t *tid, 61 int *err 62 ); 63 64 extern int rds_load_heap( 65 char *DevName, 66 rvm_offset_t DevLength, 67 char **staticAddr, 68 int *err 69 ); 70 71 extern int rds_start_heap( 72 char *startAddr, 73 int *err 74 ); 75 76 extern int rds_prealloc( 77 unsigned long size, 78 unsigned long nblocks, 79 rvm_tid_t *tid, 80 int *err 81 ); 82 83 extern char *rds_malloc( 84 unsigned long size, 85 rvm_tid_t *tid, 86 int *err 87 ); 88 89 extern int rds_free( 90 char *addr, 91 rvm_tid_t *tid, 92 int *err 93 ); 94 95 int rds_maxblock(unsigned long size); 96 97 /* 98 * Because a transaction may abort we don't actually want to free 99 * objects until the end of the transaction. So fake_free records our intention 100 * to free an object. do_free actually frees the object. It's called as part 101 * of the commit. 102 */ 103 104 typedef struct intlist { 105 unsigned long size; 106 unsigned long count; 107 char **table; 108 } intentionList_t; 109 110 #define STARTSIZE 128 /* Initial size of list, may grow over time */ 111 112 extern int rds_fake_free( 113 char *addr, 114 intentionList_t *list 115 ); 116 117 extern int rds_do_free( 118 intentionList_t *list, 119 rvm_mode_t mode 120 ); 121 122 /* Heap statistics reporting */ 123 typedef struct { 124 unsigned malloc; /* Allocation requests */ 125 unsigned prealloc; /* Preallocation requests */ 126 unsigned free; /* Block free requests */ 127 unsigned coalesce; /* Heap coalesce count */ 128 unsigned hits; /* No need to split */ 129 unsigned misses; /* Split required */ 130 unsigned large_list; /* Largest list pointer changed */ 131 unsigned large_hits; /* Large blocks present in list */ 132 unsigned large_misses; /* Large block split required */ 133 unsigned merged; /* Objects merged from coalesce */ 134 unsigned unmerged; /* Objects not merged in coalesce */ 135 unsigned freebytes; /* Number of free bytes in heap */ 136 unsigned mallocbytes; /* Bytes allocated */ 137 } rds_stats_t; 138 139 extern int rds_print_stats(); 140 extern int rds_clear_stats(int *err); 141 extern int rds_get_stats(rds_stats_t *stats); 142 143 extern int rds_tracing; 144 extern FILE *rds_tracing_file; 145 extern int rds_trace_on(FILE *); 146 extern int rds_trace_off(); 147 extern int rds_trace_dump_heap(); 148 #define RDS_LOG(format, a...)\ 149 do { \ 150 if (rds_tracing && rds_tracing_file) { \ 151 fprintf(rds_tracing_file, format, ## a);\ 152 fflush(rds_tracing_file); }\ 153 } while (0) ; 154 155 156 #endif /* _RDS_H_ */ 157