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

zebra: reduce memory usage by streams when redistributing routes #18030

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fdumontet6WIND
Copy link
Contributor

required stream size is evaluated as a fix part and variable one. the variable one depend on the number of nexthops.

@frrbot frrbot bot added the zebra label Feb 5, 2025
@fdumontet6WIND fdumontet6WIND force-pushed the mem_alloc_stream branch 2 times, most recently from 7abd16d to eaf1718 Compare February 6, 2025 12:13
Copy link
Contributor

@mjstapp mjstapp left a comment

Choose a reason for hiding this comment

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

I'm going to repeat some of the things I said in the previous version of this.

  1. encoding zapi is really something that happens... in the zclient library, and it's not really correct to force a bunch of detailed assumptions into zebra (or any other daemon) code.
  2. consider a single, authoritative "compute_size" function, that accounts for the fixed parts of the zapi_route struct, and the embedded nexthops.

zebra/zapi_msg.c Outdated
@@ -1526,6 +1544,7 @@ static void zread_interface_add(ZAPI_HANDLER_ARGS)
struct interface *ifp;

vrf_id_t vrf_id = zvrf_id(zvrf);

Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mjstapp
Copy link
Contributor

mjstapp commented Feb 6, 2025

please fix the style errors - you can run that tool yourself, in your own sandbox, and save the CI re-runs...

@fdumontet6WIND
Copy link
Contributor Author

Dear Mark,
i don't remember any comment from you in previous version of that Pull Request
regards

@donaldsharp
Copy link
Member

Look, opening multiple versions of the same PR is really not encouraged. We would prefer you use the original PR because that one has comments on it that now we cannot reference. Now we are in a state where there are comments on both of the PR's that we need to make sure it is addressed and frankly it's not very cool to do that.

@fdumontet6WIND
Copy link
Contributor Author

this is due to a bad synchronization with my github repos. commit was erazed, and new pulled request was triggered.

sorry, this was not my intention.

@github-actions github-actions bot added size/M and removed size/S labels Feb 10, 2025
@fdumontet6WIND fdumontet6WIND force-pushed the mem_alloc_stream branch 5 times, most recently from cdbf34f to 5f14149 Compare February 11, 2025 12:07
@fdumontet6WIND
Copy link
Contributor Author

ci:rerun

@fdumontet6WIND
Copy link
Contributor Author

ci:rerun error not related to that PR

Copy link
Contributor

@mjstapp mjstapp left a comment

Choose a reason for hiding this comment

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

this is really very brittle - it's not really an improvement to have a magic number in lib/zclient.c, completely disconnected from the actual struct. I understand that you don't like the current, very conservative buffer size, but the risk in this approach outweighs any benefit, imo.

@fdumontet6WIND
Copy link
Contributor Author

Mark,
i made this PR followin OOM crashs on field!

@fdumontet6WIND
Copy link
Contributor Author

itt's not a magic number, elements taken into account are explicit-ed in code comment.
thus i will add an assert to validate the size.

@github-actions github-actions bot added the rebase PR needs rebase label Feb 16, 2025
@fdumontet6WIND
Copy link
Contributor Author

ci:rerun

required stream size is evaluated as a fix part and variable one.
the variable one depend on the number of nexthops.

Signed-off-by: Francois Dumontet <[email protected]>
@@ -619,6 +619,8 @@ int zsend_redistribute_route(int cmd, struct zserv *client, const struct route_n
return -1;
}

assert(stream_get_endp(s) <= stream_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this can happen? I don't think the stream 's' will allow itself to overrrun...

* stream_putw_at(s, 0, stream_get_endp(s));
* stream_size += 2;
*/
return 74 + (34 * api->nexthop_num);
Copy link
Contributor

Choose a reason for hiding this comment

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

these are the magic numbers I was referring to - if you want to make a change, it cannot be this change.
if you want to compute a size dynamically, try computing using:
a) the size of the entire struct
b) the number of nexthops in -use
c) the number of backup nexthops in-use
d) whether the opaque data is being included

(a) includes the max number of nexthops, and it includes the "opaque" field: try using some arithmetic to subtract from (a) to find a reasonable size. this will allow (a) to change in several ways and allow the computation to remain valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants