Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108639015
D21015.id59991.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D21015.id59991.diff
View Options
Index: share/man/man9/sbuf.9
===================================================================
--- share/man/man9/sbuf.9
+++ share/man/man9/sbuf.9
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 7, 2019
+.Dd July 21, 2019
.Dt SBUF 9
.Os
.Sh NAME
@@ -43,7 +43,7 @@
.Nm sbuf_bcpy ,
.Nm sbuf_cat ,
.Nm sbuf_copyin ,
-.Nm sbuf_cpy ,
+.Nm sbuf_cpy 21
.Nm sbuf_printf ,
.Nm sbuf_vprintf ,
.Nm sbuf_putc ,
@@ -288,6 +288,11 @@
and therefore cannot be drained without being split, an error of
.Er EDEADLK
is set.
+.It Dv SBUF_NOWAIT
+Indicates that attempts to extend the storage buffer should fail in low memory
+conditions, like
+.Xr malloc 9
+.Dv M_NOWAIT .
.El
.Pp
Note that if
Index: sys/kern/subr_sbuf.c
===================================================================
--- sys/kern/subr_sbuf.c
+++ sys/kern/subr_sbuf.c
@@ -56,11 +56,11 @@
#ifdef _KERNEL
static MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers");
-#define SBMALLOC(size) malloc(size, M_SBUF, M_WAITOK|M_ZERO)
+#define SBMALLOC(size, flags) malloc(size, M_SBUF, (flags) | M_ZERO)
#define SBFREE(buf) free(buf, M_SBUF)
#else /* _KERNEL */
#define KASSERT(e, m)
-#define SBMALLOC(size) calloc(1, size)
+#define SBMALLOC(size, flags) calloc(1, size)
#define SBFREE(buf) free(buf)
#endif /* _KERNEL */
@@ -77,6 +77,8 @@
#define SBUF_NULINCLUDED(s) ((s)->s_flags & SBUF_INCLUDENUL)
#define SBUF_ISDRAINTOEOR(s) ((s)->s_flags & SBUF_DRAINTOEOR)
#define SBUF_DODRAINTOEOR(s) (SBUF_ISSECTION(s) && SBUF_ISDRAINTOEOR(s))
+#define SBUF_MALLOCFLAG(s) \
+ (((s)->s_flags & SBUF_NOWAIT) ? M_NOWAIT : M_WAITOK)
/*
* Set / clear flags
@@ -171,7 +173,7 @@
if (!SBUF_CANEXTEND(s))
return (-1);
newsize = sbuf_extendsize(s->s_size + addlen);
- newbuf = SBMALLOC(newsize);
+ newbuf = SBMALLOC(newsize, SBUF_MALLOCFLAG(s));
if (newbuf == NULL)
return (-1);
memcpy(newbuf, s->s_buf, s->s_size);
@@ -210,7 +212,7 @@
if ((flags & SBUF_AUTOEXTEND) != 0)
s->s_size = sbuf_extendsize(s->s_size);
- s->s_buf = SBMALLOC(s->s_size);
+ s->s_buf = SBMALLOC(s->s_size, M_WAITOK);
if (s->s_buf == NULL)
return (NULL);
SBUF_SETFLAG(s, SBUF_DYNAMIC);
@@ -235,7 +237,7 @@
if (s != NULL)
return (sbuf_newbuf(s, buf, length, flags));
- s = SBMALLOC(sizeof(*s));
+ s = SBMALLOC(sizeof(*s), M_WAITOK);
if (s == NULL)
return (NULL);
if (sbuf_newbuf(s, buf, length, flags) == NULL) {
Index: sys/sys/sbuf.h
===================================================================
--- sys/sys/sbuf.h
+++ sys/sys/sbuf.h
@@ -52,6 +52,7 @@
#define SBUF_AUTOEXTEND 0x00000001 /* automatically extend buffer */
#define SBUF_INCLUDENUL 0x00000002 /* nulterm byte is counted in len */
#define SBUF_DRAINTOEOR 0x00000004 /* use section 0 as drain EOR marker */
+#define SBUF_NOWAIT 0x00000008 /* Extend with non-blocking malloc */
#define SBUF_USRFLAGMSK 0x0000ffff /* mask of flags the user may specify */
#define SBUF_DYNAMIC 0x00010000 /* s_buf must be freed */
#define SBUF_FINISHED 0x00020000 /* set by sbuf_finish() */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 28, 12:58 AM (9 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16230296
Default Alt Text
D21015.id59991.diff (2 KB)
Attached To
Mode
D21015: sbuf(9): Add NOWAIT dynamic buffer extension mode
Attached
Detach File
Event Timeline
Log In to Comment