Re: [PATCH] memory tier: rename destroy_memory_type() to put_memory_type()

2023-07-06 Thread Miaohe Lin
On 2023/7/6 19:58, Xiao Yang wrote: > On 2023/7/6 14:39, Miaohe Lin wrote: >> It appears that destroy_memory_type() isn't a very good name because >> we usually will not free the memory_type here. So rename it to a more >> appropriate name i.e. put_memory_type(). >> &

[PATCH] memory tier: rename destroy_memory_type() to put_memory_type()

2023-07-06 Thread Miaohe Lin
It appears that destroy_memory_type() isn't a very good name because we usually will not free the memory_type here. So rename it to a more appropriate name i.e. put_memory_type(). Suggested-by: Huang, Ying Signed-off-by: Miaohe Lin --- drivers/dax/kmem.c | 4 ++-- include/linux

[PATCH v3 0/4] close various race windows for swap

2021-04-20 Thread Miaohe Lin
s Zhou and Tim Chen. Miaohe Lin (4): mm/swapfile: use percpu_ref to serialize against concurrent swapoff swap: fix do_swap_page() race with swapoff mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info() mm/shmem: fix shmem_swapin() race with swapoff include/linux/

[PATCH v3 2/4] swap: fix do_swap_page() race with swapoff

2021-04-20 Thread Miaohe Lin
: 0bcac06f27d7 ("mm,swap: skip swapcache for swapin of synchronous device") Reported-by: kernel test robot (auto build test ERROR) Signed-off-by: Miaohe Lin --- include/linux/swap.h | 9 + mm/memory.c | 9 + 2 files changed, 18 insertions(+) diff --git a/include/l

[PATCH v3 1/4] mm/swapfile: use percpu_ref to serialize against concurrent swapoff

2021-04-20 Thread Miaohe Lin
used together with RCU solution. Signed-off-by: Miaohe Lin --- include/linux/swap.h | 5 +-- mm/swapfile.c| 79 +++- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 144727041e78

[PATCH v3 4/4] mm/shmem: fix shmem_swapin() race with swapoff

2021-04-20 Thread Miaohe Lin
backing device is congested or not") Signed-off-by: Miaohe Lin --- mm/shmem.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 26c76b13ad23..936ba5595297 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1492,15 +1492,21 @@ static void shmem_pseudo_vma_des

[PATCH v3 3/4] mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info()

2021-04-20 Thread Miaohe Lin
cking when we really operate the PTE entries later. So checking for non_swap_entry() is not really needed here and should be removed to avoid confusion. Signed-off-by: Miaohe Lin --- mm/swap_state.c | 6 -- 1 file changed, 6 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.

Re: [PATCH v2 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-19 Thread Miaohe Lin
On 2021/4/19 15:52, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/19 15:09, Huang, Ying wrote: >>> Miaohe Lin writes: >>> >>>> On 2021/4/19 10:48, Huang, Ying wrote: >>>>> Miaohe Lin writes: >>>>> &g

Re: [PATCH v2 5/5] mm/shmem: fix shmem_swapin() race with swapoff

2021-04-19 Thread Miaohe Lin
On 2021/4/19 15:41, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/19 15:04, Huang, Ying wrote: >>> Miaohe Lin writes: >>> >>>> On 2021/4/19 10:15, Huang, Ying wrote: >>>>> Miaohe Lin writes: >>>>> >&g

Re: [PATCH v2 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-19 Thread Miaohe Lin
On 2021/4/19 15:09, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/19 10:48, Huang, Ying wrote: >>> Miaohe Lin writes: >>> >>>> We will use percpu-refcount to serialize against concurrent swapoff. This >>>> patch adds the percpu_ref

Re: [PATCH v2 5/5] mm/shmem: fix shmem_swapin() race with swapoff

2021-04-19 Thread Miaohe Lin
On 2021/4/19 15:04, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/19 10:15, Huang, Ying wrote: >>> Miaohe Lin writes: >>> >>>> When I was investigating the swap code, I found the below possible race >>>> window: >>&

Re: [PATCH v2 2/5] mm/swapfile: use percpu_ref to serialize against concurrent swapoff

2021-04-19 Thread Miaohe Lin
On 2021/4/19 10:54, Huang, Ying wrote: > Miaohe Lin writes: > >> Use percpu_ref to serialize against concurrent swapoff. Also remove the >> SWP_VALID flag because it's used together with RCU solution. >> >> Signed-off-by: Miaohe Lin >> --- >> inclu

Re: [PATCH v2 3/5] swap: fix do_swap_page() race with swapoff

2021-04-19 Thread Miaohe Lin
On 2021/4/19 10:23, Huang, Ying wrote: > Miaohe Lin writes: > >> When I was investigating the swap code, I found the below possible race >> window: >> >> CPU 1CPU 2 >> --

Re: [PATCH v2 5/5] mm/shmem: fix shmem_swapin() race with swapoff

2021-04-19 Thread Miaohe Lin
On 2021/4/19 10:15, Huang, Ying wrote: > Miaohe Lin writes: > >> When I was investigating the swap code, I found the below possible race >> window: >> >> CPU 1 CPU 2 >> -

Re: [PATCH v2 4/5] mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info()

2021-04-19 Thread Miaohe Lin
On 2021/4/19 9:53, Huang, Ying wrote: > Miaohe Lin writes: > >> While we released the pte lock, somebody else might faulted in this pte. >> So we should check whether it's swap pte first to guard against such race >> or swp_type would be unexpected. But t

Re: [PATCH v2 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-19 Thread Miaohe Lin
On 2021/4/19 10:48, Huang, Ying wrote: > Miaohe Lin writes: > >> We will use percpu-refcount to serialize against concurrent swapoff. This >> patch adds the percpu_ref support for swap. >> >> Signed-off-by: Miaohe Lin >> --- >> include/linux/swa

[PATCH v2 0/5] close various race windows for swap

2021-04-17 Thread Miaohe Lin
be found in the respective changelogs. Thanks! v1->v2: reorganize the patch-2/5 various enhance and fixup per Huang, Ying Many thanks for the comments of Huang, Ying, Dennis Zhou and Tim Chen. Miaohe Lin (5): mm/swapfile: add percpu_ref support for swap mm/swapfile: use percpu_

[PATCH v2 5/5] mm/shmem: fix shmem_swapin() race with swapoff

2021-04-17 Thread Miaohe Lin
ynchronize_rcu(); .. si->swap_file = NULL; struct inode *inode = si->swap_file->f_mapping->host;[oops!] Close this race window by using get/put_swap_device() to guard against concurrent swapoff. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2"

[PATCH v2 3/5] swap: fix do_swap_page() race with swapoff

2021-04-17 Thread Miaohe Lin
p: skip swapcache for swapin of synchronous device") Reported-by: kernel test robot (auto build test ERROR) Signed-off-by: Miaohe Lin --- include/linux/swap.h | 9 + mm/memory.c | 9 + 2 files changed, 18 insertions(+) diff --git a/include/linux/swap.h b/include/linux/swap.h

[PATCH v2 2/5] mm/swapfile: use percpu_ref to serialize against concurrent swapoff

2021-04-17 Thread Miaohe Lin
Use percpu_ref to serialize against concurrent swapoff. Also remove the SWP_VALID flag because it's used together with RCU solution. Signed-off-by: Miaohe Lin --- include/linux/swap.h | 3 +-- mm/swapfile.c| 43 +-- 2 files changed, 18 insertions

[PATCH v2 4/5] mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info()

2021-04-17 Thread Miaohe Lin
later. So checking for non_swap_entry() is not really needed here and should be removed to avoid confusion. Signed-off-by: Miaohe Lin --- mm/swap_state.c | 6 -- 1 file changed, 6 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 272ea2108c9d..df5405384520 100644 --- a/mm

[PATCH v2 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-17 Thread Miaohe Lin
We will use percpu-refcount to serialize against concurrent swapoff. This patch adds the percpu_ref support for swap. Signed-off-by: Miaohe Lin --- include/linux/swap.h | 3 +++ mm/swapfile.c| 33 + 2 files changed, 32 insertions(+), 4 deletions(-) diff

Re: [PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-16 Thread Miaohe Lin
On 2021/4/16 14:25, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/15 22:31, Dennis Zhou wrote: >>> On Thu, Apr 15, 2021 at 01:24:31PM +0800, Huang, Ying wrote: >>>> Dennis Zhou writes: >>>> >>>>> On Wed, Apr 14, 2021 at 01:

Re: [PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-15 Thread Miaohe Lin
gt; On Wed, Apr 14, 2021 at 11:59:03AM +0800, Huang, Ying wrote: >>>>>> Dennis Zhou writes: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> On Wed, Apr 14, 2021 at 10:06:48AM +0800, Huang, Ying wrote: >>>>

Re: [PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-15 Thread Miaohe Lin
On 2021/4/15 12:20, Dennis Zhou wrote: > On Thu, Apr 15, 2021 at 11:16:42AM +0800, Miaohe Lin wrote: >> On 2021/4/14 22:53, Dennis Zhou wrote: >>> On Wed, Apr 14, 2021 at 01:44:58PM +0800, Huang, Ying wrote: >>>> Dennis Zhou writes: >>>> >>>>&

Re: [PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-14 Thread Miaohe Lin
On 2021/4/15 0:13, Tim Chen wrote: > > > On 4/13/21 6:04 PM, Huang, Ying wrote: >> Tim Chen writes: >> >>> On 4/12/21 6:27 PM, Huang, Ying wrote: >>> This isn't the commit that introduces the race. You can use `git blame` find out the correct commit. For this it's commit

Re: [PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-14 Thread Miaohe Lin
lo, >>>>> >>>>> On Wed, Apr 14, 2021 at 10:06:48AM +0800, Huang, Ying wrote: >>>>>> Miaohe Lin writes: >>>>>> >>>>>>> On 2021/4/14 9:17, Huang, Ying wrote: >>>>>>>> Miaohe Lin writes: >

Re: [PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-13 Thread Miaohe Lin
On 2021/4/14 11:07, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/13 9:27, Huang, Ying wrote: >>> Miaohe Lin writes: >>> >>>> When I was investigating the swap code, I found the below possible race >>>> window: >

Re: [PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-13 Thread Miaohe Lin
On 2021/4/13 9:27, Huang, Ying wrote: > Miaohe Lin writes: > >> When I was investigating the swap code, I found the below possible race >> window: >> >> CPU 1CPU 2 >> ---

Re: [PATCH 5/5] mm/swap_state: fix swap_cluster_readahead() race with swapoff

2021-04-13 Thread Miaohe Lin
On 2021/4/13 9:36, Huang, Ying wrote: > Miaohe Lin writes: > >> swap_cluster_readahead() could race with swapoff and might dereference >> si->swap_file after it's released by swapoff. Close this race window by >> using get/put_swap_device() pair. > > I think

Re: [PATCH 3/5] mm/swap_state: fix get_shadow_from_swap_cache() race with swapoff

2021-04-13 Thread Miaohe Lin
On 2021/4/13 9:33, Huang, Ying wrote: > Miaohe Lin writes: > >> The function get_shadow_from_swap_cache() can race with swapoff, though >> it's only called by do_swap_page() now. >> >> Fixes: aae466b0052e ("mm/swap: implement workingset detection for anonymous

Re: [PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-13 Thread Miaohe Lin
On 2021/4/14 9:04, Huang, Ying wrote: > Tim Chen writes: > >> On 4/12/21 6:27 PM, Huang, Ying wrote: >> >>> >>> This isn't the commit that introduces the race. You can use `git blame` >>> find out the correct commit. For this it's commit 0bcac06f27d7 "mm, >>> swap: skip swapcache for swapin of

Re: [PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-13 Thread Miaohe Lin
On 2021/4/14 9:17, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/12 15:24, Huang, Ying wrote: >>> "Huang, Ying" writes: >>> >>>> Miaohe Lin writes: >>>> >>>>> We will use percpu-refcount to serialize aga

Re: [PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-13 Thread Miaohe Lin
On 2021/4/12 15:24, Huang, Ying wrote: > "Huang, Ying" writes: > >> Miaohe Lin writes: >> >>> We will use percpu-refcount to serialize against concurrent swapoff. This >>> patch adds the percpu_ref support for later fixup. >>> >>&

Re: [PATCH v2 5/5] mm/hugetlb: remove unused variable pseudo_vma in remove_inode_hugepages()

2021-04-12 Thread Miaohe Lin
On 2021/4/13 2:51, Mike Kravetz wrote: > On 4/10/21 12:23 AM, Miaohe Lin wrote: >> The local variable pseudo_vma is not used anymore. >> >> Signed-off-by: Miaohe Lin > > Thanks, > > That should have been removed with 1b426bac66e6 ("hugetlb: use same f

Re: [PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-12 Thread Miaohe Lin
On 2021/4/12 11:30, Huang, Ying wrote: > Miaohe Lin writes: > >> We will use percpu-refcount to serialize against concurrent swapoff. This >> patch adds the percpu_ref support for later fixup. >> >> Signed-off-by: Miaohe Lin >> --- >> include/linux/sw

Re: [PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-11 Thread Miaohe Lin
On 2021/4/12 9:44, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/10 1:17, Tim Chen wrote: >>> >>> >>> On 4/9/21 1:42 AM, Miaohe Lin wrote: >>>> On 2021/4/9 5:34, Tim Chen wrote: >>>>> >>>>> >>>>

Re: [PATCH 4/5] mm/swap_state: fix potential faulted in race in swap_ra_info()

2021-04-11 Thread Miaohe Lin
On 2021/4/12 8:55, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/4/9 16:50, Huang, Ying wrote: >>> Miaohe Lin writes: >>> >>>> While we released the pte lock, somebody else might faulted in this pte. >>>> So we should check

Re: [Question] Is there a race window between swapoff vs synchronous swap_readpage

2021-04-11 Thread Miaohe Lin
On 2021/3/30 15:27, Yu Zhao wrote: > On Tue, Mar 30, 2021 at 12:57 AM Huang, Ying wrote: >> >> Yu Zhao writes: >> >>> On Mon, Mar 29, 2021 at 9:44 PM Huang, Ying wrote: >>>> >>>> Miaohe Lin writes: >>>> >>>>>

Re: [PATCH] mm/frontswap: fix frontswap_register_ops() race with swapon and swapoff

2021-04-11 Thread Miaohe Lin
On 2021/4/11 4:02, Yu Zhao wrote: > On Sat, Apr 10, 2021 at 5:01 AM Miaohe Lin wrote: >> >> On 2021/4/10 18:42, Yu Zhao wrote: >>> On Sat, Apr 10, 2021 at 1:30 AM Miaohe Lin wrote: >>>> >>>> Hi: >>>> On 2021/4/5 18:20, Miaohe Lin wrote:

Re: [PATCH] mm/frontswap: fix frontswap_register_ops() race with swapon and swapoff

2021-04-10 Thread Miaohe Lin
On 2021/4/10 18:42, Yu Zhao wrote: > On Sat, Apr 10, 2021 at 1:30 AM Miaohe Lin wrote: >> >> Hi: >> On 2021/4/5 18:20, Miaohe Lin wrote: >>> frontswap_register_ops can race with swapon. Consider the following scene: >> >> Any comment or suggestion? Or

Re: [PATCH] mm/frontswap: fix frontswap_register_ops() race with swapon and swapoff

2021-04-10 Thread Miaohe Lin
Hi: On 2021/4/5 18:20, Miaohe Lin wrote: > frontswap_register_ops can race with swapon. Consider the following scene: Any comment or suggestion? Or is this race window too theoretical to fix? Thanks. > > CPU1

[PATCH v2 3/5] mm/hugeltb: clarify (chg - freed) won't go negative in hugetlb_unreserve_pages()

2021-04-10 Thread Miaohe Lin
file. As a result, remove_inode_hugepages will never find any huge pages associated with the inode and the passed value 'freed' will always be zero." Add a comment clarifying this to make it clear and also avoid confusion. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 3 +++ 1 file

[PATCH v2 1/5] mm/hugeltb: remove redundant VM_BUG_ON() in region_add()

2021-04-10 Thread Miaohe Lin
The same VM_BUG_ON() check is already done in the callee. Remove this extra one to simplify the code slightly. Reviewed-by: Mike Kravetz Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c22111f3da20..a03a50b7c410

[PATCH v2 4/5] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts()

2021-04-10 Thread Miaohe Lin
these cases. Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages") Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 387c9a62615e..a14bb1a03ee4 10064

[PATCH v2 0/5] Cleanup and fixup for hugetlb

2021-04-10 Thread Miaohe Lin
ove the HPAGE_RESV_OWNER check per Mike add a comment to hugetlb_unreserve_pages per Mike expand warning message a bit for hugetlb_fix_reserve_counts Add a new patch to remove unused variable Many thanks for Mike's review and suggestion! Miaohe Lin (5): mm/hugeltb: remove redundant VM_BUG

[PATCH v2 5/5] mm/hugetlb: remove unused variable pseudo_vma in remove_inode_hugepages()

2021-04-10 Thread Miaohe Lin
The local variable pseudo_vma is not used anymore. Signed-off-by: Miaohe Lin --- fs/hugetlbfs/inode.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index d81f52b87bd7..a2a42335e8fd 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c

[PATCH v2 2/5] mm/hugeltb: simplify the return code of __vma_reservation_common()

2021-04-10 Thread Miaohe Lin
. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 41 - 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a03a50b7c410..9b4c05699a90 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2163,27 +2163,26 @@ static long

Re: [PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-09 Thread Miaohe Lin
On 2021/4/10 1:17, Tim Chen wrote: > > > On 4/9/21 1:42 AM, Miaohe Lin wrote: >> On 2021/4/9 5:34, Tim Chen wrote: >>> >>> >>> On 4/8/21 6:08 AM, Miaohe Lin wrote: >>>> When I was investigating the swap code, I foun

Re: [PATCH 4/5] mm/swap_state: fix potential faulted in race in swap_ra_info()

2021-04-09 Thread Miaohe Lin
On 2021/4/9 16:50, Huang, Ying wrote: > Miaohe Lin writes: > >> While we released the pte lock, somebody else might faulted in this pte. >> So we should check whether it's swap pte first to guard against such race >> or swp_type would be unexpected. And we can als

Re: [PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-09 Thread Miaohe Lin
On 2021/4/9 5:34, Tim Chen wrote: > > > On 4/8/21 6:08 AM, Miaohe Lin wrote: >> When I was investigating the swap code, I found the below possible race >> window: >> >> CPU 1CPU 2 >> -

Re: [PATCH 0/5] close various race windows for swap

2021-04-09 Thread Miaohe Lin
On 2021/4/8 22:55, riteshh wrote: > On 21/04/08 09:08AM, Miaohe Lin wrote: >> Hi all, >> When I was investigating the swap code, I found some possible race >> windows. This series aims to fix all these races. But using current >> get/put_swap_device() to guard

Re: [PATCH 4/4] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts()

2021-04-09 Thread Miaohe Lin
On 2021/4/9 13:04, Andrew Morton wrote: > On Fri, 9 Apr 2021 11:17:49 +0800 Miaohe Lin wrote: > >> On 2021/4/9 7:25, Mike Kravetz wrote: >>> On 4/2/21 2:32 AM, Miaohe Lin wrote: >>>> A rare out of memory error would prevent removal of the r

Re: [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory()

2021-04-09 Thread Miaohe Lin
On 2021/4/9 12:37, Mike Kravetz wrote: > On 4/8/21 8:01 PM, Miaohe Lin wrote: >> On 2021/4/9 6:53, Mike Kravetz wrote: >>> >>> Yes, add a comment to hugetlb_unreserve_pages saying that !resv_map >>> implies freed == 0. >>> >> >> Sound

Re: [PATCH 4/4] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts()

2021-04-08 Thread Miaohe Lin
On 2021/4/9 7:25, Mike Kravetz wrote: > On 4/2/21 2:32 AM, Miaohe Lin wrote: >> A rare out of memory error would prevent removal of the reserve map region >> for a page. hugetlb_fix_reserve_counts() handles this rare case to avoid >> dangling with incorrect

Re: [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory()

2021-04-08 Thread Miaohe Lin
On 2021/4/9 6:53, Mike Kravetz wrote: > On 4/7/21 8:26 PM, Miaohe Lin wrote: >> On 2021/4/8 11:24, Miaohe Lin wrote: >>> On 2021/4/8 4:53, Mike Kravetz wrote: >>>> On 4/7/21 12:24 AM, Miaohe Lin wrote: >>>>> Hi: >>>>> On 2021/4/7 10:

Re: [PATCH 2/4] mm/hugeltb: simplify the return code of __vma_reservation_common()

2021-04-08 Thread Miaohe Lin
On 2021/4/9 6:40, Mike Kravetz wrote: > On 4/7/21 7:44 PM, Miaohe Lin wrote: >> On 2021/4/8 5:23, Mike Kravetz wrote: >>> On 4/6/21 8:09 PM, Miaohe Lin wrote: >>>> On 2021/4/7 10:37, Mike Kravetz wrote: >>>>> On 4/6/21 7:05 PM, Miaohe Lin wrote: >

[PATCH 3/5] mm/swap_state: fix get_shadow_from_swap_cache() race with swapoff

2021-04-08 Thread Miaohe Lin
The function get_shadow_from_swap_cache() can race with swapoff, though it's only called by do_swap_page() now. Fixes: aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU") Signed-off-by: Miaohe Lin --- mm/swap_state.c | 9 ++--- 1 file changed, 6 insert

[PATCH 2/5] swap: fix do_swap_page() race with swapoff

2021-04-08 Thread Miaohe Lin
s race window(as suggested by Huang, Ying). Fixes: 235b62176712 ("mm/swap: add cluster lock") Signed-off-by: Miaohe Lin --- include/linux/swap.h | 2 +- mm/memory.c | 10 ++ mm/swapfile.c| 28 +++- 3 files changed, 22 insertions(+), 18 de

[PATCH 1/5] mm/swapfile: add percpu_ref support for swap

2021-04-08 Thread Miaohe Lin
We will use percpu-refcount to serialize against concurrent swapoff. This patch adds the percpu_ref support for later fixup. Signed-off-by: Miaohe Lin --- include/linux/swap.h | 2 ++ mm/swapfile.c| 25 ++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff

[PATCH 5/5] mm/swap_state: fix swap_cluster_readahead() race with swapoff

2021-04-08 Thread Miaohe Lin
swap_cluster_readahead() could race with swapoff and might dereference si->swap_file after it's released by swapoff. Close this race window by using get/put_swap_device() pair. Signed-off-by: Miaohe Lin --- mm/swap_state.c | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) d

[PATCH 4/5] mm/swap_state: fix potential faulted in race in swap_ra_info()

2021-04-08 Thread Miaohe Lin
swap readahead") Signed-off-by: Miaohe Lin --- mm/swap_state.c | 13 + 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 709c260d644a..3bf0d0c297bc 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -724,10 +724,10 @@ s

[PATCH 0/5] close various race windows for swap

2021-04-08 Thread Miaohe Lin
in the respective changelogs. Thanks! Miaohe Lin (5): mm/swapfile: add percpu_ref support for swap swap: fix do_swap_page() race with swapoff mm/swap_state: fix get_shadow_from_swap_cache() race with swapoff mm/swap_state: fix potential faulted in race in swap_ra_info() mm/swap_state: fix

Re: [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory()

2021-04-07 Thread Miaohe Lin
On 2021/4/8 11:24, Miaohe Lin wrote: > On 2021/4/8 4:53, Mike Kravetz wrote: >> On 4/7/21 12:24 AM, Miaohe Lin wrote: >>> Hi: >>> On 2021/4/7 10:49, Mike Kravetz wrote: >>>> On 4/2/21 2:32 AM, Miaohe Lin wrote: >>>>> The resv_map could

Re: [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory()

2021-04-07 Thread Miaohe Lin
On 2021/4/8 4:53, Mike Kravetz wrote: > On 4/7/21 12:24 AM, Miaohe Lin wrote: >> Hi: >> On 2021/4/7 10:49, Mike Kravetz wrote: >>> On 4/2/21 2:32 AM, Miaohe Lin wrote: >>>> The resv_map could be NULL since this routine can be called in the evict >>>

Re: [PATCH 2/4] mm/hugeltb: simplify the return code of __vma_reservation_common()

2021-04-07 Thread Miaohe Lin
On 2021/4/8 5:23, Mike Kravetz wrote: > On 4/6/21 8:09 PM, Miaohe Lin wrote: >> On 2021/4/7 10:37, Mike Kravetz wrote: >>> On 4/6/21 7:05 PM, Miaohe Lin wrote: >>>> Hi: >>>> On 2021/4/7 8:53, Mike Kravetz wrote: >>>>> On 4/2/21 2:32

Re: [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory()

2021-04-07 Thread Miaohe Lin
Hi: On 2021/4/7 10:49, Mike Kravetz wrote: > On 4/2/21 2:32 AM, Miaohe Lin wrote: >> The resv_map could be NULL since this routine can be called in the evict >> inode path for all hugetlbfs inodes. So we could have chg = 0 and this >> would result in a negative v

Re: [PATCH 2/4] mm/hugeltb: simplify the return code of __vma_reservation_common()

2021-04-06 Thread Miaohe Lin
On 2021/4/7 10:37, Mike Kravetz wrote: > On 4/6/21 7:05 PM, Miaohe Lin wrote: >> Hi: >> On 2021/4/7 8:53, Mike Kravetz wrote: >>> On 4/2/21 2:32 AM, Miaohe Lin wrote: >>>> It's guaranteed that the vma is associated with a resv_map, i.e. either >>>>

Re: [PATCH 2/4] mm/hugeltb: simplify the return code of __vma_reservation_common()

2021-04-06 Thread Miaohe Lin
Hi: On 2021/4/7 8:53, Mike Kravetz wrote: > On 4/2/21 2:32 AM, Miaohe Lin wrote: >> It's guaranteed that the vma is associated with a resv_map, i.e. either >> VM_MAYSHARE or HPAGE_RESV_OWNER, when the code reaches here or we would >> have returned via !resv check above. So re

[PATCH] mm/frontswap: fix frontswap_register_ops() race with swapon and swapoff

2021-04-05 Thread Miaohe Lin
th frontswap is uninitialized yet. Fix all these by using swapon_mutex to guard against race with swapon and add swap_info_get_if_under_swapoff() to collect swap devices under swapoff. Fixes: d1dc6f1bcf1e ("frontswap: allow multiple backends") Signed-off-by: Miaohe Lin --- include/linux/

[PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory()

2021-04-02 Thread Miaohe Lin
("hugetlbfs: truncate_hugepages() takes a range of pages") Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b7864abded3d..bdff8d23803f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5413

[PATCH 4/4] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts()

2021-04-02 Thread Miaohe Lin
these cases. Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages") Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index bdff8d23803f..ca5464ed04b7 10064

[PATCH 1/4] mm/hugeltb: remove redundant VM_BUG_ON() in region_add()

2021-04-02 Thread Miaohe Lin
The same VM_BUG_ON() check is already done in the callee. Remove this extra one to simplify the code slightly. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c22111f3da20..a03a50b7c410 100644 --- a/mm/hugetlb.c

[PATCH 2/4] mm/hugeltb: simplify the return code of __vma_reservation_common()

2021-04-02 Thread Miaohe Lin
It's guaranteed that the vma is associated with a resv_map, i.e. either VM_MAYSHARE or HPAGE_RESV_OWNER, when the code reaches here or we would have returned via !resv check above. So ret must be less than 0 in the 'else' case. Simplify the return code to make this clear. Signed-off-by: Miaohe

[PATCH 0/4] Cleanup and fixup for hugetlb

2021-04-02 Thread Miaohe Lin
Hi all, This series contains cleanups to remove redundant VM_BUG_ON() and simplify the return code. Also this fixes potential wrong gbl_reserve value and handle the error case in hugetlb_fix_reserve_counts(). More details can be found in the respective changelogs. Thanks! Miaohe Lin (4): mm

Re: [PATCH] mm: memcontrol: fix forget to obtain the ref to objcg in split_page_memcg

2021-03-31 Thread Miaohe Lin
On 2021/4/1 11:35, Roman Gushchin wrote: > On Thu, Apr 01, 2021 at 11:31:16AM +0800, Miaohe Lin wrote: >> On 2021/4/1 11:01, Muchun Song wrote: >>> Christian Borntraeger reported a warning about "percpu ref >>> (obj_cgroup_release) <= 0 (-1) after switchin

Re: [PATCH] mm: memcontrol: fix forget to obtain the ref to objcg in split_page_memcg

2021-03-31 Thread Miaohe Lin
On 2021/4/1 11:01, Muchun Song wrote: > Christian Borntraeger reported a warning about "percpu ref > (obj_cgroup_release) <= 0 (-1) after switching to atomic". > Because we forgot to obtain the reference to the objcg and > wrongly obtain the reference of memcg. > > Reported-by: Christian

[PATCH 3/4] ksm: remove dedicated macro KSM_FLAG_MASK

2021-03-30 Thread Miaohe Lin
The macro KSM_FLAG_MASK is used in rmap_walk_ksm() only. So we can replace ~KSM_FLAG_MASK with PAGE_MASK to remove this dedicated macro and make code more consistent because PAGE_MASK is used elsewhere in this file. Signed-off-by: Miaohe Lin --- mm/ksm.c | 4 +--- 1 file changed, 1 insertion

[PATCH 1/4] ksm: remove redundant VM_BUG_ON_PAGE() on stable_tree_search()

2021-03-30 Thread Miaohe Lin
The same VM_BUG_ON_PAGE() check is already done in the callee. Remove these extra caller one to simplify code slightly. Signed-off-by: Miaohe Lin --- mm/ksm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 1f2c62e1d797..359afb3023b4 100644 --- a/mm/ksm.c +++ b/mm

[PATCH 4/4] ksm: fix potential missing rmap_item for stable_node

2021-03-30 Thread Miaohe Lin
ble_node return; We would miss the rmap_item for stable_node and might result in failed rmap_walk_ksm(). Fix this by set rmap_item->head to NULL when rmap_item is removed from stable tree. Fixes: 4146d2d673e8 ("ksm: make !merge_across_nodes migration safe") Signed-off-by: Miaohe

[PATCH 2/4] ksm: use GET_KSM_PAGE_NOLOCK to get ksm page in remove_rmap_item_from_tree()

2021-03-30 Thread Miaohe Lin
It's unnecessary to lock the page when get ksm page if we're going to remove the rmap item as page migration is irrelevant in this case. Use GET_KSM_PAGE_NOLOCK instead to save some page lock cycles. Signed-off-by: Miaohe Lin --- mm/ksm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions

[PATCH 0/4] Cleanup and fixup for ksm

2021-03-30 Thread Miaohe Lin
Hi all, This series contains cleanups to remove unnecessary VM_BUG_ON_PAGE and dedicated macro KSM_FLAG_MASK. Also this fixes potential missing rmap_item for stable_node which would result in failed rmap_walk_ksm(). More details can be found in the respective changelogs. Thanks! Miaohe Lin (4

Re: [Question] Is there a race window between swapoff vs synchronous swap_readpage

2021-03-30 Thread Miaohe Lin
On 2021/3/30 11:44, Huang, Ying wrote: > Miaohe Lin writes: > >> On 2021/3/30 9:57, Huang, Ying wrote: >>> Hi, Miaohe, >>> >>> Miaohe Lin writes: >>> >>>> Hi all, >>>> I am investigating the swap

Re: [Question] Is there a race window between swapoff vs synchronous swap_readpage

2021-03-29 Thread Miaohe Lin
On 2021/3/30 9:57, Huang, Ying wrote: > Hi, Miaohe, > > Miaohe Lin writes: > >> Hi all, >> I am investigating the swap code, and I found the below possible race window: >> >> CPU 1

Re: [PATCH v2 5/8] hugetlb: call update_and_free_page without hugetlb_lock

2021-03-29 Thread Miaohe Lin
by: Michal Hocko > Reviewed-by: Muchun Song Looks good to me. Thanks! Reviewed-by: Miaohe Lin > --- > mm/hugetlb.c | 32 +++- > 1 file changed, 27 insertions(+), 5 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 16bea

[Question] Is there a race window between swapoff vs synchronous swap_readpage

2021-03-29 Thread Miaohe Lin
Hi all, I am investigating the swap code, and I found the below possible race window: CPU 1 CPU 2 - - do_swap_page skip swapcache case (synchronous swap_readpage) alloc_page_vma

Re: [PATCH 4/8] hugetlb: create remove_hugetlb_page() to separate functionality

2021-03-26 Thread Miaohe Lin
On 2021/3/27 3:57, Mike Kravetz wrote: > On 3/25/21 7:10 PM, Miaohe Lin wrote: >> On 2021/3/25 8:28, Mike Kravetz wrote: >>> The new remove_hugetlb_page() routine is designed to remove a hugetlb >>> page from hugetlbfs processing. It will remove the page from the acti

Re: [PATCH 8/8] hugetlb: add lockdep_assert_held() calls for hugetlb_lock

2021-03-25 Thread Miaohe Lin
On 2021/3/25 8:28, Mike Kravetz wrote: > After making hugetlb lock irq safe and separating some functionality > done under the lock, add some lockdep_assert_held to help verify > locking. > Looks good to me. Thanks. Reviewed-by: Miaohe Lin > Signed-off-by: Mike Kravetz > -

Re: [PATCH 4/8] hugetlb: create remove_hugetlb_page() to separate functionality

2021-03-25 Thread Miaohe Lin
s > + *which operate on the resulting compound page. It seems HPageFreed and HPageTemporary is cleared. Which hugetlb specific page flags is reserverd here and why? Could you please give a simple example to clarify this in the comment to help understand this NOTE? The code looks g

Re: [PATCH 3/8] hugetlb: add per-hstate mutex to synchronize user adjustments

2021-03-25 Thread Miaohe Lin
; + struct mutex mutex; I am also with Michal and Oscar here, renaming the mutex to something closer to its function. Reviewed-by: Miaohe Lin > int next_nid_to_alloc; > int next_nid_to_free; > unsigned int order; > diff --git a/mm/hugetlb.c b/mm/hugetlb.c &

Re: [PATCH 0/8] make hugetlb put_page safe for all calling contexts

2021-03-25 Thread Miaohe Lin
Hi: On 2021/3/25 8:28, Mike Kravetz wrote: > This effort is the result a recent bug report [1]. In subsequent > discussions [2], it was deemed necessary to properly fix the hugetlb Many thanks for the effort. I have read the discussions and it is pretty long. Maybe it would be helpful if you

[PATCH 0/3] Cleanup for khugepaged

2021-03-25 Thread Miaohe Lin
Hi all, This series contains cleanups to remove unnecessary out label and meaningless !pte_present() check. Also use helper function to simplify the code. More details can be found in the respective changelogs. Thanks! Miaohe Lin (3): khugepaged: use helper function range_in_vma

[PATCH 3/3] khugepaged: remove meaningless !pte_present() check in khugepaged_scan_pmd()

2021-03-25 Thread Miaohe Lin
We know it must meet the !is_swap_pte() and !pte_none() condition if we reach here. Since !is_swap_pte() indicates pte_none() or pte_present() is met, it's guaranteed that pte must be present here. Signed-off-by: Miaohe Lin --- mm/khugepaged.c | 4 1 file changed, 4 deletions(-) diff

[PATCH 2/3] khugepaged: remove unnecessary out label in collapse_huge_page()

2021-03-25 Thread Miaohe Lin
The out label here is unneeded because it just goes to out_up_write label. Remove it to make code more concise. Signed-off-by: Miaohe Lin --- mm/khugepaged.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index ad0444f3f487

[PATCH 1/3] khugepaged: use helper function range_in_vma() in collapse_pte_mapped_thp()

2021-03-25 Thread Miaohe Lin
We could use helper function range_in_vma() to check whether the desired range is inside the vma to simplify the code. Signed-off-by: Miaohe Lin --- mm/khugepaged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b81521dfbb1a

[PATCH v3 1/5] mm/migrate.c: make putback_movable_page() static

2021-03-25 Thread Miaohe Lin
The putback_movable_page() is just called by putback_movable_pages() and we know the page is locked and both PageMovable() and PageIsolated() is checked right before calling putback_movable_page(). So we make it static and remove all the 3 VM_BUG_ON_PAGE(). Signed-off-by: Miaohe Lin --- include

[PATCH v3 5/5] Revert "mm: migrate: skip shared exec THP for NUMA balancing"

2021-03-25 Thread Miaohe Lin
e first place." Reviewed-by: Yang Shi Signed-off-by: Miaohe Lin --- mm/migrate.c | 18 ++ 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index c621c8f6fb7d..51190759e6dd 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -210

[PATCH v3 4/5] mm/migrate.c: use helper migrate_vma_collect_skip() in migrate_vma_collect_hole()

2021-03-25 Thread Miaohe Lin
It's more recommended to use helper function migrate_vma_collect_skip() to skip the unexpected case and it also helps remove some duplicated codes. Move migrate_vma_collect_skip() above migrate_vma_collect_hole() to avoid compiler warning. Reviewed-by: David Hildenbrand Signed-off-by: Miaohe Lin

[PATCH v3 2/5] mm/migrate.c: remove unnecessary rc != MIGRATEPAGE_SUCCESS check in 'else' case

2021-03-25 Thread Miaohe Lin
It's guaranteed that in the 'else' case of the rc == MIGRATEPAGE_SUCCESS check, rc does not equal to MIGRATEPAGE_SUCCESS. Remove this unnecessary check. Reviewed-by: David Hildenbrand Reviewed-by: Yang Shi Signed-off-by: Miaohe Lin --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1

[PATCH v3 3/5] mm/migrate.c: fix potential indeterminate pte entry in migrate_vma_insert_page()

2021-03-25 Thread Miaohe Lin
h CPU") Signed-off-by: Miaohe Lin --- mm/migrate.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index dacbdc9710ac..87bbad578127 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2968,6 +2968,13 @@ static void migrate_vma_insert_page(struct migrate_vma

  1   2   3   4   5   >