diff options
Diffstat (limited to 'mm/mempool.c')
-rw-r--r-- | mm/mempool.c | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/mm/mempool.c b/mm/mempool.c index 8f65464da5de..47a659dedd44 100644 --- a/mm/mempool.c +++ b/mm/mempool.c | |||
@@ -306,7 +306,7 @@ EXPORT_SYMBOL(mempool_resize); | |||
306 | * returns NULL. Note that due to preallocation, this function | 306 | * returns NULL. Note that due to preallocation, this function |
307 | * *never* fails when called from process contexts. (it might | 307 | * *never* fails when called from process contexts. (it might |
308 | * fail if called from an IRQ context.) | 308 | * fail if called from an IRQ context.) |
309 | * Note: neither __GFP_NOMEMALLOC nor __GFP_ZERO are supported. | 309 | * Note: using __GFP_ZERO is not supported. |
310 | */ | 310 | */ |
311 | void *mempool_alloc(mempool_t *pool, gfp_t gfp_mask) | 311 | void *mempool_alloc(mempool_t *pool, gfp_t gfp_mask) |
312 | { | 312 | { |
@@ -315,27 +315,16 @@ void *mempool_alloc(mempool_t *pool, gfp_t gfp_mask) | |||
315 | wait_queue_t wait; | 315 | wait_queue_t wait; |
316 | gfp_t gfp_temp; | 316 | gfp_t gfp_temp; |
317 | 317 | ||
318 | /* If oom killed, memory reserves are essential to prevent livelock */ | ||
319 | VM_WARN_ON_ONCE(gfp_mask & __GFP_NOMEMALLOC); | ||
320 | /* No element size to zero on allocation */ | ||
321 | VM_WARN_ON_ONCE(gfp_mask & __GFP_ZERO); | 318 | VM_WARN_ON_ONCE(gfp_mask & __GFP_ZERO); |
322 | |||
323 | might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM); | 319 | might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM); |
324 | 320 | ||
321 | gfp_mask |= __GFP_NOMEMALLOC; /* don't allocate emergency reserves */ | ||
325 | gfp_mask |= __GFP_NORETRY; /* don't loop in __alloc_pages */ | 322 | gfp_mask |= __GFP_NORETRY; /* don't loop in __alloc_pages */ |
326 | gfp_mask |= __GFP_NOWARN; /* failures are OK */ | 323 | gfp_mask |= __GFP_NOWARN; /* failures are OK */ |
327 | 324 | ||
328 | gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO); | 325 | gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO); |
329 | 326 | ||
330 | repeat_alloc: | 327 | repeat_alloc: |
331 | if (likely(pool->curr_nr)) { | ||
332 | /* | ||
333 | * Don't allocate from emergency reserves if there are | ||
334 | * elements available. This check is racy, but it will | ||
335 | * be rechecked each loop. | ||
336 | */ | ||
337 | gfp_temp |= __GFP_NOMEMALLOC; | ||
338 | } | ||
339 | 328 | ||
340 | element = pool->alloc(gfp_temp, pool->pool_data); | 329 | element = pool->alloc(gfp_temp, pool->pool_data); |
341 | if (likely(element != NULL)) | 330 | if (likely(element != NULL)) |
@@ -359,12 +348,11 @@ repeat_alloc: | |||
359 | * We use gfp mask w/o direct reclaim or IO for the first round. If | 348 | * We use gfp mask w/o direct reclaim or IO for the first round. If |
360 | * alloc failed with that and @pool was empty, retry immediately. | 349 | * alloc failed with that and @pool was empty, retry immediately. |
361 | */ | 350 | */ |
362 | if ((gfp_temp & ~__GFP_NOMEMALLOC) != gfp_mask) { | 351 | if (gfp_temp != gfp_mask) { |
363 | spin_unlock_irqrestore(&pool->lock, flags); | 352 | spin_unlock_irqrestore(&pool->lock, flags); |
364 | gfp_temp = gfp_mask; | 353 | gfp_temp = gfp_mask; |
365 | goto repeat_alloc; | 354 | goto repeat_alloc; |
366 | } | 355 | } |
367 | gfp_temp = gfp_mask; | ||
368 | 356 | ||
369 | /* We must not sleep if !__GFP_DIRECT_RECLAIM */ | 357 | /* We must not sleep if !__GFP_DIRECT_RECLAIM */ |
370 | if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) { | 358 | if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) { |