path: root/sys/sys/sockbuf.h
diff options
authorAlan Somers <asomers@FreeBSD.org>2014-03-13 18:42:12 +0000
committerAlan Somers <asomers@FreeBSD.org>2014-03-13 18:42:12 +0000
commitc2090e73d7c42493df79211a6851240f781d8f2c (patch)
tree13a081cb46b11967e5206f46c9ab836d127fa4ed /sys/sys/sockbuf.h
parent80cd00209b751538659f91ecdab68b843994e992 (diff)
Replace 4.4BSD Lite's unix domain socket backpressure hack with a cleaner
mechanism, based on the new SB_STOP sockbuf flag. The old hack dynamically changed the sending sockbuf's high water mark whenever adding or removing data from the receiving sockbuf. It worked for stream sockets, but it never worked for SOCK_SEQPACKET sockets because of their atomic nature. If the sockbuf was partially full, it might return EMSGSIZE instead of blocking. The new solution is based on DragonFlyBSD's fix from commit 3a6117bbe0ed6a87605c1e43e12a1438d8844380 on 2008-05-27. It adds an SB_STOP flag to sockbufs. Whenever uipc_send surpasses the socket's size limit, it sets SB_STOP on the sending sockbuf. sbspace() will then return 0 for that sockbuf, causing sosend_generic and friends to block. uipc_rcvd will likewise clear SB_STOP. There are two fringe benefits: uipc_{send,rcvd} no longer need to call chgsbsize() on every send and receive because they don't change the sockbuf's high water mark. Also, uipc_sense no longer needs to acquire the UIPC linkage lock, because it's simpler to compute the st_blksizes. There is one drawback: since sbspace() will only ever return 0 or the maximum, sosend_generic will allow the sockbuf to exceed its nominal maximum size by at most one packet of size less than the max. I don't think that's a serious problem. In fact, I'm not even positive that FreeBSD guarantees a socket will always stay within its nominal size limit. sys/sys/sockbuf.h Add the SB_STOP flag and adjust sbspace() sys/sys/unpcb.h Delete the obsolete unp_cc and unp_mbcnt fields from struct unpcb. sys/kern/uipc_usrreq.c Adjust uipc_rcvd, uipc_send, and uipc_sense to use the SB_STOP backpressure mechanism. Removing obsolete unpcb fields from db_show_unpcb. tests/sys/kern/unix_seqpacket_test.c Clear expected failures from ATF. Obtained from: DragonFly BSD PR: kern/185812 Reviewed by: silence from freebsd-net@ and rwatson@ MFC after: 3 weeks Sponsored by: Spectra Logic Corporation
Notes: svn path=/head/; revision=263116
Diffstat (limited to 'sys/sys/sockbuf.h')
1 files changed, 14 insertions, 3 deletions
diff --git a/sys/sys/sockbuf.h b/sys/sys/sockbuf.h
index 6994fd3fd60f..877b5307ee2e 100644
--- a/sys/sys/sockbuf.h
+++ b/sys/sys/sockbuf.h
@@ -52,6 +52,7 @@
#define SB_NOCOALESCE 0x200 /* don't coalesce new data into existing mbufs */
#define SB_IN_TOE 0x400 /* socket buffer is in the middle of an operation */
#define SB_AUTOSIZE 0x800 /* automatically size socket buffer */
+#define SB_STOP 0x1000 /* backpressure indicator */
#define SBS_CANTSENDMORE 0x0010 /* can't send more data to peer */
#define SBS_CANTRCVMORE 0x0020 /* can't receive more data from peer */
@@ -168,9 +169,19 @@ void sbunlock(struct sockbuf *sb);
* still be negative (cc > hiwat or mbcnt > mbmax). Should detect
* overflow and return 0. Should use "lmin" but it doesn't exist now.
-#define sbspace(sb) \
- ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
- (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
+static __inline
+sbspace(struct sockbuf *sb)
+ long bleft;
+ long mleft;
+ if (sb->sb_flags & SB_STOP)
+ return(0);
+ bleft = sb->sb_hiwat - sb->sb_cc;
+ mleft = sb->sb_mbmax - sb->sb_mbcnt;
+ return((bleft < mleft) ? bleft : mleft);
/* adjust counters in sb reflecting allocation of m */
#define sballoc(sb, m) { \