*data_mode = DATA_MODE_VMALLOC;
- /*
- * __vmalloc allocates the data pages and auxiliary structures with
- * gfp_flags that were specified, but pagetables are always allocated
- * with GFP_KERNEL, no matter what was specified as gfp_mask.
- *
- * Consequently, we must set per-process flag PF_MEMALLOC_NOIO so that
- * all allocations done by this process (including pagetables) are done
- * as if GFP_NOIO was specified.
- */
- if (gfp_mask & __GFP_NORETRY) {
- unsigned noio_flag = memalloc_noio_save();
- void *ptr = __vmalloc(c->block_size, gfp_mask);
-
- memalloc_noio_restore(noio_flag);
- return ptr;
- }
-
return __vmalloc(c->block_size, gfp_mask);
}
* dm-bufio is resistant to allocation failures (it just keeps
* one buffer reserved in cases all the allocations fail).
* So set flags to not try too hard:
- * GFP_NOWAIT: don't wait; if we need to sleep we'll release our
- * mutex and wait ourselves.
- * __GFP_NORETRY: don't retry and rather return failure
* __GFP_NOMEMALLOC: don't use emergency reserves
* __GFP_NOWARN: don't print a warning in case of failure
*
*/
while (1) {
if (dm_bufio_cache_size_latch != 1) {
- b = alloc_buffer(c, GFP_NOWAIT | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
+ unsigned nowait_flag = memalloc_nowait_save();
+ b = alloc_buffer(c, GFP_KERNEL | __GFP_NOMEMALLOC | __GFP_NOWARN);
+ memalloc_nowait_restore(nowait_flag);
if (b)
return b;
}
return NULL;
if (dm_bufio_cache_size_latch != 1 && !tried_noio_alloc) {
+ unsigned noio_flag;
+
dm_bufio_unlock(c);
- b = alloc_buffer(c, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
+ noio_flag = memalloc_noio_save();
+ b = alloc_buffer(c, GFP_KERNEL | __GFP_NOMEMALLOC | __GFP_NOWARN);
+ memalloc_noio_restore(noio_flag);
dm_bufio_lock(c);
if (b)
return b;
static inline gfp_t current_gfp_context(gfp_t flags)
{
if (unlikely(current->memalloc_noio || current->memalloc_nofs ||
- current->memalloc_nocma)) {
+ current->memalloc_nocma) || current->memalloc_nowait) {
/*
- * NOIO implies both NOIO and NOFS and it is a weaker context
- * so always make sure it makes precedence
+ * Clearing DIRECT_RECLAIM means we won't get to the point
+ * of testing IO or FS, so we don't need to bother clearing
+ * them. noio implies neither IO nor FS and it is a weaker
+ * context so always make sure it takes precedence.
*/
- if (current->memalloc_noio)
+ if (current->memalloc_nowait)
+ flags &= ~__GFP_DIRECT_RECLAIM;
+ else if (current->memalloc_noio)
flags &= ~(__GFP_IO | __GFP_FS);
else if (current->memalloc_nofs)
flags &= ~__GFP_FS;