Skip to contentSkip to conversation

mm/shmem: remove redundant entry_order variable in shmem_split_large_entry()

PATCH New Jackie Liu 2 participants 4 messages Sep 8, 2025

Subsystems (2)
lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH 1/1 mm/shmem: remove redundant entry_order variable in shmem_split_large_entry()

From: Jackie Liu <[email protected]>

Commit d53c78fffe7a ("mm/shmem: use xas_try_split() in shmem_split_large_entry()") reworked shmem_split_large_entry() to use xas_try_split() and simplified the splitting logic. After that change, the local variable entry_order became redundant since its value was always immediately copied to cur_order. Remove entry_order and use cur_order directly to simplify the code.

No functional change intended.

---
 mm/shmem.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
mm/shmem.c +4 -7
index e2c76a30802b..53d28ea6e52b 100644
@@ -2235,7 +2235,7 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index,
 {
 	struct address_space *mapping = inode->i_mapping;
 	XA_STATE_ORDER(xas, &mapping->i_pages, index, 0);
-	int split_order = 0, entry_order;
+	int split_order = 0;
 	int i;
 
 	/* Convert user data gfp flags to xarray node gfp flags */
@@ -2253,15 +2253,12 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index,
 			goto unlock;
 		}
 
-		entry_order = xas_get_order(&xas);
-
-		if (!entry_order)
+		cur_order = xas_get_order(&xas);
+		if (!cur_order)
 			goto unlock;
 
 		/* Try to split large swap entry in pagecache */
-		cur_order = entry_order;
-		swap_index = round_down(index, 1 << entry_order);
-
+		swap_index = round_down(index, 1 << cur_order);
 		split_order = xas_try_split_min_order(cur_order);
 
 		while (cur_order > 0) {
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH 1/1 mm/shmem: remove redundant entry_order variable in shmem_split_large_entry()

From: Jackie Liu <[email protected]>

Commit d53c78fffe7a ("mm/shmem: use xas_try_split() in shmem_split_large_entry()") reworked shmem_split_large_entry() to use xas_try_split() and simplified the splitting logic. After that change, the local variable entry_order became redundant since its value was always immediately copied to cur_order. Remove entry_order and use cur_order directly to simplify the code.

No functional change intended.

---
 mm/shmem.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
mm/shmem.c +4 -7
index e2c76a30802b..53d28ea6e52b 100644
@@ -2235,7 +2235,7 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index,
 {
 	struct address_space *mapping = inode->i_mapping;
 	XA_STATE_ORDER(xas, &mapping->i_pages, index, 0);
-	int split_order = 0, entry_order;
+	int split_order = 0;
 	int i;
 
 	/* Convert user data gfp flags to xarray node gfp flags */
@@ -2253,15 +2253,12 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index,
 			goto unlock;
 		}
 
-		entry_order = xas_get_order(&xas);
-
-		if (!entry_order)
+		cur_order = xas_get_order(&xas);
+		if (!cur_order)
 			goto unlock;
 
 		/* Try to split large swap entry in pagecache */
-		cur_order = entry_order;
-		swap_index = round_down(index, 1 << entry_order);
-
+		swap_index = round_down(index, 1 << cur_order);
 		split_order = xas_try_split_min_order(cur_order);
 
 		while (cur_order > 0) {
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#2 lore raw
Quoted 7 lines · Jackie Liu

From: Jackie Liu <[email protected]>

Commit d53c78fffe7a ("mm/shmem: use xas_try_split() in shmem_split_large_entry()") reworked shmem_split_large_entry() to use xas_try_split() and simplified the splitting logic. After that change, the local variable entry_order became redundant since its value was always immediately copied to cur_order. Remove entry_order and use cur_order directly to simplify the code.

The commit message is a bit misleading. It does not introduce a redundant variable by commit d53c78fffe7a. Instead, it's because after commit 93c0476e7057 ("mm/shmem, swap: rework swap entry and index calculation for large swapin"), the 'entry_order' will never be returned.

Quoted 4 lines

No functional change intended.

---

With the commit message updated:

Quoted 35 lines
  mm/shmem.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
mm/shmem.c +4 -7
index e2c76a30802b..53d28ea6e52b 100644
@@ -2235,7 +2235,7 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index,
  {
  	struct address_space *mapping = inode->i_mapping;
  	XA_STATE_ORDER(xas, &mapping->i_pages, index, 0);
-	int split_order = 0, entry_order;
+	int split_order = 0;
  	int i;
 
  	/* Convert user data gfp flags to xarray node gfp flags */
@@ -2253,15 +2253,12 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index,
  			goto unlock;
  		}
 
-		entry_order = xas_get_order(&xas);
-
-		if (!entry_order)
+		cur_order = xas_get_order(&xas);
+		if (!cur_order)
  			goto unlock;
 
  		/* Try to split large swap entry in pagecache */
-		cur_order = entry_order;
-		swap_index = round_down(index, 1 << entry_order);
-
+		swap_index = round_down(index, 1 << cur_order);
  		split_order = xas_try_split_min_order(cur_order);
 
  		while (cur_order > 0) {
author
#3 lore raw

Hi Baolin.

2025年9月8日 14:05, "Baolin Wang" <[email protected] mailto:[email protected]?to=%22Baolin%20Wang%22%20%3Cbaolin.wang%40linux.alibaba.com%3E > 写到:

Quoted 13 lines · Jackie Liu
Quoted 9 lines

From: Jackie Liu <[email protected]>
Commit d53c78fffe7a ("mm/shmem: use xas_try_split() in shmem_split_large_entry()") reworked shmem_split_large_entry() to use xas_try_split() and simplified the splitting logic. After that change, the local variable entry_order became redundant since its value was always immediately copied to cur_order. Remove entry_order and use cur_order directly to simplify the code.

The commit message is a bit misleading. It does not introduce a redundant variable by commit d53c78fffe7a. Instead, it's because after commit 93c0476e7057 ("mm/shmem, swap: rework swap entry and index calculation for large swapin"), the 'entry_order' will never be returned.

Aha, Thanks, you’re right. This is indeed the correct commit. When I applied this series of patches locally, I accidentally used an earlier prerequisite patch. I made a mistake when copying it. Thanks again—I’ll update the comment and resend version 2.

Signature · 1 line
Jackie Liu
Quoted 41 lines
Quoted 5 lines

No functional change intended.

---

With the commit message updated:

Quoted 32 lines

mm/shmem.c | 11 ++++-------

 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index e2c76a30802b..53d28ea6e52b 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2235,7 +2235,7 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index, {
struct address_space *mapping = inode->i_mapping;
XA_STATE_ORDER(xas, &mapping->i_pages, index, 0);
- int split_order = 0, entry_order;
+ int split_order = 0;
int i;

Quoted 1 line

/* Convert user data gfp flags to xarray node gfp flags */

@@ -2253,15 +2253,12 @@ static int shmem_split_large_entry(struct inode *inode, pgoff_t index, goto unlock;
}

Quoted 1 line

- entry_order = xas_get_order(&xas);

-
- if (!entry_order)
+ cur_order = xas_get_order(&xas);
+ if (!cur_order)
goto unlock;

Quoted 1 line

/* Try to split large swap entry in pagecache */

- cur_order = entry_order;
- swap_index = round_down(index, 1 << entry_order); -
+ swap_index = round_down(index, 1 << cur_order); split_order = xas_try_split_min_order(cur_order);

Quoted 1 line

while (cur_order > 0) {