lsquic_mm.h revision 06b2a236
1/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_mm.h -- Memory manager. 4 * 5 * Allocators and in this class are meant to be used for the lifetime of 6 * QUIC engine. 7 */ 8 9#ifndef LSQUIC_MM_H 10#define LSQUIC_MM_H 1 11 12struct lsquic_engine_public; 13struct lsquic_packet_in; 14struct lsquic_packet_out; 15struct ack_info; 16struct malo; 17struct mini_conn; 18 19struct pool_stats 20{ 21 unsigned ps_calls; /* Calls to get/put */ 22 unsigned ps_max; /* Maximum during this sample period */ 23 unsigned ps_max_avg, /* Average maximum value */ 24 ps_max_var; 25 unsigned ps_objs_all; /* Number of objects owned by the pool */ 26 unsigned ps_objs_out; /* Number of objects in use */ 27}; 28 29#define MM_N_OUT_BUCKETS 5 30#define MM_N_IN_BUCKETS 3 31 32struct lsquic_mm { 33 struct ack_info *acki; 34 struct { 35 struct malo *stream_frame; /* For struct stream_frame */ 36 struct malo *frame_rec_arr; /* For struct frame_rec_arr */ 37 struct malo *mini_conn; /* For struct mini_conn */ 38 struct malo *mini_conn_ietf;/* For struct ietf_mini_conn */ 39 struct malo *retry_conn; /* For struct retry_conn */ 40 struct malo *packet_in; /* For struct lsquic_packet_in */ 41 struct malo *packet_out; /* For struct lsquic_packet_out */ 42 struct malo *dcid_elem; /* For struct dcid_elem */ 43 struct malo *stream_hq_frame; /* For struct stream_hq_frame */ 44 } malo; 45 TAILQ_HEAD(, lsquic_packet_in) free_packets_in; 46 SLIST_HEAD(, packet_out_buf) packet_out_bufs[MM_N_OUT_BUCKETS]; 47 struct pool_stats packet_out_bstats[MM_N_OUT_BUCKETS]; 48 SLIST_HEAD(, packet_in_buf) packet_in_bufs[MM_N_IN_BUCKETS]; 49 SLIST_HEAD(, four_k_page) four_k_pages; 50 SLIST_HEAD(, sixteen_k_page) sixteen_k_pages; 51 char *ack_str; 52}; 53 54int 55lsquic_mm_init (struct lsquic_mm *); 56 57void 58lsquic_mm_cleanup (struct lsquic_mm *); 59 60struct lsquic_packet_in * 61lsquic_mm_get_packet_in (struct lsquic_mm *); 62 63void 64lsquic_mm_put_packet_in (struct lsquic_mm *, struct lsquic_packet_in *); 65 66#define lsquic_packet_in_put(mm, p) do { \ 67 assert((p)->pi_refcnt != 0); \ 68 if (--(p)->pi_refcnt == 0) \ 69 lsquic_mm_put_packet_in(mm, p); \ 70} while (0) 71 72struct lsquic_packet_out * 73lsquic_mm_get_packet_out (struct lsquic_mm *, struct malo *, 74 unsigned short size); 75 76void 77lsquic_mm_put_packet_out (struct lsquic_mm *, struct lsquic_packet_out *); 78 79void * 80lsquic_mm_get_packet_in_buf (struct lsquic_mm *, size_t); 81 82void 83lsquic_mm_put_packet_in_buf (struct lsquic_mm *, void *, size_t); 84 85void * 86lsquic_mm_get_4k (struct lsquic_mm *); 87 88void 89lsquic_mm_put_4k (struct lsquic_mm *, void *); 90 91void * 92lsquic_mm_get_16k (struct lsquic_mm *); 93 94void 95lsquic_mm_put_16k (struct lsquic_mm *, void *); 96 97size_t 98lsquic_mm_mem_used (const struct lsquic_mm *mm); 99 100#endif 101