diff --git a/conf/conf.c b/conf/conf.c index a2837886..9978ef23 100644 --- a/conf/conf.c +++ b/conf/conf.c @@ -89,7 +89,7 @@ struct config * config_alloc(const char *name) { pool *p = rp_new(&root_pool, "Config"); - linpool *l = lp_new(p, 4080); + linpool *l = lp_new_default(p); struct config *c = lp_allocz(l, sizeof(struct config)); /* Duplication of name string in local linear pool */ diff --git a/filter/filter_test.c b/filter/filter_test.c index 82efae0b..be7fd521 100644 --- a/filter/filter_test.c +++ b/filter/filter_test.c @@ -43,7 +43,7 @@ run_function(const void *parsed_fn_def) /* XXX: const -> non-const */ struct f_inst *f = (struct f_inst *) parsed_fn_def; - linpool *tmp = lp_new(&root_pool, 4096); + linpool *tmp = lp_new_default(&root_pool); struct f_val res = f_eval(f, tmp); rfree(tmp); diff --git a/filter/tree_test.c b/filter/tree_test.c index e224a559..5b22a9fe 100644 --- a/filter/tree_test.c +++ b/filter/tree_test.c @@ -20,7 +20,7 @@ start_conf_env(void) bt_bird_init(); pool *p = rp_new(&root_pool, "helper_pool"); - linpool *l = lp_new(p, 4080); + linpool *l = lp_new_default(p); cfg_mem = l; } diff --git a/lib/flowspec_test.c b/lib/flowspec_test.c index 36336104..69bc279d 100644 --- a/lib/flowspec_test.c +++ b/lib/flowspec_test.c @@ -401,7 +401,7 @@ t_builder4(void) resource_init(); struct flow_builder *fb = flow_builder_init(&root_pool); - linpool *lp = lp_new(&root_pool, 4096); + linpool *lp = lp_new_default(&root_pool); /* Expectation */ @@ -482,7 +482,7 @@ t_builder6(void) net_addr_ip6 ip; resource_init(); - linpool *lp = lp_new(&root_pool, 4096); + linpool *lp = lp_new_default(&root_pool); struct flow_builder *fb = flow_builder_init(&root_pool); fb->ipv6 = 1; diff --git a/lib/mempool.c b/lib/mempool.c index a8281041..3cf9c2d3 100644 --- a/lib/mempool.c +++ b/lib/mempool.c @@ -32,6 +32,8 @@ struct lp_chunk { byte data[0]; }; +const int lp_chunk_size = sizeof(struct lp_chunk); + struct linpool { resource r; byte *ptr, *end; diff --git a/lib/resource.h b/lib/resource.h index 1a0568b4..761c6adc 100644 --- a/lib/resource.h +++ b/lib/resource.h @@ -65,6 +65,11 @@ void *lp_allocu(linpool *, unsigned size); /* Unaligned */ void *lp_allocz(linpool *, unsigned size); /* With clear */ void lp_flush(linpool *); /* Free everything, but leave linpool */ +extern const int lp_chunk_size; +#define LP_GAS 1024 +#define LP_GOOD_SIZE(x) (((x + LP_GAS - 1) & (~(LP_GAS - 1))) - lp_chunk_size) +#define lp_new_default(p) lp_new(p, LP_GOOD_SIZE(LP_GAS*4)) + /* Slabs */ typedef struct slab slab; diff --git a/nest/a-path_test.c b/nest/a-path_test.c index fbf0f892..5e122396 100644 --- a/nest/a-path_test.c +++ b/nest/a-path_test.c @@ -32,7 +32,7 @@ t_as_path_match(void) struct adata *as_path = &empty_as_path; u32 first_prepended, last_prepended; first_prepended = last_prepended = 0; - struct linpool *lp = lp_new(&root_pool, 0); + struct linpool *lp = lp_new_default(&root_pool); struct f_path_mask mask[AS_PATH_LENGTH] = {}; int i; @@ -76,7 +76,7 @@ t_path_format(void) struct adata empty_as_path = {}; struct adata *as_path = &empty_as_path; - struct linpool *lp = lp_new(&root_pool, 0); + struct linpool *lp = lp_new_default(&root_pool); uint i; for (i = 4294967285; i <= 4294967294; i++) @@ -122,7 +122,7 @@ t_path_include(void) struct adata empty_as_path = {}; struct adata *as_path = &empty_as_path; - struct linpool *lp = lp_new(&root_pool, 0); + struct linpool *lp = lp_new_default(&root_pool); u32 as_nums[AS_PATH_LENGTH] = {}; int i; @@ -167,7 +167,7 @@ t_as_path_converting(void) struct adata empty_as_path = {}; struct adata *as_path = &empty_as_path; - struct linpool *lp = lp_new(&root_pool, 0); + struct linpool *lp = lp_new_default(&root_pool); #define AS_PATH_LENGTH_FOR_CONVERTING_TEST 10 int i; diff --git a/nest/a-set_test.c b/nest/a-set_test.c index f4588d65..a5081f9f 100644 --- a/nest/a-set_test.c +++ b/nest/a-set_test.c @@ -38,7 +38,7 @@ generate_set_sequence(enum set_type type) { struct adata empty_as_path = {}; set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path; - lp = lp_new(&root_pool, 0); + lp = lp_new_default(&root_pool); int i; for (i = 0; i < SET_SIZE; i++) @@ -205,7 +205,7 @@ t_set_ec_format(void) struct adata empty_as_path = {}; set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path; - lp = lp_new(&root_pool, 0); + lp = lp_new_default(&root_pool); u64 i = 0; set_sequence = ec_set_add(lp, set_sequence, i); diff --git a/nest/cli.c b/nest/cli.c index bf8bf127..aceb5770 100644 --- a/nest/cli.c +++ b/nest/cli.c @@ -313,8 +313,8 @@ cli_new(void *priv) c->event->hook = cli_event; c->event->data = c; c->cont = cli_hello; - c->parser_pool = lp_new(c->pool, 4080); - c->show_pool = lp_new(c->pool, 4080); + c->parser_pool = lp_new_default(c->pool); + c->show_pool = lp_new_default(c->pool); c->rx_buf = mb_alloc(c->pool, CLI_RX_BUF_SIZE); ev_schedule(c->event); return c; diff --git a/nest/rt-table.c b/nest/rt-table.c index bed9036e..85a951b8 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -1624,7 +1624,7 @@ rt_init(void) { rta_init(); rt_table_pool = rp_new(&root_pool, "Routing tables"); - rte_update_pool = lp_new(rt_table_pool, 4080); + rte_update_pool = lp_new_default(rt_table_pool); rte_slab = sl_new(rt_table_pool, sizeof(rte)); init_list(&routing_tables); } @@ -2304,7 +2304,7 @@ rt_init_hostcache(rtable *tab) hc_alloc_table(hc, HC_DEF_ORDER); hc->slab = sl_new(rt_table_pool, sizeof(struct hostentry)); - hc->lp = lp_new(rt_table_pool, 1008); + hc->lp = lp_new(rt_table_pool, LP_GOOD_SIZE(1024)); hc->trie = f_new_trie(hc->lp, sizeof(struct f_trie_node)); tab->hostcache = hc; diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index b9a1d157..cccced57 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -185,8 +185,8 @@ bgp_open(struct bgp_proto *p) if (!bgp_linpool) { - bgp_linpool = lp_new(proto_pool, 4080); - bgp_linpool2 = lp_new(proto_pool, 4080); + bgp_linpool = lp_new_default(proto_pool); + bgp_linpool2 = lp_new_default(proto_pool); } return 0; diff --git a/proto/static/static.c b/proto/static/static.c index f74ecee0..bb1501a5 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -410,7 +410,7 @@ static_start(struct proto *P) struct static_route *r; if (!static_lp) - static_lp = lp_new(&root_pool, 1008); + static_lp = lp_new(&root_pool, LP_GOOD_SIZE(1024)); if (p->igp_table_ip4) rt_lock_table(p->igp_table_ip4); diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index 083a8d90..8f44b007 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -1906,7 +1906,7 @@ nl_open_async(void) void krt_sys_io_init(void) { - nl_linpool = lp_new(krt_pool, 4080); + nl_linpool = lp_new_default(krt_pool); HASH_INIT(nl_table_map, krt_pool, 6); } diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index a1b10cea..f0241777 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -75,7 +75,7 @@ void krt_io_init(void) { krt_pool = rp_new(&root_pool, "Kernel Syncer"); - krt_filter_lp = lp_new(krt_pool, 4080); + krt_filter_lp = lp_new_default(krt_pool); init_list(&krt_proto_list); krt_sys_io_init(); }