linux-stable/fs/f2fs
NeilBrown 4034247a0d mm: introduce memalloc_retry_wait()
Various places in the kernel - largely in filesystems - respond to a
memory allocation failure by looping around and re-trying.  Some of
these cannot conveniently use __GFP_NOFAIL, for reasons such as:

 - a GFP_ATOMIC allocation, which __GFP_NOFAIL doesn't work on
 - a need to check for the process being signalled between failures
 - the possibility that other recovery actions could be performed
 - the allocation is quite deep in support code, and passing down an
   extra flag to say if __GFP_NOFAIL is wanted would be clumsy.

Many of these currently use congestion_wait() which (in almost all
cases) simply waits the given timeout - congestion isn't tracked for
most devices.

It isn't clear what the best delay is for loops, but it is clear that
the various filesystems shouldn't be responsible for choosing a timeout.

This patch introduces memalloc_retry_wait() with takes on that
responsibility.  Code that wants to retry a memory allocation can call
this function passing the GFP flags that were used.  It will wait
however is appropriate.

For now, it only considers __GFP_NORETRY and whatever
gfpflags_allow_blocking() tests.  If blocking is allowed without
__GFP_NORETRY, then alloc_page either made some reclaim progress, or
waited for a while, before failing.  So there is no need for much
further waiting.  memalloc_retry_wait() will wait until the current
jiffie ends.  If this condition is not met, then alloc_page() won't have
waited much if at all.  In that case memalloc_retry_wait() waits about
200ms.  This is the delay that most current loops uses.

linux/sched/mm.h needs to be included in some files now,
but linux/backing-dev.h does not.

Link: https://lkml.kernel.org/r/163754371968.13692.1277530886009912421@noble.neil.brown.name
Signed-off-by: NeilBrown <neilb@suse.de>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Chao Yu <chao@kernel.org>
Cc: Darrick J. Wong <djwong@kernel.org>
Cc: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-01-15 16:30:29 +02:00
..
acl.c vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
acl.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
checkpoint.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
compress.c Update to zstd-1.4.10 2021-11-13 15:32:30 -08:00
data.c mm: introduce memalloc_retry_wait() 2022-01-15 16:30:29 +02:00
debug.c f2fs: convert S_IRUGO to 0444 2021-08-17 11:59:05 -07:00
dir.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
extent_cache.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
f2fs.h f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
file.c f2fs-for-5.16-rc1 2021-11-13 11:20:22 -08:00
gc.c mm: introduce memalloc_retry_wait() 2022-01-15 16:30:29 +02:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: Handle casefolding with Encryption 2020-12-02 22:00:21 -08:00
inline.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
inode.c mm: introduce memalloc_retry_wait() 2022-01-15 16:30:29 +02:00
iostat.c f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
iostat.h f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
Kconfig f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
node.c mm: introduce memalloc_retry_wait() 2022-01-15 16:30:29 +02:00
node.h f2fs: introduce excess_dirty_threshold() 2021-09-20 16:12:51 -07:00
recovery.c mm: introduce memalloc_retry_wait() 2022-01-15 16:30:29 +02:00
segment.c mm: introduce memalloc_retry_wait() 2022-01-15 16:30:29 +02:00
segment.h f2fs: introduce fragment allocation mode mount option 2021-10-26 14:04:30 -07:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c mm: introduce memalloc_retry_wait() 2022-01-15 16:30:29 +02:00
sysfs.c f2fs: introduce fragment allocation mode mount option 2021-10-26 14:04:30 -07:00
verity.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
xattr.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
xattr.h f2fs: code cleanup by removing ifdef macro surrounding 2020-05-26 18:56:10 -07:00