Re: [PATCH 2/2] mm: fs: Invalidate BH LRU during page migration

2021-03-03 Thread kernel test robot
Hi Minchan,

I love your patch! Yet something to improve:

[auto build test ERROR on block/for-next]
[also build test ERROR on linux/master linus/master v5.12-rc1 next-20210303]
[cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210303-191809
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git 
for-next
config: powerpc64-randconfig-r006-20210303 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
a7cad6680b4087eff8994f1f99ac40c661a6621f)
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
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# 
https://github.com/0day-ci/linux/commit/a1c74fba81d1258e320ef52bc995cb0333e3e083
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210303-191809
git checkout a1c74fba81d1258e320ef52bc995cb0333e3e083
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross 
ARCH=powerpc64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

>> mm/swap.c:671:2: error: implicit declaration of function 'invalidate_bh_lru' 
>> [-Werror,-Wimplicit-function-declaration]
   invalidate_bh_lru(NULL);
   ^
   mm/swap.c:671:2: note: did you mean 'invalidate_bdev'?
   include/linux/blkdev.h:2021:20: note: 'invalidate_bdev' declared here
   static inline void invalidate_bdev(struct block_device *bdev)
  ^
>> mm/swap.c:860:7: error: implicit declaration of function 'has_bh_in_lru' 
>> [-Werror,-Wimplicit-function-declaration]
   has_bh_in_lru(cpu, NULL)) {
   ^
   2 errors generated.


vim +/invalidate_bh_lru +671 mm/swap.c

   634  
   635  /*
   636   * Drain pages out of the cpu's pagevecs.
   637   * Either "cpu" is the current CPU, and preemption has already been
   638   * disabled; or "cpu" is being hot-unplugged, and is already dead.
   639   */
   640  void lru_add_drain_cpu(int cpu)
   641  {
   642  struct pagevec *pvec = _cpu(lru_pvecs.lru_add, cpu);
   643  
   644  if (pagevec_count(pvec))
   645  __pagevec_lru_add(pvec);
   646  
   647  pvec = _cpu(lru_rotate.pvec, cpu);
   648  /* Disabling interrupts below acts as a compiler barrier. */
   649  if (data_race(pagevec_count(pvec))) {
   650  unsigned long flags;
   651  
   652  /* No harm done if a racing interrupt already did this 
*/
   653  local_lock_irqsave(_rotate.lock, flags);
   654  pagevec_lru_move_fn(pvec, pagevec_move_tail_fn);
   655  local_unlock_irqrestore(_rotate.lock, flags);
   656  }
   657  
   658  pvec = _cpu(lru_pvecs.lru_deactivate_file, cpu);
   659  if (pagevec_count(pvec))
   660  pagevec_lru_move_fn(pvec, lru_deactivate_file_fn);
   661  
   662  pvec = _cpu(lru_pvecs.lru_deactivate, cpu);
   663  if (pagevec_count(pvec))
   664  pagevec_lru_move_fn(pvec, lru_deactivate_fn);
   665  
   666  pvec = _cpu(lru_pvecs.lru_lazyfree, cpu);
   667  if (pagevec_count(pvec))
   668  pagevec_lru_move_fn(pvec, lru_lazyfree_fn);
   669  
   670  activate_page_drain(cpu);
 > 671  invalidate_bh_lru(NULL);
   672  }
   673  
   674  /**
   675   * deactivate_file_page - forcefully deactivate a file page
   676   * @page: page to deactivate
   677   *
   678   * This function hints the VM that @page is a good reclaim candidate,
   679   * for example if its invalidation fails due to the page being dirty
   680   * or under writeback.
   681   */
   682  void deactivate_file_page(struct page *page)
   683  {
   684  /*
   685   * In a workload with many unevictable page such as mprotect,
   686   * unevictable page deactivation for accelerating reclaim is 
pointless.
   687   */
   688  if (PageUnevictable(page))
   689  return;
   690  
   691  if (likely(get_page_unless_zero(page))) {
   692  struct pagevec *pvec;
   693  
   694  local_lock(_pvecs.lock);
   695  pvec = this_cpu_ptr(_pvecs.lru_deactivate_file);
   696  
   697  if 

Re: [PATCH 2/2] mm: fs: Invalidate BH LRU during page migration

2021-03-03 Thread kernel test robot
Hi Minchan,

I love your patch! Yet something to improve:

[auto build test ERROR on block/for-next]
[also build test ERROR on linux/master linus/master v5.12-rc1 next-20210303]
[cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210303-191809
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git 
for-next
config: arm-randconfig-r031-20210303 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.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/0day-ci/linux/commit/a1c74fba81d1258e320ef52bc995cb0333e3e083
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210303-191809
git checkout a1c74fba81d1258e320ef52bc995cb0333e3e083
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   mm/swap.c: In function 'lru_add_drain_cpu':
>> mm/swap.c:671:2: error: implicit declaration of function 
>> 'invalidate_bh_lru'; did you mean 'invalidate_bdev'? 
>> [-Werror=implicit-function-declaration]
 671 |  invalidate_bh_lru(NULL);
 |  ^
 |  invalidate_bdev
   mm/swap.c: At top level:
   mm/swap.c:874:6: error: conflicting types for 'lru_add_drain_all'
 874 | void lru_add_drain_all(void)
 |  ^
   In file included from mm/swap.c:20:
   include/linux/swap.h:348:13: note: previous declaration of 
'lru_add_drain_all' was here
 348 | extern void lru_add_drain_all(bool force_all_cpus);
 | ^
   cc1: some warnings being treated as errors


vim +671 mm/swap.c

   634  
   635  /*
   636   * Drain pages out of the cpu's pagevecs.
   637   * Either "cpu" is the current CPU, and preemption has already been
   638   * disabled; or "cpu" is being hot-unplugged, and is already dead.
   639   */
   640  void lru_add_drain_cpu(int cpu)
   641  {
   642  struct pagevec *pvec = _cpu(lru_pvecs.lru_add, cpu);
   643  
   644  if (pagevec_count(pvec))
   645  __pagevec_lru_add(pvec);
   646  
   647  pvec = _cpu(lru_rotate.pvec, cpu);
   648  /* Disabling interrupts below acts as a compiler barrier. */
   649  if (data_race(pagevec_count(pvec))) {
   650  unsigned long flags;
   651  
   652  /* No harm done if a racing interrupt already did this 
*/
   653  local_lock_irqsave(_rotate.lock, flags);
   654  pagevec_lru_move_fn(pvec, pagevec_move_tail_fn);
   655  local_unlock_irqrestore(_rotate.lock, flags);
   656  }
   657  
   658  pvec = _cpu(lru_pvecs.lru_deactivate_file, cpu);
   659  if (pagevec_count(pvec))
   660  pagevec_lru_move_fn(pvec, lru_deactivate_file_fn);
   661  
   662  pvec = _cpu(lru_pvecs.lru_deactivate, cpu);
   663  if (pagevec_count(pvec))
   664  pagevec_lru_move_fn(pvec, lru_deactivate_fn);
   665  
   666  pvec = _cpu(lru_pvecs.lru_lazyfree, cpu);
   667  if (pagevec_count(pvec))
   668  pagevec_lru_move_fn(pvec, lru_lazyfree_fn);
   669  
   670  activate_page_drain(cpu);
 > 671  invalidate_bh_lru(NULL);
   672  }
   673  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


[PATCH 2/2] mm: fs: Invalidate BH LRU during page migration

2021-03-02 Thread Minchan Kim
Pages containing buffer_heads that are in one of the per-CPU
buffer_head LRU caches will be pinned and thus cannot be migrated.
This can prevent CMA allocations from succeeding, which are often used
on platforms with co-processors (such as a DSP) that can only use
physically contiguous memory. It can also prevent memory
hot-unplugging from succeeding, which involves migrating at least
MIN_MEMORY_BLOCK_SIZE bytes of memory, which ranges from 8 MiB to 1
GiB based on the architecture in use.

Correspondingly, invalidate the BH LRU caches before a migration
starts and stop any buffer_head from being cached in the LRU caches,
until migration has finished.

Suggested-by: Matthew Wilcox 
Signed-off-by: Chris Goldsworthy 
Signed-off-by: Minchan Kim 
---
* from prev - 
https://lore.kernel.org/linux-mm/e8f3e042b902156467a5e978b57c14954213ec59.1611642039.git.cgold...@codeaurora.org/
  * consolidate bh_lru drain logic into lru pagevec - willy

 fs/buffer.c | 12 ++--
 include/linux/buffer_head.h |  2 ++
 include/linux/swap.h|  1 +
 mm/swap.c   |  5 -
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 96c7604f69b3..4492e9d4c9d3 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1301,6 +1301,14 @@ static void bh_lru_install(struct buffer_head *bh)
int i;
 
check_irqs_on();
+   /*
+* buffer_head in bh_lru could increase refcount of the page
+* until it will be invalidated. It causes page migraion failure.
+* Skip putting upcoming bh into bh_lru until migration is done.
+*/
+   if (lru_cache_disabled())
+   return;
+
bh_lru_lock();
 
b = this_cpu_ptr(_lrus);
@@ -1446,7 +1454,7 @@ EXPORT_SYMBOL(__bread_gfp);
  * This doesn't race because it runs in each cpu either in irq
  * or with preempt disabled.
  */
-static void invalidate_bh_lru(void *arg)
+void invalidate_bh_lru(void *arg)
 {
struct bh_lru *b = _cpu_var(bh_lrus);
int i;
@@ -1458,7 +1466,7 @@ static void invalidate_bh_lru(void *arg)
put_cpu_var(bh_lrus);
 }
 
-static bool has_bh_in_lru(int cpu, void *dummy)
+bool has_bh_in_lru(int cpu, void *dummy)
 {
struct bh_lru *b = per_cpu_ptr(_lrus, cpu);
int i;
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 6b47f94378c5..3d98bdabaac9 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -194,6 +194,8 @@ void __breadahead_gfp(struct block_device *, sector_t 
block, unsigned int size,
 struct buffer_head *__bread_gfp(struct block_device *,
sector_t block, unsigned size, gfp_t gfp);
 void invalidate_bh_lrus(void);
+void invalidate_bh_lru(void *);
+bool has_bh_in_lru(int cpu, void *dummy);
 struct buffer_head *alloc_buffer_head(gfp_t gfp_flags);
 void free_buffer_head(struct buffer_head * bh);
 void unlock_buffer(struct buffer_head *bh);
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 8ab7ad7157f3..94a77e618dba 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -341,6 +341,7 @@ extern void lru_cache_add(struct page *);
 extern void mark_page_accessed(struct page *);
 extern void lru_cache_disable(void);
 extern void lru_cache_enable(void);
+extern bool lru_cache_disabled(void);
 extern void lru_add_drain(void);
 extern void lru_add_drain_cpu(int cpu);
 extern void lru_add_drain_cpu_zone(struct zone *zone);
diff --git a/mm/swap.c b/mm/swap.c
index c1fa6cac04c1..88d51b9ebc8c 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "internal.h"
 
@@ -667,6 +668,7 @@ void lru_add_drain_cpu(int cpu)
pagevec_lru_move_fn(pvec, lru_lazyfree_fn);
 
activate_page_drain(cpu);
+   invalidate_bh_lru(NULL);
 }
 
 /**
@@ -854,7 +856,8 @@ void lru_add_drain_all(bool force_all_cpus)
pagevec_count(_cpu(lru_pvecs.lru_deactivate_file, cpu)) 
||
pagevec_count(_cpu(lru_pvecs.lru_deactivate, cpu)) ||
pagevec_count(_cpu(lru_pvecs.lru_lazyfree, cpu)) ||
-   need_activate_page_drain(cpu)) {
+   need_activate_page_drain(cpu) ||
+   has_bh_in_lru(cpu, NULL)) {
INIT_WORK(work, lru_add_drain_per_cpu);
queue_work_on(cpu, mm_percpu_wq, work);
__cpumask_set_cpu(cpu, _work);
-- 
2.30.1.766.gb4fecdf3b7-goog