Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory #216

Merged
merged 20 commits into from
Jul 22, 2020
Merged

Memory #216

merged 20 commits into from
Jul 22, 2020

Conversation

bdevierno1
Copy link
Contributor

@bdevierno1 bdevierno1 commented May 31, 2020

Related to issues #200 and #201
Removed a few memory leaks. Replaced some libc function calls with the corresponding recommended dpdk function calls. Created new function to free allocated memory upon manager termination. Added if statements to error check after every allocation.

Summary:

Run manager as per usual. To test with valgrind, this is highlighted in issue #200 Note that it may take up to 20 mins to finish. Possibly much longer than that if you compile with line numbers.

Here are DPDK's recommendations
DPDK highlights that replacing the libc functions will provide a performance benefit. In the tests that I ran, I did not see any significant changes in the packet speed. This is probably due to the function calls only being made once in the NF setup and not continuously being called in the NFs packet handler.

There are some libc allocations remaining. Noticeably in onvm config. These functions are called to parse the json config upon booting with a json. They are called before the initialization of dpdk in onvm_nflib_init() therefore using rte_malloc will not be possible nor will it have an impact on performance.

Usage:

This PR includes
Resolves issues
Breaking API changes
Internal API changes
Usability improvements
Bug fixes 👍
New functionality
New NF/onvm_mgr args
Changes to starting NFs
Dependency updates
Web stats updates

Merging notes:

  • Dependencies: None

TODO before merging :

  • PR is ready for review
    Test whether changes to onvm/onvm_nflib/onvm_nflib.c by using rte_calloc is causing possible packet rate loss.

Test Plan:

  • Ran the manager with speed tester as well by creating a NF chain.
  • Tested with the different flags the manager outlined in the readme.
  • Booted NFs from json config file.
  • Tested NFs such as firewall still ran smoothly after changes to json.h
  • Ran with cppcheck to ensure all previous errors were no longer highlighted.
  • Ran with valgrind to ensure no memory leaks.
  • DPDK Valgrind is not perfect, so went through code to look for any obvious memory leaks that can be resolved.

After: Memory definitely lost now zero.
Screen Shot 2020-05-31 at 10 50 40 AM
Before:
Screen Shot 2020-05-31 at 11 08 59 AM

Note that I dont believe valgrind is optimized very well for dpdk. Many of the existing 'errors' picked up by valgrind are caused during the Initialize the Environment Abstraction Layer (EAL) by DPDK function calls such as rte_eal_init(). I believe these can be ignored. Note that DPDK recommends using their cleanup function. However doing so caused errors in compile time: "is deprecated: Symbol is not yet part of stable ABI [-Werror=deprecated-declarations]"

Review:

@kevindweb

@onvm
Copy link

onvm commented May 31, 2020

In response to PR creation

CI Message

Your results will arrive shortly

Copy link

@onvm onvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In response to PR creation

CI Message

Run successful see results:
Test took: 5 minutes, 29 seconds
✔️ Pktgen performance check passed
❌ PR drops Speed Test performance below minimum requirement

[Results from nimbnode23]

  • Median TX pps for Pktgen: 7721721
    Performance rating - 100.28% (compared to 7700000 average)

  • Median TX pps for Speed Tester: 40347308
    Performance rating - 96.07% (compared to 42000000 average)

@bdevierno1
Copy link
Contributor Author

@onvm Test please.

@onvm
Copy link

onvm commented May 31, 2020

@onvm Test please.

CI Message

Your results will arrive shortly

Copy link

@onvm onvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onvm Test please.

CI Message

Run successful see results:
Test took: 5 minutes, 26 seconds
✔️ Pktgen performance check passed
❌ PR drops Speed Test performance below minimum requirement

[Results from nimbnode23]

  • Median TX pps for Pktgen: 7721721
    Performance rating - 100.28% (compared to 7700000 average)

  • Median TX pps for Speed Tester: 40462067
    Performance rating - 96.34% (compared to 42000000 average)

@bdevierno1
Copy link
Contributor Author

@onvm Test again please.

@onvm
Copy link

onvm commented May 31, 2020

@onvm Test again please.

CI Message

Your results will arrive shortly

onvm
onvm previously approved these changes May 31, 2020
Copy link

@onvm onvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onvm Test again please.

CI Message

Run successful see results:
Test took: 5 minutes, 27 seconds
✔️ Pktgen performance check passed
✔️ Speed Test performance check passed

[Results from nimbnode23]

  • Median TX pps for Pktgen: 7721721
    Performance rating - 100.28% (compared to 7700000 average)

  • Median TX pps for Speed Tester: 42008679
    Performance rating - 100.02% (compared to 42000000 average)

@bdevierno1
Copy link
Contributor Author

@onvm Test whether rte_calloc caused rate drop.

@onvm
Copy link

onvm commented May 31, 2020

@onvm Test whether rte_calloc caused rate drop.

CI Message

Your results will arrive shortly

Copy link

@onvm onvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onvm Test whether rte_calloc caused rate drop.

CI Message

Run successful see results:
Test took: 5 minutes, 25 seconds
✔️ Pktgen performance check passed
❌ PR drops Speed Test performance below minimum requirement

[Results from nimbnode23]

  • Median TX pps for Pktgen: 7721721
    Performance rating - 100.28% (compared to 7700000 average)

  • Median TX pps for Speed Tester: 40410498
    Performance rating - 96.22% (compared to 42000000 average)

@bdevierno1
Copy link
Contributor Author

@onvm Test with first solution without rte_calloc please.

@onvm
Copy link

onvm commented May 31, 2020

@onvm Test with first solution without rte_calloc please.

CI Message

Your results will arrive shortly

onvm
onvm previously approved these changes May 31, 2020
Copy link

@onvm onvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onvm Test with first solution without rte_calloc please.

CI Message

Run successful see results:
Test took: 5 minutes, 28 seconds
✔️ Pktgen performance check passed
✔️ Speed Test performance check passed

[Results from nimbnode23]

  • Median TX pps for Pktgen: 7721721
    Performance rating - 100.28% (compared to 7700000 average)

  • Median TX pps for Speed Tester: 41983113
    Performance rating - 99.96% (compared to 42000000 average)

@kevindweb
Copy link
Contributor

@bdevierno1 This is awesome! What did CI not like about your first commit? I haven't seen it that slow in a while. Also sorry I didn't see this before, but I don't think we should be changing lib/cJSON.c as we don't write anything in there. Every few months/to a year we pull from a different repository for that code and probably don't want to change memcpy->rte_memcpy as a result.

@bdevierno1
Copy link
Contributor Author

@bdevierno1 This is awesome! What did CI not like about your first commit? I haven't seen it that slow in a while. Also sorry I didn't see this before, but I don't think we should be changing lib/cJSON.c as we don't write anything in there. Every few months/to a year we pull from a different repository for that code and probably don't want to change memcpy->rte_memcpy as a result.

Cool that's fine. It took a few tries to figure out but it really does not like rte_calloc in main.c I'm going to test if there is any impact on performance when I call the function in other areas.

@bdevierno1
Copy link
Contributor Author

@onvm Test whether removing rte_calloc on libc as well impacts performance.

@onvm
Copy link

onvm commented May 31, 2020

@onvm Test whether removing rte_calloc on libc as well impacts performance.

CI Message

Your results will arrive shortly

onvm
onvm previously approved these changes May 31, 2020
Copy link

@onvm onvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onvm Test whether removing rte_calloc on libc as well impacts performance.

CI Message

Run successful see results:
Test took: 5 minutes, 25 seconds
✔️ Pktgen performance check passed
✔️ Speed Test performance check passed

[Results from nimbnode23]

  • Median TX pps for Pktgen: 7721721
    Performance rating - 100.28% (compared to 7700000 average)

  • Median TX pps for Speed Tester: 42220573
    Performance rating - 100.53% (compared to 42000000 average)

@onvm
Copy link

onvm commented Jun 9, 2020

@onvm Try again please.

CI Message

Your results will arrive shortly

@onvm
Copy link

onvm commented Jun 9, 2020

@onvm Try again please.

CI Message

Error: ERROR: Failed to post results to GitHub

@bdevierno1
Copy link
Contributor Author

@onvm Please post results.

@onvm
Copy link

onvm commented Jun 9, 2020

@onvm Please post results.

CI Message

Your results will arrive shortly

@onvm
Copy link

onvm commented Jun 9, 2020

@onvm Please post results.

CI Message

Error: ERROR: Failed to post results to GitHub

@bdevierno1
Copy link
Contributor Author

@onvm

@onvm
Copy link

onvm commented Jun 9, 2020

@onvm

CI Message

Your results will arrive shortly

onvm
onvm previously approved these changes Jun 9, 2020
Copy link

@onvm onvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onvm

CI Message

Run successful see results:
Test took: 5 minutes, 23 seconds
✔️ Pktgen performance check passed
✔️ Speed Test performance check passed

[Results from nimbnode23]

  • Median TX pps for Pktgen: 7721721
    Performance rating - 100.28% (compared to 7700000 average)

  • Median TX pps for Speed Tester: 42266681
    Performance rating - 100.63% (compared to 42000000 average)

@bdevierno1
Copy link
Contributor Author

Okay looks like using rte_zmalloc made a difference. Ready for review @catherinemeadows @dennisafa

tx_mgr[i]->nf_rx_bufs = rte_calloc(NULL, MAX_NFS, sizeof(struct packet_buf), RTE_CACHE_LINE_SIZE);
if (tx_mgr[i]->nf_rx_bufs == NULL) {
RTE_LOG(ERR, APP, "Can't allocate packet_buf struct\n");
onvm_main_free(tx_lcores,rx_lcores, tx_mgr, rx_mgr, wakeup_ctx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that calling onvm_main_free after every check may be redundant, could we maybe set a flag and move that call out of the loop so that it's called only once? We should fail on any unsuccessful allocation anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think calling onvm_main_free followed by RTE_EXIT would be best? If not I could also see using a flag or a goto label as another option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdevierno1 you probably want to just set a flag and break out of the loop. Then just log that we couldn't allocate the structs required to continue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made a change as per your suggestions. I ended up using a goto flag as using a break would exit the for loop. If I used a break in the first loop it will still enter the next loop.

@kevindweb
Copy link
Contributor

Can someone explain the difference between zmalloc and calloc? The dpdk doc entries looked quite similar so idk why zmalloc wouldn’t cause the problems calloc did

@dennisafa
Copy link
Member

Can someone explain the difference between zmalloc and calloc? The dpdk doc entries looked quite similar so idk why zmalloc wouldn’t cause the problems calloc did

They're equivalent, but rte_calloc allows you to specify a num_items to allocate variable while rte_zmalloc does not. I don't think they should cause performance fluctuations either, but we've been having those with speed tester lately

onvm/onvm_mgr/main.c Outdated Show resolved Hide resolved
onvm/onvm_mgr/main.c Show resolved Hide resolved
onvm/onvm_mgr/main.c Show resolved Hide resolved
Copy link
Member

@dennisafa dennisafa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. We can also add a doc that maybe guides devs on using DPDK correctly in the system. Maybe in our wiki
Also I don't think that this has dependencies on the other DPDK pr (refactoring to the new version) but we should double check

@twood02 twood02 added the ready-for-gatekeeper 🚪 PRs that have been approved and are ready for a final review/merge label Jul 22, 2020
@twood02
Copy link
Member

twood02 commented Jul 22, 2020

@catherinemeadows will mark this for approval since she reviewed it previously

This was linked to issues Jul 22, 2020
@dennisafa dennisafa merged commit c2b92b5 into sdnfv:develop Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🚀 ready-for-gatekeeper 🚪 PRs that have been approved and are ready for a final review/merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replacing libc functions with DPDK functions Memory Leaks
6 participants