Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/uipc_socket.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/uipc_socket.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.111.2.9 retrieving revision 1.143 diff -u -p -r1.111.2.9 -r1.143 --- src/sys/kern/uipc_socket.c 2007/11/15 11:44:56 1.111.2.9 +++ src/sys/kern/uipc_socket.c 2007/09/25 14:04:07 1.143 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.111.2.9 2007/11/15 11:44:56 yamt Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.143 2007/09/25 14:04:07 ad Exp $ */ /*- * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.111.2.9 2007/11/15 11:44:56 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.143 2007/09/25 14:04:07 ad Exp $"); #include "opt_sock_counters.h" #include "opt_sosend_loan.h" @@ -251,23 +251,30 @@ sokvafree(vaddr_t sva, vsize_t len) } static void -sodoloanfree(struct vm_page **pgs, void *buf, size_t size, bool mapped) +sodoloanfree(struct vm_page **pgs, void *buf, size_t size) { - vaddr_t sva, eva; + vaddr_t va, sva, eva; vsize_t len; - int npgs; - - KASSERT(pgs != NULL); + paddr_t pa; + int i, npgs; eva = round_page((vaddr_t) buf + size); sva = trunc_page((vaddr_t) buf); len = eva - sva; npgs = len >> PAGE_SHIFT; - if (mapped) { - pmap_kremove(sva, len); - pmap_update(pmap_kernel()); + if (__predict_false(pgs == NULL)) { + pgs = alloca(npgs * sizeof(*pgs)); + + for (i = 0, va = sva; va < eva; i++, va += PAGE_SIZE) { + if (pmap_extract(pmap_kernel(), va, &pa) == false) + panic("sodoloanfree: va 0x%lx not mapped", va); + pgs[i] = PHYS_TO_VM_PAGE(pa); + } } + + pmap_kremove(sva, len); + pmap_update(pmap_kernel()); uvm_unloan(pgs, npgs, UVM_LOAN_TOPAGE); sokvafree(sva, len); } @@ -296,6 +303,7 @@ sodopendfreel() { struct mbuf *m, *next; size_t rv = 0; + int s; KASSERT(mutex_owned(&so_pendfree_lock)); @@ -306,14 +314,14 @@ sodopendfreel() for (; m != NULL; m = next) { next = m->m_next; - KASSERT((~m->m_flags & (M_EXT|M_EXT_PAGES)) == 0); - KASSERT(m->m_ext.ext_refcnt == 0); rv += m->m_ext.ext_size; - sodoloanfree(m->m_ext.ext_pgs, m->m_ext.ext_buf, - m->m_ext.ext_size, - (m->m_ext.ext_flags & M_EXT_LAZY) == 0); - pool_cache_put(mb_cache, m); + sodoloanfree((m->m_flags & M_EXT_PAGES) ? + m->m_ext.ext_pgs : NULL, m->m_ext.ext_buf, + m->m_ext.ext_size); + s = splvm(); + pool_cache_put(&mbpool_cache, m); + splx(s); } mutex_enter(&so_pendfree_lock); @@ -326,7 +334,15 @@ void soloanfree(struct mbuf *m, void *buf, size_t size, void *arg) { - KASSERT(m != NULL); + if (m == NULL) { + + /* + * called from MEXTREMOVE. + */ + + sodoloanfree(NULL, buf, size); + return; + } /* * postpone freeing mbuf. @@ -348,12 +364,8 @@ sosend_loan(struct socket *so, struct ui struct iovec *iov = uio->uio_iov; vaddr_t sva, eva; vsize_t len; - vaddr_t lva; - int npgs, error; -#if !defined(__HAVE_LAZY_MBUF) - vaddr_t va; - int i; -#endif /* !defined(__HAVE_LAZY_MBUF) */ + vaddr_t lva, va; + int npgs, i, error; if (VMSPACE_IS_KERNEL_P(uio->uio_vmspace)) return (0); @@ -382,23 +394,16 @@ sosend_loan(struct socket *so, struct ui return (0); } -#if !defined(__HAVE_LAZY_MBUF) for (i = 0, va = lva; i < npgs; i++, va += PAGE_SIZE) pmap_kenter_pa(va, VM_PAGE_TO_PHYS(m->m_ext.ext_pgs[i]), VM_PROT_READ); pmap_update(pmap_kernel()); -#endif /* !defined(__HAVE_LAZY_MBUF) */ lva += (vaddr_t) iov->iov_base & PAGE_MASK; MEXTADD(m, (void *) lva, space, M_MBUF, soloanfree, so); m->m_flags |= M_EXT_PAGES | M_EXT_ROMAP; -#if defined(__HAVE_LAZY_MBUF) - m->m_flags |= M_EXT_LAZY; - m->m_ext.ext_flags |= M_EXT_LAZY; -#endif /* defined(__HAVE_LAZY_MBUF) */ - uio->uio_resid -= space; /* uio_offset not updated, not set/used for write(2) */ uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + space; @@ -889,7 +894,7 @@ sosend(struct socket *so, struct mbuf *a if (flags & MSG_EOR) top->m_flags |= M_EOR; } else do { - if (top == NULL) { + if (top == 0) { m = m_gethdr(M_WAIT, MT_DATA); mlen = MHLEN; m->m_pkthdr.len = 0; @@ -933,13 +938,14 @@ sosend(struct socket *so, struct mbuf *a if (atomic && top == 0 && len < mlen) MH_ALIGN(m, len); } - error = uiomove(mtod(m, void *), (int)len, uio); + error = uiomove(mtod(m, void *), (int)len, + uio); have_data: resid = uio->uio_resid; m->m_len = len; *mp = m; top->m_pkthdr.len += len; - if (error != 0) + if (error) goto release; mp = &m->m_next; if (resid <= 0) { @@ -968,10 +974,10 @@ sosend(struct socket *so, struct mbuf *a splx(s); clen = 0; - control = NULL; - top = NULL; + control = 0; + top = 0; mp = ⊤ - if (error != 0) + if (error) goto release; } while (resid && space > 0); } while (resid); @@ -1018,11 +1024,11 @@ soreceive(struct socket *so, struct mbuf type = 0; orig_resid = uio->uio_resid; - if (paddr != NULL) - *paddr = NULL; - if (controlp != NULL) - *controlp = NULL; - if (flagsp != NULL) + if (paddr) + *paddr = 0; + if (controlp) + *controlp = 0; + if (flagsp) flags = *flagsp &~ MSG_EOR; else flags = 0; @@ -1040,20 +1046,20 @@ soreceive(struct socket *so, struct mbuf error = uiomove(mtod(m, void *), (int) min(uio->uio_resid, m->m_len), uio); m = m_free(m); - } while (uio->uio_resid > 0 && error == 0 && m); + } while (uio->uio_resid && error == 0 && m); bad: - if (m != NULL) + if (m) m_freem(m); - return error; + return (error); } - if (mp != NULL) + if (mp) *mp = NULL; if (so->so_state & SS_ISCONFIRMING && uio->uio_resid) (*pr->pr_usrreq)(so, PRU_RCVD, NULL, NULL, NULL, l); restart: if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) - return error; + return (error); s = splsoftnet(); m = so->so_rcv.sb_mb; @@ -1068,20 +1074,17 @@ soreceive(struct socket *so, struct mbuf * we have to do the receive in sections, and thus risk returning * a short count if a timeout or signal occurs after we start. */ - if (m == NULL || - ((flags & MSG_DONTWAIT) == 0 && - so->so_rcv.sb_cc < uio->uio_resid && - (so->so_rcv.sb_cc < so->so_rcv.sb_lowat || - ((flags & MSG_WAITALL) && - uio->uio_resid <= so->so_rcv.sb_hiwat)) && - m->m_nextpkt == NULL && - (pr->pr_flags & PR_ATOMIC) == 0)) { + if (m == 0 || (((flags & MSG_DONTWAIT) == 0 && + so->so_rcv.sb_cc < uio->uio_resid) && + (so->so_rcv.sb_cc < so->so_rcv.sb_lowat || + ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) && + m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) { #ifdef DIAGNOSTIC - if (m == NULL && so->so_rcv.sb_cc) + if (m == 0 && so->so_rcv.sb_cc) panic("receive 1"); #endif if (so->so_error) { - if (m != NULL) + if (m) goto dontblock; error = so->so_error; if ((flags & MSG_PEEK) == 0) @@ -1089,12 +1092,12 @@ soreceive(struct socket *so, struct mbuf goto release; } if (so->so_state & SS_CANTRCVMORE) { - if (m != NULL) + if (m) goto dontblock; else goto release; } - for (; m != NULL; m = m->m_next) + for (; m; m = m->m_next) if (m->m_type == MT_OOBDATA || (m->m_flags & M_EOR)) { m = so->so_rcv.sb_mb; goto dontblock; @@ -1115,8 +1118,8 @@ soreceive(struct socket *so, struct mbuf sbunlock(&so->so_rcv); error = sbwait(&so->so_rcv); splx(s); - if (error != 0) - return error; + if (error) + return (error); goto restart; } dontblock: @@ -1125,7 +1128,7 @@ soreceive(struct socket *so, struct mbuf * While we process the initial mbufs containing address and control * info, we save a copy of m->m_nextpkt into nextrecord. */ - if (l != NULL) + if (l) l->l_proc->p_stats->p_ru.ru_msgrcv++; KASSERT(m == so->so_rcv.sb_mb); SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); @@ -1144,10 +1147,10 @@ soreceive(struct socket *so, struct mbuf } else { sbfree(&so->so_rcv, m); mbuf_removed = 1; - if (paddr != NULL) { + if (paddr) { *paddr = m; so->so_rcv.sb_mb = m->m_next; - m->m_next = NULL; + m->m_next = 0; m = so->so_rcv.sb_mb; } else { MFREE(m, so->so_rcv.sb_mb); @@ -1155,15 +1158,15 @@ soreceive(struct socket *so, struct mbuf } } } - while (m != NULL && m->m_type == MT_CONTROL && error == 0) { + while (m && m->m_type == MT_CONTROL && error == 0) { if (flags & MSG_PEEK) { - if (controlp != NULL) + if (controlp) *controlp = m_copy(m, 0, m->m_len); m = m->m_next; } else { sbfree(&so->so_rcv, m); mbuf_removed = 1; - if (controlp != NULL) { + if (controlp) { struct domain *dom = pr->pr_domain; if (dom->dom_externalize && l && mtod(m, struct cmsghdr *)->cmsg_type == @@ -1171,7 +1174,7 @@ soreceive(struct socket *so, struct mbuf error = (*dom->dom_externalize)(m, l); *controlp = m; so->so_rcv.sb_mb = m->m_next; - m->m_next = NULL; + m->m_next = 0; m = so->so_rcv.sb_mb; } else { /* @@ -1185,7 +1188,7 @@ soreceive(struct socket *so, struct mbuf m = so->so_rcv.sb_mb; } } - if (controlp != NULL) { + if (controlp) { orig_resid = 0; controlp = &(*controlp)->m_next; } @@ -1197,7 +1200,7 @@ soreceive(struct socket *so, struct mbuf * the last packet on the chain (nextrecord == NULL) and we * change m->m_nextpkt. */ - if (m != NULL) { + if (m) { if ((flags & MSG_PEEK) == 0) { m->m_nextpkt = nextrecord; /* @@ -1225,7 +1228,7 @@ soreceive(struct socket *so, struct mbuf moff = 0; offset = 0; - while (m != NULL && uio->uio_resid > 0 && error == 0) { + while (m && uio->uio_resid > 0 && error == 0) { if (m->m_type == MT_OOBDATA) { if (type != MT_OOBDATA) break; @@ -1249,13 +1252,13 @@ soreceive(struct socket *so, struct mbuf * we must note any additions to the sockbuf when we * block interrupts again. */ - if (mp == NULL) { + if (mp == 0) { SBLASTRECORDCHK(&so->so_rcv, "soreceive uiomove"); SBLASTMBUFCHK(&so->so_rcv, "soreceive uiomove"); splx(s); error = uiomove(mtod(m, char *) + moff, (int)len, uio); s = splsoftnet(); - if (error != 0) { + if (error) { /* * If any part of the record has been removed * (such as the MT_SONAME mbuf, which will @@ -1309,14 +1312,16 @@ soreceive(struct socket *so, struct mbuf SBLASTRECORDCHK(&so->so_rcv, "soreceive 3"); SBLASTMBUFCHK(&so->so_rcv, "soreceive 3"); } - } else if (flags & MSG_PEEK) - moff += len; - else { - if (mp != NULL) - *mp = m_copym(m, 0, len, M_WAIT); - m->m_data += len; - m->m_len -= len; - so->so_rcv.sb_cc -= len; + } else { + if (flags & MSG_PEEK) + moff += len; + else { + if (mp) + *mp = m_copym(m, 0, len, M_WAIT); + m->m_data += len; + m->m_len -= len; + so->so_rcv.sb_cc -= len; + } } if (so->so_oobmark) { if ((flags & MSG_PEEK) == 0) { @@ -1340,7 +1345,7 @@ soreceive(struct socket *so, struct mbuf * with a short count but without error. * Keep sockbuf locked against other readers. */ - while (flags & MSG_WAITALL && m == NULL && uio->uio_resid > 0 && + while (flags & MSG_WAITALL && m == 0 && uio->uio_resid > 0 && !sosendallatonce(so) && !nextrecord) { if (so->so_error || so->so_state & SS_CANTRCVMORE) break; @@ -1361,10 +1366,10 @@ soreceive(struct socket *so, struct mbuf SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2"); SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2"); error = sbwait(&so->so_rcv); - if (error != 0) { + if (error) { sbunlock(&so->so_rcv); splx(s); - return 0; + return (0); } if ((m = so->so_rcv.sb_mb) != NULL) nextrecord = m->m_nextpkt; @@ -1377,7 +1382,7 @@ soreceive(struct socket *so, struct mbuf (void) sbdroprecord(&so->so_rcv); } if ((flags & MSG_PEEK) == 0) { - if (m == NULL) { + if (m == 0) { /* * First part is an inline SB_EMPTY_FIXUP(). Second * part makes sure sb_lastrecord is up-to-date if @@ -1403,12 +1408,12 @@ soreceive(struct socket *so, struct mbuf goto restart; } - if (flagsp != NULL) + if (flagsp) *flagsp |= flags; release: sbunlock(&so->so_rcv); splx(s); - return error; + return (error); } int @@ -1425,7 +1430,7 @@ soshutdown(struct socket *so, int how) if (how == SHUT_WR || how == SHUT_RDWR) return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, NULL, NULL, NULL, NULL); - return 0; + return (0); } void