Linux: Never sleep in kmem_cache_alloc(..., KM_NOSLEEP) (#14926)
When a kmem cache is exhausted and needs to be expanded a new slab is allocated. KM_SLEEP callers can block and wait for the allocation, but KM_NOSLEEP callers were incorrectly allowed to block as well. Resolve this by attempting an emergency allocation as a best effort. This may fail but that's fine since any KM_NOSLEEP consumer is required to handle an allocation failure. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Adam Moss <c@yotes.com> Reviewed-by: Brian Atkinson <batkinson@lanl.gov> Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Reviewed-by: Tony Hutter <hutter2@llnl.gov>
This commit is contained in:
parent
bcd5321039
commit
93f8abeff0
|
@ -1015,9 +1015,19 @@ spl_cache_grow(spl_kmem_cache_t *skc, int flags, void **obj)
|
||||||
ASSERT0(flags & ~KM_PUBLIC_MASK);
|
ASSERT0(flags & ~KM_PUBLIC_MASK);
|
||||||
ASSERT(skc->skc_magic == SKC_MAGIC);
|
ASSERT(skc->skc_magic == SKC_MAGIC);
|
||||||
ASSERT((skc->skc_flags & KMC_SLAB) == 0);
|
ASSERT((skc->skc_flags & KMC_SLAB) == 0);
|
||||||
might_sleep();
|
|
||||||
*obj = NULL;
|
*obj = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Since we can't sleep attempt an emergency allocation to satisfy
|
||||||
|
* the request. The only alterative is to fail the allocation but
|
||||||
|
* it's preferable try. The use of KM_NOSLEEP is expected to be rare.
|
||||||
|
*/
|
||||||
|
if (flags & KM_NOSLEEP)
|
||||||
|
return (spl_emergency_alloc(skc, flags, obj));
|
||||||
|
|
||||||
|
might_sleep();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Before allocating a new slab wait for any reaping to complete and
|
* Before allocating a new slab wait for any reaping to complete and
|
||||||
* then return so the local magazine can be rechecked for new objects.
|
* then return so the local magazine can be rechecked for new objects.
|
||||||
|
|
Loading…
Reference in New Issue