Skip to content

Commit

Permalink
Compact m_hdr by packing the type and flags fields into one uint32_t.
Browse files Browse the repository at this point in the history
The mbuf type is an enumerator with only a handful of types in use and
thus reduced from int to 8bits allowing for 255 types to be specified.
Only 5 types have been in use for a long time.

The flags field gets the remaining 24 bits with 12 bits for global
persistent flags and 12 bits for protocol/layer specific overlays.
Some of the global flags/functionality can be moved to the csum_flags
or ext_flags bits in the future.

MT_VENDOR[1-4] and MT_EXP[1-4] types for vendor-internal and
experimental local mapping are added.

The size of m_hdr shrinks from 24/40 to 20/32bytes (32/64bit architectures).

Sponsored by:	The FreeBSD Foundation
  • Loading branch information
andreoppermann committed Aug 24, 2013
1 parent f53205f commit e7f914a
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions sys/sys/mbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,18 @@ struct mb_args {
};
#endif /* _KERNEL */

#if defined(__LP64__)
#define M_HDR_PAD 6
#else
#define M_HDR_PAD 2
#endif

/*
* Header present at the beginning of every mbuf.
* Size ILP32: 20
* LP64: 32
*/
struct m_hdr {
struct mbuf *mh_next; /* next buffer in chain */
struct mbuf *mh_nextpkt; /* next chain in queue/record */
caddr_t mh_data; /* location of data */
int mh_len; /* amount of data in this mbuf */
int mh_flags; /* flags; see below */
short mh_type; /* type of data in this mbuf */
uint8_t pad[M_HDR_PAD];/* word align */
int32_t mh_len; /* amount of data in this mbuf */
uint32_t mh_type:8, /* type of data in this mbuf */
mh_flags:24; /* flags; see below */
};

/*
Expand Down Expand Up @@ -206,7 +201,10 @@ struct mbuf {
#define m_dat M_dat.M_databuf

/*
* mbuf flags.
* mbuf flags of global significance and layer crossing.
* Those of only protocol/layer specific significance are to be mapped
* to M_PROTO[1-12] and cleared at layer handoff boundaries.
* NB: Limited to the lower 24 bits.
*/
#define M_EXT 0x00000001 /* has associated external storage */
#define M_PKTHDR 0x00000002 /* start of record */
Expand Down Expand Up @@ -430,12 +428,24 @@ struct mbuf {
#define CSUM_FRAGMENT 0x0 /* Unused */

/*
* mbuf types.
* mbuf types describing the content of the mbuf (including external storage).
*/
#define MT_NOTMBUF 0 /* USED INTERNALLY ONLY! Object is not mbuf */
#define MT_DATA 1 /* dynamic (data) allocation */
#define MT_HEADER MT_DATA /* packet header, use M_PKTHDR instead */

#define MT_VENDOR1 4 /* for vendor-internal use */
#define MT_VENDOR2 5 /* for vendor-internal use */
#define MT_VENDOR3 6 /* for vendor-internal use */
#define MT_VENDOR4 7 /* for vendor-internal use */

#define MT_SONAME 8 /* socket name */

#define MT_EXP1 9 /* for experimental use */
#define MT_EXP2 10 /* for experimental use */
#define MT_EXP3 11 /* for experimental use */
#define MT_EXP4 12 /* for experimental use */

#define MT_CONTROL 14 /* extra-data protocol message */
#define MT_OOBDATA 15 /* expedited data */
#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */
Expand Down

0 comments on commit e7f914a

Please sign in to comment.