2022-06-15 02:45:31

by Edward Wu

[permalink] [raw]
Subject: [PATCH] mm: cma: sync everything after EBUSY

Since file-backed memory on CMA area could take long-term pinning.

By Minchan Kim's debug commit 151e084af494 ("mm: page_alloc:
dump migrate-failed pages only at -EBUSY")
We know the pinned page comes from buffer_head, ext4 journal, FS metadata.

Sync everything after EBUSY that can unpin most file-system pages.
And raise the success rate at next time try.

Signed-off-by: Edward Wu <[email protected]>
---
mm/cma.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index eaa4b5c920a2..eefd725064e1 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -31,6 +31,7 @@
#include <linux/highmem.h>
#include <linux/io.h>
#include <linux/kmemleak.h>
+#include <linux/syscalls.h>
#include <trace/events/cma.h>

#include "cma.h"
@@ -410,6 +411,24 @@ static void cma_debug_show_areas(struct cma *cma)
static inline void cma_debug_show_areas(struct cma *cma) { }
#endif

+void cma_sync_work(struct work_struct *work)
+{
+ ksys_sync();
+ kfree(work);
+ pr_debug("%s(): EBUSY Sync complete\n", __func__);
+}
+
+void cma_ebusy_sync_pinned_pages(void)
+{
+ struct work_struct *work;
+
+ work = kmalloc(sizeof(*work), GFP_ATOMIC);
+ if (work) {
+ INIT_WORK(work, cma_sync_work);
+ schedule_work(work);
+ }
+}
+
/**
* cma_alloc() - allocate pages from contiguous area
* @cma: Contiguous memory region for which the allocation is performed.
@@ -430,6 +449,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
unsigned long i;
struct page *page = NULL;
int ret = -ENOMEM;
+ bool sys_synchronized = false;

if (!cma || !cma->count || !cma->bitmap)
goto out;
@@ -480,6 +500,11 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
if (ret != -EBUSY)
break;

+ if (!sys_synchronized) {
+ sys_synchronized = true;
+ cma_ebusy_sync_pinned_pages();
+ }
+
pr_debug("%s(): memory range at %p is busy, retrying\n",
__func__, pfn_to_page(pfn));

--
2.17.1


2022-06-15 20:03:27

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] mm: cma: sync everything after EBUSY

Hi Edward,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on akpm-mm/mm-everything]

url: https://github.com/intel-lab-lkp/linux/commits/Edward-Wu/mm-cma-sync-everything-after-EBUSY/20220615-101716
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20220616/[email protected]/config)
compiler: xtensa-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/ef04552ed13eb371365fcc55c7ae1e5c3c211168
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Edward-Wu/mm-cma-sync-everything-after-EBUSY/20220615-101716
git checkout ef04552ed13eb371365fcc55c7ae1e5c3c211168
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=xtensa SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> mm/cma.c:415:6: warning: no previous prototype for 'cma_sync_work' [-Wmissing-prototypes]
415 | void cma_sync_work(struct work_struct *work)
| ^~~~~~~~~~~~~
>> mm/cma.c:422:6: warning: no previous prototype for 'cma_ebusy_sync_pinned_pages' [-Wmissing-prototypes]
422 | void cma_ebusy_sync_pinned_pages(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/cma_sync_work +415 mm/cma.c

414
> 415 void cma_sync_work(struct work_struct *work)
416 {
417 ksys_sync();
418 kfree(work);
419 pr_debug("%s(): EBUSY Sync complete\n", __func__);
420 }
421
> 422 void cma_ebusy_sync_pinned_pages(void)
423 {
424 struct work_struct *work;
425
426 work = kmalloc(sizeof(*work), GFP_ATOMIC);
427 if (work) {
428 INIT_WORK(work, cma_sync_work);
429 schedule_work(work);
430 }
431 }
432

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-06-15 23:58:18

by Edward Wu

[permalink] [raw]
Subject: [PATCH v2] mm: cma: sync everything after EBUSY

Since file-backed memory on CMA area could take long-term pinning.

By Minchan Kim's debug commit 151e084af494 ("mm: page_alloc:
dump migrate-failed pages only at -EBUSY")
We know the pinned page comes from buffer_head, ext4 journal, FS metadata.

Sync everything after EBUSY that can unpin most file-system pages.
And raise the success rate at next time try.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Edward Wu <[email protected]>
---
v2:
- Fix compile warning

mm/cma.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index eaa4b5c920a2..28391f8ce0fd 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -31,6 +31,7 @@
#include <linux/highmem.h>
#include <linux/io.h>
#include <linux/kmemleak.h>
+#include <linux/syscalls.h>
#include <trace/events/cma.h>

#include "cma.h"
@@ -410,6 +411,24 @@ static void cma_debug_show_areas(struct cma *cma)
static inline void cma_debug_show_areas(struct cma *cma) { }
#endif

+static inline void cma_sync_work(struct work_struct *work)
+{
+ ksys_sync();
+ kfree(work);
+ pr_debug("%s(): EBUSY Sync complete\n", __func__);
+}
+
+static void cma_ebusy_sync_pinned_pages(void)
+{
+ struct work_struct *work;
+
+ work = kmalloc(sizeof(*work), GFP_ATOMIC);
+ if (work) {
+ INIT_WORK(work, cma_sync_work);
+ schedule_work(work);
+ }
+}
+
/**
* cma_alloc() - allocate pages from contiguous area
* @cma: Contiguous memory region for which the allocation is performed.
@@ -430,6 +449,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
unsigned long i;
struct page *page = NULL;
int ret = -ENOMEM;
+ bool sys_synchronized = false;

if (!cma || !cma->count || !cma->bitmap)
goto out;
@@ -480,6 +500,11 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
if (ret != -EBUSY)
break;

+ if (!sys_synchronized) {
+ sys_synchronized = true;
+ cma_ebusy_sync_pinned_pages();
+ }
+
pr_debug("%s(): memory range at %p is busy, retrying\n",
__func__, pfn_to_page(pfn));

--
2.17.1

2022-06-16 00:09:01

by Edward Wu

[permalink] [raw]
Subject: [PATCH v3] mm: cma: sync everything after EBUSY

Since file-backed memory on CMA area could take long-term pinning.

By Minchan Kim's debug commit 151e084af494 ("mm: page_alloc:
dump migrate-failed pages only at -EBUSY")
We know the pinned page comes from buffer_head, ext4 journal, FS metadata.

Sync everything after EBUSY that can unpin most file-system pages.
And raise the success rate at next time try.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Edward Wu <[email protected]>
---
V3:
- Use non-inline prototype for work function

v2:
- Fix compile warning

mm/cma.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index eaa4b5c920a2..ddb9f0fbec27 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -31,6 +31,7 @@
#include <linux/highmem.h>
#include <linux/io.h>
#include <linux/kmemleak.h>
+#include <linux/syscalls.h>
#include <trace/events/cma.h>

#include "cma.h"
@@ -410,6 +411,24 @@ static void cma_debug_show_areas(struct cma *cma)
static inline void cma_debug_show_areas(struct cma *cma) { }
#endif

+static void cma_sync_work(struct work_struct *work)
+{
+ ksys_sync();
+ kfree(work);
+ pr_debug("%s(): EBUSY Sync complete\n", __func__);
+}
+
+static void cma_ebusy_sync_pinned_pages(void)
+{
+ struct work_struct *work;
+
+ work = kmalloc(sizeof(*work), GFP_ATOMIC);
+ if (work) {
+ INIT_WORK(work, cma_sync_work);
+ schedule_work(work);
+ }
+}
+
/**
* cma_alloc() - allocate pages from contiguous area
* @cma: Contiguous memory region for which the allocation is performed.
@@ -430,6 +449,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
unsigned long i;
struct page *page = NULL;
int ret = -ENOMEM;
+ bool sys_synchronized = false;

if (!cma || !cma->count || !cma->bitmap)
goto out;
@@ -480,6 +500,11 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
if (ret != -EBUSY)
break;

+ if (!sys_synchronized) {
+ sys_synchronized = true;
+ cma_ebusy_sync_pinned_pages();
+ }
+
pr_debug("%s(): memory range at %p is busy, retrying\n",
__func__, pfn_to_page(pfn));

--
2.17.1

2022-06-21 03:05:48

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] mm: cma: sync everything after EBUSY

Hi Edward,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on akpm-mm/mm-everything]

url: https://github.com/intel-lab-lkp/linux/commits/Edward-Wu/mm-cma-sync-everything-after-EBUSY/20220615-101716
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
config: x86_64-randconfig-s022 (https://download.01.org/0day-ci/archive/20220621/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-30-g92122700-dirty
# https://github.com/intel-lab-lkp/linux/commit/ef04552ed13eb371365fcc55c7ae1e5c3c211168
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Edward-Wu/mm-cma-sync-everything-after-EBUSY/20220615-101716
git checkout ef04552ed13eb371365fcc55c7ae1e5c3c211168
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>


sparse warnings: (new ones prefixed by >>)
>> mm/cma.c:415:6: sparse: sparse: symbol 'cma_sync_work' was not declared. Should it be static?
>> mm/cma.c:422:6: sparse: sparse: symbol 'cma_ebusy_sync_pinned_pages' was not declared. Should it be static?

--
0-DAY CI Kernel Test Service
https://01.org/lkp