diff mbox series

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

Message ID 20210313103225.16607-2-linmiaohe@huawei.com (mailing list archive)
State New, archived
Headers show
Series Some cleanups for huge_memory | expand

Commit Message

Miaohe Lin March 13, 2021, 10:32 a.m. UTC
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 <linmiaohe@huawei.com>
---
 mm/huge_memory.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

Comments

Matthew Wilcox (Oracle) March 13, 2021, 8:03 p.m. UTC | #1
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 &&
> +	    range_in_vma(vma, address & HPAGE_PMD_MASK,
> +			 (address & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE))
> +		split_huge_pmd_address(vma, address, false, NULL);
> +}

This isn't "try to split".  This is "split if needed".  I think the
comments also need to be moved up here.

I'm not even sure this is really an improvement.
Miaohe Lin March 15, 2021, 2:04 a.m. UTC | #2
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 &&
>> +	    range_in_vma(vma, address & HPAGE_PMD_MASK,
>> +			 (address & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE))
>> +		split_huge_pmd_address(vma, address, false, NULL);
>> +}
> 
> This isn't "try to split".  This is "split if needed".  I think the
> comments also need to be moved up here.
> 

Make sense. Would do it in v2! Thanks!

> I'm not even sure this is really an improvement.
> .
> 

At least we can eliminate a couple of duplicated lines and use helper range_in_vma() to improve
the readability slightly. Right? :)
diff mbox series

Patch

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index bff92dea5ab3..3303576489d5 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2301,6 +2301,14 @@  void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address,
 	__split_huge_pmd(vma, pmd, address, freeze, page);
 }
 
+static inline void try_to_split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address)
+{
+	if (address & ~HPAGE_PMD_MASK &&
+	    range_in_vma(vma, address & HPAGE_PMD_MASK,
+			 (address & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE))
+		split_huge_pmd_address(vma, address, false, NULL);
+}
+
 void vma_adjust_trans_huge(struct vm_area_struct *vma,
 			     unsigned long start,
 			     unsigned long end,
@@ -2311,20 +2319,14 @@  void vma_adjust_trans_huge(struct vm_area_struct *vma,
 	 * previously contain an hugepage: check if we need to split
 	 * an huge pmd.
 	 */
-	if (start & ~HPAGE_PMD_MASK &&
-	    (start & HPAGE_PMD_MASK) >= vma->vm_start &&
-	    (start & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE <= vma->vm_end)
-		split_huge_pmd_address(vma, start, false, NULL);
+	try_to_split_huge_pmd_address(vma, start);
 
 	/*
 	 * If the new end address isn't hpage aligned and it could
 	 * previously contain an hugepage: check if we need to split
 	 * an huge pmd.
 	 */
-	if (end & ~HPAGE_PMD_MASK &&
-	    (end & HPAGE_PMD_MASK) >= vma->vm_start &&
-	    (end & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE <= vma->vm_end)
-		split_huge_pmd_address(vma, end, false, NULL);
+	try_to_split_huge_pmd_address(vma, end);
 
 	/*
 	 * If we're also updating the vma->vm_next->vm_start, if the new
@@ -2335,10 +2337,7 @@  void vma_adjust_trans_huge(struct vm_area_struct *vma,
 		struct vm_area_struct *next = vma->vm_next;
 		unsigned long nstart = next->vm_start;
 		nstart += adjust_next;
-		if (nstart & ~HPAGE_PMD_MASK &&
-		    (nstart & HPAGE_PMD_MASK) >= next->vm_start &&
-		    (nstart & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE <= next->vm_end)
-			split_huge_pmd_address(next, nstart, false, NULL);
+		try_to_split_huge_pmd_address(next, nstart);
 	}
 }