[PATCH 1/6] mm/huge_memory.c: rework the function vma_adjust_trans_huge()

2021-03-13 Thread Miaohe Lin
The current implementation of vma_adjust_trans_huge() contains some duplicated codes. Add helper function to get rid of these codes to make it more succinct. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 23 +++ 1 file changed, 11 insertions(+), 12 deletions(-) diff

[PATCH 6/6] mm/huge_memory.c: use helper function migration_entry_to_page()

2021-03-13 Thread Miaohe Lin
It's more recommended to use helper function migration_entry_to_page() to get the page via migration entry. We can also enjoy the PageLocked() check there. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b

[PATCH 4/6] mm/huge_memory.c: remove redundant PageCompound() check

2021-03-13 Thread Miaohe Lin
The !PageCompound() check limits the page must be head or tail while !PageHead() further limits it to page head only. So !PageHead() check is equivalent here. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm

[PATCH] mm/huge_memory.c: use helper function migration_entry_to_page()

2021-03-13 Thread Miaohe Lin
It's more recommended to use helper function migration_entry_to_page() to get the page via migration entry. We can also enjoy the PageLocked() check there. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b

Re: [PATCH] mm/huge_memory.c: use helper function migration_entry_to_page()

2021-03-13 Thread Miaohe Lin
Hi: On 2021/3/13 18:32, Miaohe Lin wrote: > It's more recommended to use helper function migration_entry_to_page() to > get the page via migration entry. We can also enjoy the PageLocked() > check there. > > Signed-off-by: Miaohe Lin My bad! I have send this patch inside anoth

Re: [PATCH 4/5] mm/hugetlb: simplify the code when alloc_huge_page() failed in hugetlb_no_page()

2021-03-12 Thread Miaohe Lin
On 2021/3/13 3:58, Mike Kravetz wrote: > On 3/8/21 3:28 AM, Miaohe Lin wrote: >> Rework the error handling code when alloc_huge_page() failed to remove some >> duplicated code and simplify the code slightly. >> >> Signed-off-by: Miaohe Lin >> --- >> mm/hug

Re: [PATCH v2] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-03-12 Thread Miaohe Lin
On 2021/3/13 3:09, Mike Kravetz wrote: > On 3/1/21 4:05 AM, Miaohe Lin wrote: >> The current implementation of hugetlb_cgroup for shared mappings could have >> different behavior. Consider the following two scenarios: >> >> 1.Assume initial css reference count of hugetlb

Re: [PATCH 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

2021-03-12 Thread Miaohe Lin
Hi: On 2021/3/13 4:03, Mike Kravetz wrote: > On 3/8/21 3:28 AM, Miaohe Lin wrote: >> The fault_mutex hashing overhead can be avoided in truncate_op case because >> page faults can not race with truncation in this routine. So calculate hash >> for fault_mutex only in !truncate

Re: [PATCH v2] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-03-15 Thread Miaohe Lin
On 2021/3/16 2:42, Mike Kravetz wrote: > On 3/12/21 7:11 PM, Miaohe Lin wrote: >> On 2021/3/13 3:09, Mike Kravetz wrote: >>> On 3/1/21 4:05 AM, Miaohe Lin wrote: >>>> The current implementation of hugetlb_cgroup for shared mappings could have >>>> diff

[PATCH v2 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

2021-03-15 Thread Miaohe Lin
The fault_mutex hashing overhead can be avoided in truncate_op case because page faults can not race with truncation in this routine. So calculate hash for fault_mutex only in !truncate_op case to save some cpu cycles. Reviewed-by: Mike Kravetz Signed-off-by: Miaohe Lin Cc: Mike Kravetz

[PATCH v3] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-03-15 Thread Miaohe Lin
elease the reference held by caller when they are done. Fixes: 075a61d07a8e ("hugetlb_cgroup: add accounting for shared mappings") Reported-by: kernel test robot (auto build test ERROR) Reviewed-by: Mike Kravetz Signed-off-by: Miaohe Lin Cc: Aneesh Kumar K.V Cc: Wanpeng Li Cc: Mina A

Re: [PATCH v2 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

2021-03-16 Thread Miaohe Lin
On 2021/3/16 11:07, Mike Kravetz wrote: > On 3/15/21 7:27 PM, Miaohe Lin wrote: >> The fault_mutex hashing overhead can be avoided in truncate_op case >> because page faults can not race with truncation in this routine. So >> calculate hash for fault_mutex only in !truncate

Re: [PATCH 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

2021-03-14 Thread Miaohe Lin
On 2021/3/14 5:17, Mike Kravetz wrote: > On 3/12/21 6:49 PM, Miaohe Lin wrote: >> Hi: >> On 2021/3/13 4:03, Mike Kravetz wrote: >>> On 3/8/21 3:28 AM, Miaohe Lin wrote: >>>> The fault_mutex hashing overhead can be avoided in truncate_op case because >>&

Re: [PATCH 1/6] mm/huge_memory.c: rework the function vma_adjust_trans_huge()

2021-03-14 Thread Miaohe Lin
Hi: On 2021/3/14 4:03, Matthew Wilcox wrote: > On Sat, Mar 13, 2021 at 05:32:19AM -0500, Miaohe Lin wrote: >> +static inline void try_to_split_huge_pmd_address(struct vm_area_struct >> *vma, unsigned long address) >> +{ >> +if (address & ~HPAGE_PMD_MASK

[PATCH v2 4/6] mm/huge_memory.c: remove redundant PageCompound() check

2021-03-16 Thread Miaohe Lin
The !PageCompound() check limits the page must be head or tail while !PageHead() further limits it to page head only. So !PageHead() check is equivalent here. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm

[PATCH v2 2/6] mm/huge_memory.c: make get_huge_zero_page() return bool

2021-03-16 Thread Miaohe Lin
it return bool to save READ_ONCE cpu cycles as the return value is just used to check if huge_zero_page exists. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e943ccbdc9dd

[PATCH v2 3/6] mm/huge_memory.c: rework the function do_huge_pmd_numa_page() slightly

2021-03-16 Thread Miaohe Lin
The current code that checks if migrating misplaced transhuge page is needed is pretty hard to follow. Rework it and add a comment to make its logic more clear and improve readability. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 11 +-- 1 file changed, 5 insertions(+), 6 deletions

[PATCH v2 1/6] mm/huge_memory.c: rework the function vma_adjust_trans_huge()

2021-03-16 Thread Miaohe Lin
The current implementation of vma_adjust_trans_huge() contains some duplicated codes. Add helper function to get rid of these codes to make it more succinct. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 44 +++- 1 file changed, 19 insertions(+), 25

[PATCH v2 0/6] Some cleanups for huge_memory

2021-03-16 Thread Miaohe Lin
Hi all, This series contains cleanups to rework some function logics to make it more readable, use helper function and so on. More details can be found in the respective changelogs. Thanks! v1->v2: rename try_to_split_huge_pmd_address and move up comments. Miaohe Lin (6): mm/huge_memor

[PATCH v2 6/6] mm/huge_memory.c: use helper function migration_entry_to_page()

2021-03-16 Thread Miaohe Lin
It's more recommended to use helper function migration_entry_to_page() to get the page via migration entry. We can also enjoy the PageLocked() check there. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b

[PATCH v2 5/6] mm/huge_memory.c: remove unused macro TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG

2021-03-16 Thread Miaohe Lin
The commit 4958e4d86ecb ("mm: thp: remove debug_cow switch") forgot to remove TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG macro. Remove it here. Signed-off-by: Miaohe Lin --- include/linux/huge_mm.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux

Re: [PATCH v2 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

2021-03-16 Thread Miaohe Lin
On 2021/3/17 8:27, Mike Kravetz wrote: > On 3/15/21 11:49 PM, Miaohe Lin wrote: >> On 2021/3/16 11:07, Mike Kravetz wrote: >>> On 3/15/21 7:27 PM, Miaohe Lin wrote: >>>> The fault_mutex hashing overhead can be avoided in truncate_op case >>>> becaus

Re: [PATCH v2 1/6] mm/huge_memory.c: rework the function vma_adjust_trans_huge()

2021-03-16 Thread Miaohe Lin
Hi: On 2021/3/17 4:40, Peter Xu wrote: > On Tue, Mar 16, 2021 at 08:40:02AM -0400, Miaohe Lin wrote: >> +static inline void split_huge_pmd_if_needed(struct vm_area_struct *vma, >> unsigned long address) >> +{ >> +/* >> + * If the new address isn't hpag

[PATCH v3 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

2021-03-18 Thread Miaohe Lin
The fault_mutex hashing overhead can be avoided in truncate_op case because page faults can not race with truncation in this routine. So calculate hash for fault_mutex only in !truncate_op case to save some cpu cycles. Reviewed-by: Mike Kravetz Signed-off-by: Miaohe Lin Cc: Mike Kravetz

[PATCH v3 0/6] Some cleanups for huge_memory

2021-03-18 Thread Miaohe Lin
rename try_to_split_huge_pmd_address and move up comments. Miaohe Lin (6): mm/huge_memory.c: rework the function vma_adjust_trans_huge() mm/huge_memory.c: make get_huge_zero_page() return bool mm/huge_memory.c: rework the function do_huge_pmd_numa_page() slightly mm/huge_memory.c: remove redundant PageCompound()

[PATCH v3 4/6] mm/huge_memory.c: remove redundant PageCompound() check

2021-03-18 Thread Miaohe Lin
The !PageCompound() check limits the page must be head or tail while !PageHead() further limits it to page head only. So !PageHead() check is equivalent here. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm

[PATCH v3 6/6] mm/huge_memory.c: use helper function migration_entry_to_page()

2021-03-18 Thread Miaohe Lin
It's more recommended to use helper function migration_entry_to_page() to get the page via migration entry. We can also enjoy the PageLocked() check there. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b

[PATCH v3 3/6] mm/huge_memory.c: rework the function do_huge_pmd_numa_page() slightly

2021-03-18 Thread Miaohe Lin
The current code that checks if migrating misplaced transhuge page is needed is pretty hard to follow. Rework it and add a comment to make its logic more clear and improve readability. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 11 +-- 1 file changed, 5 insertions(+), 6 deletions

[PATCH v3 1/6] mm/huge_memory.c: rework the function vma_adjust_trans_huge()

2021-03-18 Thread Miaohe Lin
The current implementation of vma_adjust_trans_huge() contains some duplicated codes. Add helper function to get rid of these codes to make it more succinct. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 44 +++- 1 file changed, 19 insertions(+), 25

[PATCH v3 2/6] mm/huge_memory.c: make get_huge_zero_page() return bool

2021-03-18 Thread Miaohe Lin
it return bool to save READ_ONCE cpu cycles as the return value is just used to check if huge_zero_page exists. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ae16a82da823

[PATCH v3 5/6] mm/huge_memory.c: remove unused macro TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG

2021-03-18 Thread Miaohe Lin
The commit 4958e4d86ecb ("mm: thp: remove debug_cow switch") forgot to remove TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG macro. Remove it here. Signed-off-by: Miaohe Lin --- include/linux/huge_mm.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux

Re: [PATCH 1/5] mm/migrate.c: remove unnecessary VM_BUG_ON_PAGE on putback_movable_page()

2021-03-21 Thread Miaohe Lin
Hi: On 2021/3/20 22:11, Rafael Aquini wrote: > On Sat, Mar 20, 2021 at 05:36:57AM -0400, Miaohe Lin wrote: >> The !PageLocked() check is implicitly done in PageMovable(). Remove this >> explicit one. >> > > I'd just keep the explicit assertion in place, regardless. >

[PATCH 0/5] Cleanup and fixup for mm/migrate.c

2021-03-20 Thread Miaohe Lin
in the respective changelogs. Thanks! Miaohe Lin (5): mm/migrate.c: remove unnecessary VM_BUG_ON_PAGE on putback_movable_page() mm/migrate.c: remove unnecessary rc != MIGRATEPAGE_SUCCESS check in 'else' case mm/migrate.c: fix potential indeterminate pte entry in migrate_vma_insert_page

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

2021-03-20 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 20a3bf75270a..271081b014cb 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2972,6 +2972,13 @@ static void migrate_vma_insert_page(struct migrate_vma

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

2021-03-20 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. Signed-off-by: Miaohe Lin --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c

[PATCH 5/5] mm/migrate.c: fix potential deadlock in NUMA balancing shared exec THP case

2021-03-20 Thread Miaohe Lin
: migrate: skip shared exec THP for NUMA balancing") Signed-off-by: Miaohe Lin --- mm/migrate.c | 4 1 file changed, 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 3e169b72d7b2..67a941c52b6d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2192,9 +2192,6 @@ int migrate_misp

[PATCH 1/5] mm/migrate.c: remove unnecessary VM_BUG_ON_PAGE on putback_movable_page()

2021-03-20 Thread Miaohe Lin
The !PageLocked() check is implicitly done in PageMovable(). Remove this explicit one. Signed-off-by: Miaohe Lin --- mm/migrate.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 47df0df8f21a..e4ca5ef508ea 100644 --- a/mm/migrate.c +++ b/mm/migrate.c

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

2021-03-20 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. Signed-off-by: Miaohe Lin --- mm/migrate.c | 28

Re: [PATCH] mm/hugetlb: use some helper functions to cleanup code

2021-03-02 Thread Miaohe Lin
On 2021/2/10 14:53, Miaohe Lin wrote: > We could use pages_per_huge_page to get the number of pages per hugepage, > use get_hstate_idx to calculate hstate index, and use hstate_is_gigantic > to check if a hstate is gigantic to make code more succinct. > > Signed-off-by: Miaohe Lin

[PATCH 2/5] khugepaged: reuse the smp_wmb() inside __SetPageUptodate()

2021-03-04 Thread Miaohe Lin
smp_wmb() is needed to avoid the copy_huge_page writes to become visible after the set_pmd_at() write here. But we can reuse the smp_wmb() inside __SetPageUptodate() to remove this redundant one. Signed-off-by: Miaohe Lin --- mm/khugepaged.c | 13 ++--- 1 file changed, 6 insertions

[PATCH 0/5] Cleanup and fixup for khugepaged

2021-03-04 Thread Miaohe Lin
Hi all, This series contains cleanups to remove unneeded return value, use helper function and so on. And there is one fix to correct the wrong result value for trace_mm_collapse_huge_page_isolate(). More details can be found in the respective changelogs. Thanks! Miaohe Lin (5): khugepaged

[PATCH 3/5] khugepaged: use helper khugepaged_test_exit() in __khugepaged_enter()

2021-03-04 Thread Miaohe Lin
Commit 4d45e75a9955 ("mm: remove the now-unnecessary mmget_still_valid() hack") have made khugepaged_test_exit() suitable for check mm->mm_users against 0. Use this helper here. Signed-off-by: Miaohe Lin --- mm/khugepaged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) di

[PATCH 1/5] khugepaged: remove unneeded return value of khugepaged_collapse_pte_mapped_thps()

2021-03-04 Thread Miaohe Lin
The return value of khugepaged_collapse_pte_mapped_thps() is never checked since it's introduced. We should remove such unneeded return value. Signed-off-by: Miaohe Lin --- mm/khugepaged.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/khugepaged.c b/mm

[PATCH 4/5] khugepaged: remove unnecessary mem_cgroup_uncharge() in collapse_[file|huge_page]

2021-03-04 Thread Miaohe Lin
ncorrectly in error path because hpage is not IS_ERR_OR_NULL(). Signed-off-by: Miaohe Lin --- mm/khugepaged.c | 4 1 file changed, 4 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index e886a8618c33..68579cdbdc9b 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1211,8 +1211,6

[PATCH 5/5] khugepaged: fix wrong result value for trace_mm_collapse_huge_page_isolate()

2021-03-04 Thread Miaohe Lin
In writable and !referenced case, the result value should be SCAN_LACK_REFERENCED_PAGE for trace_mm_collapse_huge_page_isolate() instead of default 0 (SCAN_FAIL) here. Fixes: 7d2eba0557c1 ("mm: add tracepoint for scanning pages") Signed-off-by: Miaohe Lin --- mm/khugepa

[PATCH 3/5] hugetlb_cgroup: remove unnecessary VM_BUG_ON_PAGE in hugetlb_cgroup_migrate()

2021-03-08 Thread Miaohe Lin
!PageHuge(oldhpage) is implicitly checked in page_hstate() above, so we remove this explicit one. Signed-off-by: Miaohe Lin --- mm/hugetlb_cgroup.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 8668ba87cfe4..3dde6ddf0170 100644 --- a/mm

[PATCH 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

2021-03-08 Thread Miaohe Lin
The fault_mutex hashing overhead can be avoided in truncate_op case because page faults can not race with truncation in this routine. So calculate hash for fault_mutex only in !truncate_op case to save some cpu cycles. Signed-off-by: Miaohe Lin --- fs/hugetlbfs/inode.c | 4 ++-- 1 file changed

[PATCH 1/5] mm/hugetlb: use some helper functions to cleanup code

2021-03-08 Thread Miaohe Lin
We could use pages_per_huge_page to get the number of pages per hugepage, use get_hstate_idx to calculate hstate index, and use hstate_is_gigantic to check if a hstate is gigantic to make code more succinct. Reviewed-by: Mike Kravetz Signed-off-by: Miaohe Lin --- fs/hugetlbfs/inode.c | 2

[PATCH 2/5] mm/hugetlb: optimize the surplus state transfer code in move_hugetlb_state()

2021-03-08 Thread Miaohe Lin
We should not transfer the per-node surplus state when we do not cross the node in order to save some cpu cycles Reviewed-by: Mike Kravetz Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 33a3edf79022

Re: [PATCH] mm/huge_memory.c: Remove unnecessary local variable ret2

2021-03-08 Thread Miaohe Lin
Hi: On 2021/2/10 15:24, Miaohe Lin wrote: > There is no need to use a new local variable ret2 to get the return value > of handle_userfault(). Use ret directly to make code more succinct. > > Signed-off-by: Miaohe Lin friendly ping in case it's forgotten. :) > --- > mm

[PATCH 4/5] mm/hugetlb: simplify the code when alloc_huge_page() failed in hugetlb_no_page()

2021-03-08 Thread Miaohe Lin
Rework the error handling code when alloc_huge_page() failed to remove some duplicated code and simplify the code slightly. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 9 +++-- 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 695603071f2c

[PATCH 0/5] Some cleanups for hugetlb

2021-03-08 Thread Miaohe Lin
Hi all, This series contains cleanups to remove unnecessary VM_BUG_ON_PAGE, use helper function and so on. I also collect some previous patches into this series in case they are forgotten. More details can be found in the respective changelogs. Thanks! Miaohe Lin (5): mm/hugetlb: use some

Re: [PATCH] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-03-01 Thread Miaohe Lin
> v5.11-rc6 v5.11-rc5] > [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/Miaohe

[PATCH v2] hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings

2021-03-01 Thread Miaohe Lin
for each file_region and release the reference held by caller when they are done. Fixes: 075a61d07a8e ("hugetlb_cgroup: add accounting for shared mappings") Reported-by: kernel test robot (auto build test ERROR) Signed-off-by: Miaohe Lin Cc: sta...@kernel.org --- v1->v2: Fix auto

[PATCH v2] mm/hugetlb: remove redundant reservation check condition in alloc_huge_page()

2021-03-01 Thread Miaohe Lin
in the expression: map_chg || avoid_reserve || !vma_resv_map(vma); Remove the redundant check. [Thanks Mike Kravetz for reshaping this commit message!] Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index

Re: [PATCH 0/5] Cleanup and fixup for khugepaged

2021-03-05 Thread Miaohe Lin
On 2021/3/6 1:40, Kirill A. Shutemov wrote: > On Thu, Mar 04, 2021 at 07:30:08AM -0500, Miaohe Lin wrote: >> Hi all, >> This series contains cleanups to remove unneeded return value, use >> helper function and so on. And there is one fix to correct the

Re: [PATCH 4/5] khugepaged: remove unnecessary mem_cgroup_uncharge() in collapse_[file|huge_page]

2021-03-05 Thread Miaohe Lin
On 2021/3/6 1:38, Kirill A. Shutemov wrote: > On Thu, Mar 04, 2021 at 07:30:12AM -0500, Miaohe Lin wrote: >> Since commit 7ae88534cdd9 ("mm: move mem_cgroup_uncharge out of >> __page_cache_release()"), the mem_cgroup will be uncharged when hpage is >> freed. Uncha

[PATCH v2 3/4] khugepaged: use helper khugepaged_test_exit() in __khugepaged_enter()

2021-03-05 Thread Miaohe Lin
Commit 4d45e75a9955 ("mm: remove the now-unnecessary mmget_still_valid() hack") have made khugepaged_test_exit() suitable for check mm->mm_users against 0. Use this helper here. Signed-off-by: Miaohe Lin Acked-by: Kirill A. Shutemov --- mm/khugepaged.c | 2 +- 1 file changed, 1 in

[PATCH v2 0/4] Cleanup and fixup for khugepaged

2021-03-05 Thread Miaohe Lin
tch "khugepaged: remove unnecessary mem_cgroup_uncharge() in collapse_[file|huge_page]" collect Acked-by Miaohe Lin (4): khugepaged: remove unneeded return value of khugepaged_collapse_pte_mapped_thps() khugepaged: reuse the smp_wmb() inside __SetPageUptodate() khugepage

[PATCH v2 1/4] khugepaged: remove unneeded return value of khugepaged_collapse_pte_mapped_thps()

2021-03-05 Thread Miaohe Lin
The return value of khugepaged_collapse_pte_mapped_thps() is never checked since it's introduced. We should remove such unneeded return value. Signed-off-by: Miaohe Lin Acked-by: Kirill A. Shutemov --- mm/khugepaged.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git

[PATCH v2 4/4] khugepaged: fix wrong result value for trace_mm_collapse_huge_page_isolate()

2021-03-05 Thread Miaohe Lin
In writable and !referenced case, the result value should be SCAN_LACK_REFERENCED_PAGE for trace_mm_collapse_huge_page_isolate() instead of default 0 (SCAN_FAIL) here. Fixes: 7d2eba0557c1 ("mm: add tracepoint for scanning pages") Signed-off-by: Miaohe Lin Acked-by: Kirill A. Shutemo

[PATCH v2 2/4] khugepaged: reuse the smp_wmb() inside __SetPageUptodate()

2021-03-05 Thread Miaohe Lin
smp_wmb() is needed to avoid the copy_huge_page writes to become visible after the set_pmd_at() write here. But we can reuse the smp_wmb() inside __SetPageUptodate() to remove this redundant one. Signed-off-by: Miaohe Lin Acked-by: Kirill A. Shutemov --- mm/khugepaged.c | 13 ++--- 1

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 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 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 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 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: >

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 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 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 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
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 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-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: [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 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: [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] 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 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 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 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 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 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 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 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-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] 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 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 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 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 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] 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 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

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 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 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: >>&

<    1   2   3   4   5   >