linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: cma: sync everything after EBUSY
@ 2022-06-15  2:15 Edward Wu
  2022-06-15 19:34 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Edward Wu @ 2022-06-15  2:15 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel; +Cc: surenb, minchan, edwardwu

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 <edwardwu@realtek.com>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: cma: sync everything after EBUSY
  2022-06-15  2:15 [PATCH] mm: cma: sync everything after EBUSY Edward Wu
@ 2022-06-15 19:34 ` kernel test robot
  2022-06-15 23:24 ` [PATCH v2] " Edward Wu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-06-15 19:34 UTC (permalink / raw)
  To: Edward Wu, Andrew Morton, linux-kernel
  Cc: kbuild-all, Linux Memory Management List, surenb, minchan, edwardwu

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/202206160330.nZiFjZFG-lkp@intel.com/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 <lkp@intel.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] mm: cma: sync everything after EBUSY
  2022-06-15  2:15 [PATCH] mm: cma: sync everything after EBUSY Edward Wu
  2022-06-15 19:34 ` kernel test robot
@ 2022-06-15 23:24 ` Edward Wu
  2022-06-15 23:34 ` [PATCH v3] " Edward Wu
  2022-06-21  2:38 ` [PATCH] " kernel test robot
  3 siblings, 0 replies; 5+ messages in thread
From: Edward Wu @ 2022-06-15 23:24 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel; +Cc: surenb, minchan, edwardwu

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/20220615021504.23358-1-edwardwu@realtek.com
Signed-off-by: Edward Wu <edwardwu@realtek.com>
---
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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3] mm: cma: sync everything after EBUSY
  2022-06-15  2:15 [PATCH] mm: cma: sync everything after EBUSY Edward Wu
  2022-06-15 19:34 ` kernel test robot
  2022-06-15 23:24 ` [PATCH v2] " Edward Wu
@ 2022-06-15 23:34 ` Edward Wu
  2022-06-21  2:38 ` [PATCH] " kernel test robot
  3 siblings, 0 replies; 5+ messages in thread
From: Edward Wu @ 2022-06-15 23:34 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel; +Cc: surenb, minchan, edwardwu

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/20220615021504.23358-1-edwardwu@realtek.com
Signed-off-by: Edward Wu <edwardwu@realtek.com>
---
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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: cma: sync everything after EBUSY
  2022-06-15  2:15 [PATCH] mm: cma: sync everything after EBUSY Edward Wu
                   ` (2 preceding siblings ...)
  2022-06-15 23:34 ` [PATCH v3] " Edward Wu
@ 2022-06-21  2:38 ` kernel test robot
  3 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-06-21  2:38 UTC (permalink / raw)
  To: Edward Wu, Andrew Morton, linux-kernel
  Cc: kbuild-all, Linux Memory Management List, surenb, minchan, edwardwu

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/202206211055.X7Tcbmrt-lkp@intel.com/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 <lkp@intel.com>


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-21  2:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15  2:15 [PATCH] mm: cma: sync everything after EBUSY Edward Wu
2022-06-15 19:34 ` kernel test robot
2022-06-15 23:24 ` [PATCH v2] " Edward Wu
2022-06-15 23:34 ` [PATCH v3] " Edward Wu
2022-06-21  2:38 ` [PATCH] " kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).