Re: Re: [PATCH] mm: mempolicy: fix the absence of the last bit of nodemask

From: Pan Zhang
Date: Mon Oct 14 2019 - 09:48:55 EST


On Mon 14-10:19 17:12:52, Michal Hocko wrote:
>> When I want to use set_mempolicy to get the memory from each node on the numa machine,
>> and the MPOL_INTERLEAVE flag seems to achieve this goal.
>> However, during the test, it was found that the use result of node was unbalanced.
>> The memory was allocated evenly from the nodes except the last node,
>> which obviously did not match the expectations.
>>
>> You can test as follows:
>> 1. Create a file that needs to be mmap ped:
>> dd if=/dev/zero of=./test count=1024 bs=1M

>This will already poppulate the page cache and if it fits into memory (which seems to be the case in your example output) then your mmap later will not allocate any new memory.
>
>I suspect that using numactl --interleave 0,1 dd if=/dev/zero of=./test count=1024 bs=1M
>
>will produce an output much closer to your expectation. Right?

Yes, you are right. `dd` command will 'populate the page cache and if it fits into memory'.
As a newcomer who is studying hard in this field,
I am sorry for this and I don't know much about the mechanism of memory management.

I used `malloc` again in my program to allocate memory and produced the same `confusing` result.

But as you and Vlastimil Babka said, historical reasons have made the implementation of this interface less intuitive.
Modifying manual may be a better option.

Thank you both for your reply and explanation.