Skip to content

Commit

Permalink
Memory alloc and free statistics
Browse files Browse the repository at this point in the history
It will be useful to have statistics that track the memory allocated and
freed in vRouter, specifically to debug memory leak issues. vRouter will
track alloc and free statistics per object and export that information
to applications.

Change-Id: I7ca347eb76277cf1b581c9497dda76703be2be4e
Closes-BUG: #1470798
  • Loading branch information
anandhk-juniper committed Jul 20, 2015
1 parent 8ee98bf commit cb0fe90
Show file tree
Hide file tree
Showing 29 changed files with 979 additions and 207 deletions.
4 changes: 2 additions & 2 deletions dp-core/vr_bridge.c
Expand Up @@ -297,7 +297,7 @@ bridge_entry_make_req(struct vr_route_req *resp, struct vr_bridge_entry *ent)
{
memset(resp, 0, sizeof(struct vr_route_req));
resp->rtr_req.rtr_mac_size = VR_ETHER_ALEN;
resp->rtr_req.rtr_mac = vr_zalloc(VR_ETHER_ALEN);
resp->rtr_req.rtr_mac = vr_zalloc(VR_ETHER_ALEN, VR_ROUTE_REQ_MAC_OBJECT);
if (!resp->rtr_req.rtr_mac)
return -ENOMEM;
VR_MAC_COPY(resp->rtr_req.rtr_mac, ent->be_key.be_mac);
Expand All @@ -316,7 +316,7 @@ static void
bridge_entry_req_destroy(struct vr_route_req *resp)
{
if (resp->rtr_req.rtr_mac)
vr_free(resp->rtr_req.rtr_mac);
vr_free(resp->rtr_req.rtr_mac, VR_ROUTE_REQ_MAC_OBJECT);
}

static int
Expand Down
6 changes: 3 additions & 3 deletions dp-core/vr_btable.c
Expand Up @@ -82,7 +82,7 @@ vr_btable_free(struct vr_btable *table)
}
}

vr_free(table);
vr_free(table, VR_BTABLE_OBJECT);

return;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ vr_btable_alloc(unsigned int num_entries, unsigned int entry_size)
alloc_size = sizeof(*table) + (total_parts * (sizeof(void *))) +
(total_parts * sizeof(struct vr_btable_partition));

table = vr_zalloc(alloc_size);
table = vr_zalloc(alloc_size, VR_BTABLE_OBJECT);
if (!table)
return NULL;

Expand Down Expand Up @@ -186,7 +186,7 @@ vr_btable_attach(struct iovec *iov, unsigned int iov_len,
alloc_size += (sizeof(struct vr_btable_partition) * iov_len);


table = (struct vr_btable *)vr_zalloc(alloc_size);
table = (struct vr_btable *)vr_zalloc(alloc_size, VR_BTABLE_OBJECT);
if (!table)
return NULL;

Expand Down
45 changes: 25 additions & 20 deletions dp-core/vr_flow.c
Expand Up @@ -312,7 +312,7 @@ vr_flow_queue_free(struct vrouter *router, void *arg)
vr_flow_set_forwarding_md(router, fe, vfq->vfq_index, &fmd);
vr_flush_flow_queue(router, fe, &fmd, vfq);
}
vr_free(vfq);
vr_free(vfq, VR_FLOW_QUEUE_OBJECT);
return;
}

Expand All @@ -322,7 +322,7 @@ vr_flow_queue_free_defer(struct vr_flow_md *flmd, struct vr_flow_queue *vfq)
struct vr_defer_data *vdd = flmd->flmd_defer_data;

if (!vdd) {
vr_free(vfq);
vr_free(vfq, VR_FLOW_QUEUE_OBJECT);
return;
}

Expand Down Expand Up @@ -377,7 +377,8 @@ vr_find_free_entry(struct vrouter *router, struct vr_flow *key, uint8_t type,
if (fe) {
*fe_index += index;
if (need_hold) {
fe->fe_hold_list = vr_zalloc(sizeof(struct vr_flow_queue));
fe->fe_hold_list = vr_zalloc(sizeof(struct vr_flow_queue),
VR_FLOW_QUEUE_OBJECT);
if (!fe->fe_hold_list) {
vr_reset_flow_entry(router, fe, *fe_index);
fe = NULL;
Expand Down Expand Up @@ -1126,7 +1127,7 @@ vr_flow_flush(void *arg)
}

exit_flush:
vr_free(flmd);
vr_free(flmd, VR_FLOW_METADATA_OBJECT);

return;
}
Expand Down Expand Up @@ -1292,7 +1293,8 @@ vr_flow_schedule_transition(struct vrouter *router, vr_flow_req *req,
struct vr_flow_md *flmd;
struct vr_defer_data *defer = NULL;

flmd = (struct vr_flow_md *)vr_malloc(sizeof(*flmd));
flmd = (struct vr_flow_md *)vr_malloc(sizeof(*flmd),
VR_FLOW_METADATA_OBJECT);
if (!flmd)
return -ENOMEM;

Expand All @@ -1302,7 +1304,7 @@ vr_flow_schedule_transition(struct vrouter *router, vr_flow_req *req,
if (fe->fe_hold_list) {
defer = vr_get_defer_data(sizeof(*defer));
if (!defer) {
vr_free(flmd);
vr_free(flmd, VR_FLOW_METADATA_OBJECT);
return -ENOMEM;
}
}
Expand Down Expand Up @@ -1409,7 +1411,8 @@ vr_flow_set(struct vrouter *router, vr_flow_req *req)
if ((req->fr_action == VR_FLOW_ACTION_HOLD) &&
(fe->fe_action != req->fr_action)) {
if (!fe->fe_hold_list) {
fe->fe_hold_list = vr_zalloc(sizeof(struct vr_flow_queue));
fe->fe_hold_list = vr_zalloc(sizeof(struct vr_flow_queue),
VR_FLOW_QUEUE_OBJECT);
if (!fe->fe_hold_list)
return -ENOMEM;
}
Expand Down Expand Up @@ -1479,17 +1482,17 @@ vr_flow_req_destroy(vr_flow_req *req)
return;

if (req->fr_file_path) {
vr_free(req->fr_file_path);
vr_free(req->fr_file_path, VR_FLOW_REQ_PATH_OBJECT);
req->fr_file_path = NULL;
}

if (req->fr_hold_stat && req->fr_hold_stat_size) {
vr_free(req->fr_hold_stat);
vr_free(req->fr_hold_stat, VR_FLOW_HOLD_STAT_OBJECT);
req->fr_hold_stat = NULL;
req->fr_hold_stat_size = 0;
}

vr_free(req);
vr_free(req, VR_FLOW_REQ_OBJECT);

return;
}
Expand All @@ -1499,7 +1502,7 @@ vr_flow_req_get(vr_flow_req *ref_req)
{
unsigned int hold_stat_size;
unsigned int num_cpus = vr_num_cpus;
vr_flow_req *req = vr_zalloc(sizeof(*req));
vr_flow_req *req = vr_zalloc(sizeof(*req), VR_FLOW_REQ_OBJECT);

if (!req)
return NULL;
Expand All @@ -1512,9 +1515,10 @@ vr_flow_req_get(vr_flow_req *ref_req)
}

if (vr_flow_path) {
req->fr_file_path = vr_zalloc(VR_UNIX_PATH_MAX);
req->fr_file_path = vr_zalloc(VR_UNIX_PATH_MAX,
VR_FLOW_REQ_PATH_OBJECT);
if (!req->fr_file_path) {
vr_free(req);
vr_free(req, VR_FLOW_REQ_OBJECT);
return NULL;
}
}
Expand All @@ -1523,14 +1527,14 @@ vr_flow_req_get(vr_flow_req *ref_req)
num_cpus = VR_FLOW_MAX_CPUS;

hold_stat_size = num_cpus * sizeof(uint32_t);
req->fr_hold_stat = vr_zalloc(hold_stat_size);
req->fr_hold_stat = vr_zalloc(hold_stat_size, VR_FLOW_HOLD_STAT_OBJECT);
if (!req->fr_hold_stat) {
if (vr_flow_path && req->fr_file_path) {
vr_free(req->fr_file_path);
vr_free(req->fr_file_path, VR_FLOW_REQ_PATH_OBJECT);
req->fr_file_path = NULL;
}

vr_free(req);
vr_free(req, VR_FLOW_REQ_OBJECT);
return NULL;
}
req->fr_hold_stat_size = num_cpus;
Expand Down Expand Up @@ -1613,7 +1617,7 @@ vr_flow_table_info_destroy(struct vrouter *router)
if (!router->vr_flow_table_info)
return;

vr_free(router->vr_flow_table_info);
vr_free(router->vr_flow_table_info, VR_FLOW_TABLE_INFO_OBJECT);
router->vr_flow_table_info = NULL;
router->vr_flow_table_info_size = 0;

Expand All @@ -1640,7 +1644,8 @@ vr_flow_table_info_init(struct vrouter *router)
return 0;

size = sizeof(struct vr_flow_table_info) + sizeof(uint32_t) * vr_num_cpus;
infop = (struct vr_flow_table_info *)vr_zalloc(size);
infop = (struct vr_flow_table_info *)vr_zalloc(size,
VR_FLOW_TABLE_INFO_OBJECT);
if (!infop)
return vr_module_error(-ENOMEM, __FUNCTION__, __LINE__, size);

Expand Down Expand Up @@ -1758,7 +1763,7 @@ static void
vr_link_local_ports_exit(struct vrouter *router)
{
if (router->vr_link_local_ports) {
vr_free(router->vr_link_local_ports);
vr_free(router->vr_link_local_ports, VR_FLOW_LINK_LOCAL_OBJECT);
router->vr_link_local_ports = NULL;
router->vr_link_local_ports_size = 0;
}
Expand All @@ -1779,7 +1784,7 @@ vr_link_local_ports_init(struct vrouter *router)
/* Bits to Bytes */
bytes /= 8;

router->vr_link_local_ports = vr_zalloc(bytes);
router->vr_link_local_ports = vr_zalloc(bytes, VR_FLOW_LINK_LOCAL_OBJECT);
if (!router->vr_link_local_ports)
return -1;
router->vr_link_local_ports_size = bytes;
Expand Down
32 changes: 17 additions & 15 deletions dp-core/vr_fragment.c
Expand Up @@ -151,7 +151,7 @@ vr_fragment_queue_element_free(struct vr_fragment_queue_element *vfqe,
vr_pfree(vfqe->fqe_pnode.pl_packet, drop_reason);
}

vr_free(vfqe);
vr_free(vfqe, VR_FRAGMENT_QUEUE_ELEMENT_OBJECT);
return;
}

Expand All @@ -165,7 +165,7 @@ fragment_free_frag(struct vr_fragment *frag)
vr_fragment_queue_element_free(fqe, VP_DROP_FRAGMENTS);
}

vr_free(frag);
vr_free(frag, VR_FRAGMENT_OBJECT);
return;
}

Expand Down Expand Up @@ -217,7 +217,7 @@ vr_assembler_table_scan_exit(void)
{
if (vr_assembler_table_scan_timer) {
vr_delete_timer(vr_assembler_table_scan_timer);
vr_free(vr_assembler_table_scan_timer);
vr_free(vr_assembler_table_scan_timer, VR_TIMER_OBJECT);
vr_assembler_table_scan_timer = NULL;
}

Expand All @@ -229,7 +229,7 @@ vr_assembler_table_scan_init(void (*scanner)(void *))
{
struct vr_timer *vtimer;

vr_assembler_table_scan_timer = vr_zalloc(sizeof(*vtimer));
vr_assembler_table_scan_timer = vr_zalloc(sizeof(*vtimer), VR_TIMER_OBJECT);
if (!vr_assembler_table_scan_timer)
return -ENOMEM;

Expand All @@ -239,7 +239,7 @@ vr_assembler_table_scan_init(void (*scanner)(void *))
vtimer->vt_msecs =
(VR_ASSEMBLER_TIMEOUT_TIME * 1000) / VR_LINUX_ASSEMBLER_BUCKETS;
if (vr_create_timer(vtimer)) {
vr_free(vtimer);
vr_free(vtimer, VR_TIMER_OBJECT);
vr_assembler_table_scan_timer = NULL;
}

Expand Down Expand Up @@ -288,7 +288,7 @@ vr_fragment_assembler(struct vr_fragment **head_p,
(list_length > VR_MAX_FRAGMENTS_PER_ASSEMBLER_QUEUE))
goto exit_assembly;

frag = vr_zalloc(sizeof(*frag));
frag = vr_zalloc(sizeof(*frag), VR_FRAGMENT_OBJECT);
if (!frag) {
ret = -ENOMEM;
goto exit_assembly;
Expand Down Expand Up @@ -398,7 +398,7 @@ vr_fragment_enqueue(struct vrouter *router,
goto fail;
}

fqe = vr_malloc(sizeof(*fqe));
fqe = vr_malloc(sizeof(*fqe), VR_FRAGMENT_QUEUE_ELEMENT_OBJECT);
if (!fqe) {
goto fail;
}
Expand Down Expand Up @@ -439,7 +439,7 @@ vr_fragment_enqueue(struct vrouter *router,

fail:
if (fqe)
vr_free(fqe);
vr_free(fqe, VR_FRAGMENT_QUEUE_ELEMENT_OBJECT);

vr_pfree(pkt, VP_DROP_FRAGMENTS);
return -1;
Expand Down Expand Up @@ -592,7 +592,7 @@ fragment_table_scanner_init(struct vrouter *router, struct vr_btable *table)

num_entries = vr_btable_entries(table);

scanner = vr_zalloc(sizeof(*scanner));
scanner = vr_zalloc(sizeof(*scanner), VR_FRAGMENT_SCANNER_OBJECT);
if (!scanner) {
vr_module_error(-ENOMEM, __FUNCTION__, __LINE__, num_entries);
return NULL;
Expand All @@ -603,7 +603,7 @@ fragment_table_scanner_init(struct vrouter *router, struct vr_btable *table)
scanner->sp_num_entries = num_entries;
scanner->sp_last_scanned_entry = -1;

vtimer = vr_malloc(sizeof(*vtimer));
vtimer = vr_malloc(sizeof(*vtimer), VR_TIMER_OBJECT);
if (!vtimer) {
vr_module_error(-ENOMEM, __FUNCTION__, __LINE__, num_entries);
goto fail_init;
Expand All @@ -622,7 +622,7 @@ fragment_table_scanner_init(struct vrouter *router, struct vr_btable *table)

fail_init:
if (scanner)
vr_free(scanner);
vr_free(scanner, VR_FRAGMENT_SCANNER_OBJECT);

return NULL;
}
Expand All @@ -632,15 +632,17 @@ vr_fragment_table_scanner_exit(struct vrouter *router)
{
if (router->vr_fragment_table_scanner) {
vr_delete_timer(router->vr_fragment_table_scanner);
vr_free(router->vr_fragment_table_scanner->vt_vr_arg);
vr_free(router->vr_fragment_table_scanner);
vr_free(router->vr_fragment_table_scanner->vt_vr_arg,
VR_FRAGMENT_SCANNER_OBJECT);
vr_free(router->vr_fragment_table_scanner, VR_TIMER_OBJECT);
router->vr_fragment_table_scanner = NULL;
}

if (router->vr_fragment_otable_scanner) {
vr_delete_timer(router->vr_fragment_otable_scanner);
vr_free(router->vr_fragment_otable_scanner->vt_vr_arg);
vr_free(router->vr_fragment_otable_scanner);
vr_free(router->vr_fragment_otable_scanner->vt_vr_arg,
VR_FRAGMENT_SCANNER_OBJECT);
vr_free(router->vr_fragment_otable_scanner, VR_TIMER_OBJECT);
router->vr_fragment_otable_scanner = NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions dp-core/vr_htable.c
Expand Up @@ -203,7 +203,7 @@ vr_htable_delete(vr_htable_t htable)
if (table->otable)
vr_btable_free(table->otable);

vr_free(table);
vr_free(table, VR_HTABLE_OBJECT);
}

vr_htable_t
Expand All @@ -222,7 +222,7 @@ vr_htable_create(unsigned int entries, unsigned int oentries,
return NULL;
}

table = vr_zalloc(sizeof(struct vr_htable));
table = vr_zalloc(sizeof(struct vr_htable), VR_HTABLE_OBJECT);
if (!table) {
vr_module_error(-ENOMEM, __FUNCTION__, __LINE__,
sizeof(struct vr_htable));
Expand Down

0 comments on commit cb0fe90

Please sign in to comment.