Whamcloud - gitweb
LU-16713 llite: add __GFP_NORETRY for read-ahead page 25/50625/3
authorQian Yingjin <qian@ddn.com>
Thu, 13 Apr 2023 12:28:26 +0000 (08:28 -0400)
committerOleg Drokin <green@whamcloud.com>
Tue, 9 May 2023 05:47:05 +0000 (05:47 +0000)
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 <qian@ddn.com>
Change-Id: If699429d5d5cd29bd895d8455296113aa67645fc
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50625
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/autoconf/lustre-core.m4
lustre/include/lustre_compat.h
lustre/llite/rw.c

index fa8f8b1..70cc050 100644 (file)
@@ -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 <linux/pagemap.h>
+       ],[
+               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
index 90d8872..8234332 100644 (file)
@@ -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
index a562fd7..3c6cb49 100644 (file)
@@ -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";