lsquic_mm.h revision 293df8d6
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 *packet_in; /* For struct lsquic_packet_in */ 40 struct malo *packet_out; /* For struct lsquic_packet_out */ 41 struct malo *dcid_elem; /* For struct dcid_elem */ 42 struct malo *stream_hq_frame; /* For struct stream_hq_frame */ 43 } malo; 44 TAILQ_HEAD(, lsquic_packet_in) free_packets_in; 45 SLIST_HEAD(, packet_out_buf) packet_out_bufs[MM_N_OUT_BUCKETS]; 46 struct pool_stats packet_out_bstats[MM_N_OUT_BUCKETS]; 47 SLIST_HEAD(, packet_in_buf) packet_in_bufs[MM_N_IN_BUCKETS]; 48 SLIST_HEAD(, four_k_page) four_k_pages; 49 SLIST_HEAD(, sixteen_k_page) sixteen_k_pages; 50 char *ack_str; 51}; 52 53int 54lsquic_mm_init (struct lsquic_mm *); 55 56void 57lsquic_mm_cleanup (struct lsquic_mm *); 58 59struct lsquic_packet_in * 60lsquic_mm_get_packet_in (struct lsquic_mm *); 61 62void 63lsquic_mm_put_packet_in (struct lsquic_mm *, struct lsquic_packet_in *); 64 65#define lsquic_packet_in_put(mm, p) do { \ 66 assert((p)->pi_refcnt != 0); \ 67 if (--(p)->pi_refcnt == 0) \ 68 lsquic_mm_put_packet_in(mm, p); \ 69} while (0) 70 71struct lsquic_packet_out * 72lsquic_mm_get_packet_out (struct lsquic_mm *, struct malo *, 73 unsigned short size); 74 75void 76lsquic_mm_put_packet_out (struct lsquic_mm *, struct lsquic_packet_out *); 77 78void * 79lsquic_mm_get_packet_in_buf (struct lsquic_mm *, size_t); 80 81void 82lsquic_mm_put_packet_in_buf (struct lsquic_mm *, void *, size_t); 83 84void * 85lsquic_mm_get_4k (struct lsquic_mm *); 86 87void 88lsquic_mm_put_4k (struct lsquic_mm *, void *); 89 90void * 91lsquic_mm_get_16k (struct lsquic_mm *); 92 93void 94lsquic_mm_put_16k (struct lsquic_mm *, void *); 95 96size_t 97lsquic_mm_mem_used (const struct lsquic_mm *mm); 98 99#endif 100