Bound the number of iterations a thread can perform inside
ktr_resize_pool(); this eliminates a potential livelock. Return ENOSPC only if we encountered an out-of-memory condition when trying to increase the pool size. Reviewed by: jhb, bde (style)
This commit is contained in:
parent
f27ec812b6
commit
a5896914f0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=122478
@ -168,7 +168,7 @@ sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS)
|
||||
error = SYSCTL_OUT(req, &oldsize, sizeof(u_int));
|
||||
if (error)
|
||||
return (error);
|
||||
if (newsize != wantsize)
|
||||
if (wantsize > oldsize && newsize < wantsize)
|
||||
return (ENOSPC);
|
||||
return (0);
|
||||
}
|
||||
@ -179,14 +179,16 @@ static u_int
|
||||
ktrace_resize_pool(u_int newsize)
|
||||
{
|
||||
struct ktr_request *req;
|
||||
int bound;
|
||||
|
||||
mtx_assert(&ktrace_mtx, MA_OWNED);
|
||||
print_message = 1;
|
||||
if (newsize == ktr_requestpool)
|
||||
return (newsize);
|
||||
if (newsize < ktr_requestpool)
|
||||
bound = newsize - ktr_requestpool;
|
||||
if (bound == 0)
|
||||
return (ktr_requestpool);
|
||||
if (bound < 0)
|
||||
/* Shrink pool down to newsize if possible. */
|
||||
while (ktr_requestpool > newsize) {
|
||||
while (bound++ < 0) {
|
||||
req = STAILQ_FIRST(&ktr_free);
|
||||
if (req == NULL)
|
||||
return (ktr_requestpool);
|
||||
@ -198,7 +200,7 @@ ktrace_resize_pool(u_int newsize)
|
||||
}
|
||||
else
|
||||
/* Grow pool up to newsize. */
|
||||
while (ktr_requestpool < newsize) {
|
||||
while (bound-- > 0) {
|
||||
mtx_unlock(&ktrace_mtx);
|
||||
req = malloc(sizeof(struct ktr_request), M_KTRACE,
|
||||
M_WAITOK);
|
||||
|
Loading…
Reference in New Issue
Block a user