Message ID | 20220304093409.25829-8-linmiaohe@huawei.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | A few cleanup and fixup patches for migration | expand |
On Fri, Mar 4, 2022 at 5:35 PM Miaohe Lin <linmiaohe@huawei.com> wrote: > > We could use helper macro min_t to help set the chunk_nr to simplify > the code. > > Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com> Thanks.
On Fri, 4 Mar 2022 17:34:00 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote: > We could use helper macro min_t to help set the chunk_nr to simplify > the code. > > ... > > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1858,9 +1858,7 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, > while (nr_pages) { > unsigned long chunk_nr; > > - chunk_nr = nr_pages; > - if (chunk_nr > DO_PAGES_STAT_CHUNK_NR) > - chunk_nr = DO_PAGES_STAT_CHUNK_NR; > + chunk_nr = min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR); > > if (in_compat_syscall()) { > if (get_compat_pages_array(chunk_pages, pages, Getting the types correct is better than using min_t(). --- a/mm/migrate.c~mm-migration-use-helper-macro-min_t-in-do_pages_stat-fix +++ a/mm/migrate.c @@ -1844,14 +1844,12 @@ static int do_pages_stat(struct mm_struc const void __user * __user *pages, int __user *status) { -#define DO_PAGES_STAT_CHUNK_NR 16 +#define DO_PAGES_STAT_CHUNK_NR 16UL const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR]; int chunk_status[DO_PAGES_STAT_CHUNK_NR]; while (nr_pages) { - unsigned long chunk_nr; - - chunk_nr = min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR); + unsigned long chunk_nr = min(nr_pages, DO_PAGES_STAT_CHUNK_NR); if (in_compat_syscall()) { if (get_compat_pages_array(chunk_pages, pages,
On 2022/3/7 9:14, Andrew Morton wrote: > On Fri, 4 Mar 2022 17:34:00 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote: > >> We could use helper macro min_t to help set the chunk_nr to simplify >> the code. >> >> ... >> >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -1858,9 +1858,7 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, >> while (nr_pages) { >> unsigned long chunk_nr; >> >> - chunk_nr = nr_pages; >> - if (chunk_nr > DO_PAGES_STAT_CHUNK_NR) >> - chunk_nr = DO_PAGES_STAT_CHUNK_NR; >> + chunk_nr = min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR); >> >> if (in_compat_syscall()) { >> if (get_compat_pages_array(chunk_pages, pages, > > Getting the types correct is better than using min_t(). > Looks good. Many thanks for your suggestion. Will do it in v2. Thanks. > --- a/mm/migrate.c~mm-migration-use-helper-macro-min_t-in-do_pages_stat-fix > +++ a/mm/migrate.c > @@ -1844,14 +1844,12 @@ static int do_pages_stat(struct mm_struc > const void __user * __user *pages, > int __user *status) > { > -#define DO_PAGES_STAT_CHUNK_NR 16 > +#define DO_PAGES_STAT_CHUNK_NR 16UL > const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR]; > int chunk_status[DO_PAGES_STAT_CHUNK_NR]; > > while (nr_pages) { > - unsigned long chunk_nr; > - > - chunk_nr = min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR); > + unsigned long chunk_nr = min(nr_pages, DO_PAGES_STAT_CHUNK_NR); > > if (in_compat_syscall()) { > if (get_compat_pages_array(chunk_pages, pages, > _ > > . >
diff --git a/mm/migrate.c b/mm/migrate.c index bc79d7338780..c84eec19072a 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1858,9 +1858,7 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, while (nr_pages) { unsigned long chunk_nr; - chunk_nr = nr_pages; - if (chunk_nr > DO_PAGES_STAT_CHUNK_NR) - chunk_nr = DO_PAGES_STAT_CHUNK_NR; + chunk_nr = min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR); if (in_compat_syscall()) { if (get_compat_pages_array(chunk_pages, pages,
We could use helper macro min_t to help set the chunk_nr to simplify the code. Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> --- mm/migrate.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)