linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Huaisheng HS1 Ye <yehs1@lenovo.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"mhocko@suse.com" <mhocko@suse.com>,
	"vbabka@suse.cz" <vbabka@suse.cz>,
	"mgorman@techsingularity.net" <mgorman@techsingularity.net>,
	"alexander.levin@verizon.com" <alexander.levin@verizon.com>,
	"colyli@suse.de" <colyli@suse.de>,
	NingTing Cheng <chengnt@lenovo.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
Date: Sat, 12 May 2018 11:35:00 +0000	[thread overview]
Message-ID: <HK2PR03MB1684BC9802BC2E5C1BF2DC74929E0@HK2PR03MB1684.apcprd03.prod.outlook.com> (raw)
In-Reply-To: <20180511132613.GA30263@bombadil.infradead.org>



> From: Matthew Wilcox [mailto:willy@infradead.org]
> Sent: Friday, May 11, 2018 9:26 PM> 
> On Fri, May 11, 2018 at 03:24:34AM +0000, Huaisheng HS1 Ye wrote:
> > > From: owner-linux-mm@kvack.org [mailto:owner-linux-mm@kvack.org] On Behalf Of
> Matthew
> > > Wilcox
> > > On Fri, May 11, 2018 at 12:10:25AM +0800, Huaisheng Ye wrote:
> > > > -#define __GFP_DMA	((__force gfp_t)___GFP_DMA)
> > > > -#define __GFP_HIGHMEM	((__force gfp_t)___GFP_HIGHMEM)
> > > > -#define __GFP_DMA32	((__force gfp_t)___GFP_DMA32)
> > > > +#define __GFP_DMA	((__force gfp_t)OPT_ZONE_DMA ^ ZONE_NORMAL)
> > > > +#define __GFP_HIGHMEM	((__force gfp_t)ZONE_MOVABLE ^ ZONE_NORMAL)
> > > > +#define __GFP_DMA32	((__force gfp_t)OPT_ZONE_DMA32 ^ ZONE_NORMAL)
> > >
> > > No, you've made gfp_zone even more complex than it already is.
> > > If you can't use OPT_ZONE_HIGHMEM here, then this is a waste of time.
> > >
> > Dear Matthew,
> >
> > The reason why I don't use OPT_ZONE_HIGHMEM for __GFP_HIGHMEM	 directly is that,
> for x86_64 platform there is no CONFIG_HIGHMEM, so OPT_ZONE_HIGHMEM shall always be
> equal to ZONE_NORMAL.
> 
> Right.  On 64-bit platforms, if somebody asks for HIGHMEM, they should
> get NORMAL pages.
> 
> > For gfp_zone it is impossible to distinguish the meaning of lowest 3 bits in flags.
> How can gfp_zone to understand it comes from OPT_ZONE_HIGHMEM or ZONE_NORMAL?
> > And the most pained thing is that, if __GFP_HIGHMEM with movable flag enabled, it
> means that ZONE_MOVABLE shall be returned.
> > That is different from ZONE_DMA, ZONE_DMA32 and ZONE_NORMAL.
> 
> The point of this exercise is to actually encode the zone number in
> the bottom bits of the GFP flags instead of something which has to be
> interpreted into a zone number.  When somebody sets __GFP_MOVABLE, they
> should also be setting ZONE_MOVABLE:
> 
> -#define __GFP_MOVABLE   ((__force gfp_t)___GFP_MOVABLE)  /* ZONE_MOVABLE allowed */
> +#define __GFP_MOVABLE   ((__force gfp_t)(___GFP_MOVABLE | (ZONE_MOVABLE ^ ZONE_NORMAL)))
> 
I am afraid we couldn't do that, because __GFP_MOVABLE would be used potentially with other __GFPs like __GFP_DMA and __GFP_DMA32.
Let's go back to the previous example.
We assume ZONE_DMA equals to 0, and ZONE_DMA32 equals to 1. After encoding with ZONE_NORMAL (which equals to 2), we could get that.

#define __GFP_DMA		((__force gfp_t)OPT_ZONE_DMA ^ ZONE_NORMAL)
#define __GFP_DMA32	((__force gfp_t)OPT_ZONE_DMA32 ^ ZONE_NORMAL)
__GPF_DMA	= 0b 0010
__GPF_DMA32	= 0b 0011

We assume ZONE_MOVABLE equals to 3,
#define __GFP_MOVABLE   ((__force gfp_t)(___GFP_MOVABLE | (ZONE_MOVABLE ^ ZONE_NORMAL)))
__GFP_MOVABLE = 0b 1001

If we OR'ing __GFP_MOVABLE and either __GFP_DMA or __GFP_DMA32, we could get same result as '0b 1011'.
This is unacceptable, because inline function gfp_zone couldn't distinguish that is a request of ZONE_DMA or ZONE_DMA32 from parameter flags.

Once more, I think if we want to encode ZONE_MOVABLE to __GFP_MOVABLE, then the operation of __GFP_MOVABLE OR'ing with any other __GFP* would have risk.

Sincerely,
Huaisheng Ye

> One thing that does need to change is:
> 
> -#define GFP_HIGHUSER_MOVABLE    (GFP_HIGHUSER | __GFP_MOVABLE)
> +#define GFP_HIGHUSER_MOVABLE    (GFP_USER | __GFP_MOVABLE)
> 
> otherwise we'll be OR'ing ZONE_MOVABLE and ZONE_HIGHMEM together.
> 
> > I was thinking...
> > Whether it is possible to use other judgement condition to decide OPT_ZONE_HIGHMEM
> or ZONE_MOVABLE shall be returned from gfp_zone.
> >
> > Sincerely,
> > Huaisheng Ye
> >
> >
> > > >  static inline enum zone_type gfp_zone(gfp_t flags)
> > > >  {
> > > >  	enum zone_type z;
> > > > -	int bit = (__force int) (flags & GFP_ZONEMASK);
> > > > +	z = ((__force unsigned int)flags & ___GFP_ZONE_MASK) ^ ZONE_NORMAL;
> > > > +
> > > > +	if (z > OPT_ZONE_HIGHMEM)
> > > > +		z = OPT_ZONE_HIGHMEM +
> > > > +			!!((__force unsigned int)flags & ___GFP_MOVABLE);
> > > >
> > > > -	z = (GFP_ZONE_TABLE >> (bit * GFP_ZONES_SHIFT)) &
> > > > -					 ((1 << GFP_ZONES_SHIFT) - 1);
> > > > -	VM_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
> > > > +	VM_BUG_ON(z > ZONE_MOVABLE);
> > > >  	return z;
> > > >  }
> >

  reply	other threads:[~2018-05-12 11:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1525968625-40825-1-git-send-email-yehs1@lenovo.com>
2018-05-10 16:30 ` Matthew Wilcox
2018-05-11  3:24   ` [External] " Huaisheng HS1 Ye
2018-05-11 13:26     ` Matthew Wilcox
2018-05-12 11:35       ` Huaisheng HS1 Ye [this message]
2018-05-12 14:22         ` Matthew Wilcox
2018-05-16 12:12           ` Huaisheng HS1 Ye
2018-05-18  3:03       ` Huaisheng HS1 Ye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=HK2PR03MB1684BC9802BC2E5C1BF2DC74929E0@HK2PR03MB1684.apcprd03.prod.outlook.com \
    --to=yehs1@lenovo.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.levin@verizon.com \
    --cc=chengnt@lenovo.com \
    --cc=colyli@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --subject='RE: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).