lsquic_mm.h revision de46bf2f
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov/* 350aadb33SDmitri Tikhonov * lsquic_mm.h -- Memory manager. 450aadb33SDmitri Tikhonov * 550aadb33SDmitri Tikhonov * Allocators and in this class are meant to be used for the lifetime of 650aadb33SDmitri Tikhonov * QUIC engine. 750aadb33SDmitri Tikhonov */ 850aadb33SDmitri Tikhonov 950aadb33SDmitri Tikhonov#ifndef LSQUIC_MM_H 1050aadb33SDmitri Tikhonov#define LSQUIC_MM_H 1 1150aadb33SDmitri Tikhonov 1250aadb33SDmitri Tikhonovstruct lsquic_engine_public; 1350aadb33SDmitri Tikhonovstruct lsquic_packet_in; 1450aadb33SDmitri Tikhonovstruct lsquic_packet_out; 1550aadb33SDmitri Tikhonovstruct ack_info; 1650aadb33SDmitri Tikhonovstruct malo; 175392f7a3SLiteSpeed Techstruct mini_conn; 185392f7a3SLiteSpeed Tech 195392f7a3SLiteSpeed Techstruct pool_stats 205392f7a3SLiteSpeed Tech{ 215392f7a3SLiteSpeed Tech unsigned ps_calls; /* Calls to get/put */ 225392f7a3SLiteSpeed Tech unsigned ps_max; /* Maximum during this sample period */ 235392f7a3SLiteSpeed Tech unsigned ps_max_avg, /* Average maximum value */ 245392f7a3SLiteSpeed Tech ps_max_var; 255392f7a3SLiteSpeed Tech unsigned ps_objs_all; /* Number of objects owned by the pool */ 265392f7a3SLiteSpeed Tech unsigned ps_objs_out; /* Number of objects in use */ 275392f7a3SLiteSpeed Tech}; 2850aadb33SDmitri Tikhonov 295392f7a3SLiteSpeed Tech#define MM_N_OUT_BUCKETS 5 305392f7a3SLiteSpeed Tech#define MM_N_IN_BUCKETS 3 3150aadb33SDmitri Tikhonov 3250aadb33SDmitri Tikhonovstruct lsquic_mm { 3350aadb33SDmitri Tikhonov struct ack_info *acki; 3450aadb33SDmitri Tikhonov struct { 3550aadb33SDmitri Tikhonov struct malo *stream_frame; /* For struct stream_frame */ 3650aadb33SDmitri Tikhonov struct malo *stream_rec_arr;/* For struct stream_rec_arr */ 375392f7a3SLiteSpeed Tech struct malo *mini_conn; /* For struct mini_conn */ 385392f7a3SLiteSpeed Tech struct malo *mini_conn_ietf;/* For struct ietf_mini_conn */ 395392f7a3SLiteSpeed Tech struct malo *retry_conn; /* For struct retry_conn */ 4050aadb33SDmitri Tikhonov struct malo *packet_in; /* For struct lsquic_packet_in */ 4150aadb33SDmitri Tikhonov struct malo *packet_out; /* For struct lsquic_packet_out */ 425392f7a3SLiteSpeed Tech struct malo *dcid_elem; /* For struct dcid_elem */ 435392f7a3SLiteSpeed Tech struct malo *stream_hq_frame; /* For struct stream_hq_frame */ 4450aadb33SDmitri Tikhonov } malo; 4550aadb33SDmitri Tikhonov TAILQ_HEAD(, lsquic_packet_in) free_packets_in; 4650aadb33SDmitri Tikhonov SLIST_HEAD(, packet_out_buf) packet_out_bufs[MM_N_OUT_BUCKETS]; 475392f7a3SLiteSpeed Tech struct pool_stats packet_out_bstats[MM_N_OUT_BUCKETS]; 485392f7a3SLiteSpeed Tech SLIST_HEAD(, packet_in_buf) packet_in_bufs[MM_N_IN_BUCKETS]; 4950aadb33SDmitri Tikhonov SLIST_HEAD(, four_k_page) four_k_pages; 5050aadb33SDmitri Tikhonov SLIST_HEAD(, sixteen_k_page) sixteen_k_pages; 51de46bf2fSDmitri Tikhonov char *ack_str; 5250aadb33SDmitri Tikhonov}; 5350aadb33SDmitri Tikhonov 5450aadb33SDmitri Tikhonovint 5550aadb33SDmitri Tikhonovlsquic_mm_init (struct lsquic_mm *); 5650aadb33SDmitri Tikhonov 5750aadb33SDmitri Tikhonovvoid 5850aadb33SDmitri Tikhonovlsquic_mm_cleanup (struct lsquic_mm *); 5950aadb33SDmitri Tikhonov 6050aadb33SDmitri Tikhonovstruct lsquic_packet_in * 6150aadb33SDmitri Tikhonovlsquic_mm_get_packet_in (struct lsquic_mm *); 6250aadb33SDmitri Tikhonov 6350aadb33SDmitri Tikhonovvoid 6450aadb33SDmitri Tikhonovlsquic_mm_put_packet_in (struct lsquic_mm *, struct lsquic_packet_in *); 6550aadb33SDmitri Tikhonov 6650aadb33SDmitri Tikhonov#define lsquic_packet_in_put(mm, p) do { \ 6750aadb33SDmitri Tikhonov assert((p)->pi_refcnt != 0); \ 6850aadb33SDmitri Tikhonov if (--(p)->pi_refcnt == 0) \ 6950aadb33SDmitri Tikhonov lsquic_mm_put_packet_in(mm, p); \ 7050aadb33SDmitri Tikhonov} while (0) 7150aadb33SDmitri Tikhonov 7250aadb33SDmitri Tikhonovstruct lsquic_packet_out * 7350aadb33SDmitri Tikhonovlsquic_mm_get_packet_out (struct lsquic_mm *, struct malo *, 7450aadb33SDmitri Tikhonov unsigned short size); 7550aadb33SDmitri Tikhonov 7650aadb33SDmitri Tikhonovvoid 7750aadb33SDmitri Tikhonovlsquic_mm_put_packet_out (struct lsquic_mm *, struct lsquic_packet_out *); 7850aadb33SDmitri Tikhonov 7950aadb33SDmitri Tikhonovvoid * 805392f7a3SLiteSpeed Techlsquic_mm_get_packet_in_buf (struct lsquic_mm *, size_t); 8150aadb33SDmitri Tikhonov 8250aadb33SDmitri Tikhonovvoid 835392f7a3SLiteSpeed Techlsquic_mm_put_packet_in_buf (struct lsquic_mm *, void *, size_t); 8450aadb33SDmitri Tikhonov 8550aadb33SDmitri Tikhonovvoid * 8650aadb33SDmitri Tikhonovlsquic_mm_get_4k (struct lsquic_mm *); 8750aadb33SDmitri Tikhonov 8850aadb33SDmitri Tikhonovvoid 8950aadb33SDmitri Tikhonovlsquic_mm_put_4k (struct lsquic_mm *, void *); 9050aadb33SDmitri Tikhonov 9150aadb33SDmitri Tikhonovvoid * 9250aadb33SDmitri Tikhonovlsquic_mm_get_16k (struct lsquic_mm *); 9350aadb33SDmitri Tikhonov 9450aadb33SDmitri Tikhonovvoid 9550aadb33SDmitri Tikhonovlsquic_mm_put_16k (struct lsquic_mm *, void *); 9650aadb33SDmitri Tikhonov 97c51ce338SDmitri Tikhonovsize_t 98c51ce338SDmitri Tikhonovlsquic_mm_mem_used (const struct lsquic_mm *mm); 99c51ce338SDmitri Tikhonov 10050aadb33SDmitri Tikhonov#endif 101