Message ID | 20240620212935.656243-2-david@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm/migrate: move NUMA hinting fault folio isolation + checks under PTL | expand |
On 20 Jun 2024, at 17:29, David Hildenbrand wrote: > Let's just return 0 on success, which is less confusing. > > ... especially because we got it wrong in the migrate.h stub where we > have "return -EAGAIN; /* can't migrate now */" instead of "return 0;". > Likely this wrong return value doesn't currently matter, but it > certainly adds confusion. > > We'll add migrate_misplaced_folio_prepare() next, where we want to use > the same "return 0 on success" approach, so let's just clean this up. > > Signed-off-by: David Hildenbrand <david@redhat.com> > --- > mm/huge_memory.c | 5 ++--- > mm/memory.c | 2 +- > mm/migrate.c | 4 ++-- > 3 files changed, 5 insertions(+), 6 deletions(-) > LGTM. Reviewed-by: Zi Yan <ziy@nvidia.com> -- Best Regards, Yan, Zi
On 2024/6/21 05:29, David Hildenbrand wrote: > Let's just return 0 on success, which is less confusing. > > ... especially because we got it wrong in the migrate.h stub where we > have "return -EAGAIN; /* can't migrate now */" instead of "return 0;". > Likely this wrong return value doesn't currently matter, but it > certainly adds confusion. > > We'll add migrate_misplaced_folio_prepare() next, where we want to use > the same "return 0 on success" approach, so let's just clean this up LGTM. Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> > > Signed-off-by: David Hildenbrand <david@redhat.com> > --- > mm/huge_memory.c | 5 ++--- > mm/memory.c | 2 +- > mm/migrate.c | 4 ++-- > 3 files changed, 5 insertions(+), 6 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 0fffaa58a47a..fc27dabcd8e3 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1652,7 +1652,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) > unsigned long haddr = vmf->address & HPAGE_PMD_MASK; > int nid = NUMA_NO_NODE; > int target_nid, last_cpupid = (-1 & LAST_CPUPID_MASK); > - bool migrated = false, writable = false; > + bool writable = false; > int flags = 0; > > vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); > @@ -1696,8 +1696,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) > spin_unlock(vmf->ptl); > writable = false; > > - migrated = migrate_misplaced_folio(folio, vma, target_nid); > - if (migrated) { > + if (!migrate_misplaced_folio(folio, vma, target_nid)) { > flags |= TNF_MIGRATED; > nid = target_nid; > } else { > diff --git a/mm/memory.c b/mm/memory.c > index 00728ea95583..118660de5bcc 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5354,7 +5354,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) > ignore_writable = true; > > /* Migrate to the requested node */ > - if (migrate_misplaced_folio(folio, vma, target_nid)) { > + if (!migrate_misplaced_folio(folio, vma, target_nid)) { > nid = target_nid; > flags |= TNF_MIGRATED; > } else { > diff --git a/mm/migrate.c b/mm/migrate.c > index 781979567f64..0307b54879a0 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -2629,11 +2629,11 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, > nr_succeeded); > } > BUG_ON(!list_empty(&migratepages)); > - return isolated; > + return isolated ? 0 : -EAGAIN; > > out: > folio_put(folio); > - return 0; > + return -EAGAIN; > } > #endif /* CONFIG_NUMA_BALANCING */ > #endif /* CONFIG_NUMA */
David Hildenbrand <david@redhat.com> writes: > Let's just return 0 on success, which is less confusing. > > ... especially because we got it wrong in the migrate.h stub where we > have "return -EAGAIN; /* can't migrate now */" instead of "return 0;". > Likely this wrong return value doesn't currently matter, but it > certainly adds confusion. > > We'll add migrate_misplaced_folio_prepare() next, where we want to use > the same "return 0 on success" approach, so let's just clean this up. > > Signed-off-by: David Hildenbrand <david@redhat.com> > --- > mm/huge_memory.c | 5 ++--- > mm/memory.c | 2 +- > mm/migrate.c | 4 ++-- > 3 files changed, 5 insertions(+), 6 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 0fffaa58a47a..fc27dabcd8e3 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1652,7 +1652,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) > unsigned long haddr = vmf->address & HPAGE_PMD_MASK; > int nid = NUMA_NO_NODE; > int target_nid, last_cpupid = (-1 & LAST_CPUPID_MASK); > - bool migrated = false, writable = false; > + bool writable = false; > int flags = 0; > > vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); > @@ -1696,8 +1696,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) > spin_unlock(vmf->ptl); > writable = false; > > - migrated = migrate_misplaced_folio(folio, vma, target_nid); > - if (migrated) { > + if (!migrate_misplaced_folio(folio, vma, target_nid)) { > flags |= TNF_MIGRATED; > nid = target_nid; > } else { > diff --git a/mm/memory.c b/mm/memory.c > index 00728ea95583..118660de5bcc 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5354,7 +5354,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) > ignore_writable = true; > > /* Migrate to the requested node */ > - if (migrate_misplaced_folio(folio, vma, target_nid)) { > + if (!migrate_misplaced_folio(folio, vma, target_nid)) { > nid = target_nid; > flags |= TNF_MIGRATED; > } else { > diff --git a/mm/migrate.c b/mm/migrate.c > index 781979567f64..0307b54879a0 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -2629,11 +2629,11 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, > nr_succeeded); > } > BUG_ON(!list_empty(&migratepages)); > - return isolated; > + return isolated ? 0 : -EAGAIN; Is it good to use -EAGAIN as error code always? At least if nr_remaining < 0, we can use that? Otherwise, this LGTM. Thanks! > > out: > folio_put(folio); > - return 0; > + return -EAGAIN; > } > #endif /* CONFIG_NUMA_BALANCING */ > #endif /* CONFIG_NUMA */ -- Best Regards, Huang, Ying
On 01.07.24 09:36, Huang, Ying wrote: > David Hildenbrand <david@redhat.com> writes: > >> Let's just return 0 on success, which is less confusing. >> >> ... especially because we got it wrong in the migrate.h stub where we >> have "return -EAGAIN; /* can't migrate now */" instead of "return 0;". >> Likely this wrong return value doesn't currently matter, but it >> certainly adds confusion. >> >> We'll add migrate_misplaced_folio_prepare() next, where we want to use >> the same "return 0 on success" approach, so let's just clean this up. >> >> Signed-off-by: David Hildenbrand <david@redhat.com> >> --- >> mm/huge_memory.c | 5 ++--- >> mm/memory.c | 2 +- >> mm/migrate.c | 4 ++-- >> 3 files changed, 5 insertions(+), 6 deletions(-) >> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index 0fffaa58a47a..fc27dabcd8e3 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -1652,7 +1652,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) >> unsigned long haddr = vmf->address & HPAGE_PMD_MASK; >> int nid = NUMA_NO_NODE; >> int target_nid, last_cpupid = (-1 & LAST_CPUPID_MASK); >> - bool migrated = false, writable = false; >> + bool writable = false; >> int flags = 0; >> >> vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); >> @@ -1696,8 +1696,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) >> spin_unlock(vmf->ptl); >> writable = false; >> >> - migrated = migrate_misplaced_folio(folio, vma, target_nid); >> - if (migrated) { >> + if (!migrate_misplaced_folio(folio, vma, target_nid)) { >> flags |= TNF_MIGRATED; >> nid = target_nid; >> } else { >> diff --git a/mm/memory.c b/mm/memory.c >> index 00728ea95583..118660de5bcc 100644 >> --- a/mm/memory.c >> +++ b/mm/memory.c >> @@ -5354,7 +5354,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) >> ignore_writable = true; >> >> /* Migrate to the requested node */ >> - if (migrate_misplaced_folio(folio, vma, target_nid)) { >> + if (!migrate_misplaced_folio(folio, vma, target_nid)) { >> nid = target_nid; >> flags |= TNF_MIGRATED; >> } else { >> diff --git a/mm/migrate.c b/mm/migrate.c >> index 781979567f64..0307b54879a0 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -2629,11 +2629,11 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, >> nr_succeeded); >> } >> BUG_ON(!list_empty(&migratepages)); >> - return isolated; >> + return isolated ? 0 : -EAGAIN; > > Is it good to use -EAGAIN as error code always? At least if > nr_remaining < 0, we can use that? Thanks for the review. I kept it simple for now, because the migrate_misplaced_folio_prepare() stub has: return -EAGAIN; /* can't migrate now */ and it doesn't really make a difference right now which exact return value we use. (maybe some cases, like the stub, should return -EINVAL or -EOPNOTSUPP once we start caring about the exact value)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0fffaa58a47a..fc27dabcd8e3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1652,7 +1652,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) unsigned long haddr = vmf->address & HPAGE_PMD_MASK; int nid = NUMA_NO_NODE; int target_nid, last_cpupid = (-1 & LAST_CPUPID_MASK); - bool migrated = false, writable = false; + bool writable = false; int flags = 0; vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); @@ -1696,8 +1696,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) spin_unlock(vmf->ptl); writable = false; - migrated = migrate_misplaced_folio(folio, vma, target_nid); - if (migrated) { + if (!migrate_misplaced_folio(folio, vma, target_nid)) { flags |= TNF_MIGRATED; nid = target_nid; } else { diff --git a/mm/memory.c b/mm/memory.c index 00728ea95583..118660de5bcc 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5354,7 +5354,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) ignore_writable = true; /* Migrate to the requested node */ - if (migrate_misplaced_folio(folio, vma, target_nid)) { + if (!migrate_misplaced_folio(folio, vma, target_nid)) { nid = target_nid; flags |= TNF_MIGRATED; } else { diff --git a/mm/migrate.c b/mm/migrate.c index 781979567f64..0307b54879a0 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2629,11 +2629,11 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, nr_succeeded); } BUG_ON(!list_empty(&migratepages)); - return isolated; + return isolated ? 0 : -EAGAIN; out: folio_put(folio); - return 0; + return -EAGAIN; } #endif /* CONFIG_NUMA_BALANCING */ #endif /* CONFIG_NUMA */
Let's just return 0 on success, which is less confusing. ... especially because we got it wrong in the migrate.h stub where we have "return -EAGAIN; /* can't migrate now */" instead of "return 0;". Likely this wrong return value doesn't currently matter, but it certainly adds confusion. We'll add migrate_misplaced_folio_prepare() next, where we want to use the same "return 0 on success" approach, so let's just clean this up. Signed-off-by: David Hildenbrand <david@redhat.com> --- mm/huge_memory.c | 5 ++--- mm/memory.c | 2 +- mm/migrate.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-)