2017-03-03 11:24:41

by Xishi Qiu

[permalink] [raw]
Subject: [PATCH 1/2] mm: use is_migrate_highatomic() to simplify the code

Introduce two helpers, is_migrate_highatomic() and is_migrate_highatomic_page().
Simplify the code, no functional changes.

Signed-off-by: Xishi Qiu <[email protected]>
---
include/linux/mmzone.h | 5 +++++
mm/page_alloc.c | 14 ++++++--------
2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 8e02b37..8124440 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -66,6 +66,11 @@ enum {
/* In mm/page_alloc.c; keep in sync also with show_migration_types() there */
extern char * const migratetype_names[MIGRATE_TYPES];

+#define is_migrate_highatomic(migratetype) \
+ (migratetype == MIGRATE_HIGHATOMIC)
+#define is_migrate_highatomic_page(_page) \
+ (get_pageblock_migratetype(_page) == MIGRATE_HIGHATOMIC)
+
#ifdef CONFIG_CMA
# define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
# define is_migrate_cma_page(_page) (get_pageblock_migratetype(_page) == MIGRATE_CMA)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9f9623d..40d79a6 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2040,8 +2040,8 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone,

/* Yoink! */
mt = get_pageblock_migratetype(page);
- if (mt != MIGRATE_HIGHATOMIC &&
- !is_migrate_isolate(mt) && !is_migrate_cma(mt)) {
+ if (!is_migrate_highatomic(mt) && !is_migrate_isolate(mt)
+ && !is_migrate_cma(mt)) {
zone->nr_reserved_highatomic += pageblock_nr_pages;
set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC);
move_freepages_block(zone, page, MIGRATE_HIGHATOMIC);
@@ -2098,8 +2098,7 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,
* from highatomic to ac->migratetype. So we should
* adjust the count once.
*/
- if (get_pageblock_migratetype(page) ==
- MIGRATE_HIGHATOMIC) {
+ if (is_migrate_highatomic_page(page)) {
/*
* It should never happen but changes to
* locking could inadvertently allow a per-cpu
@@ -2156,8 +2155,7 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,

page = list_first_entry(&area->free_list[fallback_mt],
struct page, lru);
- if (can_steal &&
- get_pageblock_migratetype(page) != MIGRATE_HIGHATOMIC)
+ if (can_steal && !is_migrate_highatomic_page(page))
steal_suitable_fallback(zone, page, start_migratetype);

/* Remove the page from the freelists */
@@ -2494,7 +2492,7 @@ void free_hot_cold_page(struct page *page, bool cold)
/*
* We only track unmovable, reclaimable and movable on pcp lists.
* Free ISOLATE pages back to the allocator because they are being
- * offlined but treat RESERVE as movable pages so we can get those
+ * offlined but treat HIGHATOMIC as movable pages so we can get those
* areas back if necessary. Otherwise, we may have to free
* excessively into the page allocator
*/
@@ -2605,7 +2603,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
for (; page < endpage; page += pageblock_nr_pages) {
int mt = get_pageblock_migratetype(page);
if (!is_migrate_isolate(mt) && !is_migrate_cma(mt)
- && mt != MIGRATE_HIGHATOMIC)
+ && !is_migrate_highatomic(mt))
set_pageblock_migratetype(page,
MIGRATE_MOVABLE);
}
--
1.8.3.1



2017-03-03 11:23:49

by Xishi Qiu

[permalink] [raw]
Subject: [PATCH 2/2] mm: use is_migrate_isolate_page() to simplify the code

Use is_migrate_isolate_page() to simplify the code, no functional changes.

Signed-off-by: Xishi Qiu <[email protected]>
---
mm/page_isolation.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/page_isolation.c b/mm/page_isolation.c
index f4e17a5..7927bbb 100644
--- a/mm/page_isolation.c
+++ b/mm/page_isolation.c
@@ -88,7 +88,7 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)

zone = page_zone(page);
spin_lock_irqsave(&zone->lock, flags);
- if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
+ if (!is_migrate_isolate_page(page))
goto out;

/*
@@ -205,7 +205,7 @@ int undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
pfn < end_pfn;
pfn += pageblock_nr_pages) {
page = __first_valid_page(pfn, pageblock_nr_pages);
- if (!page || get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
+ if (!page || !is_migrate_isolate_page(page))
continue;
unset_migratetype_isolate(page, migratetype);
}
@@ -262,7 +262,7 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
*/
for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {
page = __first_valid_page(pfn, pageblock_nr_pages);
- if (page && get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
+ if (page && !is_migrate_isolate_page(page))
break;
}
page = __first_valid_page(start_pfn, end_pfn - start_pfn);
--
1.8.3.1


2017-03-03 13:19:27

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH 2/2] mm: use is_migrate_isolate_page() to simplify the code

On Fri 03-03-17 19:12:49, Xishi Qiu wrote:
> Use is_migrate_isolate_page() to simplify the code, no functional changes.
>
> Signed-off-by: Xishi Qiu <[email protected]>

Acked-by: Michal Hocko <[email protected]>

> ---
> mm/page_isolation.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/page_isolation.c b/mm/page_isolation.c
> index f4e17a5..7927bbb 100644
> --- a/mm/page_isolation.c
> +++ b/mm/page_isolation.c
> @@ -88,7 +88,7 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
>
> zone = page_zone(page);
> spin_lock_irqsave(&zone->lock, flags);
> - if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
> + if (!is_migrate_isolate_page(page))
> goto out;
>
> /*
> @@ -205,7 +205,7 @@ int undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
> pfn < end_pfn;
> pfn += pageblock_nr_pages) {
> page = __first_valid_page(pfn, pageblock_nr_pages);
> - if (!page || get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
> + if (!page || !is_migrate_isolate_page(page))
> continue;
> unset_migratetype_isolate(page, migratetype);
> }
> @@ -262,7 +262,7 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
> */
> for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {
> page = __first_valid_page(pfn, pageblock_nr_pages);
> - if (page && get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
> + if (page && !is_migrate_isolate_page(page))
> break;
> }
> page = __first_valid_page(start_pfn, end_pfn - start_pfn);
> --
> 1.8.3.1
>

--
Michal Hocko
SUSE Labs

2017-03-03 15:52:46

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH 1/2] mm: use is_migrate_highatomic() to simplify the code

On Fri 03-03-17 19:10:13, Xishi Qiu wrote:
> Introduce two helpers, is_migrate_highatomic() and is_migrate_highatomic_page().
> Simplify the code, no functional changes.

static inline helpers would be nicer than macros

> Signed-off-by: Xishi Qiu <[email protected]>

OK this fits with other MIGRATE_$FOO types

Acked-by: Michal Hocko <[email protected]>

> ---
> include/linux/mmzone.h | 5 +++++
> mm/page_alloc.c | 14 ++++++--------
> 2 files changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 8e02b37..8124440 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -66,6 +66,11 @@ enum {
> /* In mm/page_alloc.c; keep in sync also with show_migration_types() there */
> extern char * const migratetype_names[MIGRATE_TYPES];
>
> +#define is_migrate_highatomic(migratetype) \
> + (migratetype == MIGRATE_HIGHATOMIC)
> +#define is_migrate_highatomic_page(_page) \
> + (get_pageblock_migratetype(_page) == MIGRATE_HIGHATOMIC)
> +
> #ifdef CONFIG_CMA
> # define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
> # define is_migrate_cma_page(_page) (get_pageblock_migratetype(_page) == MIGRATE_CMA)
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 9f9623d..40d79a6 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2040,8 +2040,8 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone,
>
> /* Yoink! */
> mt = get_pageblock_migratetype(page);
> - if (mt != MIGRATE_HIGHATOMIC &&
> - !is_migrate_isolate(mt) && !is_migrate_cma(mt)) {
> + if (!is_migrate_highatomic(mt) && !is_migrate_isolate(mt)
> + && !is_migrate_cma(mt)) {
> zone->nr_reserved_highatomic += pageblock_nr_pages;
> set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC);
> move_freepages_block(zone, page, MIGRATE_HIGHATOMIC);
> @@ -2098,8 +2098,7 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,
> * from highatomic to ac->migratetype. So we should
> * adjust the count once.
> */
> - if (get_pageblock_migratetype(page) ==
> - MIGRATE_HIGHATOMIC) {
> + if (is_migrate_highatomic_page(page)) {
> /*
> * It should never happen but changes to
> * locking could inadvertently allow a per-cpu
> @@ -2156,8 +2155,7 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,
>
> page = list_first_entry(&area->free_list[fallback_mt],
> struct page, lru);
> - if (can_steal &&
> - get_pageblock_migratetype(page) != MIGRATE_HIGHATOMIC)
> + if (can_steal && !is_migrate_highatomic_page(page))
> steal_suitable_fallback(zone, page, start_migratetype);
>
> /* Remove the page from the freelists */
> @@ -2494,7 +2492,7 @@ void free_hot_cold_page(struct page *page, bool cold)
> /*
> * We only track unmovable, reclaimable and movable on pcp lists.
> * Free ISOLATE pages back to the allocator because they are being
> - * offlined but treat RESERVE as movable pages so we can get those
> + * offlined but treat HIGHATOMIC as movable pages so we can get those
> * areas back if necessary. Otherwise, we may have to free
> * excessively into the page allocator
> */
> @@ -2605,7 +2603,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
> for (; page < endpage; page += pageblock_nr_pages) {
> int mt = get_pageblock_migratetype(page);
> if (!is_migrate_isolate(mt) && !is_migrate_cma(mt)
> - && mt != MIGRATE_HIGHATOMIC)
> + && !is_migrate_highatomic(mt))
> set_pageblock_migratetype(page,
> MIGRATE_MOVABLE);
> }
> --
> 1.8.3.1
>

--
Michal Hocko
SUSE Labs

2017-03-03 23:15:56

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 1/2] mm: use is_migrate_highatomic() to simplify the code

On Fri, 3 Mar 2017 14:18:08 +0100 Michal Hocko <[email protected]> wrote:

> On Fri 03-03-17 19:10:13, Xishi Qiu wrote:
> > Introduce two helpers, is_migrate_highatomic() and is_migrate_highatomic_page().
> > Simplify the code, no functional changes.
>
> static inline helpers would be nicer than macros

Always.

We made a big dependency mess in mmzone.h. internal.h works.

--- a/include/linux/mmzone.h~mm-use-is_migrate_highatomic-to-simplify-the-code-fix
+++ a/include/linux/mmzone.h
@@ -35,7 +35,7 @@
*/
#define PAGE_ALLOC_COSTLY_ORDER 3

-enum {
+enum migratetype {
MIGRATE_UNMOVABLE,
MIGRATE_MOVABLE,
MIGRATE_RECLAIMABLE,
@@ -66,11 +66,6 @@ enum {
/* In mm/page_alloc.c; keep in sync also with show_migration_types() there */
extern char * const migratetype_names[MIGRATE_TYPES];

-#define is_migrate_highatomic(migratetype) \
- (migratetype == MIGRATE_HIGHATOMIC)
-#define is_migrate_highatomic_page(_page) \
- (get_pageblock_migratetype(_page) == MIGRATE_HIGHATOMIC)
-
#ifdef CONFIG_CMA
# define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
# define is_migrate_cma_page(_page) (get_pageblock_migratetype(_page) == MIGRATE_CMA)
diff -puN mm/page_alloc.c~mm-use-is_migrate_highatomic-to-simplify-the-code-fix mm/page_alloc.c
diff -puN mm/internal.h~mm-use-is_migrate_highatomic-to-simplify-the-code-fix mm/internal.h
--- a/mm/internal.h~mm-use-is_migrate_highatomic-to-simplify-the-code-fix
+++ a/mm/internal.h
@@ -503,4 +503,14 @@ extern const struct trace_print_flags pa
extern const struct trace_print_flags vmaflag_names[];
extern const struct trace_print_flags gfpflag_names[];

+static inline bool is_migrate_highatomic(enum migratetype migratetype)
+{
+ return migratetype == MIGRATE_HIGHATOMIC;
+}
+
+static inline bool is_migrate_highatomic_page(struct page *page)
+{
+ return get_pageblock_migratetype(page) == MIGRATE_HIGHATOMIC;
+}
+
#endif /* __MM_INTERNAL_H */
_

2017-03-06 14:18:49

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH 1/2] mm: use is_migrate_highatomic() to simplify the code

On Fri 03-03-17 15:06:19, Andrew Morton wrote:
> On Fri, 3 Mar 2017 14:18:08 +0100 Michal Hocko <[email protected]> wrote:
>
> > On Fri 03-03-17 19:10:13, Xishi Qiu wrote:
> > > Introduce two helpers, is_migrate_highatomic() and is_migrate_highatomic_page().
> > > Simplify the code, no functional changes.
> >
> > static inline helpers would be nicer than macros
>
> Always.
>
> We made a big dependency mess in mmzone.h. internal.h works.

Just too bad we have three different header files for
is_migrate_isolate{_page} - include/linux/page-isolation.h
is_migrate_cma{_page} - include/linux/mmzone.h
is_migrate_highatomic{_page} - mm/internal.h

I guess we want all of them in internal.h?

--
Michal Hocko
SUSE Labs

2017-03-06 20:51:00

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 1/2] mm: use is_migrate_highatomic() to simplify the code

On Mon, 6 Mar 2017 14:38:33 +0100 Michal Hocko <[email protected]> wrote:

> On Fri 03-03-17 15:06:19, Andrew Morton wrote:
> > On Fri, 3 Mar 2017 14:18:08 +0100 Michal Hocko <[email protected]> wrote:
> >
> > > On Fri 03-03-17 19:10:13, Xishi Qiu wrote:
> > > > Introduce two helpers, is_migrate_highatomic() and is_migrate_highatomic_page().
> > > > Simplify the code, no functional changes.
> > >
> > > static inline helpers would be nicer than macros
> >
> > Always.
> >
> > We made a big dependency mess in mmzone.h. internal.h works.
>
> Just too bad we have three different header files for
> is_migrate_isolate{_page} - include/linux/page-isolation.h
> is_migrate_cma{_page} - include/linux/mmzone.h
> is_migrate_highatomic{_page} - mm/internal.h
>
> I guess we want all of them in internal.h?

I suppose so. arch/powerpc/mm/mmu_context_iommu.c is using
is_migrate_cma_page which would need some attention.

2017-03-08 14:53:50

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH 1/2] mm: use is_migrate_highatomic() to simplify the code

On Mon 06-03-17 12:43:18, Andrew Morton wrote:
> On Mon, 6 Mar 2017 14:38:33 +0100 Michal Hocko <[email protected]> wrote:
>
> > On Fri 03-03-17 15:06:19, Andrew Morton wrote:
> > > On Fri, 3 Mar 2017 14:18:08 +0100 Michal Hocko <[email protected]> wrote:
> > >
> > > > On Fri 03-03-17 19:10:13, Xishi Qiu wrote:
> > > > > Introduce two helpers, is_migrate_highatomic() and is_migrate_highatomic_page().
> > > > > Simplify the code, no functional changes.
> > > >
> > > > static inline helpers would be nicer than macros
> > >
> > > Always.
> > >
> > > We made a big dependency mess in mmzone.h. internal.h works.
> >
> > Just too bad we have three different header files for
> > is_migrate_isolate{_page} - include/linux/page-isolation.h
> > is_migrate_cma{_page} - include/linux/mmzone.h
> > is_migrate_highatomic{_page} - mm/internal.h
> >
> > I guess we want all of them in internal.h?
>
> I suppose so. arch/powerpc/mm/mmu_context_iommu.c is using
> is_migrate_cma_page which would need some attention.

Ble. I am really wondering whether these helpers actually make the end
result really worth all the troubles and the mess.

--
Michal Hocko
SUSE Labs