From 8db5d39f669f03aa6d8ad4962f82453b3cc11b42 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Thu, 13 Apr 2023 08:28:26 -0400 Subject: [PATCH] LU-16713 llite: add __GFP_NORETRY for read-ahead page We need __GFP_NORETRY for read-ahead page, otherwise the read process would be OOM killed when reached cgroup memory limits. Signed-off-by: Qian Yingjin Change-Id: If699429d5d5cd29bd895d8455296113aa67645fc Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50625 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Patrick Farrell Reviewed-by: Oleg Drokin --- lustre/autoconf/lustre-core.m4 | 23 +++++++++++++++++++++++ lustre/include/lustre_compat.h | 5 +++++ lustre/llite/rw.c | 11 ++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index fa8f8b1..70cc050 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -1013,6 +1013,27 @@ AC_DEFUN([LC_HAVE_FILE_OPERATIONS_READ_WRITE_ITER], [ ]) # LC_HAVE_FILE_OPERATIONS_READ_WRITE_ITER # +# LC_PAGECACHE_GET_PAGE +# +# Kernel version 3.16 commit 2457aec63745e235bcafb7ef312b182d8682f0fc +# @pagecache_get_page was introduced since Linux 3.16 +# +AC_DEFUN([LC_SRC_PAGECACHE_GET_PAGE], [ + LB2_LINUX_TEST_SRC([pagecache_get_page], [ + #include + ],[ + pagecache_get_page(NULL, 0, 0, 0); + ]) +]) +AC_DEFUN([LC_PAGECACHE_GET_PAGE], [ + AC_MSG_CHECKING([if 'pagecache_get_page' exists]) + LB2_LINUX_TEST_RESULT([pagecache_get_page], [ + AC_DEFINE(HAVE_PAGECACHE_GET_PAGE, 1, + ['pagecache_get_page' is available]) + ]) +]) # LC_PAGECACHE_GET_PAGE + +# # LC_HAVE_INTERVAL_BLK_INTEGRITY # # 3.17 replace sector_size with interval in struct blk_integrity @@ -3696,6 +3717,7 @@ AC_DEFUN([LC_PROG_LINUX_SRC], [ LC_SRC_HAVE_IOV_ITER_INIT_DIRECTION LC_SRC_HAVE_IOV_ITER_TRUNCATE LC_SRC_HAVE_FILE_OPERATIONS_READ_WRITE_ITER + LC_SRC_PAGECACHE_GET_PAGE # 3.17 LC_SRC_HAVE_INTERVAL_BLK_INTEGRITY @@ -3944,6 +3966,7 @@ AC_DEFUN([LC_PROG_LINUX_RESULTS], [ LC_HAVE_IOV_ITER_INIT_DIRECTION LC_HAVE_IOV_ITER_TRUNCATE LC_HAVE_FILE_OPERATIONS_READ_WRITE_ITER + LC_PAGECACHE_GET_PAGE # 3.17 LC_HAVE_INTERVAL_BLK_INTEGRITY diff --git a/lustre/include/lustre_compat.h b/lustre/include/lustre_compat.h index 90d8872..8234332 100644 --- a/lustre/include/lustre_compat.h +++ b/lustre/include/lustre_compat.h @@ -172,6 +172,11 @@ static inline bool d_is_positive(const struct dentry *dentry) # define inode_trylock(inode) mutex_trylock(&(inode)->i_mutex) #endif +#ifndef HAVE_PAGECACHE_GET_PAGE +#define pagecache_get_page(mapping, index, fp, gfp) \ + grab_cache_page_nowait(mapping, index) +#endif + /* Old kernels lacked both Xarray support and the page cache * using Xarrays. Our back ported Xarray support introduces * the real xa_is_value() but we need a wrapper as well for diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index a562fd7..3c6cb49 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -215,7 +215,16 @@ static int ll_read_ahead_page(const struct lu_env *env, struct cl_io *io, switch (hint) { case MAYNEED: - vmpage = grab_cache_page_nowait(inode->i_mapping, index); + /* + * We need __GFP_NORETRY here for read-ahead page, otherwise + * the process will fail with OOM killed due to memcg limit. + * See @readahead_gfp_mask for an example. + */ + vmpage = pagecache_get_page(inode->i_mapping, index, + FGP_LOCK | FGP_CREAT | + FGP_NOFS | FGP_NOWAIT, + mapping_gfp_mask(inode->i_mapping) | + __GFP_NORETRY | __GFP_NOWARN); if (vmpage == NULL) { which = RA_STAT_FAILED_GRAB_PAGE; msg = "g_c_p_n failed"; -- 1.8.3.1