* Return the number of fragments an mbuf will use. This is usually * used as a proxy for the number of scatter/gather elements needed by * a DMA engine to access an mbuf. In general mapped mbufs are * assumed to be backed by physically contiguous buffers that only * need a single fragment. Unmapped mbufs, on the other hand, can * span disjoint physical pages. */
| 1438 | * span disjoint physical pages. |
| 1439 | */ |
| 1440 | static int |
| 1441 | frags_per_mbuf(struct mbuf *m) |
| 1442 | { |
| 1443 | int frags; |
| 1444 | |
| 1445 | if ((m->m_flags & M_EXTPG) == 0) |
| 1446 | return (1); |
| 1447 | |
| 1448 | /* |
| 1449 | * The header and trailer are counted as a single fragment |
| 1450 | * each when present. |
| 1451 | * |
| 1452 | * XXX: This overestimates the number of fragments by assuming |
| 1453 | * all the backing physical pages are disjoint. |
| 1454 | */ |
| 1455 | frags = 0; |
| 1456 | if (m->m_epg_hdrlen != 0) |
| 1457 | frags++; |
| 1458 | frags += m->m_epg_npgs; |
| 1459 | if (m->m_epg_trllen != 0) |
| 1460 | frags++; |
| 1461 | |
| 1462 | return (frags); |
| 1463 | } |
| 1464 | |
| 1465 | /* |
| 1466 | * Defragment an mbuf chain, returning at most maxfrags separate |