All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/page_alloc: cleanup __alloc_pages_direct_compact()
@ 2019-08-17 10:51 Pengfei Li
  2019-08-19 13:50 ` Vlastimil Babka
  0 siblings, 1 reply; 4+ messages in thread
From: Pengfei Li @ 2019-08-17 10:51 UTC (permalink / raw)
  To: akpm
  Cc: mhocko, vbabka, osalvador, pavel.tatashin, mgorman, linux-mm,
	linux-kernel, Pengfei Li

This patch cleans up the if(page).

No functional change.

Signed-off-by: Pengfei Li <lpf.vector@gmail.com>
---
 mm/page_alloc.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 272c6de1bf4e..51f056ac09f5 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3890,6 +3890,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 		enum compact_priority prio, enum compact_result *compact_result)
 {
 	struct page *page = NULL;
+	struct zone *zone;
 	unsigned long pflags;
 	unsigned int noreclaim_flag;
 
@@ -3911,23 +3912,26 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 	 */
 	count_vm_event(COMPACTSTALL);
 
-	/* Prep a captured page if available */
-	if (page)
+	if (page) {
+		/* Prep a captured page if available */
 		prep_new_page(page, order, gfp_mask, alloc_flags);
-
-	/* Try get a page from the freelist if available */
-	if (!page)
+	} else {
+		/* Try get a page from the freelist if available */
 		page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);
 
-	if (page) {
-		struct zone *zone = page_zone(page);
-
-		zone->compact_blockskip_flush = false;
-		compaction_defer_reset(zone, order, true);
-		count_vm_event(COMPACTSUCCESS);
-		return page;
+		if (!page)
+			goto failed;
 	}
 
+	zone = page_zone(page);
+	zone->compact_blockskip_flush = false;
+	compaction_defer_reset(zone, order, true);
+
+	count_vm_event(COMPACTSUCCESS);
+
+	return page;
+
+failed:
 	/*
 	 * It's bad if compaction run occurs and fails. The most likely reason
 	 * is that pages exist, but not enough to satisfy watermarks.
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/page_alloc: cleanup __alloc_pages_direct_compact()
  2019-08-17 10:51 [PATCH] mm/page_alloc: cleanup __alloc_pages_direct_compact() Pengfei Li
@ 2019-08-19 13:50 ` Vlastimil Babka
  2019-08-19 15:29     ` Pengfei Li
  0 siblings, 1 reply; 4+ messages in thread
From: Vlastimil Babka @ 2019-08-19 13:50 UTC (permalink / raw)
  To: Pengfei Li, akpm
  Cc: mhocko, osalvador, pavel.tatashin, mgorman, linux-mm, linux-kernel

On 8/17/19 12:51 PM, Pengfei Li wrote:
> This patch cleans up the if(page).
> 
> No functional change.
> 
> Signed-off-by: Pengfei Li <lpf.vector@gmail.com>

I don't see much benefit here. The indentation wasn't that bad that it
had to be reduced using goto. But the patch is not incorrect so I'm not
NACKing.

> ---
>  mm/page_alloc.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 272c6de1bf4e..51f056ac09f5 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3890,6 +3890,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
>  		enum compact_priority prio, enum compact_result *compact_result)
>  {
>  	struct page *page = NULL;
> +	struct zone *zone;
>  	unsigned long pflags;
>  	unsigned int noreclaim_flag;
>  
> @@ -3911,23 +3912,26 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
>  	 */
>  	count_vm_event(COMPACTSTALL);
>  
> -	/* Prep a captured page if available */
> -	if (page)
> +	if (page) {
> +		/* Prep a captured page if available */
>  		prep_new_page(page, order, gfp_mask, alloc_flags);
> -
> -	/* Try get a page from the freelist if available */
> -	if (!page)
> +	} else {
> +		/* Try get a page from the freelist if available */
>  		page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);
>  
> -	if (page) {
> -		struct zone *zone = page_zone(page);
> -
> -		zone->compact_blockskip_flush = false;
> -		compaction_defer_reset(zone, order, true);
> -		count_vm_event(COMPACTSUCCESS);
> -		return page;
> +		if (!page)
> +			goto failed;
>  	}
>  
> +	zone = page_zone(page);
> +	zone->compact_blockskip_flush = false;
> +	compaction_defer_reset(zone, order, true);
> +
> +	count_vm_event(COMPACTSUCCESS);
> +
> +	return page;
> +
> +failed:
>  	/*
>  	 * It's bad if compaction run occurs and fails. The most likely reason
>  	 * is that pages exist, but not enough to satisfy watermarks.
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/page_alloc: cleanup __alloc_pages_direct_compact()
  2019-08-19 13:50 ` Vlastimil Babka
@ 2019-08-19 15:29     ` Pengfei Li
  0 siblings, 0 replies; 4+ messages in thread
From: Pengfei Li @ 2019-08-19 15:29 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Andrew Morton, mhocko, osalvador, pavel.tatashin, Mel Gorman,
	linux-mm, linux-kernel

On Mon, Aug 19, 2019 at 9:50 PM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 8/17/19 12:51 PM, Pengfei Li wrote:
> > This patch cleans up the if(page).
> >
> > No functional change.
> >
> > Signed-off-by: Pengfei Li <lpf.vector@gmail.com>
>
> I don't see much benefit here. The indentation wasn't that bad that it
> had to be reduced using goto. But the patch is not incorrect so I'm not
> NACKing.
>

Thanks for your review and comments.

This patch reduces the number of times the if(page)
(as the compiler does), and the downside is that there is a goto.

If this improves readability, accept it. Otherwise, leave it as it is.

Thanks again.

---
Pengfei


> > ---
> >  mm/page_alloc.c | 28 ++++++++++++++++------------
> >  1 file changed, 16 insertions(+), 12 deletions(-)
> >
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index 272c6de1bf4e..51f056ac09f5 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -3890,6 +3890,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> >               enum compact_priority prio, enum compact_result *compact_result)
> >  {
> >       struct page *page = NULL;
> > +     struct zone *zone;
> >       unsigned long pflags;
> >       unsigned int noreclaim_flag;
> >
> > @@ -3911,23 +3912,26 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> >        */
> >       count_vm_event(COMPACTSTALL);
> >
> > -     /* Prep a captured page if available */
> > -     if (page)
> > +     if (page) {
> > +             /* Prep a captured page if available */
> >               prep_new_page(page, order, gfp_mask, alloc_flags);
> > -
> > -     /* Try get a page from the freelist if available */
> > -     if (!page)
> > +     } else {
> > +             /* Try get a page from the freelist if available */
> >               page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);
> >
> > -     if (page) {
> > -             struct zone *zone = page_zone(page);
> > -
> > -             zone->compact_blockskip_flush = false;
> > -             compaction_defer_reset(zone, order, true);
> > -             count_vm_event(COMPACTSUCCESS);
> > -             return page;
> > +             if (!page)
> > +                     goto failed;
> >       }
> >
> > +     zone = page_zone(page);
> > +     zone->compact_blockskip_flush = false;
> > +     compaction_defer_reset(zone, order, true);
> > +
> > +     count_vm_event(COMPACTSUCCESS);
> > +
> > +     return page;
> > +
> > +failed:
> >       /*
> >        * It's bad if compaction run occurs and fails. The most likely reason
> >        * is that pages exist, but not enough to satisfy watermarks.
> >
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/page_alloc: cleanup __alloc_pages_direct_compact()
@ 2019-08-19 15:29     ` Pengfei Li
  0 siblings, 0 replies; 4+ messages in thread
From: Pengfei Li @ 2019-08-19 15:29 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Andrew Morton, mhocko, osalvador, pavel.tatashin, Mel Gorman,
	linux-mm, linux-kernel

On Mon, Aug 19, 2019 at 9:50 PM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 8/17/19 12:51 PM, Pengfei Li wrote:
> > This patch cleans up the if(page).
> >
> > No functional change.
> >
> > Signed-off-by: Pengfei Li <lpf.vector@gmail.com>
>
> I don't see much benefit here. The indentation wasn't that bad that it
> had to be reduced using goto. But the patch is not incorrect so I'm not
> NACKing.
>

Thanks for your review and comments.

This patch reduces the number of times the if(page)
(as the compiler does), and the downside is that there is a goto.

If this improves readability, accept it. Otherwise, leave it as it is.

Thanks again.

---
Pengfei


> > ---
> >  mm/page_alloc.c | 28 ++++++++++++++++------------
> >  1 file changed, 16 insertions(+), 12 deletions(-)
> >
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index 272c6de1bf4e..51f056ac09f5 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -3890,6 +3890,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> >               enum compact_priority prio, enum compact_result *compact_result)
> >  {
> >       struct page *page = NULL;
> > +     struct zone *zone;
> >       unsigned long pflags;
> >       unsigned int noreclaim_flag;
> >
> > @@ -3911,23 +3912,26 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> >        */
> >       count_vm_event(COMPACTSTALL);
> >
> > -     /* Prep a captured page if available */
> > -     if (page)
> > +     if (page) {
> > +             /* Prep a captured page if available */
> >               prep_new_page(page, order, gfp_mask, alloc_flags);
> > -
> > -     /* Try get a page from the freelist if available */
> > -     if (!page)
> > +     } else {
> > +             /* Try get a page from the freelist if available */
> >               page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);
> >
> > -     if (page) {
> > -             struct zone *zone = page_zone(page);
> > -
> > -             zone->compact_blockskip_flush = false;
> > -             compaction_defer_reset(zone, order, true);
> > -             count_vm_event(COMPACTSUCCESS);
> > -             return page;
> > +             if (!page)
> > +                     goto failed;
> >       }
> >
> > +     zone = page_zone(page);
> > +     zone->compact_blockskip_flush = false;
> > +     compaction_defer_reset(zone, order, true);
> > +
> > +     count_vm_event(COMPACTSUCCESS);
> > +
> > +     return page;
> > +
> > +failed:
> >       /*
> >        * It's bad if compaction run occurs and fails. The most likely reason
> >        * is that pages exist, but not enough to satisfy watermarks.
> >
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-19 15:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-17 10:51 [PATCH] mm/page_alloc: cleanup __alloc_pages_direct_compact() Pengfei Li
2019-08-19 13:50 ` Vlastimil Babka
2019-08-19 15:29   ` Pengfei Li
2019-08-19 15:29     ` Pengfei Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.