1#include <linux/bug.h> 2 3#ifdef CONFIG_ZCACHE_DEBUG 4 5/* we try to keep these statistics SMP-consistent */ 6extern ssize_t zcache_obj_count; 7static atomic_t zcache_obj_atomic = ATOMIC_INIT(0); 8extern ssize_t zcache_obj_count_max; 9static inline void inc_zcache_obj_count(void) 10{ 11 zcache_obj_count = atomic_inc_return(&zcache_obj_atomic); 12 if (zcache_obj_count > zcache_obj_count_max) 13 zcache_obj_count_max = zcache_obj_count; 14} 15static inline void dec_zcache_obj_count(void) 16{ 17 zcache_obj_count = atomic_dec_return(&zcache_obj_atomic); 18 BUG_ON(zcache_obj_count < 0); 19}; 20extern ssize_t zcache_objnode_count; 21static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0); 22extern ssize_t zcache_objnode_count_max; 23static inline void inc_zcache_objnode_count(void) 24{ 25 zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic); 26 if (zcache_objnode_count > zcache_objnode_count_max) 27 zcache_objnode_count_max = zcache_objnode_count; 28}; 29static inline void dec_zcache_objnode_count(void) 30{ 31 zcache_objnode_count = atomic_dec_return(&zcache_objnode_atomic); 32 BUG_ON(zcache_objnode_count < 0); 33}; 34extern u64 zcache_eph_zbytes; 35static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0); 36extern u64 zcache_eph_zbytes_max; 37static inline void inc_zcache_eph_zbytes(unsigned clen) 38{ 39 zcache_eph_zbytes = atomic_long_add_return(clen, &zcache_eph_zbytes_atomic); 40 if (zcache_eph_zbytes > zcache_eph_zbytes_max) 41 zcache_eph_zbytes_max = zcache_eph_zbytes; 42}; 43static inline void dec_zcache_eph_zbytes(unsigned zsize) 44{ 45 zcache_eph_zbytes = atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic); 46}; 47extern u64 zcache_pers_zbytes; 48static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0); 49extern u64 zcache_pers_zbytes_max; 50static inline void inc_zcache_pers_zbytes(unsigned clen) 51{ 52 zcache_pers_zbytes = atomic_long_add_return(clen, &zcache_pers_zbytes_atomic); 53 if (zcache_pers_zbytes > zcache_pers_zbytes_max) 54 zcache_pers_zbytes_max = zcache_pers_zbytes; 55} 56static inline void dec_zcache_pers_zbytes(unsigned zsize) 57{ 58 zcache_pers_zbytes = atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic); 59} 60extern ssize_t zcache_eph_pageframes; 61static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0); 62extern ssize_t zcache_eph_pageframes_max; 63static inline void inc_zcache_eph_pageframes(void) 64{ 65 zcache_eph_pageframes = atomic_inc_return(&zcache_eph_pageframes_atomic); 66 if (zcache_eph_pageframes > zcache_eph_pageframes_max) 67 zcache_eph_pageframes_max = zcache_eph_pageframes; 68}; 69static inline void dec_zcache_eph_pageframes(void) 70{ 71 zcache_eph_pageframes = atomic_dec_return(&zcache_eph_pageframes_atomic); 72}; 73extern ssize_t zcache_pers_pageframes; 74static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0); 75extern ssize_t zcache_pers_pageframes_max; 76static inline void inc_zcache_pers_pageframes(void) 77{ 78 zcache_pers_pageframes = atomic_inc_return(&zcache_pers_pageframes_atomic); 79 if (zcache_pers_pageframes > zcache_pers_pageframes_max) 80 zcache_pers_pageframes_max = zcache_pers_pageframes; 81} 82static inline void dec_zcache_pers_pageframes(void) 83{ 84 zcache_pers_pageframes = atomic_dec_return(&zcache_pers_pageframes_atomic); 85} 86extern ssize_t zcache_pageframes_alloced; 87static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0); 88static inline void inc_zcache_pageframes_alloced(void) 89{ 90 zcache_pageframes_alloced = atomic_inc_return(&zcache_pageframes_alloced_atomic); 91}; 92extern ssize_t zcache_pageframes_freed; 93static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0); 94static inline void inc_zcache_pageframes_freed(void) 95{ 96 zcache_pageframes_freed = atomic_inc_return(&zcache_pageframes_freed_atomic); 97} 98extern ssize_t zcache_eph_zpages; 99static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0); 100extern ssize_t zcache_eph_zpages_max; 101static inline void inc_zcache_eph_zpages(void) 102{ 103 zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic); 104 if (zcache_eph_zpages > zcache_eph_zpages_max) 105 zcache_eph_zpages_max = zcache_eph_zpages; 106} 107static inline void dec_zcache_eph_zpages(unsigned zpages) 108{ 109 zcache_eph_zpages = atomic_sub_return(zpages, &zcache_eph_zpages_atomic); 110} 111extern ssize_t zcache_pers_zpages; 112static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0); 113extern ssize_t zcache_pers_zpages_max; 114static inline void inc_zcache_pers_zpages(void) 115{ 116 zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic); 117 if (zcache_pers_zpages > zcache_pers_zpages_max) 118 zcache_pers_zpages_max = zcache_pers_zpages; 119} 120static inline void dec_zcache_pers_zpages(unsigned zpages) 121{ 122 zcache_pers_zpages = atomic_sub_return(zpages, &zcache_pers_zpages_atomic); 123} 124 125extern ssize_t zcache_zero_filled_pages; 126static atomic_t zcache_zero_filled_pages_atomic = ATOMIC_INIT(0); 127extern ssize_t zcache_zero_filled_pages_max; 128static inline void inc_zcache_zero_filled_pages(void) 129{ 130 zcache_zero_filled_pages = atomic_inc_return( 131 &zcache_zero_filled_pages_atomic); 132 if (zcache_zero_filled_pages > zcache_zero_filled_pages_max) 133 zcache_zero_filled_pages_max = zcache_zero_filled_pages; 134} 135static inline void dec_zcache_zero_filled_pages(void) 136{ 137 zcache_zero_filled_pages = atomic_dec_return( 138 &zcache_zero_filled_pages_atomic); 139} 140static inline unsigned long curr_pageframes_count(void) 141{ 142 return zcache_pageframes_alloced - 143 atomic_read(&zcache_pageframes_freed_atomic) - 144 atomic_read(&zcache_eph_pageframes_atomic) - 145 atomic_read(&zcache_pers_pageframes_atomic); 146}; 147/* but for the rest of these, counting races are ok */ 148extern ssize_t zcache_flush_total; 149extern ssize_t zcache_flush_found; 150extern ssize_t zcache_flobj_total; 151extern ssize_t zcache_flobj_found; 152extern ssize_t zcache_failed_eph_puts; 153extern ssize_t zcache_failed_pers_puts; 154extern ssize_t zcache_failed_getfreepages; 155extern ssize_t zcache_failed_alloc; 156extern ssize_t zcache_put_to_flush; 157extern ssize_t zcache_compress_poor; 158extern ssize_t zcache_mean_compress_poor; 159extern ssize_t zcache_eph_ate_tail; 160extern ssize_t zcache_eph_ate_tail_failed; 161extern ssize_t zcache_pers_ate_eph; 162extern ssize_t zcache_pers_ate_eph_failed; 163extern ssize_t zcache_evicted_eph_zpages; 164extern ssize_t zcache_evicted_eph_pageframes; 165 166extern ssize_t zcache_last_active_file_pageframes; 167extern ssize_t zcache_last_inactive_file_pageframes; 168extern ssize_t zcache_last_active_anon_pageframes; 169extern ssize_t zcache_last_inactive_anon_pageframes; 170static ssize_t zcache_eph_nonactive_puts_ignored; 171static ssize_t zcache_pers_nonactive_puts_ignored; 172#ifdef CONFIG_ZCACHE_WRITEBACK 173extern ssize_t zcache_writtenback_pages; 174extern ssize_t zcache_outstanding_writeback_pages; 175#endif 176 177static inline void inc_zcache_flush_total(void) 178{ 179 zcache_flush_total++; 180}; 181static inline void inc_zcache_flush_found(void) 182{ 183 zcache_flush_found++; 184}; 185static inline void inc_zcache_flobj_total(void) 186{ 187 zcache_flobj_total++; 188}; 189static inline void inc_zcache_flobj_found(void) 190{ 191 zcache_flobj_found++; 192}; 193static inline void inc_zcache_failed_eph_puts(void) 194{ 195 zcache_failed_eph_puts++; 196}; 197static inline void inc_zcache_failed_pers_puts(void) 198{ 199 zcache_failed_pers_puts++; 200}; 201static inline void inc_zcache_failed_getfreepages(void) 202{ 203 zcache_failed_getfreepages++; 204}; 205static inline void inc_zcache_failed_alloc(void) 206{ 207 zcache_failed_alloc++; 208}; 209static inline void inc_zcache_put_to_flush(void) 210{ 211 zcache_put_to_flush++; 212}; 213static inline void inc_zcache_compress_poor(void) 214{ 215 zcache_compress_poor++; 216}; 217static inline void inc_zcache_mean_compress_poor(void) 218{ 219 zcache_mean_compress_poor++; 220}; 221static inline void inc_zcache_eph_ate_tail(void) 222{ 223 zcache_eph_ate_tail++; 224}; 225static inline void inc_zcache_eph_ate_tail_failed(void) 226{ 227 zcache_eph_ate_tail_failed++; 228}; 229static inline void inc_zcache_pers_ate_eph(void) 230{ 231 zcache_pers_ate_eph++; 232}; 233static inline void inc_zcache_pers_ate_eph_failed(void) 234{ 235 zcache_pers_ate_eph_failed++; 236}; 237static inline void inc_zcache_evicted_eph_zpages(unsigned zpages) 238{ 239 zcache_evicted_eph_zpages += zpages; 240}; 241static inline void inc_zcache_evicted_eph_pageframes(void) 242{ 243 zcache_evicted_eph_pageframes++; 244}; 245 246static inline void inc_zcache_eph_nonactive_puts_ignored(void) 247{ 248 zcache_eph_nonactive_puts_ignored++; 249}; 250static inline void inc_zcache_pers_nonactive_puts_ignored(void) 251{ 252 zcache_pers_nonactive_puts_ignored++; 253}; 254 255int zcache_debugfs_init(void); 256#else 257static inline void inc_zcache_obj_count(void) { }; 258static inline void dec_zcache_obj_count(void) { }; 259static inline void inc_zcache_objnode_count(void) { }; 260static inline void dec_zcache_objnode_count(void) { }; 261static inline void inc_zcache_eph_zbytes(unsigned clen) { }; 262static inline void dec_zcache_eph_zbytes(unsigned zsize) { }; 263static inline void inc_zcache_pers_zbytes(unsigned clen) { }; 264static inline void dec_zcache_pers_zbytes(unsigned zsize) { }; 265static inline void inc_zcache_eph_pageframes(void) { }; 266static inline void dec_zcache_eph_pageframes(void) { }; 267static inline void inc_zcache_pers_pageframes(void) { }; 268static inline void dec_zcache_pers_pageframes(void) { }; 269static inline void inc_zcache_pageframes_alloced(void) { }; 270static inline void inc_zcache_pageframes_freed(void) { }; 271static inline void inc_zcache_eph_zpages(void) { }; 272static inline void dec_zcache_eph_zpages(unsigned zpages) { }; 273static inline void inc_zcache_pers_zpages(void) { }; 274static inline void dec_zcache_pers_zpages(unsigned zpages) { }; 275static inline void inc_zcache_zero_filled_pages(void) { }; 276static inline void dec_zcache_zero_filled_pages(void) { }; 277static inline unsigned long curr_pageframes_count(void) 278{ 279 return 0; 280}; 281static inline int zcache_debugfs_init(void) 282{ 283 return 0; 284}; 285static inline void inc_zcache_flush_total(void) { }; 286static inline void inc_zcache_flush_found(void) { }; 287static inline void inc_zcache_flobj_total(void) { }; 288static inline void inc_zcache_flobj_found(void) { }; 289static inline void inc_zcache_failed_eph_puts(void) { }; 290static inline void inc_zcache_failed_pers_puts(void) { }; 291static inline void inc_zcache_failed_getfreepages(void) { }; 292static inline void inc_zcache_failed_alloc(void) { }; 293static inline void inc_zcache_put_to_flush(void) { }; 294static inline void inc_zcache_compress_poor(void) { }; 295static inline void inc_zcache_mean_compress_poor(void) { }; 296static inline void inc_zcache_eph_ate_tail(void) { }; 297static inline void inc_zcache_eph_ate_tail_failed(void) { }; 298static inline void inc_zcache_pers_ate_eph(void) { }; 299static inline void inc_zcache_pers_ate_eph_failed(void) { }; 300static inline void inc_zcache_evicted_eph_zpages(unsigned zpages) { }; 301static inline void inc_zcache_evicted_eph_pageframes(void) { }; 302 303static inline void inc_zcache_eph_nonactive_puts_ignored(void) { }; 304static inline void inc_zcache_pers_nonactive_puts_ignored(void) { }; 305#endif 306