* [PATCH] mm: align up min_free_kbytes to multipy of 4
@ 2019-06-09 9:10 ChenGang
2019-06-09 14:53 ` Wei Yang
2019-06-10 7:26 ` Michal Hocko
0 siblings, 2 replies; 6+ messages in thread
From: ChenGang @ 2019-06-09 9:10 UTC (permalink / raw)
To: akpm, mhocko, vbabka, osalvador, pavel.tatashin
Cc: mgorman, rppt, richard.weiyang, alexander.h.duyck, linux-mm,
linux-kernel, ChenGang
Usually the value of min_free_kbytes is multiply of 4,
and in this case ,the right shift is ok.
But if it's not, the right-shifting operation will lose the low 2 bits,
and this cause kernel don't reserve enough memory.
So it's necessary to align the value of min_free_kbytes to multiply of 4.
For example, if min_free_kbytes is 64, then should keep 16 pages,
but if min_free_kbytes is 65 or 66, then should keep 17 pages.
Signed-off-by: ChenGang <cg.chen@huawei.com>
---
mm/page_alloc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d66bc8a..1baeeba 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7611,7 +7611,8 @@ static void setup_per_zone_lowmem_reserve(void)
static void __setup_per_zone_wmarks(void)
{
- unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10);
+ unsigned long pages_min =
+ (PAGE_ALIGN(min_free_kbytes * 1024) / 1024) >> (PAGE_SHIFT - 10);
unsigned long lowmem_pages = 0;
struct zone *zone;
unsigned long flags;
--
1.8.5.6
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm: align up min_free_kbytes to multipy of 4
2019-06-09 9:10 [PATCH] mm: align up min_free_kbytes to multipy of 4 ChenGang
@ 2019-06-09 14:53 ` Wei Yang
2019-06-10 7:26 ` Michal Hocko
1 sibling, 0 replies; 6+ messages in thread
From: Wei Yang @ 2019-06-09 14:53 UTC (permalink / raw)
To: ChenGang
Cc: akpm, mhocko, vbabka, osalvador, pavel.tatashin, mgorman, rppt,
richard.weiyang, alexander.h.duyck, linux-mm, linux-kernel
On Sun, Jun 09, 2019 at 05:10:28PM +0800, ChenGang wrote:
>Usually the value of min_free_kbytes is multiply of 4,
>and in this case ,the right shift is ok.
>But if it's not, the right-shifting operation will lose the low 2 bits,
But PAGE_SHIFT is not always 12.
>and this cause kernel don't reserve enough memory.
>So it's necessary to align the value of min_free_kbytes to multiply of 4.
>For example, if min_free_kbytes is 64, then should keep 16 pages,
>but if min_free_kbytes is 65 or 66, then should keep 17 pages.
>
>Signed-off-by: ChenGang <cg.chen@huawei.com>
>---
> mm/page_alloc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>index d66bc8a..1baeeba 100644
>--- a/mm/page_alloc.c
>+++ b/mm/page_alloc.c
>@@ -7611,7 +7611,8 @@ static void setup_per_zone_lowmem_reserve(void)
>
> static void __setup_per_zone_wmarks(void)
> {
>- unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10);
>+ unsigned long pages_min =
>+ (PAGE_ALIGN(min_free_kbytes * 1024) / 1024) >> (PAGE_SHIFT - 10);
In my mind, pages_min is an estimated value. Do we need to be so precise?
> unsigned long lowmem_pages = 0;
> struct zone *zone;
> unsigned long flags;
>--
>1.8.5.6
--
Wei Yang
Help you, Help me
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm: align up min_free_kbytes to multipy of 4
2019-06-09 9:10 [PATCH] mm: align up min_free_kbytes to multipy of 4 ChenGang
2019-06-09 14:53 ` Wei Yang
@ 2019-06-10 7:26 ` Michal Hocko
1 sibling, 0 replies; 6+ messages in thread
From: Michal Hocko @ 2019-06-10 7:26 UTC (permalink / raw)
To: ChenGang
Cc: akpm, vbabka, osalvador, pavel.tatashin, mgorman, rppt,
richard.weiyang, alexander.h.duyck, linux-mm, linux-kernel
On Sun 09-06-19 17:10:28, ChenGang wrote:
> Usually the value of min_free_kbytes is multiply of 4,
> and in this case ,the right shift is ok.
> But if it's not, the right-shifting operation will lose the low 2 bits,
> and this cause kernel don't reserve enough memory.
> So it's necessary to align the value of min_free_kbytes to multiply of 4.
> For example, if min_free_kbytes is 64, then should keep 16 pages,
> but if min_free_kbytes is 65 or 66, then should keep 17 pages.
Could you describe the actual problem? Do we ever generate
min_free_kbytes that would lead to unexpected reserves or is this trying
to compensate for those values being configured from the userspace? If
later why do we care at all?
Have you seen this to be an actual problem or is this mostly motivated
by the code reading?
> Signed-off-by: ChenGang <cg.chen@huawei.com>
> ---
> mm/page_alloc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index d66bc8a..1baeeba 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7611,7 +7611,8 @@ static void setup_per_zone_lowmem_reserve(void)
>
> static void __setup_per_zone_wmarks(void)
> {
> - unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10);
> + unsigned long pages_min =
> + (PAGE_ALIGN(min_free_kbytes * 1024) / 1024) >> (PAGE_SHIFT - 10);
> unsigned long lowmem_pages = 0;
> struct zone *zone;
> unsigned long flags;
> --
> 1.8.5.6
>
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm: align up min_free_kbytes to multipy of 4
2019-06-11 12:16 Chengang (L)
@ 2019-06-11 13:08 ` Michal Hocko
0 siblings, 0 replies; 6+ messages in thread
From: Michal Hocko @ 2019-06-11 13:08 UTC (permalink / raw)
To: Chengang (L)
Cc: akpm, vbabka, osalvador, pavel.tatashin, mgorman, rppt,
richard.weiyang, alexander.h.duyck, linux-mm, linux-kernel
On Tue 11-06-19 12:16:35, Chengang (L) wrote:
> Hi Michal
>
>
> >On Sun 09-06-19 17:10:28, ChenGang wrote:
> >> Usually the value of min_free_kbytes is multiply of 4, and in this
> >> case ,the right shift is ok.
> >> But if it's not, the right-shifting operation will lose the low 2
> >> bits, and this cause kernel don't reserve enough memory.
> >> So it's necessary to align the value of min_free_kbytes to multiply of 4.
> >> For example, if min_free_kbytes is 64, then should keep 16 pages, but
> >> if min_free_kbytes is 65 or 66, then should keep 17 pages.
>
> >Could you describe the actual problem? Do we ever generate min_free_kbytes that would lead to unexpected reserves or is this trying to compensate for those values being configured from the userspace? If later why do we care at all?
>
> >Have you seen this to be an actual problem or is this mostly motivated by the code reading?
>
> I haven't seen an actual problem, and it's motivated by code
> reading. Users can configure this value through interface
> /proc/sys/vm/min_free_kbytes, so I think a bit precious is better.
The interface is intended for admins and they should better know what
they are doing, right? Using an ad-hoc valus is not something that is a
common usecase.
That being said, your change makes the code slightly harder to read and
the benefit is not entirely clear from the changelog (which btw. sounds
like there is a real problem which is not described in the user visible
terms). So if you really believe this change is worth it, then make sure
you justify it by exaplain what is a negative consequence of a dubious
value set by an admin.
> >> Signed-off-by: ChenGang <cg.chen@huawei.com>
> >> ---
> >> mm/page_alloc.c | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d66bc8a..1baeeba
> >> 100644
> >> --- a/mm/page_alloc.c
> >> +++ b/mm/page_alloc.c
> >> @@ -7611,7 +7611,8 @@ static void setup_per_zone_lowmem_reserve(void)
> >>
> >> static void __setup_per_zone_wmarks(void) {
> >> - unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10);
> >> + unsigned long pages_min =
> >> + (PAGE_ALIGN(min_free_kbytes * 1024) / 1024) >> (PAGE_SHIFT - 10);
> >> unsigned long lowmem_pages = 0;
> >> struct zone *zone;
> >> unsigned long flags;
> >> --
> >> 1.8.5.6
> >>
>
> >--
> >Michal Hocko
> >SUSE Labs
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm: align up min_free_kbytes to multipy of 4
@ 2019-06-11 12:16 Chengang (L)
2019-06-11 13:08 ` Michal Hocko
0 siblings, 1 reply; 6+ messages in thread
From: Chengang (L) @ 2019-06-11 12:16 UTC (permalink / raw)
To: Michal Hocko
Cc: akpm, vbabka, osalvador, pavel.tatashin, mgorman, rppt,
richard.weiyang, alexander.h.duyck, linux-mm, linux-kernel
Hi Michal
>On Sun 09-06-19 17:10:28, ChenGang wrote:
>> Usually the value of min_free_kbytes is multiply of 4, and in this
>> case ,the right shift is ok.
>> But if it's not, the right-shifting operation will lose the low 2
>> bits, and this cause kernel don't reserve enough memory.
>> So it's necessary to align the value of min_free_kbytes to multiply of 4.
>> For example, if min_free_kbytes is 64, then should keep 16 pages, but
>> if min_free_kbytes is 65 or 66, then should keep 17 pages.
>Could you describe the actual problem? Do we ever generate min_free_kbytes that would lead to unexpected reserves or is this trying to compensate for those values being configured from the userspace? If later why do we care at all?
>Have you seen this to be an actual problem or is this mostly motivated by the code reading?
I haven't seen an actual problem, and it's motivated by code reading. Users can configure this value through interface /proc/sys/vm/min_free_kbytes, so I think a bit precious is better.
>> Signed-off-by: ChenGang <cg.chen@huawei.com>
>> ---
>> mm/page_alloc.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d66bc8a..1baeeba
>> 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -7611,7 +7611,8 @@ static void setup_per_zone_lowmem_reserve(void)
>>
>> static void __setup_per_zone_wmarks(void) {
>> - unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10);
>> + unsigned long pages_min =
>> + (PAGE_ALIGN(min_free_kbytes * 1024) / 1024) >> (PAGE_SHIFT - 10);
>> unsigned long lowmem_pages = 0;
>> struct zone *zone;
>> unsigned long flags;
>> --
>> 1.8.5.6
>>
>--
>Michal Hocko
>SUSE Labs
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm: align up min_free_kbytes to multipy of 4
@ 2019-06-11 12:10 Chengang (L)
0 siblings, 0 replies; 6+ messages in thread
From: Chengang (L) @ 2019-06-11 12:10 UTC (permalink / raw)
To: Wei Yang
Cc: akpm, mhocko, vbabka, osalvador, pavel.tatashin, mgorman, rppt,
alexander.h.duyck, linux-mm, linux-kernel
Hi Wei Yang
>On Sun, Jun 09, 2019 at 05:10:28PM +0800, ChenGang wrote:
>>Usually the value of min_free_kbytes is multiply of 4, and in this case
>>,the right shift is ok.
>>But if it's not, the right-shifting operation will lose the low 2 bits,
>But PAGE_SHIFT is not always 12.
You are right, and this is not the key point, this is just an example.
>>and this cause kernel don't reserve enough memory.
>>So it's necessary to align the value of min_free_kbytes to multiply of 4.
>>For example, if min_free_kbytes is 64, then should keep 16 pages, but
>>if min_free_kbytes is 65 or 66, then should keep 17 pages.
>>
>>Signed-off-by: ChenGang <cg.chen@huawei.com>
>>---
>> mm/page_alloc.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>>diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d66bc8a..1baeeba
>>100644
>>--- a/mm/page_alloc.c
>>+++ b/mm/page_alloc.c
>>@@ -7611,7 +7611,8 @@ static void setup_per_zone_lowmem_reserve(void)
>>
>> static void __setup_per_zone_wmarks(void) {
>>- unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10);
>>+ unsigned long pages_min =
>>+ (PAGE_ALIGN(min_free_kbytes * 1024) / 1024) >> (PAGE_SHIFT - 10);
>In my mind, pages_min is an estimated value. Do we need to be so precise?
This is the key point, user can set this value through interface/proc/sys/vm/min_free_kbytes, so a bit more precise is better.
>> unsigned long lowmem_pages = 0;
>> struct zone *zone;
>> unsigned long flags;
>>--
>>1.8.5.6
>--
>Wei Yang
>Help you, Help me
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-06-11 13:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-09 9:10 [PATCH] mm: align up min_free_kbytes to multipy of 4 ChenGang
2019-06-09 14:53 ` Wei Yang
2019-06-10 7:26 ` Michal Hocko
2019-06-11 12:10 Chengang (L)
2019-06-11 12:16 Chengang (L)
2019-06-11 13:08 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox