lsquic_mm.h revision a74702c6
1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 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 */
36b8fa6195SDmitri Tikhonov        struct malo     *frame_rec_arr; /* For struct frame_rec_arr */
375392f7a3SLiteSpeed Tech        struct malo     *mini_conn;     /* For struct mini_conn */
385392f7a3SLiteSpeed Tech        struct malo     *mini_conn_ietf;/* For struct ietf_mini_conn */
3950aadb33SDmitri Tikhonov        struct malo     *packet_in;     /* For struct lsquic_packet_in */
4050aadb33SDmitri Tikhonov        struct malo     *packet_out;    /* For struct lsquic_packet_out */
415392f7a3SLiteSpeed Tech        struct malo     *dcid_elem;     /* For struct dcid_elem */
425392f7a3SLiteSpeed Tech        struct malo     *stream_hq_frame;   /* For struct stream_hq_frame */
4350aadb33SDmitri Tikhonov    }                    malo;
4450aadb33SDmitri Tikhonov    TAILQ_HEAD(, lsquic_packet_in)  free_packets_in;
4550aadb33SDmitri Tikhonov    SLIST_HEAD(, packet_out_buf)    packet_out_bufs[MM_N_OUT_BUCKETS];
465392f7a3SLiteSpeed Tech    struct pool_stats               packet_out_bstats[MM_N_OUT_BUCKETS];
475392f7a3SLiteSpeed Tech    SLIST_HEAD(, packet_in_buf)     packet_in_bufs[MM_N_IN_BUCKETS];
4850aadb33SDmitri Tikhonov    SLIST_HEAD(, four_k_page)       four_k_pages;
4950aadb33SDmitri Tikhonov    SLIST_HEAD(, sixteen_k_page)    sixteen_k_pages;
50de46bf2fSDmitri Tikhonov    char                *ack_str;
5150aadb33SDmitri Tikhonov};
5250aadb33SDmitri Tikhonov
5350aadb33SDmitri Tikhonovint
5450aadb33SDmitri Tikhonovlsquic_mm_init (struct lsquic_mm *);
5550aadb33SDmitri Tikhonov
5650aadb33SDmitri Tikhonovvoid
5750aadb33SDmitri Tikhonovlsquic_mm_cleanup (struct lsquic_mm *);
5850aadb33SDmitri Tikhonov
5950aadb33SDmitri Tikhonovstruct lsquic_packet_in *
6050aadb33SDmitri Tikhonovlsquic_mm_get_packet_in (struct lsquic_mm *);
6150aadb33SDmitri Tikhonov
6250aadb33SDmitri Tikhonovvoid
6350aadb33SDmitri Tikhonovlsquic_mm_put_packet_in (struct lsquic_mm *, struct lsquic_packet_in *);
6450aadb33SDmitri Tikhonov
6550aadb33SDmitri Tikhonov#define lsquic_packet_in_put(mm, p) do {                                \
6650aadb33SDmitri Tikhonov    assert((p)->pi_refcnt != 0);                                        \
6750aadb33SDmitri Tikhonov    if (--(p)->pi_refcnt == 0)                                          \
6850aadb33SDmitri Tikhonov        lsquic_mm_put_packet_in(mm, p);                                 \
6950aadb33SDmitri Tikhonov} while (0)
7050aadb33SDmitri Tikhonov
7150aadb33SDmitri Tikhonovstruct lsquic_packet_out *
7250aadb33SDmitri Tikhonovlsquic_mm_get_packet_out (struct lsquic_mm *, struct malo *,
7350aadb33SDmitri Tikhonov                          unsigned short size);
7450aadb33SDmitri Tikhonov
7550aadb33SDmitri Tikhonovvoid
7650aadb33SDmitri Tikhonovlsquic_mm_put_packet_out (struct lsquic_mm *, struct lsquic_packet_out *);
7750aadb33SDmitri Tikhonov
7850aadb33SDmitri Tikhonovvoid *
795392f7a3SLiteSpeed Techlsquic_mm_get_packet_in_buf (struct lsquic_mm *, size_t);
8050aadb33SDmitri Tikhonov
8150aadb33SDmitri Tikhonovvoid
825392f7a3SLiteSpeed Techlsquic_mm_put_packet_in_buf (struct lsquic_mm *, void *, size_t);
8350aadb33SDmitri Tikhonov
8450aadb33SDmitri Tikhonovvoid *
8550aadb33SDmitri Tikhonovlsquic_mm_get_4k (struct lsquic_mm *);
8650aadb33SDmitri Tikhonov
8750aadb33SDmitri Tikhonovvoid
8850aadb33SDmitri Tikhonovlsquic_mm_put_4k (struct lsquic_mm *, void *);
8950aadb33SDmitri Tikhonov
9050aadb33SDmitri Tikhonovvoid *
9150aadb33SDmitri Tikhonovlsquic_mm_get_16k (struct lsquic_mm *);
9250aadb33SDmitri Tikhonov
9350aadb33SDmitri Tikhonovvoid
9450aadb33SDmitri Tikhonovlsquic_mm_put_16k (struct lsquic_mm *, void *);
9550aadb33SDmitri Tikhonov
96c51ce338SDmitri Tikhonovsize_t
97c51ce338SDmitri Tikhonovlsquic_mm_mem_used (const struct lsquic_mm *mm);
98c51ce338SDmitri Tikhonov
9950aadb33SDmitri Tikhonov#endif
100