Page MenuHomeFreeBSD

mbuf: provide new type for mbuf manipulation - mbuf chain
ClosedPublic

Authored by glebius on Feb 29 2024, 7:02 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 25, 9:44 AM
Unknown Object (File)
Sun, Nov 24, 2:12 PM
Unknown Object (File)
Sat, Nov 23, 9:10 PM
Unknown Object (File)
Fri, Nov 22, 11:19 PM
Unknown Object (File)
Thu, Nov 21, 5:48 AM
Unknown Object (File)
Wed, Nov 20, 9:05 AM
Unknown Object (File)
Wed, Nov 20, 6:16 AM
Unknown Object (File)
Tue, Nov 5, 10:50 AM
Subscribers

Details

Summary

It tracks both the first mbuf and last mbuf, making it handy to use inside
functions that are interested in both. It also tracks length of data and
memory usage. It can be allocated on stack and passed to an mbuf
allocation or another mbuf manipulation function. It can be embedded into
some kernel facility internal structure representing most simple data
buffer. It uses modern queue(3) based linkage, but is also compatible with
old style m_next linkage. Transitioning older code to new type can be done
gradually - a code that doesn't understand the chain yet, can be supplied
with STAILQ_FIRST(&mc.mc_q). So you can have a mix of old style and new
style code in one function as a temporary solution.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 56342
Build 53230: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Feb 29 2024, 9:29 AM
markj added inline comments.
sys/sys/mbuf.h
1698

I know this is painful to change at this point, but I don't like the mc_ prefix. It seems too terse. mchain_ is only four characters longer, and is consistent with mbufq_.

1730

Assert that the chain is empty?

sys/sys/mbuf.h
1698

I was thinking of mc_foo() functions to be substitute for m_foo() functions in many places, with local variable named mc instead if two variables named m and tail, seeing mchain as an alternative to mbuf itself, rather than to mbufq. Also, to be fully consistent with mbufq the prefix should be mbufc_.

Let me work on other things you noticed and let's come back to that later.

sys/sys/mbuf.h
1730

Why? The supposed usage of this KPI is that mc has just been allocated on stack. A prologue of a function that makes use of mchain, but was called by old code:

foo(struct mbuf *m)
{
      struct mchain mc;

      mc_init_m(&mc, m);
markj added inline comments.
sys/sys/mbuf.h
1698

Ok. I think if the mbuf_* KPIs were added today, they'd be more likely to have an mbuf_ prefix rather than m_. Though, now I also see some mb_ functions (e.g., mb_dupcl()) and I wonder why the prefix is different. Anyway, I will not push further on the name.

1730

I see now, ok.

Provide mc_first(), mc_last(), mc_empty(), mc_freem().

This revision now requires review to proceed.Mar 18 2024, 6:11 PM
This revision is now accepted and ready to land.Mar 19 2024, 5:04 AM