Skip to content

Commit

Permalink
BMP: simplified update queuing and better memory performance
Browse files Browse the repository at this point in the history
This commit is quite a substantial rework of the underlying layers in
BMP TX:

- several unnecessary layers of indirection dropped, including most of
  the original BMP's buffer machinery
- all messages are now written directly into one protocol's buffer
  allocated for the whole time big enough to fit every possible message
- output blocks are allocated by pages and immediately returned when
  used, improving the overall memory footprint
- no intermediary allocation is done from the heap altogether
- there is a documented and configurable limit on the TX queue size
  • Loading branch information
marenamat authored and Ondrej Zajicek committed Dec 2, 2024
1 parent 460321c commit e6a100b
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 347 deletions.
12 changes: 12 additions & 0 deletions doc/bird.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -3808,6 +3808,15 @@ by default and have to be enabled during installation by the configure option
routes (in <ref id="bgp-import-table" name="BGP import tables">) and post-policy
routes (in regular routing tables). All BGP protocols are monitored automatically.

<sect1>Configuration (incomplete)
<label id="bmp-config">

<p><descrip>
<tag><label id="bmp-tx-buffer-limit">tx buffer limit <m/number/</tag>
How much data we are going to queue before we call the session stuck
and restart it, in megabytes. Default value: 1024 (effectively 1 gigabyte).
</descrip>

<sect1>Example
<label id="bmp-exam">

Expand All @@ -3821,6 +3830,9 @@ protocol bmp {

# Monitor accepted routes (passed import filters)
monitoring rib in post_policy;

# Allow only 64M of pending data
tx buffer limit 64;
}
</code>

Expand Down
2 changes: 1 addition & 1 deletion proto/bgp/bgp.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ int bgp_get_attr(const struct eattr *e, byte *buf, int buflen);
void bgp_get_route_info(struct rte *, byte *buf);
int bgp_total_aigp_metric_(rte *e, u64 *metric, const struct adata **ad);

byte * bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n, const struct rte *new, const struct rte_src *src);
byte * bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, byte *end, const net_addr *n, const struct rte *new, const struct rte_src *src);

#define BGP_AIGP_METRIC 1
#define BGP_AIGP_MAX U64(0xffffffffffffffff)
Expand Down
8 changes: 3 additions & 5 deletions proto/bgp/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -2482,12 +2482,10 @@ bgp_create_mp_unreach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *
#ifdef CONFIG_BMP

static byte *
bgp_create_update_bmp(struct bgp_channel *c, byte *buf, struct bgp_bucket *buck, bool update)
bgp_create_update_bmp(struct bgp_channel *c, byte *buf, byte *end, struct bgp_bucket *buck, bool update)
{
struct bgp_proto *p = (void *) c->c.proto;
byte *end = buf + (BGP_MAX_EXT_MSG_LENGTH - BGP_HEADER_LENGTH);
byte *res = NULL;
/* FIXME: must be a bit shorter */

struct lp_state tmpp;
lp_save(tmp_linpool, &tmpp);
Expand Down Expand Up @@ -2535,7 +2533,7 @@ bgp_bmp_prepare_bgp_hdr(byte *buf, const u16 msg_size, const u8 msg_type)
}

byte *
bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n,
bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, byte *end, const net_addr *n,
const struct rte *new, const struct rte_src *src)
{
// struct bgp_proto *p = (void *) c->c.proto;
Expand All @@ -2561,7 +2559,7 @@ bgp_bmp_encode_rte(struct bgp_channel *c, byte *buf, const net_addr *n,
net_copy(px->net, n);
add_tail(&b->prefixes, &px->buck_node);

byte *end = bgp_create_update_bmp(c, pkt, b, !!new);
end = bgp_create_update_bmp(c, pkt, end, b, !!new);

if (end)
bgp_bmp_prepare_bgp_hdr(buf, end - buf, PKT_UPDATE);
Expand Down
4 changes: 2 additions & 2 deletions proto/bmp/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
src := bmp.c buffer.c map.c
src := bmp.c map.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)

tests_objs := $(tests_objs) $(src-o-files)
tests_objs := $(tests_objs) $(src-o-files)
Loading

0 comments on commit e6a100b

Please sign in to comment.