RE: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-26 Thread Luck, Tony
> gfpflags_to_migratetype()
>   if (memory_mirror_enabled()) { /* We want to mirror all unmovable pages */
>   if (!(gfp_mask & __GFP_MOVABLE))
>return MIGRATE_MIRROR
>   }

I'm not sure that we can divide memory into just two buckets of "mirrored" and 
"movable".

My expectation is that there will be memory that is neither mirrored, nor 
movable.  We'd
allocate that memory to user proceses.  Uncorrected errors in that memory would 
result
in the death of the process (except in the case where the page is a clean copy 
mapped from
a disk file ... e.g. .text mapping instructions from an executable).  Linux 
would offline
the affected 4K page so as not to hit the problem again.

-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-26 Thread Xishi Qiu
On 2015/6/26 16:34, Kamezawa Hiroyuki wrote:

> On 2015/06/26 10:43, Xishi Qiu wrote:
>> On 2015/6/26 7:54, Kamezawa Hiroyuki wrote:
>>
>>> On 2015/06/25 18:44, Xishi Qiu wrote:
 On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:

> On 2015/06/09 19:04, Xishi Qiu wrote:
>> On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:
>>
>>> On 2015/06/04 22:04, Xishi Qiu wrote:
 Add the buddy system interface for address range mirroring feature.
 Allocate mirrored pages in MIGRATE_MIRROR list. If there is no 
 mirrored pages
 left, use other types pages.

 Signed-off-by: Xishi Qiu 
 ---
  mm/page_alloc.c | 40 +++-
  1 file changed, 39 insertions(+), 1 deletion(-)

 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
 index d4d2066..0fb55288 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long 
 pfn)

  return false;
  }
 +
 +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
 +{
 +/*
 + * Do not alloc mirrored memory below 4G, because 0-4G is
 + * all mirrored by default, and the list is always empty.
 + */
 +if (high_zoneidx < ZONE_NORMAL)
 +return false;
 +
 +/* Alloc mirrored memory for only kernel */
 +if (gfp_flags & __GFP_MIRROR)
 +return true;
>>>
>>> GFP_KERNEL itself should imply mirror, I think.
>>>
>>
>> Hi Kame,
>>
>> How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | 
>> __GFP_FS | __GFP_MIRROR) ?
>>
>
> Hm it cannot cover GFP_ATOMIC at el.
>
> I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
> !__GFP_MOVABLE


 Hi Kame,

 Can we distinguish allocations form user or kernel only by GFP flags?

>>>
>>> Allocation from user and file caches are now *always* done with 
>>> __GFP_MOVABLE.
>>>
>>> By this, pages will be allocated from MIGRATE_MOVABLE migration type.
>>> MOVABLE migration type means it's can
>>> be the target for page compaction or memory-hot-remove.
>>>
>>> Thanks,
>>> -Kame
>>>
>>
>> So if we want all kernel memory allocated from mirror, how about change like 
>> this?
>> __alloc_pages_nodemask()
>>gfpflags_to_migratetype()
>>  if (!(gfp_mask & __GFP_MOVABLE))
>> return MIGRATE_MIRROR
> 
> Maybe used with jump label can reduce performance impact.

Hi Kame,

I am not understand jump label, but I wil try.

> ==
> static inline bool memory_mirror_enabled(void)
> {
> return static_key_false(_mirror_enabled);
> }
> 
> 
> 
> gfpflags_to_migratetype()
>   if (memory_mirror_enabled()) { /* We want to mirror all unmovable pages */
>   if (!(gfp_mask & __GFP_MOVABLE))
>return MIGRATE_MIRROR
>   }
> ==
> 
> BTW, I think current memory compaction code scans ranges of MOVABLE migrate 
> type.
> So, if you use other migration type than MOVABLE for user pages, you may see
> page fragmentation. If you want to expand this MIRROR to user pages, please 
> check
> mm/compaction.c
> 

As Tony said "how can we minimize the run-time impact on systems that don't have
any mirrored memory.", I think the idea "kernel only from MIRROR / user only 
from
MOVABLE" may be better.

Thanks,
Xishi Qiu



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-26 Thread Kamezawa Hiroyuki

On 2015/06/26 10:43, Xishi Qiu wrote:

On 2015/6/26 7:54, Kamezawa Hiroyuki wrote:


On 2015/06/25 18:44, Xishi Qiu wrote:

On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:


On 2015/06/09 19:04, Xishi Qiu wrote:

On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:


On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu 
---
 mm/page_alloc.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

 return false;
 }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+/*
+ * Do not alloc mirrored memory below 4G, because 0-4G is
+ * all mirrored by default, and the list is always empty.
+ */
+if (high_zoneidx < ZONE_NORMAL)
+return false;
+
+/* Alloc mirrored memory for only kernel */
+if (gfp_flags & __GFP_MIRROR)
+return true;


GFP_KERNEL itself should imply mirror, I think.



Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?



Hm it cannot cover GFP_ATOMIC at el.

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE



Hi Kame,

Can we distinguish allocations form user or kernel only by GFP flags?



Allocation from user and file caches are now *always* done with __GFP_MOVABLE.

By this, pages will be allocated from MIGRATE_MOVABLE migration type.
MOVABLE migration type means it's can
be the target for page compaction or memory-hot-remove.

Thanks,
-Kame



So if we want all kernel memory allocated from mirror, how about change like 
this?
__alloc_pages_nodemask()
   gfpflags_to_migratetype()
 if (!(gfp_mask & __GFP_MOVABLE))
return MIGRATE_MIRROR


Maybe used with jump label can reduce performance impact.
==
static inline bool memory_mirror_enabled(void)
{
return static_key_false(_mirror_enabled);
}



gfpflags_to_migratetype()
  if (memory_mirror_enabled()) { /* We want to mirror all unmovable pages */
  if (!(gfp_mask & __GFP_MOVABLE))
   return MIGRATE_MIRROR
  }
==

BTW, I think current memory compaction code scans ranges of MOVABLE migrate 
type.
So, if you use other migration type than MOVABLE for user pages, you may see
page fragmentation. If you want to expand this MIRROR to user pages, please 
check
mm/compaction.c


Thanks,
-Kame




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-26 Thread Kamezawa Hiroyuki

On 2015/06/26 10:43, Xishi Qiu wrote:

On 2015/6/26 7:54, Kamezawa Hiroyuki wrote:


On 2015/06/25 18:44, Xishi Qiu wrote:

On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:


On 2015/06/09 19:04, Xishi Qiu wrote:

On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:


On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu qiuxi...@huawei.com
---
 mm/page_alloc.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

 return false;
 }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+/*
+ * Do not alloc mirrored memory below 4G, because 0-4G is
+ * all mirrored by default, and the list is always empty.
+ */
+if (high_zoneidx  ZONE_NORMAL)
+return false;
+
+/* Alloc mirrored memory for only kernel */
+if (gfp_flags  __GFP_MIRROR)
+return true;


GFP_KERNEL itself should imply mirror, I think.



Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?



Hm it cannot cover GFP_ATOMIC at el.

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE



Hi Kame,

Can we distinguish allocations form user or kernel only by GFP flags?



Allocation from user and file caches are now *always* done with __GFP_MOVABLE.

By this, pages will be allocated from MIGRATE_MOVABLE migration type.
MOVABLE migration type means it's can
be the target for page compaction or memory-hot-remove.

Thanks,
-Kame



So if we want all kernel memory allocated from mirror, how about change like 
this?
__alloc_pages_nodemask()
   gfpflags_to_migratetype()
 if (!(gfp_mask  __GFP_MOVABLE))
return MIGRATE_MIRROR


Maybe used with jump label can reduce performance impact.
==
static inline bool memory_mirror_enabled(void)
{
return static_key_false(memory_mirror_enabled);
}



gfpflags_to_migratetype()
  if (memory_mirror_enabled()) { /* We want to mirror all unmovable pages */
  if (!(gfp_mask  __GFP_MOVABLE))
   return MIGRATE_MIRROR
  }
==

BTW, I think current memory compaction code scans ranges of MOVABLE migrate 
type.
So, if you use other migration type than MOVABLE for user pages, you may see
page fragmentation. If you want to expand this MIRROR to user pages, please 
check
mm/compaction.c


Thanks,
-Kame




--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-26 Thread Luck, Tony
 gfpflags_to_migratetype()
   if (memory_mirror_enabled()) { /* We want to mirror all unmovable pages */
   if (!(gfp_mask  __GFP_MOVABLE))
return MIGRATE_MIRROR
   }

I'm not sure that we can divide memory into just two buckets of mirrored and 
movable.

My expectation is that there will be memory that is neither mirrored, nor 
movable.  We'd
allocate that memory to user proceses.  Uncorrected errors in that memory would 
result
in the death of the process (except in the case where the page is a clean copy 
mapped from
a disk file ... e.g. .text mapping instructions from an executable).  Linux 
would offline
the affected 4K page so as not to hit the problem again.

-Tony
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-26 Thread Xishi Qiu
On 2015/6/26 16:34, Kamezawa Hiroyuki wrote:

 On 2015/06/26 10:43, Xishi Qiu wrote:
 On 2015/6/26 7:54, Kamezawa Hiroyuki wrote:

 On 2015/06/25 18:44, Xishi Qiu wrote:
 On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:

 On 2015/06/09 19:04, Xishi Qiu wrote:
 On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:

 On 2015/06/04 22:04, Xishi Qiu wrote:
 Add the buddy system interface for address range mirroring feature.
 Allocate mirrored pages in MIGRATE_MIRROR list. If there is no 
 mirrored pages
 left, use other types pages.

 Signed-off-by: Xishi Qiu qiuxi...@huawei.com
 ---
  mm/page_alloc.c | 40 +++-
  1 file changed, 39 insertions(+), 1 deletion(-)

 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
 index d4d2066..0fb55288 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long 
 pfn)

  return false;
  }
 +
 +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
 +{
 +/*
 + * Do not alloc mirrored memory below 4G, because 0-4G is
 + * all mirrored by default, and the list is always empty.
 + */
 +if (high_zoneidx  ZONE_NORMAL)
 +return false;
 +
 +/* Alloc mirrored memory for only kernel */
 +if (gfp_flags  __GFP_MIRROR)
 +return true;

 GFP_KERNEL itself should imply mirror, I think.


 Hi Kame,

 How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | 
 __GFP_FS | __GFP_MIRROR) ?


 Hm it cannot cover GFP_ATOMIC at el.

 I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
 !__GFP_MOVABLE


 Hi Kame,

 Can we distinguish allocations form user or kernel only by GFP flags?


 Allocation from user and file caches are now *always* done with 
 __GFP_MOVABLE.

 By this, pages will be allocated from MIGRATE_MOVABLE migration type.
 MOVABLE migration type means it's can
 be the target for page compaction or memory-hot-remove.

 Thanks,
 -Kame


 So if we want all kernel memory allocated from mirror, how about change like 
 this?
 __alloc_pages_nodemask()
gfpflags_to_migratetype()
  if (!(gfp_mask  __GFP_MOVABLE))
 return MIGRATE_MIRROR
 
 Maybe used with jump label can reduce performance impact.

Hi Kame,

I am not understand jump label, but I wil try.

 ==
 static inline bool memory_mirror_enabled(void)
 {
 return static_key_false(memory_mirror_enabled);
 }
 
 
 
 gfpflags_to_migratetype()
   if (memory_mirror_enabled()) { /* We want to mirror all unmovable pages */
   if (!(gfp_mask  __GFP_MOVABLE))
return MIGRATE_MIRROR
   }
 ==
 
 BTW, I think current memory compaction code scans ranges of MOVABLE migrate 
 type.
 So, if you use other migration type than MOVABLE for user pages, you may see
 page fragmentation. If you want to expand this MIRROR to user pages, please 
 check
 mm/compaction.c
 

As Tony said how can we minimize the run-time impact on systems that don't have
any mirrored memory., I think the idea kernel only from MIRROR / user only 
from
MOVABLE may be better.

Thanks,
Xishi Qiu



--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-25 Thread Xishi Qiu
On 2015/6/26 7:54, Kamezawa Hiroyuki wrote:

> On 2015/06/25 18:44, Xishi Qiu wrote:
>> On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:
>>
>>> On 2015/06/09 19:04, Xishi Qiu wrote:
 On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:

> On 2015/06/04 22:04, Xishi Qiu wrote:
>> Add the buddy system interface for address range mirroring feature.
>> Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored 
>> pages
>> left, use other types pages.
>>
>> Signed-off-by: Xishi Qiu 
>> ---
>> mm/page_alloc.c | 40 +++-
>> 1 file changed, 39 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index d4d2066..0fb55288 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)
>>
>> return false;
>> }
>> +
>> +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
>> +{
>> +/*
>> + * Do not alloc mirrored memory below 4G, because 0-4G is
>> + * all mirrored by default, and the list is always empty.
>> + */
>> +if (high_zoneidx < ZONE_NORMAL)
>> +return false;
>> +
>> +/* Alloc mirrored memory for only kernel */
>> +if (gfp_flags & __GFP_MIRROR)
>> +return true;
>
> GFP_KERNEL itself should imply mirror, I think.
>

 Hi Kame,

 How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS 
 | __GFP_MIRROR) ?

>>>
>>> Hm it cannot cover GFP_ATOMIC at el.
>>>
>>> I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
>>> !__GFP_MOVABLE
>>
>>
>> Hi Kame,
>>
>> Can we distinguish allocations form user or kernel only by GFP flags?
>>
> 
> Allocation from user and file caches are now *always* done with __GFP_MOVABLE.
> 
> By this, pages will be allocated from MIGRATE_MOVABLE migration type.
> MOVABLE migration type means it's can
> be the target for page compaction or memory-hot-remove.
> 
> Thanks,
> -Kame
> 

So if we want all kernel memory allocated from mirror, how about change like 
this?
__alloc_pages_nodemask()
  gfpflags_to_migratetype()
if (!(gfp_mask & __GFP_MOVABLE))
return MIGRATE_MIRROR

Thanks,
Xishi Qiu

> 
> 
> 
> 
> 
> 
> 
> .
> 



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-25 Thread Kamezawa Hiroyuki

On 2015/06/25 18:44, Xishi Qiu wrote:

On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:


On 2015/06/09 19:04, Xishi Qiu wrote:

On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:


On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu 
---
mm/page_alloc.c | 40 +++-
1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

return false;
}
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+/*
+ * Do not alloc mirrored memory below 4G, because 0-4G is
+ * all mirrored by default, and the list is always empty.
+ */
+if (high_zoneidx < ZONE_NORMAL)
+return false;
+
+/* Alloc mirrored memory for only kernel */
+if (gfp_flags & __GFP_MIRROR)
+return true;


GFP_KERNEL itself should imply mirror, I think.



Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?



Hm it cannot cover GFP_ATOMIC at el.

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE



Hi Kame,

Can we distinguish allocations form user or kernel only by GFP flags?



Allocation from user and file caches are now *always* done with __GFP_MOVABLE.

By this, pages will be allocated from MIGRATE_MOVABLE migration type.
MOVABLE migration type means it's can
be the target for page compaction or memory-hot-remove.

Thanks,
-Kame







--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-25 Thread Xishi Qiu
On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:

> On 2015/06/09 19:04, Xishi Qiu wrote:
>> On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:
>>
>>> On 2015/06/04 22:04, Xishi Qiu wrote:
 Add the buddy system interface for address range mirroring feature.
 Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored 
 pages
 left, use other types pages.

 Signed-off-by: Xishi Qiu 
 ---
mm/page_alloc.c | 40 +++-
1 file changed, 39 insertions(+), 1 deletion(-)

 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
 index d4d2066..0fb55288 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

return false;
}
 +
 +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
 +{
 +/*
 + * Do not alloc mirrored memory below 4G, because 0-4G is
 + * all mirrored by default, and the list is always empty.
 + */
 +if (high_zoneidx < ZONE_NORMAL)
 +return false;
 +
 +/* Alloc mirrored memory for only kernel */
 +if (gfp_flags & __GFP_MIRROR)
 +return true;
>>>
>>> GFP_KERNEL itself should imply mirror, I think.
>>>
>>
>> Hi Kame,
>>
>> How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
>> __GFP_MIRROR) ?
>>
> 
> Hm it cannot cover GFP_ATOMIC at el.
> 
> I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
> !__GFP_MOVABLE


Hi Kame,

Can we distinguish allocations form user or kernel only by GFP flags?

Thanks,
Xishi Qiu

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-25 Thread Xishi Qiu
On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:

 On 2015/06/09 19:04, Xishi Qiu wrote:
 On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:

 On 2015/06/04 22:04, Xishi Qiu wrote:
 Add the buddy system interface for address range mirroring feature.
 Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored 
 pages
 left, use other types pages.

 Signed-off-by: Xishi Qiu qiuxi...@huawei.com
 ---
mm/page_alloc.c | 40 +++-
1 file changed, 39 insertions(+), 1 deletion(-)

 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
 index d4d2066..0fb55288 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

return false;
}
 +
 +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
 +{
 +/*
 + * Do not alloc mirrored memory below 4G, because 0-4G is
 + * all mirrored by default, and the list is always empty.
 + */
 +if (high_zoneidx  ZONE_NORMAL)
 +return false;
 +
 +/* Alloc mirrored memory for only kernel */
 +if (gfp_flags  __GFP_MIRROR)
 +return true;

 GFP_KERNEL itself should imply mirror, I think.


 Hi Kame,

 How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
 __GFP_MIRROR) ?

 
 Hm it cannot cover GFP_ATOMIC at el.
 
 I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
 !__GFP_MOVABLE


Hi Kame,

Can we distinguish allocations form user or kernel only by GFP flags?

Thanks,
Xishi Qiu

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-25 Thread Kamezawa Hiroyuki

On 2015/06/25 18:44, Xishi Qiu wrote:

On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:


On 2015/06/09 19:04, Xishi Qiu wrote:

On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:


On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu qiuxi...@huawei.com
---
mm/page_alloc.c | 40 +++-
1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

return false;
}
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+/*
+ * Do not alloc mirrored memory below 4G, because 0-4G is
+ * all mirrored by default, and the list is always empty.
+ */
+if (high_zoneidx  ZONE_NORMAL)
+return false;
+
+/* Alloc mirrored memory for only kernel */
+if (gfp_flags  __GFP_MIRROR)
+return true;


GFP_KERNEL itself should imply mirror, I think.



Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?



Hm it cannot cover GFP_ATOMIC at el.

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE



Hi Kame,

Can we distinguish allocations form user or kernel only by GFP flags?



Allocation from user and file caches are now *always* done with __GFP_MOVABLE.

By this, pages will be allocated from MIGRATE_MOVABLE migration type.
MOVABLE migration type means it's can
be the target for page compaction or memory-hot-remove.

Thanks,
-Kame







--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-25 Thread Xishi Qiu
On 2015/6/26 7:54, Kamezawa Hiroyuki wrote:

 On 2015/06/25 18:44, Xishi Qiu wrote:
 On 2015/6/10 11:06, Kamezawa Hiroyuki wrote:

 On 2015/06/09 19:04, Xishi Qiu wrote:
 On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:

 On 2015/06/04 22:04, Xishi Qiu wrote:
 Add the buddy system interface for address range mirroring feature.
 Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored 
 pages
 left, use other types pages.

 Signed-off-by: Xishi Qiu qiuxi...@huawei.com
 ---
 mm/page_alloc.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
 index d4d2066..0fb55288 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

 return false;
 }
 +
 +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
 +{
 +/*
 + * Do not alloc mirrored memory below 4G, because 0-4G is
 + * all mirrored by default, and the list is always empty.
 + */
 +if (high_zoneidx  ZONE_NORMAL)
 +return false;
 +
 +/* Alloc mirrored memory for only kernel */
 +if (gfp_flags  __GFP_MIRROR)
 +return true;

 GFP_KERNEL itself should imply mirror, I think.


 Hi Kame,

 How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS 
 | __GFP_MIRROR) ?


 Hm it cannot cover GFP_ATOMIC at el.

 I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
 !__GFP_MOVABLE


 Hi Kame,

 Can we distinguish allocations form user or kernel only by GFP flags?

 
 Allocation from user and file caches are now *always* done with __GFP_MOVABLE.
 
 By this, pages will be allocated from MIGRATE_MOVABLE migration type.
 MOVABLE migration type means it's can
 be the target for page compaction or memory-hot-remove.
 
 Thanks,
 -Kame
 

So if we want all kernel memory allocated from mirror, how about change like 
this?
__alloc_pages_nodemask()
  gfpflags_to_migratetype()
if (!(gfp_mask  __GFP_MOVABLE))
return MIGRATE_MIRROR

Thanks,
Xishi Qiu

 
 
 
 
 
 
 
 .
 



--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-15 Thread Kamezawa Hiroyuki

On 2015/06/16 2:20, Luck, Tony wrote:

On Mon, Jun 15, 2015 at 05:47:27PM +0900, Kamezawa Hiroyuki wrote:

So, there are 3 ideas.

  (1) kernel only from MIRROR / user only from MOVABLE (Tony)
  (2) kernel only from MIRROR / user from MOVABLE + MIRROR(ASAP)  (AKPM 
suggested)
  This makes use of the fact MOVABLE memory is reclaimable but Tony pointed 
out
  the memory reclaim can be critical for GFP_ATOMIC.
  (3) kernel only from MIRROR / user from MOVABLE, special user from MIRROR 
(Xishi)

2 Implementation ideas.
   - creating ZONE
   - creating new alloation attribute

I don't convince whether we need some new structure in mm. Isn't it good to use
ZONE_MOVABLE for not-mirrored memory ?
Then, disable fallback from ZONE_MOVABLE -> ZONE_NORMAL for (1) and (3)


We might need to rename it ... right now the memory hotplug
people use ZONE_MOVABLE to indicate regions of physical memory
that can be removed from the system.  I'm wondering whether
people will want systems that have both removable and mirrored
areas?  Then we have four attribute combinations:

mirror=no  removable=no  - prefer to use for user, could use for kernel if we 
run out of mirror
mirror=no  removable=yes - can only be used for user (kernel allocation makes 
it not-removable)
mirror=yes removable=no  - use for kernel, possibly for special users if we 
define some interface
mirror=yes removable=yes - must not use for kernel ... would have to give to 
user ... seems like a bad idea to configure a system this way



Thank you for clarification. I see "mirror=no, removable=no" case may require a 
new name.

IMHO, the value of Address-Based-Memory-Mirror is that users can protect their 
system's
important functions without using full-memory mirror. So, I feel thinking
"mirror=no, removable=no" just makes our discussion/implemenation complex 
without real
user value.

Shouldn't we start with just thiking 2 cases of
 mirror=no  removable=yes
 mirror=yes removable=no
?

And then, if the naming is problem, alias name can be added.

Thanks,
-Kame






--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-15 Thread Luck, Tony
On Mon, Jun 15, 2015 at 05:47:27PM +0900, Kamezawa Hiroyuki wrote:
> So, there are 3 ideas.
> 
>  (1) kernel only from MIRROR / user only from MOVABLE (Tony)
>  (2) kernel only from MIRROR / user from MOVABLE + MIRROR(ASAP)  (AKPM 
> suggested)
>  This makes use of the fact MOVABLE memory is reclaimable but Tony 
> pointed out
>  the memory reclaim can be critical for GFP_ATOMIC.
>  (3) kernel only from MIRROR / user from MOVABLE, special user from MIRROR 
> (Xishi)
> 
> 2 Implementation ideas.
>   - creating ZONE
>   - creating new alloation attribute
> 
> I don't convince whether we need some new structure in mm. Isn't it good to 
> use
> ZONE_MOVABLE for not-mirrored memory ?
> Then, disable fallback from ZONE_MOVABLE -> ZONE_NORMAL for (1) and (3)

We might need to rename it ... right now the memory hotplug
people use ZONE_MOVABLE to indicate regions of physical memory
that can be removed from the system.  I'm wondering whether
people will want systems that have both removable and mirrored
areas?  Then we have four attribute combinations:

mirror=no  removable=no  - prefer to use for user, could use for kernel if we 
run out of mirror
mirror=no  removable=yes - can only be used for user (kernel allocation makes 
it not-removable)
mirror=yes removable=no  - use for kernel, possibly for special users if we 
define some interface
mirror=yes removable=yes - must not use for kernel ... would have to give to 
user ... seems like a bad idea to configure a system this way

-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-15 Thread Kamezawa Hiroyuki

On 2015/06/11 5:40, Luck, Tony wrote:

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE


HIGHMEM shouldn't matter - partial memory mirror only makes any sense on X86_64 
systems ... 32-bit kernels
don't even boot on systems with 64GB, and the minimum rational configuration 
for a machine that supports
mirror is 128GB (4 cpu sockets * 2 memory controller per socket * 4 channels 
per controller * 4GB DIMM ...
leaving any channels empty likely leaves you short of memory bandwidth for 
these high core count processors).

MOVABLE is mostly the opposite of MIRROR - we never want to fill a kernel 
allocation from a MOVABLE page. I
want all kernel allocations to be from MIRROR.



So, there are 3 ideas.

 (1) kernel only from MIRROR / user only from MOVABLE (Tony)
 (2) kernel only from MIRROR / user from MOVABLE + MIRROR(ASAP)  (AKPM 
suggested)
 This makes use of the fact MOVABLE memory is reclaimable but Tony pointed 
out
 the memory reclaim can be critical for GFP_ATOMIC.
 (3) kernel only from MIRROR / user from MOVABLE, special user from MIRROR 
(Xishi)

2 Implementation ideas.
  - creating ZONE
  - creating new alloation attribute

I don't convince whether we need some new structure in mm. Isn't it good to use
ZONE_MOVABLE for not-mirrored memory ?
Then, disable fallback from ZONE_MOVABLE -> ZONE_NORMAL for (1) and (3)

Thanks,
-Kame


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-15 Thread Kamezawa Hiroyuki

On 2015/06/11 5:40, Luck, Tony wrote:

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE


HIGHMEM shouldn't matter - partial memory mirror only makes any sense on X86_64 
systems ... 32-bit kernels
don't even boot on systems with 64GB, and the minimum rational configuration 
for a machine that supports
mirror is 128GB (4 cpu sockets * 2 memory controller per socket * 4 channels 
per controller * 4GB DIMM ...
leaving any channels empty likely leaves you short of memory bandwidth for 
these high core count processors).

MOVABLE is mostly the opposite of MIRROR - we never want to fill a kernel 
allocation from a MOVABLE page. I
want all kernel allocations to be from MIRROR.



So, there are 3 ideas.

 (1) kernel only from MIRROR / user only from MOVABLE (Tony)
 (2) kernel only from MIRROR / user from MOVABLE + MIRROR(ASAP)  (AKPM 
suggested)
 This makes use of the fact MOVABLE memory is reclaimable but Tony pointed 
out
 the memory reclaim can be critical for GFP_ATOMIC.
 (3) kernel only from MIRROR / user from MOVABLE, special user from MIRROR 
(Xishi)

2 Implementation ideas.
  - creating ZONE
  - creating new alloation attribute

I don't convince whether we need some new structure in mm. Isn't it good to use
ZONE_MOVABLE for not-mirrored memory ?
Then, disable fallback from ZONE_MOVABLE - ZONE_NORMAL for (1) and (3)

Thanks,
-Kame


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-15 Thread Luck, Tony
On Mon, Jun 15, 2015 at 05:47:27PM +0900, Kamezawa Hiroyuki wrote:
 So, there are 3 ideas.
 
  (1) kernel only from MIRROR / user only from MOVABLE (Tony)
  (2) kernel only from MIRROR / user from MOVABLE + MIRROR(ASAP)  (AKPM 
 suggested)
  This makes use of the fact MOVABLE memory is reclaimable but Tony 
 pointed out
  the memory reclaim can be critical for GFP_ATOMIC.
  (3) kernel only from MIRROR / user from MOVABLE, special user from MIRROR 
 (Xishi)
 
 2 Implementation ideas.
   - creating ZONE
   - creating new alloation attribute
 
 I don't convince whether we need some new structure in mm. Isn't it good to 
 use
 ZONE_MOVABLE for not-mirrored memory ?
 Then, disable fallback from ZONE_MOVABLE - ZONE_NORMAL for (1) and (3)

We might need to rename it ... right now the memory hotplug
people use ZONE_MOVABLE to indicate regions of physical memory
that can be removed from the system.  I'm wondering whether
people will want systems that have both removable and mirrored
areas?  Then we have four attribute combinations:

mirror=no  removable=no  - prefer to use for user, could use for kernel if we 
run out of mirror
mirror=no  removable=yes - can only be used for user (kernel allocation makes 
it not-removable)
mirror=yes removable=no  - use for kernel, possibly for special users if we 
define some interface
mirror=yes removable=yes - must not use for kernel ... would have to give to 
user ... seems like a bad idea to configure a system this way

-Tony
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-15 Thread Kamezawa Hiroyuki

On 2015/06/16 2:20, Luck, Tony wrote:

On Mon, Jun 15, 2015 at 05:47:27PM +0900, Kamezawa Hiroyuki wrote:

So, there are 3 ideas.

  (1) kernel only from MIRROR / user only from MOVABLE (Tony)
  (2) kernel only from MIRROR / user from MOVABLE + MIRROR(ASAP)  (AKPM 
suggested)
  This makes use of the fact MOVABLE memory is reclaimable but Tony pointed 
out
  the memory reclaim can be critical for GFP_ATOMIC.
  (3) kernel only from MIRROR / user from MOVABLE, special user from MIRROR 
(Xishi)

2 Implementation ideas.
   - creating ZONE
   - creating new alloation attribute

I don't convince whether we need some new structure in mm. Isn't it good to use
ZONE_MOVABLE for not-mirrored memory ?
Then, disable fallback from ZONE_MOVABLE - ZONE_NORMAL for (1) and (3)


We might need to rename it ... right now the memory hotplug
people use ZONE_MOVABLE to indicate regions of physical memory
that can be removed from the system.  I'm wondering whether
people will want systems that have both removable and mirrored
areas?  Then we have four attribute combinations:

mirror=no  removable=no  - prefer to use for user, could use for kernel if we 
run out of mirror
mirror=no  removable=yes - can only be used for user (kernel allocation makes 
it not-removable)
mirror=yes removable=no  - use for kernel, possibly for special users if we 
define some interface
mirror=yes removable=yes - must not use for kernel ... would have to give to 
user ... seems like a bad idea to configure a system this way



Thank you for clarification. I see mirror=no, removable=no case may require a 
new name.

IMHO, the value of Address-Based-Memory-Mirror is that users can protect their 
system's
important functions without using full-memory mirror. So, I feel thinking
mirror=no, removable=no just makes our discussion/implemenation complex 
without real
user value.

Shouldn't we start with just thiking 2 cases of
 mirror=no  removable=yes
 mirror=yes removable=no
?

And then, if the naming is problem, alias name can be added.

Thanks,
-Kame






--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-10 Thread Luck, Tony
> I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
> !__GFP_MOVABLE

HIGHMEM shouldn't matter - partial memory mirror only makes any sense on X86_64 
systems ... 32-bit kernels
don't even boot on systems with 64GB, and the minimum rational configuration 
for a machine that supports
mirror is 128GB (4 cpu sockets * 2 memory controller per socket * 4 channels 
per controller * 4GB DIMM ...
leaving any channels empty likely leaves you short of memory bandwidth for 
these high core count processors).

MOVABLE is mostly the opposite of MIRROR - we never want to fill a kernel 
allocation from a MOVABLE page. I
want all kernel allocations to be from MIRROR.

-Tony


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-10 Thread Luck, Tony
 I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or 
 !__GFP_MOVABLE

HIGHMEM shouldn't matter - partial memory mirror only makes any sense on X86_64 
systems ... 32-bit kernels
don't even boot on systems with 64GB, and the minimum rational configuration 
for a machine that supports
mirror is 128GB (4 cpu sockets * 2 memory controller per socket * 4 channels 
per controller * 4GB DIMM ...
leaving any channels empty likely leaves you short of memory bandwidth for 
these high core count processors).

MOVABLE is mostly the opposite of MIRROR - we never want to fill a kernel 
allocation from a MOVABLE page. I
want all kernel allocations to be from MIRROR.

-Tony


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-09 Thread Kamezawa Hiroyuki

On 2015/06/09 19:04, Xishi Qiu wrote:

On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:


On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu 
---
   mm/page_alloc.c | 40 +++-
   1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

   return false;
   }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+/*
+ * Do not alloc mirrored memory below 4G, because 0-4G is
+ * all mirrored by default, and the list is always empty.
+ */
+if (high_zoneidx < ZONE_NORMAL)
+return false;
+
+/* Alloc mirrored memory for only kernel */
+if (gfp_flags & __GFP_MIRROR)
+return true;


GFP_KERNEL itself should imply mirror, I think.



Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?



Hm it cannot cover GFP_ATOMIC at el.

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE

thanks,
-Kame

Thanks,
-Kame



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-09 Thread Xishi Qiu
On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:

> On 2015/06/04 22:04, Xishi Qiu wrote:
>> Add the buddy system interface for address range mirroring feature.
>> Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
>> left, use other types pages.
>>
>> Signed-off-by: Xishi Qiu 
>> ---
>>   mm/page_alloc.c | 40 +++-
>>   1 file changed, 39 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index d4d2066..0fb55288 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)
>>
>>   return false;
>>   }
>> +
>> +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
>> +{
>> +/*
>> + * Do not alloc mirrored memory below 4G, because 0-4G is
>> + * all mirrored by default, and the list is always empty.
>> + */
>> +if (high_zoneidx < ZONE_NORMAL)
>> +return false;
>> +
>> +/* Alloc mirrored memory for only kernel */
>> +if (gfp_flags & __GFP_MIRROR)
>> +return true;
> 
> GFP_KERNEL itself should imply mirror, I think.
> 

Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?

Thanks,
Xishi Qiu

>> +
>> +/* Alloc mirrored memory for both user and kernel */
>> +if (sysctl_mirrorable)
>> +return true;
> 
> Reading this, I think this sysctl is not good. The user cannot know what is 
> mirrored
> because memory may not be mirrored until the sysctl is set.
> 
> Thanks,
> -Kame
> 
> 
>> +
>> +return false;
>> +}
>>   #endif
>>
>>   /*
>> @@ -1796,7 +1816,10 @@ struct page *buffered_rmqueue(struct zone 
>> *preferred_zone,
>>   WARN_ON_ONCE(order > 1);
>>   }
>>   spin_lock_irqsave(>lock, flags);
>> -page = __rmqueue(zone, order, migratetype);
>> +if (is_migrate_mirror(migratetype))
>> +page = __rmqueue_smallest(zone, order, migratetype);
>> +else
>> +page = __rmqueue(zone, order, migratetype);
>>   spin_unlock(>lock);
>>   if (!page)
>>   goto failed;
>> @@ -2928,6 +2951,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int 
>> order,
>>   if (IS_ENABLED(CONFIG_CMA) && ac.migratetype == MIGRATE_MOVABLE)
>>   alloc_flags |= ALLOC_CMA;
>>
>> +#ifdef CONFIG_MEMORY_MIRROR
>> +if (change_to_mirror(gfp_mask, ac.high_zoneidx))
>> +ac.migratetype = MIGRATE_MIRROR;
>> +#endif
>> +
>>   retry_cpuset:
>>   cpuset_mems_cookie = read_mems_allowed_begin();
>>
>> @@ -2943,9 +2971,19 @@ retry_cpuset:
>>
>>   /* First allocation attempt */
>>   alloc_mask = gfp_mask|__GFP_HARDWALL;
>> +retry:
>>   page = get_page_from_freelist(alloc_mask, order, alloc_flags, );
>>   if (unlikely(!page)) {
>>   /*
>> + * If there is no mirrored memory, we will alloc other
>> + * types memory.
>> + */
>> +if (is_migrate_mirror(ac.migratetype)) {
>> +ac.migratetype = gfpflags_to_migratetype(gfp_mask);
>> +goto retry;
>> +}
>> +
>> +/*
>>* Runtime PM, block IO and its error handling path
>>* can deadlock because I/O on the device might not
>>* complete.
>>
> 
> 
> 
> .
> 



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-09 Thread Kamezawa Hiroyuki

On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu 
---
  mm/page_alloc.c | 40 +++-
  1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

return false;
  }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+   /*
+* Do not alloc mirrored memory below 4G, because 0-4G is
+* all mirrored by default, and the list is always empty.
+*/
+   if (high_zoneidx < ZONE_NORMAL)
+   return false;
+
+   /* Alloc mirrored memory for only kernel */
+   if (gfp_flags & __GFP_MIRROR)
+   return true;


GFP_KERNEL itself should imply mirror, I think.


+
+   /* Alloc mirrored memory for both user and kernel */
+   if (sysctl_mirrorable)
+   return true;


Reading this, I think this sysctl is not good. The user cannot know what is 
mirrored
because memory may not be mirrored until the sysctl is set.

Thanks,
-Kame



+
+   return false;
+}
  #endif

  /*
@@ -1796,7 +1816,10 @@ struct page *buffered_rmqueue(struct zone 
*preferred_zone,
WARN_ON_ONCE(order > 1);
}
spin_lock_irqsave(>lock, flags);
-   page = __rmqueue(zone, order, migratetype);
+   if (is_migrate_mirror(migratetype))
+   page = __rmqueue_smallest(zone, order, migratetype);
+   else
+   page = __rmqueue(zone, order, migratetype);
spin_unlock(>lock);
if (!page)
goto failed;
@@ -2928,6 +2951,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int 
order,
if (IS_ENABLED(CONFIG_CMA) && ac.migratetype == MIGRATE_MOVABLE)
alloc_flags |= ALLOC_CMA;

+#ifdef CONFIG_MEMORY_MIRROR
+   if (change_to_mirror(gfp_mask, ac.high_zoneidx))
+   ac.migratetype = MIGRATE_MIRROR;
+#endif
+
  retry_cpuset:
cpuset_mems_cookie = read_mems_allowed_begin();

@@ -2943,9 +2971,19 @@ retry_cpuset:

/* First allocation attempt */
alloc_mask = gfp_mask|__GFP_HARDWALL;
+retry:
page = get_page_from_freelist(alloc_mask, order, alloc_flags, );
if (unlikely(!page)) {
/*
+* If there is no mirrored memory, we will alloc other
+* types memory.
+*/
+   if (is_migrate_mirror(ac.migratetype)) {
+   ac.migratetype = gfpflags_to_migratetype(gfp_mask);
+   goto retry;
+   }
+
+   /*
 * Runtime PM, block IO and its error handling path
 * can deadlock because I/O on the device might not
 * complete.




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-09 Thread Xishi Qiu
On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:

 On 2015/06/04 22:04, Xishi Qiu wrote:
 Add the buddy system interface for address range mirroring feature.
 Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
 left, use other types pages.

 Signed-off-by: Xishi Qiu qiuxi...@huawei.com
 ---
   mm/page_alloc.c | 40 +++-
   1 file changed, 39 insertions(+), 1 deletion(-)

 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
 index d4d2066..0fb55288 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

   return false;
   }
 +
 +static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
 +{
 +/*
 + * Do not alloc mirrored memory below 4G, because 0-4G is
 + * all mirrored by default, and the list is always empty.
 + */
 +if (high_zoneidx  ZONE_NORMAL)
 +return false;
 +
 +/* Alloc mirrored memory for only kernel */
 +if (gfp_flags  __GFP_MIRROR)
 +return true;
 
 GFP_KERNEL itself should imply mirror, I think.
 

Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?

Thanks,
Xishi Qiu

 +
 +/* Alloc mirrored memory for both user and kernel */
 +if (sysctl_mirrorable)
 +return true;
 
 Reading this, I think this sysctl is not good. The user cannot know what is 
 mirrored
 because memory may not be mirrored until the sysctl is set.
 
 Thanks,
 -Kame
 
 
 +
 +return false;
 +}
   #endif

   /*
 @@ -1796,7 +1816,10 @@ struct page *buffered_rmqueue(struct zone 
 *preferred_zone,
   WARN_ON_ONCE(order  1);
   }
   spin_lock_irqsave(zone-lock, flags);
 -page = __rmqueue(zone, order, migratetype);
 +if (is_migrate_mirror(migratetype))
 +page = __rmqueue_smallest(zone, order, migratetype);
 +else
 +page = __rmqueue(zone, order, migratetype);
   spin_unlock(zone-lock);
   if (!page)
   goto failed;
 @@ -2928,6 +2951,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int 
 order,
   if (IS_ENABLED(CONFIG_CMA)  ac.migratetype == MIGRATE_MOVABLE)
   alloc_flags |= ALLOC_CMA;

 +#ifdef CONFIG_MEMORY_MIRROR
 +if (change_to_mirror(gfp_mask, ac.high_zoneidx))
 +ac.migratetype = MIGRATE_MIRROR;
 +#endif
 +
   retry_cpuset:
   cpuset_mems_cookie = read_mems_allowed_begin();

 @@ -2943,9 +2971,19 @@ retry_cpuset:

   /* First allocation attempt */
   alloc_mask = gfp_mask|__GFP_HARDWALL;
 +retry:
   page = get_page_from_freelist(alloc_mask, order, alloc_flags, ac);
   if (unlikely(!page)) {
   /*
 + * If there is no mirrored memory, we will alloc other
 + * types memory.
 + */
 +if (is_migrate_mirror(ac.migratetype)) {
 +ac.migratetype = gfpflags_to_migratetype(gfp_mask);
 +goto retry;
 +}
 +
 +/*
* Runtime PM, block IO and its error handling path
* can deadlock because I/O on the device might not
* complete.

 
 
 
 .
 



--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-09 Thread Kamezawa Hiroyuki

On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu qiuxi...@huawei.com
---
  mm/page_alloc.c | 40 +++-
  1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

return false;
  }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+   /*
+* Do not alloc mirrored memory below 4G, because 0-4G is
+* all mirrored by default, and the list is always empty.
+*/
+   if (high_zoneidx  ZONE_NORMAL)
+   return false;
+
+   /* Alloc mirrored memory for only kernel */
+   if (gfp_flags  __GFP_MIRROR)
+   return true;


GFP_KERNEL itself should imply mirror, I think.


+
+   /* Alloc mirrored memory for both user and kernel */
+   if (sysctl_mirrorable)
+   return true;


Reading this, I think this sysctl is not good. The user cannot know what is 
mirrored
because memory may not be mirrored until the sysctl is set.

Thanks,
-Kame



+
+   return false;
+}
  #endif

  /*
@@ -1796,7 +1816,10 @@ struct page *buffered_rmqueue(struct zone 
*preferred_zone,
WARN_ON_ONCE(order  1);
}
spin_lock_irqsave(zone-lock, flags);
-   page = __rmqueue(zone, order, migratetype);
+   if (is_migrate_mirror(migratetype))
+   page = __rmqueue_smallest(zone, order, migratetype);
+   else
+   page = __rmqueue(zone, order, migratetype);
spin_unlock(zone-lock);
if (!page)
goto failed;
@@ -2928,6 +2951,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int 
order,
if (IS_ENABLED(CONFIG_CMA)  ac.migratetype == MIGRATE_MOVABLE)
alloc_flags |= ALLOC_CMA;

+#ifdef CONFIG_MEMORY_MIRROR
+   if (change_to_mirror(gfp_mask, ac.high_zoneidx))
+   ac.migratetype = MIGRATE_MIRROR;
+#endif
+
  retry_cpuset:
cpuset_mems_cookie = read_mems_allowed_begin();

@@ -2943,9 +2971,19 @@ retry_cpuset:

/* First allocation attempt */
alloc_mask = gfp_mask|__GFP_HARDWALL;
+retry:
page = get_page_from_freelist(alloc_mask, order, alloc_flags, ac);
if (unlikely(!page)) {
/*
+* If there is no mirrored memory, we will alloc other
+* types memory.
+*/
+   if (is_migrate_mirror(ac.migratetype)) {
+   ac.migratetype = gfpflags_to_migratetype(gfp_mask);
+   goto retry;
+   }
+
+   /*
 * Runtime PM, block IO and its error handling path
 * can deadlock because I/O on the device might not
 * complete.




--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-09 Thread Kamezawa Hiroyuki

On 2015/06/09 19:04, Xishi Qiu wrote:

On 2015/6/9 15:12, Kamezawa Hiroyuki wrote:


On 2015/06/04 22:04, Xishi Qiu wrote:

Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu qiuxi...@huawei.com
---
   mm/page_alloc.c | 40 +++-
   1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)

   return false;
   }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+/*
+ * Do not alloc mirrored memory below 4G, because 0-4G is
+ * all mirrored by default, and the list is always empty.
+ */
+if (high_zoneidx  ZONE_NORMAL)
+return false;
+
+/* Alloc mirrored memory for only kernel */
+if (gfp_flags  __GFP_MIRROR)
+return true;


GFP_KERNEL itself should imply mirror, I think.



Hi Kame,

How about like this: #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS | 
__GFP_MIRROR) ?



Hm it cannot cover GFP_ATOMIC at el.

I guess, mirrored memory should be allocated if !__GFP_HIGHMEM or !__GFP_MOVABLE

thanks,
-Kame

Thanks,
-Kame



--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-04 Thread Xishi Qiu
On 2015/6/5 1:09, Luck, Tony wrote:

> +#ifdef CONFIG_MEMORY_MIRROR
> + if (change_to_mirror(gfp_mask, ac.high_zoneidx))
> + ac.migratetype = MIGRATE_MIRROR;
> +#endif
> 
> We may have to be smarter than this here. I'd like to encourage the
> enterprise Linux distributions to set CONFIG_MEMORY_MIRROR=y
> But the reality is that most systems will not configure any mirrored
> memory - so we don't want the common code path for memory
> allocation to call functions that set the migrate type, try to allocate
> and then fall back to a non-mirror when that may be a complete waste
> of time.
> 
> Maybe a global "got_mirror" that is true if we have some mirrored
> memory.  Then code is
> 
>   if (got_mirror && change_to_mirror(...))
> 

Yes, I will change next time.

Thanks,

> .
> 



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-04 Thread Luck, Tony
+#ifdef CONFIG_MEMORY_MIRROR
+   if (change_to_mirror(gfp_mask, ac.high_zoneidx))
+   ac.migratetype = MIGRATE_MIRROR;
+#endif

We may have to be smarter than this here. I'd like to encourage the
enterprise Linux distributions to set CONFIG_MEMORY_MIRROR=y
But the reality is that most systems will not configure any mirrored
memory - so we don't want the common code path for memory
allocation to call functions that set the migrate type, try to allocate
and then fall back to a non-mirror when that may be a complete waste
of time.

Maybe a global "got_mirror" that is true if we have some mirrored
memory.  Then code is

if (got_mirror && change_to_mirror(...))
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH 10/12] mm: add the buddy system interface

2015-06-04 Thread Xishi Qiu
Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu 
---
 mm/page_alloc.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)
 
return false;
 }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+   /*
+* Do not alloc mirrored memory below 4G, because 0-4G is
+* all mirrored by default, and the list is always empty.
+*/
+   if (high_zoneidx < ZONE_NORMAL)
+   return false;
+
+   /* Alloc mirrored memory for only kernel */
+   if (gfp_flags & __GFP_MIRROR)
+   return true;
+
+   /* Alloc mirrored memory for both user and kernel */
+   if (sysctl_mirrorable)
+   return true;
+
+   return false;
+}
 #endif
 
 /*
@@ -1796,7 +1816,10 @@ struct page *buffered_rmqueue(struct zone 
*preferred_zone,
WARN_ON_ONCE(order > 1);
}
spin_lock_irqsave(>lock, flags);
-   page = __rmqueue(zone, order, migratetype);
+   if (is_migrate_mirror(migratetype))
+   page = __rmqueue_smallest(zone, order, migratetype);
+   else
+   page = __rmqueue(zone, order, migratetype);
spin_unlock(>lock);
if (!page)
goto failed;
@@ -2928,6 +2951,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int 
order,
if (IS_ENABLED(CONFIG_CMA) && ac.migratetype == MIGRATE_MOVABLE)
alloc_flags |= ALLOC_CMA;
 
+#ifdef CONFIG_MEMORY_MIRROR
+   if (change_to_mirror(gfp_mask, ac.high_zoneidx))
+   ac.migratetype = MIGRATE_MIRROR;
+#endif
+
 retry_cpuset:
cpuset_mems_cookie = read_mems_allowed_begin();
 
@@ -2943,9 +2971,19 @@ retry_cpuset:
 
/* First allocation attempt */
alloc_mask = gfp_mask|__GFP_HARDWALL;
+retry:
page = get_page_from_freelist(alloc_mask, order, alloc_flags, );
if (unlikely(!page)) {
/*
+* If there is no mirrored memory, we will alloc other
+* types memory.
+*/
+   if (is_migrate_mirror(ac.migratetype)) {
+   ac.migratetype = gfpflags_to_migratetype(gfp_mask);
+   goto retry;
+   }
+
+   /*
 * Runtime PM, block IO and its error handling path
 * can deadlock because I/O on the device might not
 * complete.
-- 
2.0.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-04 Thread Xishi Qiu
On 2015/6/5 1:09, Luck, Tony wrote:

 +#ifdef CONFIG_MEMORY_MIRROR
 + if (change_to_mirror(gfp_mask, ac.high_zoneidx))
 + ac.migratetype = MIGRATE_MIRROR;
 +#endif
 
 We may have to be smarter than this here. I'd like to encourage the
 enterprise Linux distributions to set CONFIG_MEMORY_MIRROR=y
 But the reality is that most systems will not configure any mirrored
 memory - so we don't want the common code path for memory
 allocation to call functions that set the migrate type, try to allocate
 and then fall back to a non-mirror when that may be a complete waste
 of time.
 
 Maybe a global got_mirror that is true if we have some mirrored
 memory.  Then code is
 
   if (got_mirror  change_to_mirror(...))
 

Yes, I will change next time.

Thanks,

 .
 



--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [RFC PATCH 10/12] mm: add the buddy system interface

2015-06-04 Thread Luck, Tony
+#ifdef CONFIG_MEMORY_MIRROR
+   if (change_to_mirror(gfp_mask, ac.high_zoneidx))
+   ac.migratetype = MIGRATE_MIRROR;
+#endif

We may have to be smarter than this here. I'd like to encourage the
enterprise Linux distributions to set CONFIG_MEMORY_MIRROR=y
But the reality is that most systems will not configure any mirrored
memory - so we don't want the common code path for memory
allocation to call functions that set the migrate type, try to allocate
and then fall back to a non-mirror when that may be a complete waste
of time.

Maybe a global got_mirror that is true if we have some mirrored
memory.  Then code is

if (got_mirror  change_to_mirror(...))
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH 10/12] mm: add the buddy system interface

2015-06-04 Thread Xishi Qiu
Add the buddy system interface for address range mirroring feature.
Allocate mirrored pages in MIGRATE_MIRROR list. If there is no mirrored pages
left, use other types pages.

Signed-off-by: Xishi Qiu qiuxi...@huawei.com
---
 mm/page_alloc.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d4d2066..0fb55288 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -599,6 +599,26 @@ static inline bool is_mirror_pfn(unsigned long pfn)
 
return false;
 }
+
+static inline bool change_to_mirror(gfp_t gfp_flags, int high_zoneidx)
+{
+   /*
+* Do not alloc mirrored memory below 4G, because 0-4G is
+* all mirrored by default, and the list is always empty.
+*/
+   if (high_zoneidx  ZONE_NORMAL)
+   return false;
+
+   /* Alloc mirrored memory for only kernel */
+   if (gfp_flags  __GFP_MIRROR)
+   return true;
+
+   /* Alloc mirrored memory for both user and kernel */
+   if (sysctl_mirrorable)
+   return true;
+
+   return false;
+}
 #endif
 
 /*
@@ -1796,7 +1816,10 @@ struct page *buffered_rmqueue(struct zone 
*preferred_zone,
WARN_ON_ONCE(order  1);
}
spin_lock_irqsave(zone-lock, flags);
-   page = __rmqueue(zone, order, migratetype);
+   if (is_migrate_mirror(migratetype))
+   page = __rmqueue_smallest(zone, order, migratetype);
+   else
+   page = __rmqueue(zone, order, migratetype);
spin_unlock(zone-lock);
if (!page)
goto failed;
@@ -2928,6 +2951,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int 
order,
if (IS_ENABLED(CONFIG_CMA)  ac.migratetype == MIGRATE_MOVABLE)
alloc_flags |= ALLOC_CMA;
 
+#ifdef CONFIG_MEMORY_MIRROR
+   if (change_to_mirror(gfp_mask, ac.high_zoneidx))
+   ac.migratetype = MIGRATE_MIRROR;
+#endif
+
 retry_cpuset:
cpuset_mems_cookie = read_mems_allowed_begin();
 
@@ -2943,9 +2971,19 @@ retry_cpuset:
 
/* First allocation attempt */
alloc_mask = gfp_mask|__GFP_HARDWALL;
+retry:
page = get_page_from_freelist(alloc_mask, order, alloc_flags, ac);
if (unlikely(!page)) {
/*
+* If there is no mirrored memory, we will alloc other
+* types memory.
+*/
+   if (is_migrate_mirror(ac.migratetype)) {
+   ac.migratetype = gfpflags_to_migratetype(gfp_mask);
+   goto retry;
+   }
+
+   /*
 * Runtime PM, block IO and its error handling path
 * can deadlock because I/O on the device might not
 * complete.
-- 
2.0.0


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/