zebra: fix Out Of Memory issue when displaying large route tables in JSON#16093
zebra: fix Out Of Memory issue when displaying large route tables in JSON#16093ton31337 merged 5 commits intoFRRouting:masterfrom
Conversation
6465567 to
6e7f73c
Compare
ton31337
left a comment
There was a problem hiding this comment.
I'm curious in what kind of setup OOM is happening? 128Mb of memory? My point is if we really need this custom crafted stuff versus reusing what the library offers?
Tested with a full-route and "show ip route json". Got a peak of 8.6g, which is not reasonable. |
|
We already do the same thing for "show bgp XX json" Line 11950 in f771251 |
|
Ah, GiB is not cool ;-) |
6e7f73c to
70058a3
Compare
|
@donaldsharp, the patch is improving a little bit the performances. It was tested with 760K routes. Before patches After patches |
|
tested this code locally and I am seeing significant savings in run time too. Let's get this in. |
|
Once CI finishes I'll get this in |
70058a3 to
f130e87
Compare
mjstapp
left a comment
There was a problem hiding this comment.
please fix your commits - we can't really have "revert", and "fix", "fix", "fix". please rebase the changes into a series of commits that's meaningful.
f130e87 to
790e52e
Compare
"fix" commits were pushed by mistake. Done |
790e52e to
718d130
Compare
…command 'show ip route vrf all json'" This reverts commit 0e2fc3d. This fix was correct but not optimal for memory consumption at scale. Signed-off-by: Louis Scalbert <[email protected]>
Add helpers to print json keys in order to prepare the next commits. Signed-off-by: Louis Scalbert <[email protected]>
0e2fc3d ("vtysh, zebra: Fix malformed json output for multiple vrfs in command 'show ip route vrf all json'") has been reverted in the previous commit. Although the fix was correct, it was consuming too muca memory when displaying large route tables. A root JSON object was storing all the JSON objects containing the route tables, each containing their respective prefixes in JSON objects. This resulted in excessive memory allocation for JSON objects, potentially leading to an out-of-memory error on the machine. To Fix the memory consumption issue for the "show ip[v6] route vrf all json" command, display the tables one by one and free the memory of each JSON object after it has been displayed. Signed-off-by: Louis Scalbert <[email protected]>
When displaying a route table in JSON, a table JSON object is storing all the prefix JSON objects containing the prefix information. This results in excessive memory allocation for JSON objects, potentially leading to an out-of-memory error on the machine with large routing tables. To Fix the memory consumption issue for the "show ip[v6] route [vrf XX] json" command, display the prefixes one by one and free the memory of each JSON object after it has been displayed. Signed-off-by: Louis Scalbert <[email protected]>
Check that "show ip route vrf XXX json" and the JSON at key "XXX" of "show ip route vrf all json" gives the same output. Signed-off-by: Louis Scalbert <[email protected]>
718d130 to
2d6dcc0
Compare
|
ci:rerun |
…oute commands in scaled setups (#1410) <!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md ** Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" or "resolves #xxxx" Please provide the following information: --> #### Why I did it Fix memory consumption with zebra during the show ipv6 route commands in scaled setups ##### Work item tracking - Microsoft ADO **(number only)**: #### How I did it Ported fix FRRouting/frr#16093 as patch #### How to verify it Run vtysh -c 'show ipv6 route json' in scaled setup and check zebra memory consumption. <!-- If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012. --> #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 - [ ] 202205 - [ ] 202211 #### Tested branch (Please provide the tested image version) <!-- - Please provide tested image version - e.g. - [x] 20201231.100 --> - [ ] <!-- image version 1 --> - [ ] <!-- image version 2 --> #### Description for the changelog <!-- Write a short (one line) summary that describes the changes in this pull request for inclusion in the changelog: --> <!-- Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU. --> #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md --> #### A picture of a cute animal (not mandatory but encouraged)
The command show ip[v6] route [vrf (all|XX)] json may cause an out-of-memory error when attempting to display large route tables.
Currently, JSON objects are created for every prefix and stored in a table JSON object. Once all the prefixes are collected, the table JSON is dumped, and all associated JSON objects are freed. Since commit 0e2fc3d, table JSON objects for each VRF are stored in a root JSON object. Similarly, the root JSON is dumped, and all related JSON objects are freed.
When the route tables are large, this process allocates a significant amount of memory for all the JSON objects containing the prefixes. In some cases, this leads to a crash of the protocol daemon due to insufficient memory on the machine.
To address this, instead of storing all the prefix JSON objects in underlying JSON objects before displaying them, modify the approach to allocate a JSON object for the first prefix, display it, and then free it. Repeat this process for each subsequent prefix object.