From ccdbca57e06e839efdf8a2a0a9a2cbc0fbe3e060 Mon Sep 17 00:00:00 2001 From: pelikan Date: Fri, 3 Jan 2014 12:48:58 +0000 Subject: [PATCH] Switch frequently allocated structs from malloc(M_DEVBUF) to separate pools. ok henning, "looks fine" mikeb, input from guenther. --- sys/net/hfsc.c | 37 +++++++++++++++++-------------------- sys/net/pf.c | 3 ++- sys/net/pf_ioctl.c | 8 +++++++- sys/net/pfvar.h | 4 +++- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/sys/net/hfsc.c b/sys/net/hfsc.c index b838484ac28..7709310da35 100644 --- a/sys/net/hfsc.c +++ b/sys/net/hfsc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hfsc.c,v 1.5 2014/01/01 17:46:43 pelikan Exp $ */ +/* $OpenBSD: hfsc.c,v 1.6 2014/01/03 12:48:58 pelikan Exp $ */ /* * Copyright (c) 2012-2013 Henning Brauer @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -265,9 +266,8 @@ hfsc_class_create(struct hfsc_if *hif, struct hfsc_sc *rsc, if (hif->hif_classes >= HFSC_MAX_CLASSES) return (NULL); - cl = malloc(sizeof(struct hfsc_class), M_DEVBUF, M_WAITOK|M_ZERO); - cl->cl_q = malloc(sizeof(struct hfsc_classq), M_DEVBUF, - M_WAITOK|M_ZERO); + cl = pool_get(&hfsc_class_pl, PR_WAITOK | PR_ZERO); + cl->cl_q = pool_get(&hfsc_classq_pl, PR_WAITOK | PR_ZERO); cl->cl_actc = hfsc_actlist_alloc(); if (qlimit == 0) @@ -307,21 +307,18 @@ hfsc_class_create(struct hfsc_if *hif, struct hfsc_sc *rsc, #endif /* RED_NOTYET */ if (rsc != NULL && (rsc->m1 != 0 || rsc->m2 != 0)) { - cl->cl_rsc = malloc(sizeof(struct hfsc_internal_sc), M_DEVBUF, - M_WAITOK); + cl->cl_rsc = pool_get(&hfsc_internal_sc_pl, PR_WAITOK); hfsc_sc2isc(rsc, cl->cl_rsc); hfsc_rtsc_init(&cl->cl_deadline, cl->cl_rsc, 0, 0); hfsc_rtsc_init(&cl->cl_eligible, cl->cl_rsc, 0, 0); } if (fsc != NULL && (fsc->m1 != 0 || fsc->m2 != 0)) { - cl->cl_fsc = malloc(sizeof(struct hfsc_internal_sc), M_DEVBUF, - M_WAITOK); + cl->cl_fsc = pool_get(&hfsc_internal_sc_pl, PR_WAITOK); hfsc_sc2isc(fsc, cl->cl_fsc); hfsc_rtsc_init(&cl->cl_virtual, cl->cl_fsc, 0, 0); } if (usc != NULL && (usc->m1 != 0 || usc->m2 != 0)) { - cl->cl_usc = malloc(sizeof(struct hfsc_internal_sc), M_DEVBUF, - M_WAITOK); + cl->cl_usc = pool_get(&hfsc_internal_sc_pl, PR_WAITOK); hfsc_sc2isc(usc, cl->cl_usc); hfsc_rtsc_init(&cl->cl_ulimit, cl->cl_usc, 0, 0); } @@ -383,14 +380,14 @@ err_ret: } #endif if (cl->cl_fsc != NULL) - free(cl->cl_fsc, M_DEVBUF); + pool_put(&hfsc_internal_sc_pl, cl->cl_fsc); if (cl->cl_rsc != NULL) - free(cl->cl_rsc, M_DEVBUF); + pool_put(&hfsc_internal_sc_pl, cl->cl_rsc); if (cl->cl_usc != NULL) - free(cl->cl_usc, M_DEVBUF); + pool_put(&hfsc_internal_sc_pl, cl->cl_usc); if (cl->cl_q != NULL) - free(cl->cl_q, M_DEVBUF); - free(cl, M_DEVBUF); + pool_put(&hfsc_classq_pl, cl->cl_q); + pool_put(&hfsc_class_pl, cl); return (NULL); } @@ -447,13 +444,13 @@ hfsc_class_destroy(struct hfsc_class *cl) cl->cl_hif->hif_defaultclass = NULL; if (cl->cl_usc != NULL) - free(cl->cl_usc, M_DEVBUF); + pool_put(&hfsc_internal_sc_pl, cl->cl_usc); if (cl->cl_fsc != NULL) - free(cl->cl_fsc, M_DEVBUF); + pool_put(&hfsc_internal_sc_pl, cl->cl_fsc); if (cl->cl_rsc != NULL) - free(cl->cl_rsc, M_DEVBUF); - free(cl->cl_q, M_DEVBUF); - free(cl, M_DEVBUF); + pool_put(&hfsc_internal_sc_pl, cl->cl_rsc); + pool_put(&hfsc_classq_pl, cl->cl_q); + pool_put(&hfsc_class_pl, cl); return (0); } diff --git a/sys/net/pf.c b/sys/net/pf.c index cf66f928649..8c1b180ab81 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.862 2013/11/18 20:30:04 bluhm Exp $ */ +/* $OpenBSD: pf.c,v 1.863 2014/01/03 12:48:58 pelikan Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -144,6 +144,7 @@ union pf_headers { struct pool pf_src_tree_pl, pf_rule_pl, pf_queue_pl; struct pool pf_state_pl, pf_state_key_pl, pf_state_item_pl; struct pool pf_altq_pl, pf_rule_item_pl, pf_sn_item_pl; +struct pool hfsc_class_pl, hfsc_classq_pl, hfsc_internal_sc_pl; void pf_init_threshold(struct pf_threshold *, u_int32_t, u_int32_t); diff --git a/sys/net/pf_ioctl.c b/sys/net/pf_ioctl.c index af7dae5635c..6db18b611c6 100644 --- a/sys/net/pf_ioctl.c +++ b/sys/net/pf_ioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_ioctl.c,v 1.266 2014/01/03 12:43:09 pelikan Exp $ */ +/* $OpenBSD: pf_ioctl.c,v 1.267 2014/01/03 12:48:58 pelikan Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -179,6 +179,12 @@ pfattach(int num) &pool_allocator_nointr); pool_init(&pf_queue_pl, sizeof(struct pf_queuespec), 0, 0, 0, "pfqueuepl", NULL); + pool_init(&hfsc_class_pl, sizeof(struct hfsc_class), 0, 0, PR_WAITOK, + "hfscclass", NULL); + pool_init(&hfsc_classq_pl, sizeof(struct hfsc_classq), 0, 0, PR_WAITOK, + "hfscclassq", NULL); + pool_init(&hfsc_internal_sc_pl, sizeof(struct hfsc_internal_sc), 0, 0, + PR_WAITOK, "hfscintsc", NULL); pfr_initialize(); pfi_initialize(); pf_osfp_initialize(); diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index c3f262be0a0..78fc16db72a 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfvar.h,v 1.394 2014/01/03 12:43:09 pelikan Exp $ */ +/* $OpenBSD: pfvar.h,v 1.395 2014/01/03 12:48:58 pelikan Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1804,6 +1804,8 @@ extern struct pool pf_src_tree_pl, pf_sn_item_pl, pf_rule_pl; extern struct pool pf_state_pl, pf_state_key_pl, pf_state_item_pl, pf_altq_pl, pf_rule_item_pl, pf_queue_pl; extern struct pool pf_state_scrub_pl; +extern struct pool hfsc_class_pl, hfsc_classq_pl, + hfsc_internal_sc_pl; extern void pf_purge_thread(void *); extern void pf_purge_expired_src_nodes(int); extern void pf_purge_expired_states(u_int32_t); -- 2.20.1