Skip to contentSkip to conversation

mm: use vma_policy() to get vm_policy

PATCH In review Shivank Garg 3 participants 3 messages Nov 1, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: use vma_policy() to get vm_policy

Instead of accessing vma->vm_policy directly, use vma_policy() like other places for consistency.

---
 ipc/shm.c      |  2 +-
 mm/mempolicy.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
ipc/shm.c +1 -1
index 99564c870084..ebd45e48b0d4 100644
@@ -577,7 +577,7 @@ static struct mempolicy *shm_get_policy(struct vm_area_struct *vma,
 					unsigned long addr, pgoff_t *ilx)
 {
 	struct shm_file_data *sfd = shm_file_data(vma->vm_file);
-	struct mempolicy *mpol = vma->vm_policy;
+	struct mempolicy *mpol = vma_policy(vma);
 
 	if (sfd->vm_ops->get_policy)
 		mpol = sfd->vm_ops->get_policy(vma, addr, ilx);
mm/mempolicy.c +8 -8
index b646fab3e45e..7ccbeb9966f0 100644
@@ -420,7 +420,7 @@ void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
 	mmap_write_lock(mm);
 	for_each_vma(vmi, vma) {
 		vma_start_write(vma);
-		mpol_rebind_policy(vma->vm_policy, new);
+		mpol_rebind_policy(vma_policy(vma), new);
 	}
 	mmap_write_unlock(mm);
 }
@@ -805,8 +805,8 @@ static int vma_replace_policy(struct vm_area_struct *vma,
 			goto err_out;
 	}
 
-	old = vma->vm_policy;
-	vma->vm_policy = new; /* protected by mmap_lock */
+	old = vma_policy(vma);
+	vma_policy(vma) = new; /* protected by mmap_lock */
 	mpol_put(old);
 
 	return 0;
@@ -830,7 +830,7 @@ static int mbind_range(struct vma_iterator *vmi, struct vm_area_struct *vma,
 		vmstart = vma->vm_start;
 	}
 
-	if (mpol_equal(vma->vm_policy, new_pol)) {
+	if (mpol_equal(vma_policy(vma), new_pol)) {
 		*prev = vma;
 		return 0;
 	}
@@ -1797,7 +1797,7 @@ struct mempolicy *__get_vma_policy(struct vm_area_struct *vma,
 {
 	*ilx = 0;
 	return (vma->vm_ops && vma->vm_ops->get_policy) ?
-		vma->vm_ops->get_policy(vma, addr, ilx) : vma->vm_policy;
+		vma->vm_ops->get_policy(vma, addr, ilx) : vma_policy(vma);
 }
 
 /*
@@ -1847,7 +1847,7 @@ bool vma_policy_mof(struct vm_area_struct *vma)
 		return ret;
 	}
 
-	pol = vma->vm_policy;
+	pol = vma_policy(vma);
 	if (!pol)
 		pol = get_task_policy(current);
 
@@ -2559,11 +2559,11 @@ unsigned long alloc_pages_bulk_array_mempolicy_noprof(gfp_t gfp,
 
 int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
 {
-	struct mempolicy *pol = mpol_dup(src->vm_policy);
+	struct mempolicy *pol = mpol_dup(vma_policy(src));
 
 	if (IS_ERR(pol))
 		return PTR_ERR(pol);
-	dst->vm_policy = pol;
+	vma_policy(dst) = pol;
 	return 0;
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Shivank Garg

Instead of accessing vma->vm_policy directly, use vma_policy() like other places for consistency.

NAK. The vma_policy(vma) wrapper exists to avoid #ifdef CONFIG_NUMAs all over the place; there is no point to it inside CONFIG_NUMA source.

Hugh

Quoted 85 lines
---
 ipc/shm.c      |  2 +-
 mm/mempolicy.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
ipc/shm.c +1 -1
index 99564c870084..ebd45e48b0d4 100644
@@ -577,7 +577,7 @@ static struct mempolicy *shm_get_policy(struct vm_area_struct *vma,
 					unsigned long addr, pgoff_t *ilx)
 {
 	struct shm_file_data *sfd = shm_file_data(vma->vm_file);
-	struct mempolicy *mpol = vma->vm_policy;
+	struct mempolicy *mpol = vma_policy(vma);
 
 	if (sfd->vm_ops->get_policy)
 		mpol = sfd->vm_ops->get_policy(vma, addr, ilx);
mm/mempolicy.c +8 -8
index b646fab3e45e..7ccbeb9966f0 100644
@@ -420,7 +420,7 @@ void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
 	mmap_write_lock(mm);
 	for_each_vma(vmi, vma) {
 		vma_start_write(vma);
-		mpol_rebind_policy(vma->vm_policy, new);
+		mpol_rebind_policy(vma_policy(vma), new);
 	}
 	mmap_write_unlock(mm);
 }
@@ -805,8 +805,8 @@ static int vma_replace_policy(struct vm_area_struct *vma,
 			goto err_out;
 	}
 
-	old = vma->vm_policy;
-	vma->vm_policy = new; /* protected by mmap_lock */
+	old = vma_policy(vma);
+	vma_policy(vma) = new; /* protected by mmap_lock */
 	mpol_put(old);
 
 	return 0;
@@ -830,7 +830,7 @@ static int mbind_range(struct vma_iterator *vmi, struct vm_area_struct *vma,
 		vmstart = vma->vm_start;
 	}
 
-	if (mpol_equal(vma->vm_policy, new_pol)) {
+	if (mpol_equal(vma_policy(vma), new_pol)) {
 		*prev = vma;
 		return 0;
 	}
@@ -1797,7 +1797,7 @@ struct mempolicy *__get_vma_policy(struct vm_area_struct *vma,
 {
 	*ilx = 0;
 	return (vma->vm_ops && vma->vm_ops->get_policy) ?
-		vma->vm_ops->get_policy(vma, addr, ilx) : vma->vm_policy;
+		vma->vm_ops->get_policy(vma, addr, ilx) : vma_policy(vma);
 }
 
 /*
@@ -1847,7 +1847,7 @@ bool vma_policy_mof(struct vm_area_struct *vma)
 		return ret;
 	}
 
-	pol = vma->vm_policy;
+	pol = vma_policy(vma);
 	if (!pol)
 		pol = get_task_policy(current);
 
@@ -2559,11 +2559,11 @@ unsigned long alloc_pages_bulk_array_mempolicy_noprof(gfp_t gfp,
 
 int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
 {
-	struct mempolicy *pol = mpol_dup(src->vm_policy);
+	struct mempolicy *pol = mpol_dup(vma_policy(src));
 
 	if (IS_ERR(pol))
 		return PTR_ERR(pol);
-	dst->vm_policy = pol;
+	vma_policy(dst) = pol;
 	return 0;
 }
 
Signature · 1 line
2.34.1
maintainer
#2 lore raw
Quoted 5 lines · Hugh Dickins
Quoted 3 lines · Shivank Garg

Instead of accessing vma->vm_policy directly, use vma_policy() like other places for consistency.

Quoted 7 lines
Quoted 1 line

NAK. The vma_policy(vma) wrapper exists to avoid #ifdef CONFIG_NUMAs all over the place; there is no point to it inside CONFIG_NUMA source.

Hugh

In that case we should do the opposite of this patch inside mempolicy.c

Only 1 place to update

~Gregory

mm/mempolicy.c +1 -1
index b858e22b259d..beffdc17aad5 100644
@@ -1572,7 +1572,7 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
                 * or MPOL_PREFERRED_MANY we return error. We don't reset
                 * the home node for vmas we already updated before.
                 */
-               old = vma_policy(vma);
+               old = vma->vm_policy;
                if (!old) {
                        prev = vma;
                        continue;