All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
@ 2018-05-10 16:10 Huaisheng Ye
  2018-05-10 16:30 ` Matthew Wilcox
  0 siblings, 1 reply; 8+ messages in thread
From: Huaisheng Ye @ 2018-05-10 16:10 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: mhocko, willy, vbabka, mgorman, alexander.levin, colyli, chengnt,
	linux-kernel, Huaisheng Ye

Replace GFP_ZONE_TABLE and GFP_ZONE_BAD with encoded zone
number.

Delete ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 from GFP bitmasks,
the bottom three bits of GFP mask is reserved for storing encoded
zone number.

The encoding method is XOR. Get zone number from enum zone_type,
then encode the number with ZONE_NORMAL by XOR operation.
The goal is to make sure ZONE_NORMAL can be encoded to zero. So,
the compatibility can be guaranteed, such as GFP_KERNEL and GFP_ATOMIC
can be used as before.

Reserve __GFP_MOVABLE in bit 3, so that it can continue to be used as
a flag. Same as before, __GFP_MOVABLE respresents movable migrate type
for ZONE_DMA, ZONE_DMA32, and ZONE_NORMAL. But when it is enabled with
__GFP_HIGHMEM, ZONE_MOVABLE shall be returned instead of ZONE_HIGHMEM.

Decode zone number within gfp_zone, firstly decode its number with
bottom three bits of flags. Then, return correct zone_type according
to flag movable if zone type is larger than OPT_ZONE_HIGHMEM.

The theory of encoding and decoding is,
	A ^ B ^ B = A

Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Huaisheng Ye <yehs1@lenovo.com>
---
 include/linux/gfp.h | 94 +++++++----------------------------------------------
 1 file changed, 11 insertions(+), 83 deletions(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 1a4582b..578cef7 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -16,9 +16,7 @@
  */
 
 /* Plain integer GFP bitmasks. Do not use this directly. */
-#define ___GFP_DMA		0x01u
-#define ___GFP_HIGHMEM		0x02u
-#define ___GFP_DMA32		0x04u
+#define ___GFP_ZONE_MASK	0x07u
 #define ___GFP_MOVABLE		0x08u
 #define ___GFP_RECLAIMABLE	0x10u
 #define ___GFP_HIGH		0x20u
@@ -53,11 +51,11 @@
  * without the underscores and use them consistently. The definitions here may
  * be used in bit comparisons.
  */
-#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)
 #define __GFP_MOVABLE	((__force gfp_t)___GFP_MOVABLE)  /* ZONE_MOVABLE allowed */
-#define GFP_ZONEMASK	(__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE)
+#define GFP_ZONEMASK	((__force gfp_t)___GFP_ZONE_MASK | ___GFP_MOVABLE)
 
 /*
  * Page mobility and placement hints
@@ -326,86 +324,16 @@ static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
 #define OPT_ZONE_DMA32 ZONE_NORMAL
 #endif
 
-/*
- * GFP_ZONE_TABLE is a word size bitstring that is used for looking up the
- * zone to use given the lowest 4 bits of gfp_t. Entries are GFP_ZONES_SHIFT
- * bits long and there are 16 of them to cover all possible combinations of
- * __GFP_DMA, __GFP_DMA32, __GFP_MOVABLE and __GFP_HIGHMEM.
- *
- * The zone fallback order is MOVABLE=>HIGHMEM=>NORMAL=>DMA32=>DMA.
- * But GFP_MOVABLE is not only a zone specifier but also an allocation
- * policy. Therefore __GFP_MOVABLE plus another zone selector is valid.
- * Only 1 bit of the lowest 3 bits (DMA,DMA32,HIGHMEM) can be set to "1".
- *
- *       bit       result
- *       =================
- *       0x0    => NORMAL
- *       0x1    => DMA or NORMAL
- *       0x2    => HIGHMEM or NORMAL
- *       0x3    => BAD (DMA+HIGHMEM)
- *       0x4    => DMA32 or DMA or NORMAL
- *       0x5    => BAD (DMA+DMA32)
- *       0x6    => BAD (HIGHMEM+DMA32)
- *       0x7    => BAD (HIGHMEM+DMA32+DMA)
- *       0x8    => NORMAL (MOVABLE+0)
- *       0x9    => DMA or NORMAL (MOVABLE+DMA)
- *       0xa    => MOVABLE (Movable is valid only if HIGHMEM is set too)
- *       0xb    => BAD (MOVABLE+HIGHMEM+DMA)
- *       0xc    => DMA32 (MOVABLE+DMA32)
- *       0xd    => BAD (MOVABLE+DMA32+DMA)
- *       0xe    => BAD (MOVABLE+DMA32+HIGHMEM)
- *       0xf    => BAD (MOVABLE+DMA32+HIGHMEM+DMA)
- *
- * GFP_ZONES_SHIFT must be <= 2 on 32 bit platforms.
- */
-
-#if defined(CONFIG_ZONE_DEVICE) && (MAX_NR_ZONES-1) <= 4
-/* ZONE_DEVICE is not a valid GFP zone specifier */
-#define GFP_ZONES_SHIFT 2
-#else
-#define GFP_ZONES_SHIFT ZONES_SHIFT
-#endif
-
-#if 16 * GFP_ZONES_SHIFT > BITS_PER_LONG
-#error GFP_ZONES_SHIFT too large to create GFP_ZONE_TABLE integer
-#endif
-
-#define GFP_ZONE_TABLE ( \
-	(ZONE_NORMAL << 0 * GFP_ZONES_SHIFT)				       \
-	| (OPT_ZONE_DMA << ___GFP_DMA * GFP_ZONES_SHIFT)		       \
-	| (OPT_ZONE_HIGHMEM << ___GFP_HIGHMEM * GFP_ZONES_SHIFT)	       \
-	| (OPT_ZONE_DMA32 << ___GFP_DMA32 * GFP_ZONES_SHIFT)		       \
-	| (ZONE_NORMAL << ___GFP_MOVABLE * GFP_ZONES_SHIFT)		       \
-	| (OPT_ZONE_DMA << (___GFP_MOVABLE | ___GFP_DMA) * GFP_ZONES_SHIFT)    \
-	| (ZONE_MOVABLE << (___GFP_MOVABLE | ___GFP_HIGHMEM) * GFP_ZONES_SHIFT)\
-	| (OPT_ZONE_DMA32 << (___GFP_MOVABLE | ___GFP_DMA32) * GFP_ZONES_SHIFT)\
-)
-
-/*
- * GFP_ZONE_BAD is a bitmap for all combinations of __GFP_DMA, __GFP_DMA32
- * __GFP_HIGHMEM and __GFP_MOVABLE that are not permitted. One flag per
- * entry starting with bit 0. Bit is set if the combination is not
- * allowed.
- */
-#define GFP_ZONE_BAD ( \
-	1 << (___GFP_DMA | ___GFP_HIGHMEM)				      \
-	| 1 << (___GFP_DMA | ___GFP_DMA32)				      \
-	| 1 << (___GFP_DMA32 | ___GFP_HIGHMEM)				      \
-	| 1 << (___GFP_DMA | ___GFP_DMA32 | ___GFP_HIGHMEM)		      \
-	| 1 << (___GFP_MOVABLE | ___GFP_HIGHMEM | ___GFP_DMA)		      \
-	| 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_DMA)		      \
-	| 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_HIGHMEM)		      \
-	| 1 << (___GFP_MOVABLE | ___GFP_DMA32 | ___GFP_DMA | ___GFP_HIGHMEM)  \
-)
-
 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;
 }
 
-- 
1.8.3.1

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

* Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
  2018-05-10 16:10 [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD Huaisheng Ye
@ 2018-05-10 16:30 ` Matthew Wilcox
  2018-05-11  3:24   ` [External] " Huaisheng HS1 Ye
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2018-05-10 16:30 UTC (permalink / raw)
  To: Huaisheng Ye
  Cc: akpm, linux-mm, mhocko, vbabka, mgorman, alexander.levin, colyli,
	chengnt, linux-kernel

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.

>  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;
>  }

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

* RE: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
  2018-05-10 16:30 ` Matthew Wilcox
@ 2018-05-11  3:24   ` Huaisheng HS1 Ye
  2018-05-11 13:26     ` Matthew Wilcox
  0 siblings, 1 reply; 8+ messages in thread
From: Huaisheng HS1 Ye @ 2018-05-11  3:24 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: akpm, linux-mm, mhocko, vbabka, mgorman, alexander.levin, colyli,
	NingTing Cheng, linux-kernel

> 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.

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.

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;
> >  }

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

* Re: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
  2018-05-11  3:24   ` [External] " Huaisheng HS1 Ye
@ 2018-05-11 13:26     ` Matthew Wilcox
  2018-05-12 11:35       ` Huaisheng HS1 Ye
  2018-05-18  3:03       ` Huaisheng HS1 Ye
  0 siblings, 2 replies; 8+ messages in thread
From: Matthew Wilcox @ 2018-05-11 13:26 UTC (permalink / raw)
  To: Huaisheng HS1 Ye
  Cc: akpm, linux-mm, mhocko, vbabka, mgorman, alexander.levin, colyli,
	NingTing Cheng, linux-kernel

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)))

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;
> > >  }
> 

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

* RE: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
  2018-05-11 13:26     ` Matthew Wilcox
@ 2018-05-12 11:35       ` Huaisheng HS1 Ye
  2018-05-12 14:22         ` Matthew Wilcox
  2018-05-18  3:03       ` Huaisheng HS1 Ye
  1 sibling, 1 reply; 8+ messages in thread
From: Huaisheng HS1 Ye @ 2018-05-12 11:35 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: akpm, linux-mm, mhocko, vbabka, mgorman, alexander.levin, colyli,
	NingTing Cheng, linux-kernel



> 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;
> > > >  }
> >

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

* Re: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
  2018-05-12 11:35       ` Huaisheng HS1 Ye
@ 2018-05-12 14:22         ` Matthew Wilcox
  2018-05-16 12:12           ` Huaisheng HS1 Ye
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2018-05-12 14:22 UTC (permalink / raw)
  To: Huaisheng HS1 Ye
  Cc: akpm, linux-mm, mhocko, vbabka, mgorman, alexander.levin, colyli,
	NingTing Cheng, linux-kernel

On Sat, May 12, 2018 at 11:35:00AM +0000, Huaisheng HS1 Ye wrote:
> > 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.

That's not a combination that makes much sense.  I know it's permitted today
(and it has the effect of being a no-op), but when you think about it, it
doesn't actually make any sense.

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

* RE: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
  2018-05-12 14:22         ` Matthew Wilcox
@ 2018-05-16 12:12           ` Huaisheng HS1 Ye
  0 siblings, 0 replies; 8+ messages in thread
From: Huaisheng HS1 Ye @ 2018-05-16 12:12 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: akpm, linux-mm, mhocko, vbabka, mgorman, alexander.levin, colyli,
	NingTing Cheng, linux-kernel

> From: Matthew Wilcox [mailto:willy@infradead.org]
> Sent: Saturday, May 12, 2018 10:23 PM> 
> On Sat, May 12, 2018 at 11:35:00AM +0000, Huaisheng HS1 Ye wrote:
> > > 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.
> 
> That's not a combination that makes much sense.  I know it's permitted today
> (and it has the effect of being a no-op), but when you think about it, it
> doesn't actually make any sense.

Yes, you are right.
After checking almost all references of __GFP_MOVABLE and other __GFP_* flags, perhaps I was far to get excessive pursuit of logical correctness.
For those nonsense combinations, I should ignore them.
Current GFP_ZONE_TABLE can ensure all logical correctness. That makes me want to pursue same effect.

Next, I will revise the patch according to your advice, then try to get overall testing result as far as possible.
There are many combinations because of a lot of conditions in file system and drivers. Hope I could test all things related to the lower 4 bits of gfp.

Sincerely,
Huaisheng Ye

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

* RE: [External]  Re: [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD
  2018-05-11 13:26     ` Matthew Wilcox
  2018-05-12 11:35       ` Huaisheng HS1 Ye
@ 2018-05-18  3:03       ` Huaisheng HS1 Ye
  1 sibling, 0 replies; 8+ messages in thread
From: Huaisheng HS1 Ye @ 2018-05-18  3:03 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: akpm, linux-mm, mhocko, vbabka, mgorman, alexander.levin, colyli,
	NingTing Cheng, linux-kernel

> 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)))
> 
> 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.

Dear Matthew,

After thinking it over and over, I am afraid there is something needs to be discussed here.
You know current X86_64 config file of kernel doesn't enable CONFIG_HIGHMEM, that is to say from this below,

#define __GFP_HIGHMEM	((__force gfp_t)OPT_ZONE_HIGHMEM ^ ZONE_NORMAL)

__GFP_HIGHMEM should equal to 0b0000, same as the value of ZONE_NORMAL gets encoded.
If we define __GFP_MOVABLE like this,

#define __GFP_MOVABLE   ((__force gfp_t)(___GFP_MOVABLE | (ZONE_MOVABLE ^ ZONE_NORMAL)))

Just like your introduced before, with this modification when somebody sets __GFP_MOVABLE, they should also be setting ZONE_MOVABLE.
That brings us a problem, current mm (GFP_ZONE_TABLE) treats __GFP_MOVABLE as ZONE_NORMAL with movable policy, if without __GFP_HIGHMEM.
The mm shall allocate a page or pages from migrate movable list of ZONE_NORMAL's freelist.
So that conflicts with this modification. And I have checked current kernel, some of function directly set parameter gfp like this.

For example, in fs/ext4/extents.c __read_extent_tree_block,
	bh = sb_getblk_gfp(inode->i_sb, pblk, __GFP_MOVABLE | GFP_NOFS);

for these situations, I think only modify GFP_HIGHUSER_MOVABLE is not enough. I am preparing a workaround to solve this in the V2 patch.
Later I will upload it to email loop.

Sincerely,
Huaisheng Ye


> > 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;
> > > >  }
> >

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

end of thread, other threads:[~2018-05-18  3:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-10 16:10 [PATCH v1] include/linux/gfp.h: getting rid of GFP_ZONE_TABLE/BAD Huaisheng Ye
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
2018-05-12 14:22         ` Matthew Wilcox
2018-05-16 12:12           ` Huaisheng HS1 Ye
2018-05-18  3:03       ` Huaisheng HS1 Ye

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.