Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144502007
D2165.1775054523.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D2165.1775054523.diff
View Options
Index: head/sys/rpc/svc.h
===================================================================
--- head/sys/rpc/svc.h
+++ head/sys/rpc/svc.h
@@ -371,10 +371,10 @@
* amount of memory used by RPC requests which are queued
* waiting for execution.
*/
- unsigned int sp_space_low;
- unsigned int sp_space_high;
- unsigned int sp_space_used;
- unsigned int sp_space_used_highest;
+ unsigned long sp_space_low;
+ unsigned long sp_space_high;
+ unsigned long sp_space_used;
+ unsigned long sp_space_used_highest;
bool_t sp_space_throttled;
int sp_space_throttle_count;
Index: head/sys/rpc/svc.c
===================================================================
--- head/sys/rpc/svc.c
+++ head/sys/rpc/svc.c
@@ -73,7 +73,7 @@
char *);
static void svc_new_thread(SVCGROUP *grp);
static void xprt_unregister_locked(SVCXPRT *xprt);
-static void svc_change_space_used(SVCPOOL *pool, int delta);
+static void svc_change_space_used(SVCPOOL *pool, long delta);
static bool_t svc_request_space_available(SVCPOOL *pool);
/* *************** SVCXPRT related stuff **************** */
@@ -113,13 +113,14 @@
}
/*
- * Don't use more than a quarter of mbuf clusters or more than
- * 45Mb buffering requests.
+ * Don't use more than a quarter of mbuf clusters. Nota bene:
+ * nmbclusters is an int, but nmbclusters*MCLBYTES may overflow
+ * on LP64 architectures, so cast to u_long to avoid undefined
+ * behavior. (ILP32 architectures cannot have nmbclusters
+ * large enough to overflow for other reasons.)
*/
- pool->sp_space_high = nmbclusters * MCLBYTES / 4;
- if (pool->sp_space_high > 45 << 20)
- pool->sp_space_high = 45 << 20;
- pool->sp_space_low = 2 * pool->sp_space_high / 3;
+ pool->sp_space_high = (u_long)nmbclusters * MCLBYTES / 4;
+ pool->sp_space_low = (pool->sp_space_high / 3) * 2;
sysctl_ctx_init(&pool->sp_sysctl);
if (sysctl_base) {
@@ -139,24 +140,24 @@
"groups", CTLFLAG_RD, &pool->sp_groupcount, 0,
"Number of thread groups");
- SYSCTL_ADD_UINT(&pool->sp_sysctl, sysctl_base, OID_AUTO,
+ SYSCTL_ADD_ULONG(&pool->sp_sysctl, sysctl_base, OID_AUTO,
"request_space_used", CTLFLAG_RD,
- &pool->sp_space_used, 0,
+ &pool->sp_space_used,
"Space in parsed but not handled requests.");
- SYSCTL_ADD_UINT(&pool->sp_sysctl, sysctl_base, OID_AUTO,
+ SYSCTL_ADD_ULONG(&pool->sp_sysctl, sysctl_base, OID_AUTO,
"request_space_used_highest", CTLFLAG_RD,
- &pool->sp_space_used_highest, 0,
+ &pool->sp_space_used_highest,
"Highest space used since reboot.");
- SYSCTL_ADD_UINT(&pool->sp_sysctl, sysctl_base, OID_AUTO,
+ SYSCTL_ADD_ULONG(&pool->sp_sysctl, sysctl_base, OID_AUTO,
"request_space_high", CTLFLAG_RW,
- &pool->sp_space_high, 0,
+ &pool->sp_space_high,
"Maximum space in parsed but not handled requests.");
- SYSCTL_ADD_UINT(&pool->sp_sysctl, sysctl_base, OID_AUTO,
+ SYSCTL_ADD_ULONG(&pool->sp_sysctl, sysctl_base, OID_AUTO,
"request_space_low", CTLFLAG_RW,
- &pool->sp_space_low, 0,
+ &pool->sp_space_low,
"Low water mark for request space.");
SYSCTL_ADD_INT(&pool->sp_sysctl, sysctl_base, OID_AUTO,
@@ -1064,11 +1065,11 @@
}
static void
-svc_change_space_used(SVCPOOL *pool, int delta)
+svc_change_space_used(SVCPOOL *pool, long delta)
{
- unsigned int value;
+ unsigned long value;
- value = atomic_fetchadd_int(&pool->sp_space_used, delta) + delta;
+ value = atomic_fetchadd_long(&pool->sp_space_used, delta) + delta;
if (delta > 0) {
if (value >= pool->sp_space_high && !pool->sp_space_throttled) {
pool->sp_space_throttled = TRUE;
@@ -1102,7 +1103,7 @@
enum xprt_stat stat;
struct svc_req *rqstp;
struct proc *p;
- size_t sz;
+ long sz;
int error;
st = mem_alloc(sizeof(*st));
@@ -1259,17 +1260,16 @@
/*
* Execute what we have queued.
*/
- sz = 0;
mtx_lock(&st->st_lock);
while ((rqstp = STAILQ_FIRST(&st->st_reqs)) != NULL) {
STAILQ_REMOVE_HEAD(&st->st_reqs, rq_link);
mtx_unlock(&st->st_lock);
- sz += rqstp->rq_size;
+ sz = (long)rqstp->rq_size;
svc_executereq(rqstp);
+ svc_change_space_used(pool, -sz);
mtx_lock(&st->st_lock);
}
mtx_unlock(&st->st_lock);
- svc_change_space_used(pool, -sz);
mtx_lock(&grp->sg_lock);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 1, 2:42 PM (12 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28238903
Default Alt Text
D2165.1775054523.diff (4 KB)
Attached To
Mode
D2165: Remove antique hard-coded limit and integer overflow bugs in kernel RPC request throttling code
Attached
Detach File
Event Timeline
Log In to Comment