I noticed the phys_index and end_phys_index under
/sys/devices/system/memory/memoryXXX/ have the same value, e.g.
(for the test machine, one memory block has 8 sections, that is
sections_per_block equals 8)
# cd /sys/devices/system/memory/memory100/
# cat phys_index end_phys_index
00000064
00000064
Seems they should reflect the start/end section number respectively, which
also matches what is said in Documentation/memory-hotplug.txt
This patch tries to modify that so the two files could show the start/end
section number of the memory block.
After this change, output of the above example looks like:
# cat phys_index end_phys_index
00000320
00000327
Signed-off-by: Li Zhong <[email protected]>
---
drivers/base/memory.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index bece691..b10f2fa 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -114,7 +114,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
struct memory_block *mem = to_memory_block(dev);
unsigned long phys_index;
- phys_index = mem->start_section_nr / sections_per_block;
+ phys_index = mem->start_section_nr;
return sprintf(buf, "%08lx\n", phys_index);
}
@@ -124,7 +124,7 @@ static ssize_t show_mem_end_phys_index(struct device *dev,
struct memory_block *mem = to_memory_block(dev);
unsigned long phys_index;
- phys_index = mem->end_section_nr / sections_per_block;
+ phys_index = mem->end_section_nr;
return sprintf(buf, "%08lx\n", phys_index);
}
On 04/02/2014 01:56 AM, Li Zhong wrote:
> I noticed the phys_index and end_phys_index under
> /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
> (for the test machine, one memory block has 8 sections, that is
> sections_per_block equals 8)
>
> # cd /sys/devices/system/memory/memory100/
> # cat phys_index end_phys_index
> 00000064
> 00000064
>
> Seems they should reflect the start/end section number respectively, which
> also matches what is said in Documentation/memory-hotplug.txt
This changes a user-visible interface. Won't this break userspace?
Add ccing
On 04/02/2014 04:56 PM, Li Zhong wrote:
> I noticed the phys_index and end_phys_index under
> /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
> (for the test machine, one memory block has 8 sections, that is
> sections_per_block equals 8)
>
> # cd /sys/devices/system/memory/memory100/
> # cat phys_index end_phys_index
> 00000064
> 00000064
>
> Seems they should reflect the start/end section number respectively, which
> also matches what is said in Documentation/memory-hotplug.txt
Indeed. I've noticed this before. The value in 'end_phys_index' doesn't
match what it really means. But, the name itself is vague, it looks like
it is the index of some page frame. (we keep this name for compatibility?)
The corresponding member in struct memory_block is:
struct memory_block {
unsigned long start_section_nr;
unsigned long end_section_nr;
...
The two members seem to have the right name, and have the right value in kernel.
>
> This patch tries to modify that so the two files could show the start/end
> section number of the memory block.
>
> After this change, output of the above example looks like:
>
> # cat phys_index end_phys_index
> 00000320
> 00000327
>
> Signed-off-by: Li Zhong <[email protected]>
> ---
> drivers/base/memory.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index bece691..b10f2fa 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -114,7 +114,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> struct memory_block *mem = to_memory_block(dev);
> unsigned long phys_index;
>
> - phys_index = mem->start_section_nr / sections_per_block;
> + phys_index = mem->start_section_nr;
> return sprintf(buf, "%08lx\n", phys_index);
> }
>
> @@ -124,7 +124,7 @@ static ssize_t show_mem_end_phys_index(struct device *dev,
> struct memory_block *mem = to_memory_block(dev);
> unsigned long phys_index;
>
> - phys_index = mem->end_section_nr / sections_per_block;
> + phys_index = mem->end_section_nr;
> return sprintf(buf, "%08lx\n", phys_index);
> }
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
Thanks.
Zhang Yanfei
On Wed, 2014-04-02 at 09:09 -0700, Dave Hansen wrote:
> On 04/02/2014 01:56 AM, Li Zhong wrote:
> > I noticed the phys_index and end_phys_index under
> > /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
> > (for the test machine, one memory block has 8 sections, that is
> > sections_per_block equals 8)
> >
> > # cd /sys/devices/system/memory/memory100/
> > # cat phys_index end_phys_index
> > 00000064
> > 00000064
> >
> > Seems they should reflect the start/end section number respectively, which
> > also matches what is said in Documentation/memory-hotplug.txt
>
> This changes a user-visible interface. Won't this break userspace?
Hi Dave,
Hmm, I think so... Thank you for the reminder
Do you have some better ideas to fix this? Maybe we should leave the
code unchanged, just change the corresponding document (just it seems
that the end_phys_index will always be the same as phys_index)? And if
the section numbers are really needed, then we could create two new
files later, e.g. start_section_nr, end_section_nr?
Thanks,
Zhong
>
On Thu, 2014-04-03 at 09:37 +0800, Zhang Yanfei wrote:
> Add ccing
>
> On 04/02/2014 04:56 PM, Li Zhong wrote:
> > I noticed the phys_index and end_phys_index under
> > /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
> > (for the test machine, one memory block has 8 sections, that is
> > sections_per_block equals 8)
> >
> > # cd /sys/devices/system/memory/memory100/
> > # cat phys_index end_phys_index
> > 00000064
> > 00000064
> >
> > Seems they should reflect the start/end section number respectively, which
> > also matches what is said in Documentation/memory-hotplug.txt
>
Hi Yanfei,
Thanks for the review.
> Indeed. I've noticed this before. The value in 'end_phys_index' doesn't
> match what it really means. But, the name itself is vague, it looks like
> it is the index of some page frame. (we keep this name for compatibility?)
I guess so, Dave just reminded me that the RFC would also break
userspace..
And now my plan is:
leave the code unchanged
update the document, state the end_phys_index/phys_index are the same,
and means the memory block index
[optional] create two new files start_sec_nr, end_sec_nr if needed
Do you have any other suggestions?
Thanks, Zhong
>
> The corresponding member in struct memory_block is:
>
> struct memory_block {
> unsigned long start_section_nr;
> unsigned long end_section_nr;
> ...
>
> The two members seem to have the right name, and have the right value in kernel.
>
>
> >
> > This patch tries to modify that so the two files could show the start/end
> > section number of the memory block.
> >
> > After this change, output of the above example looks like:
> >
> > # cat phys_index end_phys_index
> > 00000320
> > 00000327
> >
> > Signed-off-by: Li Zhong <[email protected]>
> > ---
> > drivers/base/memory.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> > index bece691..b10f2fa 100644
> > --- a/drivers/base/memory.c
> > +++ b/drivers/base/memory.c
> > @@ -114,7 +114,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> > struct memory_block *mem = to_memory_block(dev);
> > unsigned long phys_index;
> >
> > - phys_index = mem->start_section_nr / sections_per_block;
> > + phys_index = mem->start_section_nr;
> > return sprintf(buf, "%08lx\n", phys_index);
> > }
> >
> > @@ -124,7 +124,7 @@ static ssize_t show_mem_end_phys_index(struct device *dev,
> > struct memory_block *mem = to_memory_block(dev);
> > unsigned long phys_index;
> >
> > - phys_index = mem->end_section_nr / sections_per_block;
> > + phys_index = mem->end_section_nr;
> > return sprintf(buf, "%08lx\n", phys_index);
> > }
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to [email protected]
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >
>
>
On 04/03/2014 10:37 AM, Li Zhong wrote:
> On Thu, 2014-04-03 at 09:37 +0800, Zhang Yanfei wrote:
>> Add ccing
>>
>> On 04/02/2014 04:56 PM, Li Zhong wrote:
>>> I noticed the phys_index and end_phys_index under
>>> /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
>>> (for the test machine, one memory block has 8 sections, that is
>>> sections_per_block equals 8)
>>>
>>> # cd /sys/devices/system/memory/memory100/
>>> # cat phys_index end_phys_index
>>> 00000064
>>> 00000064
>>>
>>> Seems they should reflect the start/end section number respectively, which
>>> also matches what is said in Documentation/memory-hotplug.txt
>>
> Hi Yanfei,
>
> Thanks for the review.
>
>> Indeed. I've noticed this before. The value in 'end_phys_index' doesn't
>> match what it really means. But, the name itself is vague, it looks like
>> it is the index of some page frame. (we keep this name for compatibility?)
>
> I guess so, Dave just reminded me that the RFC would also break
> userspace..
>
> And now my plan is:
> leave the code unchanged
> update the document, state the end_phys_index/phys_index are the same,
> and means the memory block index
Ah. I doubt whether there is userspace tool which is using the two sysfiles?
for example, the memory100 directory itself can tell us which block it is.
So why there is the two files under it give the same meaning.
If there is userspace tool using the two files, does it use 'end_phys_index'
in the correct way? That said, if a userspace tool knows what the 'end_phys_index'
really mean, does it still need it since we have 'phys_index' with the same value?
> [optional] create two new files start_sec_nr, end_sec_nr if needed
These two are the really meaningful sysfiles for userspace, IMO.
>
> Do you have any other suggestions?
No. I think we should wait for other guys to comment more.
Thanks.
>
> Thanks, Zhong
>
>>
>> The corresponding member in struct memory_block is:
>>
>> struct memory_block {
>> unsigned long start_section_nr;
>> unsigned long end_section_nr;
>> ...
>>
>> The two members seem to have the right name, and have the right value in kernel.
>>
>>
>>>
>>> This patch tries to modify that so the two files could show the start/end
>>> section number of the memory block.
>>>
>>> After this change, output of the above example looks like:
>>>
>>> # cat phys_index end_phys_index
>>> 00000320
>>> 00000327
>>>
>>> Signed-off-by: Li Zhong <[email protected]>
>>> ---
>>> drivers/base/memory.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
>>> index bece691..b10f2fa 100644
>>> --- a/drivers/base/memory.c
>>> +++ b/drivers/base/memory.c
>>> @@ -114,7 +114,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
>>> struct memory_block *mem = to_memory_block(dev);
>>> unsigned long phys_index;
>>>
>>> - phys_index = mem->start_section_nr / sections_per_block;
>>> + phys_index = mem->start_section_nr;
>>> return sprintf(buf, "%08lx\n", phys_index);
>>> }
>>>
>>> @@ -124,7 +124,7 @@ static ssize_t show_mem_end_phys_index(struct device *dev,
>>> struct memory_block *mem = to_memory_block(dev);
>>> unsigned long phys_index;
>>>
>>> - phys_index = mem->end_section_nr / sections_per_block;
>>> + phys_index = mem->end_section_nr;
>>> return sprintf(buf, "%08lx\n", phys_index);
>>> }
>>>
>>>
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>>> the body of a message to [email protected]
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>> Please read the FAQ at http://www.tux.org/lkml/
>>>
>>
>>
>
>
> .
>
--
Thanks.
Zhang Yanfei
On Thu, 2014-04-03 at 11:06 +0800, Zhang Yanfei wrote:
> On 04/03/2014 10:37 AM, Li Zhong wrote:
> > On Thu, 2014-04-03 at 09:37 +0800, Zhang Yanfei wrote:
> >> Add ccing
> >>
> >> On 04/02/2014 04:56 PM, Li Zhong wrote:
> >>> I noticed the phys_index and end_phys_index under
> >>> /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
> >>> (for the test machine, one memory block has 8 sections, that is
> >>> sections_per_block equals 8)
> >>>
> >>> # cd /sys/devices/system/memory/memory100/
> >>> # cat phys_index end_phys_index
> >>> 00000064
> >>> 00000064
> >>>
> >>> Seems they should reflect the start/end section number respectively, which
> >>> also matches what is said in Documentation/memory-hotplug.txt
> >>
> > Hi Yanfei,
> >
> > Thanks for the review.
> >
> >> Indeed. I've noticed this before. The value in 'end_phys_index' doesn't
> >> match what it really means. But, the name itself is vague, it looks like
> >> it is the index of some page frame. (we keep this name for compatibility?)
> >
> > I guess so, Dave just reminded me that the RFC would also break
> > userspace..
> >
> > And now my plan is:
> > leave the code unchanged
> > update the document, state the end_phys_index/phys_index are the same,
> > and means the memory block index
>
> Ah. I doubt whether there is userspace tool which is using the two sysfiles?
> for example, the memory100 directory itself can tell us which block it is.
> So why there is the two files under it give the same meaning.
>
> If there is userspace tool using the two files, does it use 'end_phys_index'
> in the correct way? That said, if a userspace tool knows what the 'end_phys_index'
> really mean, does it still need it since we have 'phys_index' with the same value?
For the end_phys_index, I totally agree with you. If somebody tries to
use it, say as the end section number, he should finally be able to find
that the value is not what he expects. But who knows ...
For phys_index, I guess it is also reasonable for some userspace tool to
just loop for each memoryXXX directory under /sys/devices/system/memory,
and use the phys_index as the memory block index for the directory,
instead of extracting the XXX from the directory name memoryXXX
Don't know whether there are some generic rules for handling such kind
of compatibility issues...
> > [optional] create two new files start_sec_nr, end_sec_nr if needed
>
> These two are the really meaningful sysfiles for userspace, IMO.
OK, I see.
>
> >
> > Do you have any other suggestions?
>
> No. I think we should wait for other guys to comment more.
OK, let's wait.
Thanks, Zhong
>
> Thanks.
>
> >
> > Thanks, Zhong
> >
> >>
> >> The corresponding member in struct memory_block is:
> >>
> >> struct memory_block {
> >> unsigned long start_section_nr;
> >> unsigned long end_section_nr;
> >> ...
> >>
> >> The two members seem to have the right name, and have the right value in kernel.
> >>
> >>
> >>>
> >>> This patch tries to modify that so the two files could show the start/end
> >>> section number of the memory block.
> >>>
> >>> After this change, output of the above example looks like:
> >>>
> >>> # cat phys_index end_phys_index
> >>> 00000320
> >>> 00000327
> >>>
> >>> Signed-off-by: Li Zhong <[email protected]>
> >>> ---
> >>> drivers/base/memory.c | 4 ++--
> >>> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> >>> index bece691..b10f2fa 100644
> >>> --- a/drivers/base/memory.c
> >>> +++ b/drivers/base/memory.c
> >>> @@ -114,7 +114,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> >>> struct memory_block *mem = to_memory_block(dev);
> >>> unsigned long phys_index;
> >>>
> >>> - phys_index = mem->start_section_nr / sections_per_block;
> >>> + phys_index = mem->start_section_nr;
> >>> return sprintf(buf, "%08lx\n", phys_index);
> >>> }
> >>>
> >>> @@ -124,7 +124,7 @@ static ssize_t show_mem_end_phys_index(struct device *dev,
> >>> struct memory_block *mem = to_memory_block(dev);
> >>> unsigned long phys_index;
> >>>
> >>> - phys_index = mem->end_section_nr / sections_per_block;
> >>> + phys_index = mem->end_section_nr;
> >>> return sprintf(buf, "%08lx\n", phys_index);
> >>> }
> >>>
> >>>
> >>>
> >>> --
> >>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> >>> the body of a message to [email protected]
> >>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> >>> Please read the FAQ at http://www.tux.org/lkml/
> >>>
> >>
> >>
> >
> >
> > .
> >
>
>
On Wed, Apr 2, 2014 at 12:09 PM, Dave Hansen <[email protected]> wrote:
> On 04/02/2014 01:56 AM, Li Zhong wrote:
>> I noticed the phys_index and end_phys_index under
>> /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
>> (for the test machine, one memory block has 8 sections, that is
>> sections_per_block equals 8)
>>
>> # cd /sys/devices/system/memory/memory100/
>> # cat phys_index end_phys_index
>> 00000064
>> 00000064
>>
>> Seems they should reflect the start/end section number respectively, which
>> also matches what is said in Documentation/memory-hotplug.txt
>
> This changes a user-visible interface. Won't this break userspace?
But who uses this? This is totally broken and I think nobody can use
meaningfully.
I bet we can fix this right now.
(2014/04/02 17:56), Li Zhong wrote:
> I noticed the phys_index and end_phys_index under
> /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
> (for the test machine, one memory block has 8 sections, that is
> sections_per_block equals 8)
>
> # cd /sys/devices/system/memory/memory100/
> # cat phys_index end_phys_index
> 00000064
> 00000064
>
> Seems they should reflect the start/end section number respectively, which
> also matches what is said in Documentation/memory-hotplug.txt
>
> This patch tries to modify that so the two files could show the start/end
> section number of the memory block.
>
> After this change, output of the above example looks like:
>
> # cat phys_index end_phys_index
> 00000320
> 00000327
>
> Signed-off-by: Li Zhong <[email protected]>
> ---
Good catch! This is a bug. So I think the bug should be fixed.
Reviewed-by: Yasuaki Ishimatsu <[email protected]>
Thanks,
Yasuaki Ishimatsu
> drivers/base/memory.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index bece691..b10f2fa 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -114,7 +114,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> struct memory_block *mem = to_memory_block(dev);
> unsigned long phys_index;
>
> - phys_index = mem->start_section_nr / sections_per_block;
> + phys_index = mem->start_section_nr;
> return sprintf(buf, "%08lx\n", phys_index);
> }
>
> @@ -124,7 +124,7 @@ static ssize_t show_mem_end_phys_index(struct device *dev,
> struct memory_block *mem = to_memory_block(dev);
> unsigned long phys_index;
>
> - phys_index = mem->end_section_nr / sections_per_block;
> + phys_index = mem->end_section_nr;
> return sprintf(buf, "%08lx\n", phys_index);
> }
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
On Fri, 2014-04-04 at 10:29 +0900, Yasuaki Ishimatsu wrote:
> (2014/04/02 17:56), Li Zhong wrote:
> > I noticed the phys_index and end_phys_index under
> > /sys/devices/system/memory/memoryXXX/ have the same value, e.g.
> > (for the test machine, one memory block has 8 sections, that is
> > sections_per_block equals 8)
> >
> > # cd /sys/devices/system/memory/memory100/
> > # cat phys_index end_phys_index
> > 00000064
> > 00000064
> >
> > Seems they should reflect the start/end section number respectively, which
> > also matches what is said in Documentation/memory-hotplug.txt
> >
> > This patch tries to modify that so the two files could show the start/end
> > section number of the memory block.
> >
> > After this change, output of the above example looks like:
> >
> > # cat phys_index end_phys_index
> > 00000320
> > 00000327
> >
> > Signed-off-by: Li Zhong <[email protected]>
> > ---
>
> Good catch! This is a bug. So I think the bug should be fixed.
>
> Reviewed-by: Yasuaki Ishimatsu <[email protected]>
Thank you all for the review.
If Dave and others don't have further objections, it seems this small
userspace incompatibility could be accepted by most of us, and I don't
need to make a version 2.
Thanks, Zhong
> Thanks,
> Yasuaki Ishimatsu
>
> > drivers/base/memory.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> > index bece691..b10f2fa 100644
> > --- a/drivers/base/memory.c
> > +++ b/drivers/base/memory.c
> > @@ -114,7 +114,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> > struct memory_block *mem = to_memory_block(dev);
> > unsigned long phys_index;
> >
> > - phys_index = mem->start_section_nr / sections_per_block;
> > + phys_index = mem->start_section_nr;
> > return sprintf(buf, "%08lx\n", phys_index);
> > }
> >
> > @@ -124,7 +124,7 @@ static ssize_t show_mem_end_phys_index(struct device *dev,
> > struct memory_block *mem = to_memory_block(dev);
> > unsigned long phys_index;
> >
> > - phys_index = mem->end_section_nr / sections_per_block;
> > + phys_index = mem->end_section_nr;
> > return sprintf(buf, "%08lx\n", phys_index);
> > }
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to [email protected]
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
On 04/08/2014 01:27 AM, Li Zhong wrote:
> If Dave and others don't have further objections, it seems this small
> userspace incompatibility could be accepted by most of us, and I don't
> need to make a version 2.
Let me ask another question then. What are the units of
phys_index/end_phys_index? How do we expose those units to userspace?
On 04/08/2014 11:13 AM, Dave Hansen wrote:
> On 04/08/2014 01:27 AM, Li Zhong wrote:
>> If Dave and others don't have further objections, it seems this small
>> userspace incompatibility could be accepted by most of us, and I don't
>> need to make a version 2.
>
> Let me ask another question then. What are the units of
> phys_index/end_phys_index? How do we expose those units to userspace?
>
The documentation for these files just states that the files contain
the first and last section id of memory in the memory block for
phys_index and end_phys_index respectively.
I'm not sure the values have ever been units of anything, at least not
that I remember.
-Nathan
On 04/08/2014 11:23 AM, Nathan Fontenot wrote:
> On 04/08/2014 11:13 AM, Dave Hansen wrote:
>> On 04/08/2014 01:27 AM, Li Zhong wrote:
>>> If Dave and others don't have further objections, it seems this small
>>> userspace incompatibility could be accepted by most of us, and I don't
>>> need to make a version 2.
>>
>> Let me ask another question then. What are the units of
>> phys_index/end_phys_index? How do we expose those units to userspace?
>>
>
> The documentation for these files just states that the files contain
> the first and last section id of memory in the memory block for
> phys_index and end_phys_index respectively.
>
> I'm not sure the values have ever been units of anything, at least not
> that I remember.
<sigh>
There are two units. SECTION_SIZE, which is completely internal to the
kernel, and block_size_bytes which used to be the same as SECTION_SIZE,
but is not now. Which one of those two is phys_index/end_phys_index in,
and if it is in terms of SECTION_SIZE like this patch proposes, how do
we tell userspace how large SECTION_SIZE is?
block_size_bytes is supposed to tell you how large the sections are. In
the case where we lumped a bunch of sections together, we also bumped up
block_size_bytes. That's why we currently divide the *ACTUAL* section
number in phys_index/end_phys_index by block_size_bytes.
That document really needs to be updated to stop referring to sections
(at least in the descriptions of the user interface). We can not change
the units of phys_index/end_phys_index without also changing
block_size_bytes.
On Tue, 2014-04-08 at 12:47 -0700, Dave Hansen wrote:
> On 04/08/2014 11:23 AM, Nathan Fontenot wrote:
> > On 04/08/2014 11:13 AM, Dave Hansen wrote:
> >> On 04/08/2014 01:27 AM, Li Zhong wrote:
> >>> If Dave and others don't have further objections, it seems this small
> >>> userspace incompatibility could be accepted by most of us, and I don't
> >>> need to make a version 2.
> >>
> >> Let me ask another question then. What are the units of
> >> phys_index/end_phys_index? How do we expose those units to userspace?
> >>
> >
> > The documentation for these files just states that the files contain
> > the first and last section id of memory in the memory block for
> > phys_index and end_phys_index respectively.
> >
> > I'm not sure the values have ever been units of anything, at least not
> > that I remember.
>
> <sigh>
>
> There are two units. SECTION_SIZE, which is completely internal to the
> kernel, and block_size_bytes which used to be the same as SECTION_SIZE,
> but is not now. Which one of those two is phys_index/end_phys_index in,
> and if it is in terms of SECTION_SIZE like this patch proposes, how do
> we tell userspace how large SECTION_SIZE is?
With this patch, I think we could still tell how large SECTION_SIZE is.
block_size_bytes tells us the size of the block, and
end_phys_index-phys_index+1, tells us the numbers of sections in the
block, and then we could know the SECTION_SIZE by a division.
Not that obvious, but if needed, we could easily add a file telling us
section_size or sections_per_block.
>
> block_size_bytes is supposed to tell you how large the sections are. In
> the case where we lumped a bunch of sections together, we also bumped up
> block_size_bytes. That's why we currently divide the *ACTUAL* section
> number in phys_index/end_phys_index by block_size_bytes.
>
> That document really needs to be updated to stop referring to sections
> (at least in the descriptions of the user interface). We can not change
> the units of phys_index/end_phys_index without also changing
> block_size_bytes.
How about adding a new section_size_bytes together with this patch?
Or do you mean we don't need to expose any information related to
SECTION to userspace?
Thanks,
Zhong
On 04/09/2014 02:20 AM, Li Zhong wrote:
> Or do you mean we don't need to expose any information related to
> SECTION to userspace?
Right, we don't need to expose sections themselves to userspace. Do we?
On 04/09/2014 10:49 AM, Dave Hansen wrote:
> On 04/09/2014 02:20 AM, Li Zhong wrote:
>> Or do you mean we don't need to expose any information related to
>> SECTION to userspace?
>
> Right, we don't need to expose sections themselves to userspace. Do we?
>
No. the layout in sysfs is based in block_size_bytes so I do not see any
need to expose sections to userspace.
-Nathan
On 04/08/2014 02:47 PM, Dave Hansen wrote:
> On 04/08/2014 11:23 AM, Nathan Fontenot wrote:
>> On 04/08/2014 11:13 AM, Dave Hansen wrote:
>>> On 04/08/2014 01:27 AM, Li Zhong wrote:
>>>> If Dave and others don't have further objections, it seems this small
>>>> userspace incompatibility could be accepted by most of us, and I don't
>>>> need to make a version 2.
>>>
>>> Let me ask another question then. What are the units of
>>> phys_index/end_phys_index? How do we expose those units to userspace?
>>>
>>
>> The documentation for these files just states that the files contain
>> the first and last section id of memory in the memory block for
>> phys_index and end_phys_index respectively.
>>
>> I'm not sure the values have ever been units of anything, at least not
>> that I remember.
>
> <sigh>
>
> There are two units. SECTION_SIZE, which is completely internal to the
> kernel, and block_size_bytes which used to be the same as SECTION_SIZE,
> but is not now. Which one of those two is phys_index/end_phys_index in,
> and if it is in terms of SECTION_SIZE like this patch proposes, how do
> we tell userspace how large SECTION_SIZE is?
>
> block_size_bytes is supposed to tell you how large the sections are. In
> the case where we lumped a bunch of sections together, we also bumped up
> block_size_bytes. That's why we currently divide the *ACTUAL* section
> number in phys_index/end_phys_index by block_size_bytes.
>
> That document really needs to be updated to stop referring to sections
> (at least in the descriptions of the user interface). We can not change
> the units of phys_index/end_phys_index without also changing
> block_size_bytes.
>
Re-reading the documentation. You're correct, it needs help.
-Nathan
On 04/08/2014 02:47 PM, Dave Hansen wrote:
>
> That document really needs to be updated to stop referring to sections
> (at least in the descriptions of the user interface). We can not change
> the units of phys_index/end_phys_index without also changing
> block_size_bytes.
>
Here is a first pass at updating the documentation.
I have tried to update the documentation to refer to memory blocks instead
of memory sections where appropriate and added a paragraph to explain
that memory blocks are mode of memory sections.
Thoughts?
-Nathan
---
Documentation/memory-hotplug.txt | 113 ++++++++++++++++++++-------------------
1 file changed, 59 insertions(+), 54 deletions(-)
Index: linux/Documentation/memory-hotplug.txt
===================================================================
--- linux.orig/Documentation/memory-hotplug.txt
+++ linux/Documentation/memory-hotplug.txt
@@ -88,16 +88,21 @@ phase by hand.
1.3. Unit of Memory online/offline operation
------------
-Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
-into chunks of the same size. The chunk is called a "section". The size of
-a section is architecture dependent. For example, power uses 16MiB, ia64 uses
-1GiB. The unit of online/offline operation is "one section". (see Section 3.)
+Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
+into chunks of the same size. These chunks are called "sections". The size of
+a memory section is architecture dependent. For example, power uses 16MiB, ia64
+uses 1GiB.
+
+Memory sections are combined into chunks referred to as "memory blocks". The
+size of a memory block is architecture dependent and represents the logical
+unit upon which memory online/offline operations are to be performed. The
+default size of a memory block is the same as memory section size unless an
+architecture specifies otherwise. (see Section 3.)
-To determine the size of sections, please read this file:
+To determine the size (in bytes) of a memory block please read this file:
/sys/devices/system/memory/block_size_bytes
-This file shows the size of sections in byte.
-----------------------
2. Kernel Configuration
@@ -123,14 +128,15 @@ config options.
(CONFIG_ACPI_CONTAINER).
This option can be kernel module too.
+
--------------------------------
-4 sysfs files for memory hotplug
+3 sysfs files for memory hotplug
--------------------------------
-All sections have their device information in sysfs. Each section is part of
-a memory block under /sys/devices/system/memory as
+All memory blocks have their device information in sysfs. Each memory block
+is described under /sys/devices/system/memory as
/sys/devices/system/memory/memoryXXX
-(XXX is the section id.)
+(XXX is the memory block id.)
Now, XXX is defined as (start_address_of_section / section_size) of the first
section contained in the memory block. The files 'phys_index' and
@@ -141,13 +147,13 @@ range. Currently there is no way to dete
the existence of one should not affect the hotplug capabilities of the memory
block.
-For example, assume 1GiB section size. A device for a memory starting at
+For example, assume 1GiB memory block size. A device for a memory starting at
0x100000000 is /sys/device/system/memory/memory4
(0x100000000 / 1Gib = 4)
This device covers address range [0x100000000 ... 0x140000000)
-Under each section, you can see 4 or 5 files, the end_phys_index file being
-a recent addition and not present on older kernels.
+Under each memory block, you can see 4 or 5 files, the end_phys_index file
+being a recent addition and not present on older kernels.
/sys/devices/system/memory/memoryXXX/start_phys_index
/sys/devices/system/memory/memoryXXX/end_phys_index
@@ -185,6 +191,7 @@ For example:
A backlink will also be created:
/sys/devices/system/memory/memory9/node0 -> ../../node/node0
+
--------------------------------
4. Physical memory hot-add phase
--------------------------------
@@ -227,11 +234,10 @@ You can tell the physical address of new
% echo start_address_of_new_memory > /sys/devices/system/memory/probe
-Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
-memory range is hot-added. In this case, hotplug script is not called (in
-current implementation). You'll have to online memory by yourself.
-Please see "How to online memory" in this text.
-
+Then, [start_address_of_new_memory, start_address_of_new_memory +
+memory_block_size] memory range is hot-added. In this case, hotplug script is
+not called (in current implementation). You'll have to online memory by
+yourself. Please see "How to online memory" in this text.
------------------------------
@@ -240,36 +246,36 @@ Please see "How to online memory" in thi
5.1. State of memory
------------
-To see (online/offline) state of memory section, read 'state' file.
+To see (online/offline) state of a memory block, read 'state' file.
% cat /sys/device/system/memory/memoryXXX/state
-If the memory section is online, you'll read "online".
-If the memory section is offline, you'll read "offline".
+If the memory block is online, you'll read "online".
+If the memory block is offline, you'll read "offline".
5.2. How to online memory
------------
Even if the memory is hot-added, it is not at ready-to-use state.
-For using newly added memory, you have to "online" the memory section.
+For using newly added memory, you have to "online" the memory block.
-For onlining, you have to write "online" to the section's state file as:
+For onlining, you have to write "online" to the memory block's state file as:
% echo online > /sys/devices/system/memory/memoryXXX/state
-This onlining will not change the ZONE type of the target memory section,
-If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
+This onlining will not change the ZONE type of the target memory block,
+If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
% echo online_movable > /sys/devices/system/memory/memoryXXX/state
-(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
+(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
-And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
+And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
% echo online_kernel > /sys/devices/system/memory/memoryXXX/state
-(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
+(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
-After this, section memoryXXX's state will be 'online' and the amount of
+After this, memory block XXX's state will be 'online' and the amount of
available memory will be increased.
Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
@@ -284,22 +290,22 @@ This may be changed in future.
6.1 Memory offline and ZONE_MOVABLE
------------
Memory offlining is more complicated than memory online. Because memory offline
-has to make the whole memory section be unused, memory offline can fail if
-the section includes memory which cannot be freed.
+has to make the whole memory block be unused, memory offline can fail if
+the memort block includes memory which cannot be freed.
In general, memory offline can use 2 techniques.
-(1) reclaim and free all memory in the section.
-(2) migrate all pages in the section.
+(1) reclaim and free all memory in the memory block.
+(2) migrate all pages in the memory block.
In the current implementation, Linux's memory offline uses method (2), freeing
-all pages in the section by page migration. But not all pages are
+all pages in the memory block by page migration. But not all pages are
migratable. Under current Linux, migratable pages are anonymous pages and
-page caches. For offlining a section by migration, the kernel has to guarantee
-that the section contains only migratable pages.
+page caches. For offlining a memory block by migration, the kernel has to
+guarantee that the memory block contains only migratable pages.
-Now, a boot option for making a section which consists of migratable pages is
-supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
+Now, a boot option for making a memory block which consists of migratable pages
+is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
create ZONE_MOVABLE...a zone which is just used for movable pages.
(See also Documentation/kernel-parameters.txt)
@@ -315,28 +321,27 @@ creates ZONE_MOVABLE as following.
Size of memory for movable pages (for offline) is ZZZZ.
-Note) Unfortunately, there is no information to show which section belongs
+Note: Unfortunately, there is no information to show which memory block belongs
to ZONE_MOVABLE. This is TBD.
6.2. How to offline memory
------------
-You can offline a section by using the same sysfs interface that was used in
-memory onlining.
+You can offline a memory block by using the same sysfs interface that was used
+in memory onlining.
% echo offline > /sys/devices/system/memory/memoryXXX/state
-If offline succeeds, the state of the memory section is changed to be "offline".
+If offline succeeds, the state of the memory block is changed to be "offline".
If it fails, some error core (like -EBUSY) will be returned by the kernel.
-Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
-If it doesn't contain 'unmovable' memory, you'll get success.
+Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
+it. If it doesn't contain 'unmovable' memory, you'll get success.
-A section under ZONE_MOVABLE is considered to be able to be offlined easily.
-But under some busy state, it may return -EBUSY. Even if a memory section
-cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
-offline it (or not).
-(For example, a page is referred to by some kernel internal call and released
- soon.)
+A memory block under ZONE_MOVABLE is considered to be able to be offlined
+easily. But under some busy state, it may return -EBUSY. Even if a memory
+block cannot be offlined due to -EBUSY, you can retry offlining it and may be
+able to offline it (or not). (For example, a page is referred to by some kernel
+internal call and released soon.)
Consideration:
Memory hotplug's design direction is to make the possibility of memory offlining
@@ -373,11 +378,11 @@ MEMORY_GOING_OFFLINE
Generated to begin the process of offlining memory. Allocations are no
longer possible from the memory but some of the memory to be offlined
is still in use. The callback can be used to free memory known to a
- subsystem from the indicated memory section.
+ subsystem from the indicated memory block.
MEMORY_CANCEL_OFFLINE
Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
- the section that we attempted to offline.
+ the memory block that we attempted to offline.
MEMORY_OFFLINE
Generated after offlining memory is complete.
@@ -413,8 +418,8 @@ node if necessary.
--------------
- allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
sysctl or new control file.
- - showing memory section and physical device relationship.
- - showing memory section is under ZONE_MOVABLE or not
+ - showing memory block and physical device relationship.
+ - showing memory block is under ZONE_MOVABLE or not
- test and make it better memory offlining.
- support HugeTLB page migration and offlining.
- memmap removing at memory offline.
On 04/10/2014 01:39 AM, Nathan Fontenot wrote:
> On 04/08/2014 02:47 PM, Dave Hansen wrote:
>>
>> That document really needs to be updated to stop referring to sections
>> (at least in the descriptions of the user interface). We can not change
>> the units of phys_index/end_phys_index without also changing
>> block_size_bytes.
>>
>
> Here is a first pass at updating the documentation.
>
> I have tried to update the documentation to refer to memory blocks instead
> of memory sections where appropriate and added a paragraph to explain
> that memory blocks are mode of memory sections.
>
> Thoughts?
I think the change is basically ok. So
Reviewed-by: Zhang Yanfei <[email protected]>
Only one nitpick below.
>
> -Nathan
> ---
> Documentation/memory-hotplug.txt | 113 ++++++++++++++++++++-------------------
> 1 file changed, 59 insertions(+), 54 deletions(-)
>
> Index: linux/Documentation/memory-hotplug.txt
> ===================================================================
> --- linux.orig/Documentation/memory-hotplug.txt
> +++ linux/Documentation/memory-hotplug.txt
> @@ -88,16 +88,21 @@ phase by hand.
>
> 1.3. Unit of Memory online/offline operation
> ------------
> -Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
> -into chunks of the same size. The chunk is called a "section". The size of
> -a section is architecture dependent. For example, power uses 16MiB, ia64 uses
> -1GiB. The unit of online/offline operation is "one section". (see Section 3.)
> +Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
> +into chunks of the same size. These chunks are called "sections". The size of
> +a memory section is architecture dependent. For example, power uses 16MiB, ia64
> +uses 1GiB.
> +
> +Memory sections are combined into chunks referred to as "memory blocks". The
> +size of a memory block is architecture dependent and represents the logical
> +unit upon which memory online/offline operations are to be performed. The
> +default size of a memory block is the same as memory section size unless an
> +architecture specifies otherwise. (see Section 3.)
>
> -To determine the size of sections, please read this file:
> +To determine the size (in bytes) of a memory block please read this file:
>
> /sys/devices/system/memory/block_size_bytes
>
> -This file shows the size of sections in byte.
>
> -----------------------
> 2. Kernel Configuration
> @@ -123,14 +128,15 @@ config options.
> (CONFIG_ACPI_CONTAINER).
> This option can be kernel module too.
>
> +
> --------------------------------
> -4 sysfs files for memory hotplug
> +3 sysfs files for memory hotplug
> --------------------------------
> -All sections have their device information in sysfs. Each section is part of
> -a memory block under /sys/devices/system/memory as
> +All memory blocks have their device information in sysfs. Each memory block
> +is described under /sys/devices/system/memory as
>
> /sys/devices/system/memory/memoryXXX
> -(XXX is the section id.)
> +(XXX is the memory block id.)
>
> Now, XXX is defined as (start_address_of_section / section_size) of the first
> section contained in the memory block. The files 'phys_index' and
> @@ -141,13 +147,13 @@ range. Currently there is no way to dete
> the existence of one should not affect the hotplug capabilities of the memory
> block.
>
> -For example, assume 1GiB section size. A device for a memory starting at
> +For example, assume 1GiB memory block size. A device for a memory starting at
> 0x100000000 is /sys/device/system/memory/memory4
> (0x100000000 / 1Gib = 4)
> This device covers address range [0x100000000 ... 0x140000000)
>
> -Under each section, you can see 4 or 5 files, the end_phys_index file being
> -a recent addition and not present on older kernels.
> +Under each memory block, you can see 4 or 5 files, the end_phys_index file
> +being a recent addition and not present on older kernels.
>
> /sys/devices/system/memory/memoryXXX/start_phys_index
> /sys/devices/system/memory/memoryXXX/end_phys_index
> @@ -185,6 +191,7 @@ For example:
> A backlink will also be created:
> /sys/devices/system/memory/memory9/node0 -> ../../node/node0
>
> +
> --------------------------------
> 4. Physical memory hot-add phase
> --------------------------------
> @@ -227,11 +234,10 @@ You can tell the physical address of new
>
> % echo start_address_of_new_memory > /sys/devices/system/memory/probe
>
> -Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
> -memory range is hot-added. In this case, hotplug script is not called (in
> -current implementation). You'll have to online memory by yourself.
> -Please see "How to online memory" in this text.
> -
> +Then, [start_address_of_new_memory, start_address_of_new_memory +
> +memory_block_size] memory range is hot-added. In this case, hotplug script is
> +not called (in current implementation). You'll have to online memory by
> +yourself. Please see "How to online memory" in this text.
>
>
> ------------------------------
> @@ -240,36 +246,36 @@ Please see "How to online memory" in thi
>
> 5.1. State of memory
> ------------
> -To see (online/offline) state of memory section, read 'state' file.
> +To see (online/offline) state of a memory block, read 'state' file.
>
> % cat /sys/device/system/memory/memoryXXX/state
>
>
> -If the memory section is online, you'll read "online".
> -If the memory section is offline, you'll read "offline".
> +If the memory block is online, you'll read "online".
> +If the memory block is offline, you'll read "offline".
>
>
> 5.2. How to online memory
> ------------
> Even if the memory is hot-added, it is not at ready-to-use state.
> -For using newly added memory, you have to "online" the memory section.
> +For using newly added memory, you have to "online" the memory block.
>
> -For onlining, you have to write "online" to the section's state file as:
> +For onlining, you have to write "online" to the memory block's state file as:
>
> % echo online > /sys/devices/system/memory/memoryXXX/state
>
> -This onlining will not change the ZONE type of the target memory section,
> -If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
> +This onlining will not change the ZONE type of the target memory block,
> +If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
>
> % echo online_movable > /sys/devices/system/memory/memoryXXX/state
> -(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
> +(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
>
> -And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
> +And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
>
> % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
> -(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
> +(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
>
> -After this, section memoryXXX's state will be 'online' and the amount of
> +After this, memory block XXX's state will be 'online' and the amount of
> available memory will be increased.
>
> Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
> @@ -284,22 +290,22 @@ This may be changed in future.
> 6.1 Memory offline and ZONE_MOVABLE
> ------------
> Memory offlining is more complicated than memory online. Because memory offline
> -has to make the whole memory section be unused, memory offline can fail if
> -the section includes memory which cannot be freed.
> +has to make the whole memory block be unused, memory offline can fail if
> +the memort block includes memory which cannot be freed.
^^^^^^
memory
>
> In general, memory offline can use 2 techniques.
>
> -(1) reclaim and free all memory in the section.
> -(2) migrate all pages in the section.
> +(1) reclaim and free all memory in the memory block.
> +(2) migrate all pages in the memory block.
>
> In the current implementation, Linux's memory offline uses method (2), freeing
> -all pages in the section by page migration. But not all pages are
> +all pages in the memory block by page migration. But not all pages are
> migratable. Under current Linux, migratable pages are anonymous pages and
> -page caches. For offlining a section by migration, the kernel has to guarantee
> -that the section contains only migratable pages.
> +page caches. For offlining a memory block by migration, the kernel has to
> +guarantee that the memory block contains only migratable pages.
>
> -Now, a boot option for making a section which consists of migratable pages is
> -supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> +Now, a boot option for making a memory block which consists of migratable pages
> +is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> create ZONE_MOVABLE...a zone which is just used for movable pages.
> (See also Documentation/kernel-parameters.txt)
>
> @@ -315,28 +321,27 @@ creates ZONE_MOVABLE as following.
> Size of memory for movable pages (for offline) is ZZZZ.
>
>
> -Note) Unfortunately, there is no information to show which section belongs
> +Note: Unfortunately, there is no information to show which memory block belongs
> to ZONE_MOVABLE. This is TBD.
>
>
> 6.2. How to offline memory
> ------------
> -You can offline a section by using the same sysfs interface that was used in
> -memory onlining.
> +You can offline a memory block by using the same sysfs interface that was used
> +in memory onlining.
>
> % echo offline > /sys/devices/system/memory/memoryXXX/state
>
> -If offline succeeds, the state of the memory section is changed to be "offline".
> +If offline succeeds, the state of the memory block is changed to be "offline".
> If it fails, some error core (like -EBUSY) will be returned by the kernel.
> -Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
> -If it doesn't contain 'unmovable' memory, you'll get success.
> +Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
> +it. If it doesn't contain 'unmovable' memory, you'll get success.
>
> -A section under ZONE_MOVABLE is considered to be able to be offlined easily.
> -But under some busy state, it may return -EBUSY. Even if a memory section
> -cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
> -offline it (or not).
> -(For example, a page is referred to by some kernel internal call and released
> - soon.)
> +A memory block under ZONE_MOVABLE is considered to be able to be offlined
> +easily. But under some busy state, it may return -EBUSY. Even if a memory
> +block cannot be offlined due to -EBUSY, you can retry offlining it and may be
> +able to offline it (or not). (For example, a page is referred to by some kernel
> +internal call and released soon.)
>
> Consideration:
> Memory hotplug's design direction is to make the possibility of memory offlining
> @@ -373,11 +378,11 @@ MEMORY_GOING_OFFLINE
> Generated to begin the process of offlining memory. Allocations are no
> longer possible from the memory but some of the memory to be offlined
> is still in use. The callback can be used to free memory known to a
> - subsystem from the indicated memory section.
> + subsystem from the indicated memory block.
>
> MEMORY_CANCEL_OFFLINE
> Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
> - the section that we attempted to offline.
> + the memory block that we attempted to offline.
>
> MEMORY_OFFLINE
> Generated after offlining memory is complete.
> @@ -413,8 +418,8 @@ node if necessary.
> --------------
> - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
> sysctl or new control file.
> - - showing memory section and physical device relationship.
> - - showing memory section is under ZONE_MOVABLE or not
> + - showing memory block and physical device relationship.
> + - showing memory block is under ZONE_MOVABLE or not
> - test and make it better memory offlining.
> - support HugeTLB page migration and offlining.
> - memmap removing at memory offline.
>
> .
>
--
Thanks.
Zhang Yanfei
On Wed, 2014-04-09 at 08:49 -0700, Dave Hansen wrote:
> On 04/09/2014 02:20 AM, Li Zhong wrote:
> > Or do you mean we don't need to expose any information related to
> > SECTION to userspace?
>
> Right, we don't need to expose sections themselves to userspace. Do we?
>
OK, I agree with that.
Yanfei, I recall you once expressed your preference for section
numbers?
Thanks, Zhong
On 04/10/2014 11:14 AM, Li Zhong wrote:
> On Wed, 2014-04-09 at 08:49 -0700, Dave Hansen wrote:
>> On 04/09/2014 02:20 AM, Li Zhong wrote:
>>> Or do you mean we don't need to expose any information related to
>>> SECTION to userspace?
>>
>> Right, we don't need to expose sections themselves to userspace. Do we?
>>
> OK, I agree with that.
>
> Yanfei, I recall you once expressed your preference for section
> numbers?
Hmmm.... Looking at the git log:
commit d33601644cd3b09afb2edd9474517edc441c8fad
Author: Nathan Fontenot <[email protected]>
Date: Thu Jan 20 10:44:29 2011 -0600
memory hotplug: Update phys_index to [start|end]_section_nr
Update the 'phys_index' property of a the memory_block struct to be
called start_section_nr, and add a end_section_nr property. The
data tracked here is the same but the updated naming is more in line
with what is stored here, namely the first and last section number
that the memory block spans.
The names presented to userspace remain the same, phys_index for
start_section_nr and end_phys_index for end_section_nr, to avoid breaking
anything in userspace.
This also updates the node sysfs code to be aware of the new capability for
a memory block to contain multiple memory sections and be aware of the memory
block structure name changes (start_section_nr). This requires an additional
parameter to unregister_mem_sect_under_nodes so that we know which memory
section of the memory block to unregister.
Signed-off-by: Nathan Fontenot <[email protected]>
Reviewed-by: Robin Holt <[email protected]>
Reviewed-by: KAMEZAWA Hiroyuki <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
So obviously, Nathan added the end_phys_index sysfile to present the last section
number of a memory block (for end_section_nr), but what he did in the patch
seems not matching the log.
So what is the motivation of adding this 'end_phys_index' file here?
Confused.
--
Thanks.
Zhang Yanfei
On Wed, 2014-04-09 at 12:39 -0500, Nathan Fontenot wrote:
> On 04/08/2014 02:47 PM, Dave Hansen wrote:
> >
> > That document really needs to be updated to stop referring to sections
> > (at least in the descriptions of the user interface). We can not change
> > the units of phys_index/end_phys_index without also changing
> > block_size_bytes.
> >
>
> Here is a first pass at updating the documentation.
>
> I have tried to update the documentation to refer to memory blocks instead
> of memory sections where appropriate and added a paragraph to explain
> that memory blocks are mode of memory sections.
>
> Thoughts?
If we all agree to hide the information about sections, then I think we
also need to update the section id's used for phys_index/end_phys_index,
something like following on top of yours?
--
diff --git a/Documentation/memory-hotplug.txt b/Documentation/memory-hotplug.txt
index 92d15e2..9fbb025 100644
--- a/Documentation/memory-hotplug.txt
+++ b/Documentation/memory-hotplug.txt
@@ -138,10 +138,7 @@ is described under /sys/devices/system/memory as
/sys/devices/system/memory/memoryXXX
(XXX is the memory block id.)
-Now, XXX is defined as (start_address_of_section / section_size) of the first
-section contained in the memory block. The files 'phys_index' and
-'end_phys_index' under each directory report the beginning and end section id's
-for the memory block covered by the sysfs directory. It is expected that all
+For the memory block covered by the sysfs directory. It is expected that all
memory sections in this range are present and no memory holes exist in the
range. Currently there is no way to determine if there is a memory hole, but
the existence of one should not affect the hotplug capabilities of the memory
@@ -155,16 +152,14 @@ This device covers address range [0x100000000 ... 0x140000000)
Under each memory block, you can see 4 or 5 files, the end_phys_index file
being a recent addition and not present on older kernels.
-/sys/devices/system/memory/memoryXXX/start_phys_index
+/sys/devices/system/memory/memoryXXX/phys_index
/sys/devices/system/memory/memoryXXX/end_phys_index
/sys/devices/system/memory/memoryXXX/phys_device
/sys/devices/system/memory/memoryXXX/state
/sys/devices/system/memory/memoryXXX/removable
-'phys_index' : read-only and contains section id of the first section
- in the memory block, same as XXX.
-'end_phys_index' : read-only and contains section id of the last section
- in the memory block.
+'phys_index' : read-only and contains memory block id, same as XXX.
+'end_phys_index' : read-only and contains memory block id, same as XXX.
'state' : read-write
at read: contains online/offline state of memory.
at write: user can specify "online_kernel",
--
Not sure whether it is proper to remove end_phys_index, too?
Thanks,
Zhong
>
> -Nathan
> ---
> Documentation/memory-hotplug.txt | 113 ++++++++++++++++++++-------------------
> 1 file changed, 59 insertions(+), 54 deletions(-)
>
> Index: linux/Documentation/memory-hotplug.txt
> ===================================================================
> --- linux.orig/Documentation/memory-hotplug.txt
> +++ linux/Documentation/memory-hotplug.txt
> @@ -88,16 +88,21 @@ phase by hand.
>
> 1.3. Unit of Memory online/offline operation
> ------------
> -Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
> -into chunks of the same size. The chunk is called a "section". The size of
> -a section is architecture dependent. For example, power uses 16MiB, ia64 uses
> -1GiB. The unit of online/offline operation is "one section". (see Section 3.)
> +Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
> +into chunks of the same size. These chunks are called "sections". The size of
> +a memory section is architecture dependent. For example, power uses 16MiB, ia64
> +uses 1GiB.
> +
> +Memory sections are combined into chunks referred to as "memory blocks". The
> +size of a memory block is architecture dependent and represents the logical
> +unit upon which memory online/offline operations are to be performed. The
> +default size of a memory block is the same as memory section size unless an
> +architecture specifies otherwise. (see Section 3.)
>
> -To determine the size of sections, please read this file:
> +To determine the size (in bytes) of a memory block please read this file:
>
> /sys/devices/system/memory/block_size_bytes
>
> -This file shows the size of sections in byte.
>
> -----------------------
> 2. Kernel Configuration
> @@ -123,14 +128,15 @@ config options.
> (CONFIG_ACPI_CONTAINER).
> This option can be kernel module too.
>
> +
> --------------------------------
> -4 sysfs files for memory hotplug
> +3 sysfs files for memory hotplug
> --------------------------------
> -All sections have their device information in sysfs. Each section is part of
> -a memory block under /sys/devices/system/memory as
> +All memory blocks have their device information in sysfs. Each memory block
> +is described under /sys/devices/system/memory as
>
> /sys/devices/system/memory/memoryXXX
> -(XXX is the section id.)
> +(XXX is the memory block id.)
>
> Now, XXX is defined as (start_address_of_section / section_size) of the first
> section contained in the memory block. The files 'phys_index' and
> @@ -141,13 +147,13 @@ range. Currently there is no way to dete
> the existence of one should not affect the hotplug capabilities of the memory
> block.
>
> -For example, assume 1GiB section size. A device for a memory starting at
> +For example, assume 1GiB memory block size. A device for a memory starting at
> 0x100000000 is /sys/device/system/memory/memory4
> (0x100000000 / 1Gib = 4)
> This device covers address range [0x100000000 ... 0x140000000)
>
> -Under each section, you can see 4 or 5 files, the end_phys_index file being
> -a recent addition and not present on older kernels.
> +Under each memory block, you can see 4 or 5 files, the end_phys_index file
> +being a recent addition and not present on older kernels.
>
> /sys/devices/system/memory/memoryXXX/start_phys_index
> /sys/devices/system/memory/memoryXXX/end_phys_index
> @@ -185,6 +191,7 @@ For example:
> A backlink will also be created:
> /sys/devices/system/memory/memory9/node0 -> ../../node/node0
>
> +
> --------------------------------
> 4. Physical memory hot-add phase
> --------------------------------
> @@ -227,11 +234,10 @@ You can tell the physical address of new
>
> % echo start_address_of_new_memory > /sys/devices/system/memory/probe
>
> -Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
> -memory range is hot-added. In this case, hotplug script is not called (in
> -current implementation). You'll have to online memory by yourself.
> -Please see "How to online memory" in this text.
> -
> +Then, [start_address_of_new_memory, start_address_of_new_memory +
> +memory_block_size] memory range is hot-added. In this case, hotplug script is
> +not called (in current implementation). You'll have to online memory by
> +yourself. Please see "How to online memory" in this text.
>
>
> ------------------------------
> @@ -240,36 +246,36 @@ Please see "How to online memory" in thi
>
> 5.1. State of memory
> ------------
> -To see (online/offline) state of memory section, read 'state' file.
> +To see (online/offline) state of a memory block, read 'state' file.
>
> % cat /sys/device/system/memory/memoryXXX/state
>
>
> -If the memory section is online, you'll read "online".
> -If the memory section is offline, you'll read "offline".
> +If the memory block is online, you'll read "online".
> +If the memory block is offline, you'll read "offline".
>
>
> 5.2. How to online memory
> ------------
> Even if the memory is hot-added, it is not at ready-to-use state.
> -For using newly added memory, you have to "online" the memory section.
> +For using newly added memory, you have to "online" the memory block.
>
> -For onlining, you have to write "online" to the section's state file as:
> +For onlining, you have to write "online" to the memory block's state file as:
>
> % echo online > /sys/devices/system/memory/memoryXXX/state
>
> -This onlining will not change the ZONE type of the target memory section,
> -If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
> +This onlining will not change the ZONE type of the target memory block,
> +If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
>
> % echo online_movable > /sys/devices/system/memory/memoryXXX/state
> -(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
> +(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
>
> -And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
> +And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
>
> % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
> -(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
> +(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
>
> -After this, section memoryXXX's state will be 'online' and the amount of
> +After this, memory block XXX's state will be 'online' and the amount of
> available memory will be increased.
>
> Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
> @@ -284,22 +290,22 @@ This may be changed in future.
> 6.1 Memory offline and ZONE_MOVABLE
> ------------
> Memory offlining is more complicated than memory online. Because memory offline
> -has to make the whole memory section be unused, memory offline can fail if
> -the section includes memory which cannot be freed.
> +has to make the whole memory block be unused, memory offline can fail if
> +the memort block includes memory which cannot be freed.
>
> In general, memory offline can use 2 techniques.
>
> -(1) reclaim and free all memory in the section.
> -(2) migrate all pages in the section.
> +(1) reclaim and free all memory in the memory block.
> +(2) migrate all pages in the memory block.
>
> In the current implementation, Linux's memory offline uses method (2), freeing
> -all pages in the section by page migration. But not all pages are
> +all pages in the memory block by page migration. But not all pages are
> migratable. Under current Linux, migratable pages are anonymous pages and
> -page caches. For offlining a section by migration, the kernel has to guarantee
> -that the section contains only migratable pages.
> +page caches. For offlining a memory block by migration, the kernel has to
> +guarantee that the memory block contains only migratable pages.
>
> -Now, a boot option for making a section which consists of migratable pages is
> -supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> +Now, a boot option for making a memory block which consists of migratable pages
> +is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> create ZONE_MOVABLE...a zone which is just used for movable pages.
> (See also Documentation/kernel-parameters.txt)
>
> @@ -315,28 +321,27 @@ creates ZONE_MOVABLE as following.
> Size of memory for movable pages (for offline) is ZZZZ.
>
>
> -Note) Unfortunately, there is no information to show which section belongs
> +Note: Unfortunately, there is no information to show which memory block belongs
> to ZONE_MOVABLE. This is TBD.
>
>
> 6.2. How to offline memory
> ------------
> -You can offline a section by using the same sysfs interface that was used in
> -memory onlining.
> +You can offline a memory block by using the same sysfs interface that was used
> +in memory onlining.
>
> % echo offline > /sys/devices/system/memory/memoryXXX/state
>
> -If offline succeeds, the state of the memory section is changed to be "offline".
> +If offline succeeds, the state of the memory block is changed to be "offline".
> If it fails, some error core (like -EBUSY) will be returned by the kernel.
> -Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
> -If it doesn't contain 'unmovable' memory, you'll get success.
> +Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
> +it. If it doesn't contain 'unmovable' memory, you'll get success.
>
> -A section under ZONE_MOVABLE is considered to be able to be offlined easily.
> -But under some busy state, it may return -EBUSY. Even if a memory section
> -cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
> -offline it (or not).
> -(For example, a page is referred to by some kernel internal call and released
> - soon.)
> +A memory block under ZONE_MOVABLE is considered to be able to be offlined
> +easily. But under some busy state, it may return -EBUSY. Even if a memory
> +block cannot be offlined due to -EBUSY, you can retry offlining it and may be
> +able to offline it (or not). (For example, a page is referred to by some kernel
> +internal call and released soon.)
>
> Consideration:
> Memory hotplug's design direction is to make the possibility of memory offlining
> @@ -373,11 +378,11 @@ MEMORY_GOING_OFFLINE
> Generated to begin the process of offlining memory. Allocations are no
> longer possible from the memory but some of the memory to be offlined
> is still in use. The callback can be used to free memory known to a
> - subsystem from the indicated memory section.
> + subsystem from the indicated memory block.
>
> MEMORY_CANCEL_OFFLINE
> Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
> - the section that we attempted to offline.
> + the memory block that we attempted to offline.
>
> MEMORY_OFFLINE
> Generated after offlining memory is complete.
> @@ -413,8 +418,8 @@ node if necessary.
> --------------
> - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
> sysctl or new control file.
> - - showing memory section and physical device relationship.
> - - showing memory section is under ZONE_MOVABLE or not
> + - showing memory block and physical device relationship.
> + - showing memory block is under ZONE_MOVABLE or not
> - test and make it better memory offlining.
> - support HugeTLB page migration and offlining.
> - memmap removing at memory offline.
On 04/09/2014 11:17 PM, Li Zhong wrote:
> On Wed, 2014-04-09 at 12:39 -0500, Nathan Fontenot wrote:
>> On 04/08/2014 02:47 PM, Dave Hansen wrote:
>>>
>>> That document really needs to be updated to stop referring to sections
>>> (at least in the descriptions of the user interface). We can not change
>>> the units of phys_index/end_phys_index without also changing
>>> block_size_bytes.
>>>
>>
>> Here is a first pass at updating the documentation.
>>
>> I have tried to update the documentation to refer to memory blocks instead
>> of memory sections where appropriate and added a paragraph to explain
>> that memory blocks are mode of memory sections.
>>
>> Thoughts?
>
> If we all agree to hide the information about sections, then I think we
> also need to update the section id's used for phys_index/end_phys_index,
> something like following on top of yours?
>
> --
> diff --git a/Documentation/memory-hotplug.txt b/Documentation/memory-hotplug.txt
> index 92d15e2..9fbb025 100644
> --- a/Documentation/memory-hotplug.txt
> +++ b/Documentation/memory-hotplug.txt
> @@ -138,10 +138,7 @@ is described under /sys/devices/system/memory as
> /sys/devices/system/memory/memoryXXX
> (XXX is the memory block id.)
>
> -Now, XXX is defined as (start_address_of_section / section_size) of the first
> -section contained in the memory block. The files 'phys_index' and
> -'end_phys_index' under each directory report the beginning and end section id's
> -for the memory block covered by the sysfs directory. It is expected that all
> +For the memory block covered by the sysfs directory. It is expected that all
> memory sections in this range are present and no memory holes exist in the
> range. Currently there is no way to determine if there is a memory hole, but
> the existence of one should not affect the hotplug capabilities of the memory
> @@ -155,16 +152,14 @@ This device covers address range [0x100000000 ... 0x140000000)
> Under each memory block, you can see 4 or 5 files, the end_phys_index file
> being a recent addition and not present on older kernels.
>
> -/sys/devices/system/memory/memoryXXX/start_phys_index
> +/sys/devices/system/memory/memoryXXX/phys_index
> /sys/devices/system/memory/memoryXXX/end_phys_index
> /sys/devices/system/memory/memoryXXX/phys_device
> /sys/devices/system/memory/memoryXXX/state
> /sys/devices/system/memory/memoryXXX/removable
>
> -'phys_index' : read-only and contains section id of the first section
> - in the memory block, same as XXX.
> -'end_phys_index' : read-only and contains section id of the last section
> - in the memory block.
> +'phys_index' : read-only and contains memory block id, same as XXX.
> +'end_phys_index' : read-only and contains memory block id, same as XXX.
> 'state' : read-write
> at read: contains online/offline state of memory.
> at write: user can specify "online_kernel",
> --
>
> Not sure whether it is proper to remove end_phys_index, too?
If we are going to leave the code as it is today such that the start_phys_index
and end_phys_index files both contain the same value I don't see why we should
not do this.
Li Zhong, unless anyone has objections, can you submit a patch to update the
files in sysfs and the documentation?
-Nathan
>
> Thanks,
> Zhong
>
>
>
>
>>
>> -Nathan
>> ---
>> Documentation/memory-hotplug.txt | 113 ++++++++++++++++++++-------------------
>> 1 file changed, 59 insertions(+), 54 deletions(-)
>>
>> Index: linux/Documentation/memory-hotplug.txt
>> ===================================================================
>> --- linux.orig/Documentation/memory-hotplug.txt
>> +++ linux/Documentation/memory-hotplug.txt
>> @@ -88,16 +88,21 @@ phase by hand.
>>
>> 1.3. Unit of Memory online/offline operation
>> ------------
>> -Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
>> -into chunks of the same size. The chunk is called a "section". The size of
>> -a section is architecture dependent. For example, power uses 16MiB, ia64 uses
>> -1GiB. The unit of online/offline operation is "one section". (see Section 3.)
>> +Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
>> +into chunks of the same size. These chunks are called "sections". The size of
>> +a memory section is architecture dependent. For example, power uses 16MiB, ia64
>> +uses 1GiB.
>> +
>> +Memory sections are combined into chunks referred to as "memory blocks". The
>> +size of a memory block is architecture dependent and represents the logical
>> +unit upon which memory online/offline operations are to be performed. The
>> +default size of a memory block is the same as memory section size unless an
>> +architecture specifies otherwise. (see Section 3.)
>>
>> -To determine the size of sections, please read this file:
>> +To determine the size (in bytes) of a memory block please read this file:
>>
>> /sys/devices/system/memory/block_size_bytes
>>
>> -This file shows the size of sections in byte.
>>
>> -----------------------
>> 2. Kernel Configuration
>> @@ -123,14 +128,15 @@ config options.
>> (CONFIG_ACPI_CONTAINER).
>> This option can be kernel module too.
>>
>> +
>> --------------------------------
>> -4 sysfs files for memory hotplug
>> +3 sysfs files for memory hotplug
>> --------------------------------
>> -All sections have their device information in sysfs. Each section is part of
>> -a memory block under /sys/devices/system/memory as
>> +All memory blocks have their device information in sysfs. Each memory block
>> +is described under /sys/devices/system/memory as
>>
>> /sys/devices/system/memory/memoryXXX
>> -(XXX is the section id.)
>> +(XXX is the memory block id.)
>>
>> Now, XXX is defined as (start_address_of_section / section_size) of the first
>> section contained in the memory block. The files 'phys_index' and
>> @@ -141,13 +147,13 @@ range. Currently there is no way to dete
>> the existence of one should not affect the hotplug capabilities of the memory
>> block.
>>
>> -For example, assume 1GiB section size. A device for a memory starting at
>> +For example, assume 1GiB memory block size. A device for a memory starting at
>> 0x100000000 is /sys/device/system/memory/memory4
>> (0x100000000 / 1Gib = 4)
>> This device covers address range [0x100000000 ... 0x140000000)
>>
>> -Under each section, you can see 4 or 5 files, the end_phys_index file being
>> -a recent addition and not present on older kernels.
>> +Under each memory block, you can see 4 or 5 files, the end_phys_index file
>> +being a recent addition and not present on older kernels.
>>
>> /sys/devices/system/memory/memoryXXX/start_phys_index
>> /sys/devices/system/memory/memoryXXX/end_phys_index
>> @@ -185,6 +191,7 @@ For example:
>> A backlink will also be created:
>> /sys/devices/system/memory/memory9/node0 -> ../../node/node0
>>
>> +
>> --------------------------------
>> 4. Physical memory hot-add phase
>> --------------------------------
>> @@ -227,11 +234,10 @@ You can tell the physical address of new
>>
>> % echo start_address_of_new_memory > /sys/devices/system/memory/probe
>>
>> -Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
>> -memory range is hot-added. In this case, hotplug script is not called (in
>> -current implementation). You'll have to online memory by yourself.
>> -Please see "How to online memory" in this text.
>> -
>> +Then, [start_address_of_new_memory, start_address_of_new_memory +
>> +memory_block_size] memory range is hot-added. In this case, hotplug script is
>> +not called (in current implementation). You'll have to online memory by
>> +yourself. Please see "How to online memory" in this text.
>>
>>
>> ------------------------------
>> @@ -240,36 +246,36 @@ Please see "How to online memory" in thi
>>
>> 5.1. State of memory
>> ------------
>> -To see (online/offline) state of memory section, read 'state' file.
>> +To see (online/offline) state of a memory block, read 'state' file.
>>
>> % cat /sys/device/system/memory/memoryXXX/state
>>
>>
>> -If the memory section is online, you'll read "online".
>> -If the memory section is offline, you'll read "offline".
>> +If the memory block is online, you'll read "online".
>> +If the memory block is offline, you'll read "offline".
>>
>>
>> 5.2. How to online memory
>> ------------
>> Even if the memory is hot-added, it is not at ready-to-use state.
>> -For using newly added memory, you have to "online" the memory section.
>> +For using newly added memory, you have to "online" the memory block.
>>
>> -For onlining, you have to write "online" to the section's state file as:
>> +For onlining, you have to write "online" to the memory block's state file as:
>>
>> % echo online > /sys/devices/system/memory/memoryXXX/state
>>
>> -This onlining will not change the ZONE type of the target memory section,
>> -If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
>> +This onlining will not change the ZONE type of the target memory block,
>> +If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
>>
>> % echo online_movable > /sys/devices/system/memory/memoryXXX/state
>> -(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
>> +(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
>>
>> -And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
>> +And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
>>
>> % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
>> -(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
>> +(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
>>
>> -After this, section memoryXXX's state will be 'online' and the amount of
>> +After this, memory block XXX's state will be 'online' and the amount of
>> available memory will be increased.
>>
>> Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
>> @@ -284,22 +290,22 @@ This may be changed in future.
>> 6.1 Memory offline and ZONE_MOVABLE
>> ------------
>> Memory offlining is more complicated than memory online. Because memory offline
>> -has to make the whole memory section be unused, memory offline can fail if
>> -the section includes memory which cannot be freed.
>> +has to make the whole memory block be unused, memory offline can fail if
>> +the memort block includes memory which cannot be freed.
>>
>> In general, memory offline can use 2 techniques.
>>
>> -(1) reclaim and free all memory in the section.
>> -(2) migrate all pages in the section.
>> +(1) reclaim and free all memory in the memory block.
>> +(2) migrate all pages in the memory block.
>>
>> In the current implementation, Linux's memory offline uses method (2), freeing
>> -all pages in the section by page migration. But not all pages are
>> +all pages in the memory block by page migration. But not all pages are
>> migratable. Under current Linux, migratable pages are anonymous pages and
>> -page caches. For offlining a section by migration, the kernel has to guarantee
>> -that the section contains only migratable pages.
>> +page caches. For offlining a memory block by migration, the kernel has to
>> +guarantee that the memory block contains only migratable pages.
>>
>> -Now, a boot option for making a section which consists of migratable pages is
>> -supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
>> +Now, a boot option for making a memory block which consists of migratable pages
>> +is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
>> create ZONE_MOVABLE...a zone which is just used for movable pages.
>> (See also Documentation/kernel-parameters.txt)
>>
>> @@ -315,28 +321,27 @@ creates ZONE_MOVABLE as following.
>> Size of memory for movable pages (for offline) is ZZZZ.
>>
>>
>> -Note) Unfortunately, there is no information to show which section belongs
>> +Note: Unfortunately, there is no information to show which memory block belongs
>> to ZONE_MOVABLE. This is TBD.
>>
>>
>> 6.2. How to offline memory
>> ------------
>> -You can offline a section by using the same sysfs interface that was used in
>> -memory onlining.
>> +You can offline a memory block by using the same sysfs interface that was used
>> +in memory onlining.
>>
>> % echo offline > /sys/devices/system/memory/memoryXXX/state
>>
>> -If offline succeeds, the state of the memory section is changed to be "offline".
>> +If offline succeeds, the state of the memory block is changed to be "offline".
>> If it fails, some error core (like -EBUSY) will be returned by the kernel.
>> -Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
>> -If it doesn't contain 'unmovable' memory, you'll get success.
>> +Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
>> +it. If it doesn't contain 'unmovable' memory, you'll get success.
>>
>> -A section under ZONE_MOVABLE is considered to be able to be offlined easily.
>> -But under some busy state, it may return -EBUSY. Even if a memory section
>> -cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
>> -offline it (or not).
>> -(For example, a page is referred to by some kernel internal call and released
>> - soon.)
>> +A memory block under ZONE_MOVABLE is considered to be able to be offlined
>> +easily. But under some busy state, it may return -EBUSY. Even if a memory
>> +block cannot be offlined due to -EBUSY, you can retry offlining it and may be
>> +able to offline it (or not). (For example, a page is referred to by some kernel
>> +internal call and released soon.)
>>
>> Consideration:
>> Memory hotplug's design direction is to make the possibility of memory offlining
>> @@ -373,11 +378,11 @@ MEMORY_GOING_OFFLINE
>> Generated to begin the process of offlining memory. Allocations are no
>> longer possible from the memory but some of the memory to be offlined
>> is still in use. The callback can be used to free memory known to a
>> - subsystem from the indicated memory section.
>> + subsystem from the indicated memory block.
>>
>> MEMORY_CANCEL_OFFLINE
>> Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
>> - the section that we attempted to offline.
>> + the memory block that we attempted to offline.
>>
>> MEMORY_OFFLINE
>> Generated after offlining memory is complete.
>> @@ -413,8 +418,8 @@ node if necessary.
>> --------------
>> - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
>> sysctl or new control file.
>> - - showing memory section and physical device relationship.
>> - - showing memory section is under ZONE_MOVABLE or not
>> + - showing memory block and physical device relationship.
>> + - showing memory block is under ZONE_MOVABLE or not
>> - test and make it better memory offlining.
>> - support HugeTLB page migration and offlining.
>> - memmap removing at memory offline.
>
>
Seems we all agree that information about SECTION, e.g. section size,
sections per memory block should be kept as kernel internals, and not
exposed to userspace.
This patch updates Documentation/memory-hotplug.txt to refer to memory
blocks instead of memory sections where appropriate and added a
paragraph to explain that memory blocks are made of memory sections.
The documentation update is mostly provided by Nathan.
Also, as end_phys_index in code is actually not the end section id, but
the end memory block id, which should always be the same as phys_index.
So it is removed here.
Signed-off-by: Li Zhong <[email protected]>
---
Documentation/memory-hotplug.txt | 125 +++++++++++++++++++-------------------
drivers/base/memory.c | 12 ----
2 files changed, 61 insertions(+), 76 deletions(-)
diff --git a/Documentation/memory-hotplug.txt b/Documentation/memory-hotplug.txt
index 58340d5..1aa239f 100644
--- a/Documentation/memory-hotplug.txt
+++ b/Documentation/memory-hotplug.txt
@@ -88,16 +88,21 @@ phase by hand.
1.3. Unit of Memory online/offline operation
------------
-Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
-into chunks of the same size. The chunk is called a "section". The size of
-a section is architecture dependent. For example, power uses 16MiB, ia64 uses
-1GiB. The unit of online/offline operation is "one section". (see Section 3.)
+Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
+into chunks of the same size. These chunks are called "sections". The size of
+a memory section is architecture dependent. For example, power uses 16MiB, ia64
+uses 1GiB.
-To determine the size of sections, please read this file:
+Memory sections are combined into chunks referred to as "memory blocks". The
+size of a memory block is architecture dependent and represents the logical
+unit upon which memory online/offline operations are to be performed. The
+default size of a memory block is the same as memory section size unless an
+architecture specifies otherwise. (see Section 3.)
+
+To determine the size (in bytes) of a memory block please read this file:
/sys/devices/system/memory/block_size_bytes
-This file shows the size of sections in byte.
-----------------------
2. Kernel Configuration
@@ -123,42 +128,35 @@ config options.
(CONFIG_ACPI_CONTAINER).
This option can be kernel module too.
+
--------------------------------
-4 sysfs files for memory hotplug
+3 sysfs files for memory hotplug
--------------------------------
-All sections have their device information in sysfs. Each section is part of
-a memory block under /sys/devices/system/memory as
+All memory blocks have their device information in sysfs. Each memory block
+is described under /sys/devices/system/memory as
/sys/devices/system/memory/memoryXXX
-(XXX is the section id.)
+(XXX is the memory block id.)
-Now, XXX is defined as (start_address_of_section / section_size) of the first
-section contained in the memory block. The files 'phys_index' and
-'end_phys_index' under each directory report the beginning and end section id's
-for the memory block covered by the sysfs directory. It is expected that all
+For the memory block covered by the sysfs directory. It is expected that all
memory sections in this range are present and no memory holes exist in the
range. Currently there is no way to determine if there is a memory hole, but
the existence of one should not affect the hotplug capabilities of the memory
block.
-For example, assume 1GiB section size. A device for a memory starting at
+For example, assume 1GiB memory block size. A device for a memory starting at
0x100000000 is /sys/device/system/memory/memory4
(0x100000000 / 1Gib = 4)
This device covers address range [0x100000000 ... 0x140000000)
-Under each section, you can see 4 or 5 files, the end_phys_index file being
-a recent addition and not present on older kernels.
+Under each memory block, you can see 4 files:
-/sys/devices/system/memory/memoryXXX/start_phys_index
-/sys/devices/system/memory/memoryXXX/end_phys_index
+/sys/devices/system/memory/memoryXXX/phys_index
/sys/devices/system/memory/memoryXXX/phys_device
/sys/devices/system/memory/memoryXXX/state
/sys/devices/system/memory/memoryXXX/removable
-'phys_index' : read-only and contains section id of the first section
- in the memory block, same as XXX.
-'end_phys_index' : read-only and contains section id of the last section
- in the memory block.
+'phys_index' : read-only and contains memory block id, same as XXX.
'state' : read-write
at read: contains online/offline state of memory.
at write: user can specify "online_kernel",
@@ -185,6 +183,7 @@ For example:
A backlink will also be created:
/sys/devices/system/memory/memory9/node0 -> ../../node/node0
+
--------------------------------
4. Physical memory hot-add phase
--------------------------------
@@ -227,11 +226,10 @@ You can tell the physical address of new memory to the kernel by
% echo start_address_of_new_memory > /sys/devices/system/memory/probe
-Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
-memory range is hot-added. In this case, hotplug script is not called (in
-current implementation). You'll have to online memory by yourself.
-Please see "How to online memory" in this text.
-
+Then, [start_address_of_new_memory, start_address_of_new_memory +
+memory_block_size] memory range is hot-added. In this case, hotplug script is
+not called (in current implementation). You'll have to online memory by
+yourself. Please see "How to online memory" in this text.
------------------------------
@@ -240,36 +238,36 @@ Please see "How to online memory" in this text.
5.1. State of memory
------------
-To see (online/offline) state of memory section, read 'state' file.
+To see (online/offline) state of a memory block, read 'state' file.
% cat /sys/device/system/memory/memoryXXX/state
-If the memory section is online, you'll read "online".
-If the memory section is offline, you'll read "offline".
+If the memory block is online, you'll read "online".
+If the memory block is offline, you'll read "offline".
5.2. How to online memory
------------
Even if the memory is hot-added, it is not at ready-to-use state.
-For using newly added memory, you have to "online" the memory section.
+For using newly added memory, you have to "online" the memory block.
-For onlining, you have to write "online" to the section's state file as:
+For onlining, you have to write "online" to the memory block's state file as:
% echo online > /sys/devices/system/memory/memoryXXX/state
-This onlining will not change the ZONE type of the target memory section,
-If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
+This onlining will not change the ZONE type of the target memory block,
+If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
% echo online_movable > /sys/devices/system/memory/memoryXXX/state
-(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
+(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
-And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
+And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
% echo online_kernel > /sys/devices/system/memory/memoryXXX/state
-(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
+(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
-After this, section memoryXXX's state will be 'online' and the amount of
+After this, memory block XXX's state will be 'online' and the amount of
available memory will be increased.
Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
@@ -284,22 +282,22 @@ This may be changed in future.
6.1 Memory offline and ZONE_MOVABLE
------------
Memory offlining is more complicated than memory online. Because memory offline
-has to make the whole memory section be unused, memory offline can fail if
-the section includes memory which cannot be freed.
+has to make the whole memory block be unused, memory offline can fail if
+the memort block includes memory which cannot be freed.
In general, memory offline can use 2 techniques.
-(1) reclaim and free all memory in the section.
-(2) migrate all pages in the section.
+(1) reclaim and free all memory in the memory block.
+(2) migrate all pages in the memory block.
In the current implementation, Linux's memory offline uses method (2), freeing
-all pages in the section by page migration. But not all pages are
+all pages in the memory block by page migration. But not all pages are
migratable. Under current Linux, migratable pages are anonymous pages and
-page caches. For offlining a section by migration, the kernel has to guarantee
-that the section contains only migratable pages.
+page caches. For offlining a memory block by migration, the kernel has to
+guarantee that the memory block contains only migratable pages.
-Now, a boot option for making a section which consists of migratable pages is
-supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
+Now, a boot option for making a memory block which consists of migratable pages
+is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
create ZONE_MOVABLE...a zone which is just used for movable pages.
(See also Documentation/kernel-parameters.txt)
@@ -315,28 +313,27 @@ creates ZONE_MOVABLE as following.
Size of memory for movable pages (for offline) is ZZZZ.
-Note) Unfortunately, there is no information to show which section belongs
+Note: Unfortunately, there is no information to show which memory block belongs
to ZONE_MOVABLE. This is TBD.
6.2. How to offline memory
------------
-You can offline a section by using the same sysfs interface that was used in
-memory onlining.
+You can offline a memory block by using the same sysfs interface that was used
+in memory onlining.
% echo offline > /sys/devices/system/memory/memoryXXX/state
-If offline succeeds, the state of the memory section is changed to be "offline".
+If offline succeeds, the state of the memory block is changed to be "offline".
If it fails, some error core (like -EBUSY) will be returned by the kernel.
-Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
-If it doesn't contain 'unmovable' memory, you'll get success.
+Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
+it. If it doesn't contain 'unmovable' memory, you'll get success.
-A section under ZONE_MOVABLE is considered to be able to be offlined easily.
-But under some busy state, it may return -EBUSY. Even if a memory section
-cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
-offline it (or not).
-(For example, a page is referred to by some kernel internal call and released
- soon.)
+A memory block under ZONE_MOVABLE is considered to be able to be offlined
+easily. But under some busy state, it may return -EBUSY. Even if a memory
+block cannot be offlined due to -EBUSY, you can retry offlining it and may be
+able to offline it (or not). (For example, a page is referred to by some kernel
+internal call and released soon.)
Consideration:
Memory hotplug's design direction is to make the possibility of memory offlining
@@ -373,11 +370,11 @@ MEMORY_GOING_OFFLINE
Generated to begin the process of offlining memory. Allocations are no
longer possible from the memory but some of the memory to be offlined
is still in use. The callback can be used to free memory known to a
- subsystem from the indicated memory section.
+ subsystem from the indicated memory block.
MEMORY_CANCEL_OFFLINE
Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
- the section that we attempted to offline.
+ the memory block that we attempted to offline.
MEMORY_OFFLINE
Generated after offlining memory is complete.
@@ -413,8 +410,8 @@ node if necessary.
--------------
- allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
sysctl or new control file.
- - showing memory section and physical device relationship.
- - showing memory section is under ZONE_MOVABLE or not
+ - showing memory block and physical device relationship.
+ - showing memory block is under ZONE_MOVABLE or not
- test and make it better memory offlining.
- support HugeTLB page migration and offlining.
- memmap removing at memory offline.
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index bece691..89f752d 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -118,16 +118,6 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
return sprintf(buf, "%08lx\n", phys_index);
}
-static ssize_t show_mem_end_phys_index(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- struct memory_block *mem = to_memory_block(dev);
- unsigned long phys_index;
-
- phys_index = mem->end_section_nr / sections_per_block;
- return sprintf(buf, "%08lx\n", phys_index);
-}
-
/*
* Show whether the section of memory is likely to be hot-removable
*/
@@ -384,7 +374,6 @@ static ssize_t show_phys_device(struct device *dev,
}
static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
-static DEVICE_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
@@ -529,7 +518,6 @@ struct memory_block *find_memory_block(struct mem_section *section)
static struct attribute *memory_memblk_attrs[] = {
&dev_attr_phys_index.attr,
- &dev_attr_end_phys_index.attr,
&dev_attr_state.attr,
&dev_attr_phys_device.attr,
&dev_attr_removable.attr,
On 04/14/2014 04:43 PM, Li Zhong wrote:
> Seems we all agree that information about SECTION, e.g. section size,
> sections per memory block should be kept as kernel internals, and not
> exposed to userspace.
>
> This patch updates Documentation/memory-hotplug.txt to refer to memory
> blocks instead of memory sections where appropriate and added a
> paragraph to explain that memory blocks are made of memory sections.
> The documentation update is mostly provided by Nathan.
>
> Also, as end_phys_index in code is actually not the end section id, but
> the end memory block id, which should always be the same as phys_index.
> So it is removed here.
>
> Signed-off-by: Li Zhong <[email protected]>
Reviewed-by: Zhang Yanfei <[email protected]>
Still the nitpick there.
> ---
> Documentation/memory-hotplug.txt | 125 +++++++++++++++++++-------------------
> drivers/base/memory.c | 12 ----
> 2 files changed, 61 insertions(+), 76 deletions(-)
>
> diff --git a/Documentation/memory-hotplug.txt b/Documentation/memory-hotplug.txt
> index 58340d5..1aa239f 100644
> --- a/Documentation/memory-hotplug.txt
> +++ b/Documentation/memory-hotplug.txt
> @@ -88,16 +88,21 @@ phase by hand.
>
> 1.3. Unit of Memory online/offline operation
> ------------
> -Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
> -into chunks of the same size. The chunk is called a "section". The size of
> -a section is architecture dependent. For example, power uses 16MiB, ia64 uses
> -1GiB. The unit of online/offline operation is "one section". (see Section 3.)
> +Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
> +into chunks of the same size. These chunks are called "sections". The size of
> +a memory section is architecture dependent. For example, power uses 16MiB, ia64
> +uses 1GiB.
>
> -To determine the size of sections, please read this file:
> +Memory sections are combined into chunks referred to as "memory blocks". The
> +size of a memory block is architecture dependent and represents the logical
> +unit upon which memory online/offline operations are to be performed. The
> +default size of a memory block is the same as memory section size unless an
> +architecture specifies otherwise. (see Section 3.)
> +
> +To determine the size (in bytes) of a memory block please read this file:
>
> /sys/devices/system/memory/block_size_bytes
>
> -This file shows the size of sections in byte.
>
> -----------------------
> 2. Kernel Configuration
> @@ -123,42 +128,35 @@ config options.
> (CONFIG_ACPI_CONTAINER).
> This option can be kernel module too.
>
> +
> --------------------------------
> -4 sysfs files for memory hotplug
> +3 sysfs files for memory hotplug
> --------------------------------
> -All sections have their device information in sysfs. Each section is part of
> -a memory block under /sys/devices/system/memory as
> +All memory blocks have their device information in sysfs. Each memory block
> +is described under /sys/devices/system/memory as
>
> /sys/devices/system/memory/memoryXXX
> -(XXX is the section id.)
> +(XXX is the memory block id.)
>
> -Now, XXX is defined as (start_address_of_section / section_size) of the first
> -section contained in the memory block. The files 'phys_index' and
> -'end_phys_index' under each directory report the beginning and end section id's
> -for the memory block covered by the sysfs directory. It is expected that all
> +For the memory block covered by the sysfs directory. It is expected that all
> memory sections in this range are present and no memory holes exist in the
> range. Currently there is no way to determine if there is a memory hole, but
> the existence of one should not affect the hotplug capabilities of the memory
> block.
>
> -For example, assume 1GiB section size. A device for a memory starting at
> +For example, assume 1GiB memory block size. A device for a memory starting at
> 0x100000000 is /sys/device/system/memory/memory4
> (0x100000000 / 1Gib = 4)
> This device covers address range [0x100000000 ... 0x140000000)
>
> -Under each section, you can see 4 or 5 files, the end_phys_index file being
> -a recent addition and not present on older kernels.
> +Under each memory block, you can see 4 files:
>
> -/sys/devices/system/memory/memoryXXX/start_phys_index
> -/sys/devices/system/memory/memoryXXX/end_phys_index
> +/sys/devices/system/memory/memoryXXX/phys_index
> /sys/devices/system/memory/memoryXXX/phys_device
> /sys/devices/system/memory/memoryXXX/state
> /sys/devices/system/memory/memoryXXX/removable
>
> -'phys_index' : read-only and contains section id of the first section
> - in the memory block, same as XXX.
> -'end_phys_index' : read-only and contains section id of the last section
> - in the memory block.
> +'phys_index' : read-only and contains memory block id, same as XXX.
> 'state' : read-write
> at read: contains online/offline state of memory.
> at write: user can specify "online_kernel",
> @@ -185,6 +183,7 @@ For example:
> A backlink will also be created:
> /sys/devices/system/memory/memory9/node0 -> ../../node/node0
>
> +
> --------------------------------
> 4. Physical memory hot-add phase
> --------------------------------
> @@ -227,11 +226,10 @@ You can tell the physical address of new memory to the kernel by
>
> % echo start_address_of_new_memory > /sys/devices/system/memory/probe
>
> -Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
> -memory range is hot-added. In this case, hotplug script is not called (in
> -current implementation). You'll have to online memory by yourself.
> -Please see "How to online memory" in this text.
> -
> +Then, [start_address_of_new_memory, start_address_of_new_memory +
> +memory_block_size] memory range is hot-added. In this case, hotplug script is
> +not called (in current implementation). You'll have to online memory by
> +yourself. Please see "How to online memory" in this text.
>
>
> ------------------------------
> @@ -240,36 +238,36 @@ Please see "How to online memory" in this text.
>
> 5.1. State of memory
> ------------
> -To see (online/offline) state of memory section, read 'state' file.
> +To see (online/offline) state of a memory block, read 'state' file.
>
> % cat /sys/device/system/memory/memoryXXX/state
>
>
> -If the memory section is online, you'll read "online".
> -If the memory section is offline, you'll read "offline".
> +If the memory block is online, you'll read "online".
> +If the memory block is offline, you'll read "offline".
>
>
> 5.2. How to online memory
> ------------
> Even if the memory is hot-added, it is not at ready-to-use state.
> -For using newly added memory, you have to "online" the memory section.
> +For using newly added memory, you have to "online" the memory block.
>
> -For onlining, you have to write "online" to the section's state file as:
> +For onlining, you have to write "online" to the memory block's state file as:
>
> % echo online > /sys/devices/system/memory/memoryXXX/state
>
> -This onlining will not change the ZONE type of the target memory section,
> -If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
> +This onlining will not change the ZONE type of the target memory block,
> +If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
>
> % echo online_movable > /sys/devices/system/memory/memoryXXX/state
> -(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
> +(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
>
> -And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
> +And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
>
> % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
> -(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
> +(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
>
> -After this, section memoryXXX's state will be 'online' and the amount of
> +After this, memory block XXX's state will be 'online' and the amount of
> available memory will be increased.
>
> Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
> @@ -284,22 +282,22 @@ This may be changed in future.
> 6.1 Memory offline and ZONE_MOVABLE
> ------------
> Memory offlining is more complicated than memory online. Because memory offline
> -has to make the whole memory section be unused, memory offline can fail if
> -the section includes memory which cannot be freed.
> +has to make the whole memory block be unused, memory offline can fail if
> +the memort block includes memory which cannot be freed.
^^^^^^
>
> In general, memory offline can use 2 techniques.
>
> -(1) reclaim and free all memory in the section.
> -(2) migrate all pages in the section.
> +(1) reclaim and free all memory in the memory block.
> +(2) migrate all pages in the memory block.
>
> In the current implementation, Linux's memory offline uses method (2), freeing
> -all pages in the section by page migration. But not all pages are
> +all pages in the memory block by page migration. But not all pages are
> migratable. Under current Linux, migratable pages are anonymous pages and
> -page caches. For offlining a section by migration, the kernel has to guarantee
> -that the section contains only migratable pages.
> +page caches. For offlining a memory block by migration, the kernel has to
> +guarantee that the memory block contains only migratable pages.
>
> -Now, a boot option for making a section which consists of migratable pages is
> -supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> +Now, a boot option for making a memory block which consists of migratable pages
> +is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> create ZONE_MOVABLE...a zone which is just used for movable pages.
> (See also Documentation/kernel-parameters.txt)
>
> @@ -315,28 +313,27 @@ creates ZONE_MOVABLE as following.
> Size of memory for movable pages (for offline) is ZZZZ.
>
>
> -Note) Unfortunately, there is no information to show which section belongs
> +Note: Unfortunately, there is no information to show which memory block belongs
> to ZONE_MOVABLE. This is TBD.
>
>
> 6.2. How to offline memory
> ------------
> -You can offline a section by using the same sysfs interface that was used in
> -memory onlining.
> +You can offline a memory block by using the same sysfs interface that was used
> +in memory onlining.
>
> % echo offline > /sys/devices/system/memory/memoryXXX/state
>
> -If offline succeeds, the state of the memory section is changed to be "offline".
> +If offline succeeds, the state of the memory block is changed to be "offline".
> If it fails, some error core (like -EBUSY) will be returned by the kernel.
> -Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
> -If it doesn't contain 'unmovable' memory, you'll get success.
> +Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
> +it. If it doesn't contain 'unmovable' memory, you'll get success.
>
> -A section under ZONE_MOVABLE is considered to be able to be offlined easily.
> -But under some busy state, it may return -EBUSY. Even if a memory section
> -cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
> -offline it (or not).
> -(For example, a page is referred to by some kernel internal call and released
> - soon.)
> +A memory block under ZONE_MOVABLE is considered to be able to be offlined
> +easily. But under some busy state, it may return -EBUSY. Even if a memory
> +block cannot be offlined due to -EBUSY, you can retry offlining it and may be
> +able to offline it (or not). (For example, a page is referred to by some kernel
> +internal call and released soon.)
>
> Consideration:
> Memory hotplug's design direction is to make the possibility of memory offlining
> @@ -373,11 +370,11 @@ MEMORY_GOING_OFFLINE
> Generated to begin the process of offlining memory. Allocations are no
> longer possible from the memory but some of the memory to be offlined
> is still in use. The callback can be used to free memory known to a
> - subsystem from the indicated memory section.
> + subsystem from the indicated memory block.
>
> MEMORY_CANCEL_OFFLINE
> Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
> - the section that we attempted to offline.
> + the memory block that we attempted to offline.
>
> MEMORY_OFFLINE
> Generated after offlining memory is complete.
> @@ -413,8 +410,8 @@ node if necessary.
> --------------
> - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
> sysctl or new control file.
> - - showing memory section and physical device relationship.
> - - showing memory section is under ZONE_MOVABLE or not
> + - showing memory block and physical device relationship.
> + - showing memory block is under ZONE_MOVABLE or not
> - test and make it better memory offlining.
> - support HugeTLB page migration and offlining.
> - memmap removing at memory offline.
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index bece691..89f752d 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -118,16 +118,6 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> return sprintf(buf, "%08lx\n", phys_index);
> }
>
> -static ssize_t show_mem_end_phys_index(struct device *dev,
> - struct device_attribute *attr, char *buf)
> -{
> - struct memory_block *mem = to_memory_block(dev);
> - unsigned long phys_index;
> -
> - phys_index = mem->end_section_nr / sections_per_block;
> - return sprintf(buf, "%08lx\n", phys_index);
> -}
> -
> /*
> * Show whether the section of memory is likely to be hot-removable
> */
> @@ -384,7 +374,6 @@ static ssize_t show_phys_device(struct device *dev,
> }
>
> static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
> -static DEVICE_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
> static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
> static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
> static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
> @@ -529,7 +518,6 @@ struct memory_block *find_memory_block(struct mem_section *section)
>
> static struct attribute *memory_memblk_attrs[] = {
> &dev_attr_phys_index.attr,
> - &dev_attr_end_phys_index.attr,
> &dev_attr_state.attr,
> &dev_attr_phys_device.attr,
> &dev_attr_removable.attr,
>
>
>
>
> .
>
--
Thanks.
Zhang Yanfei
On Mon, 2014-04-14 at 17:13 +0800, Zhang Yanfei wrote:
> On 04/14/2014 04:43 PM, Li Zhong wrote:
> > Seems we all agree that information about SECTION, e.g. section size,
> > sections per memory block should be kept as kernel internals, and not
> > exposed to userspace.
> >
> > This patch updates Documentation/memory-hotplug.txt to refer to memory
> > blocks instead of memory sections where appropriate and added a
> > paragraph to explain that memory blocks are made of memory sections.
> > The documentation update is mostly provided by Nathan.
> >
> > Also, as end_phys_index in code is actually not the end section id, but
> > the end memory block id, which should always be the same as phys_index.
> > So it is removed here.
> >
> > Signed-off-by: Li Zhong <[email protected]>
>
> Reviewed-by: Zhang Yanfei <[email protected]>
>
> Still the nitpick there.
Ao.. Will fix it in next version.
Thanks, Zhong
>
> > ---
> > Documentation/memory-hotplug.txt | 125 +++++++++++++++++++-------------------
> > drivers/base/memory.c | 12 ----
> > 2 files changed, 61 insertions(+), 76 deletions(-)
> >
> > diff --git a/Documentation/memory-hotplug.txt b/Documentation/memory-hotplug.txt
> > index 58340d5..1aa239f 100644
> > --- a/Documentation/memory-hotplug.txt
> > +++ b/Documentation/memory-hotplug.txt
> > @@ -88,16 +88,21 @@ phase by hand.
> >
> > 1.3. Unit of Memory online/offline operation
> > ------------
> > -Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
> > -into chunks of the same size. The chunk is called a "section". The size of
> > -a section is architecture dependent. For example, power uses 16MiB, ia64 uses
> > -1GiB. The unit of online/offline operation is "one section". (see Section 3.)
> > +Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
> > +into chunks of the same size. These chunks are called "sections". The size of
> > +a memory section is architecture dependent. For example, power uses 16MiB, ia64
> > +uses 1GiB.
> >
> > -To determine the size of sections, please read this file:
> > +Memory sections are combined into chunks referred to as "memory blocks". The
> > +size of a memory block is architecture dependent and represents the logical
> > +unit upon which memory online/offline operations are to be performed. The
> > +default size of a memory block is the same as memory section size unless an
> > +architecture specifies otherwise. (see Section 3.)
> > +
> > +To determine the size (in bytes) of a memory block please read this file:
> >
> > /sys/devices/system/memory/block_size_bytes
> >
> > -This file shows the size of sections in byte.
> >
> > -----------------------
> > 2. Kernel Configuration
> > @@ -123,42 +128,35 @@ config options.
> > (CONFIG_ACPI_CONTAINER).
> > This option can be kernel module too.
> >
> > +
> > --------------------------------
> > -4 sysfs files for memory hotplug
> > +3 sysfs files for memory hotplug
> > --------------------------------
> > -All sections have their device information in sysfs. Each section is part of
> > -a memory block under /sys/devices/system/memory as
> > +All memory blocks have their device information in sysfs. Each memory block
> > +is described under /sys/devices/system/memory as
> >
> > /sys/devices/system/memory/memoryXXX
> > -(XXX is the section id.)
> > +(XXX is the memory block id.)
> >
> > -Now, XXX is defined as (start_address_of_section / section_size) of the first
> > -section contained in the memory block. The files 'phys_index' and
> > -'end_phys_index' under each directory report the beginning and end section id's
> > -for the memory block covered by the sysfs directory. It is expected that all
> > +For the memory block covered by the sysfs directory. It is expected that all
> > memory sections in this range are present and no memory holes exist in the
> > range. Currently there is no way to determine if there is a memory hole, but
> > the existence of one should not affect the hotplug capabilities of the memory
> > block.
> >
> > -For example, assume 1GiB section size. A device for a memory starting at
> > +For example, assume 1GiB memory block size. A device for a memory starting at
> > 0x100000000 is /sys/device/system/memory/memory4
> > (0x100000000 / 1Gib = 4)
> > This device covers address range [0x100000000 ... 0x140000000)
> >
> > -Under each section, you can see 4 or 5 files, the end_phys_index file being
> > -a recent addition and not present on older kernels.
> > +Under each memory block, you can see 4 files:
> >
> > -/sys/devices/system/memory/memoryXXX/start_phys_index
> > -/sys/devices/system/memory/memoryXXX/end_phys_index
> > +/sys/devices/system/memory/memoryXXX/phys_index
> > /sys/devices/system/memory/memoryXXX/phys_device
> > /sys/devices/system/memory/memoryXXX/state
> > /sys/devices/system/memory/memoryXXX/removable
> >
> > -'phys_index' : read-only and contains section id of the first section
> > - in the memory block, same as XXX.
> > -'end_phys_index' : read-only and contains section id of the last section
> > - in the memory block.
> > +'phys_index' : read-only and contains memory block id, same as XXX.
> > 'state' : read-write
> > at read: contains online/offline state of memory.
> > at write: user can specify "online_kernel",
> > @@ -185,6 +183,7 @@ For example:
> > A backlink will also be created:
> > /sys/devices/system/memory/memory9/node0 -> ../../node/node0
> >
> > +
> > --------------------------------
> > 4. Physical memory hot-add phase
> > --------------------------------
> > @@ -227,11 +226,10 @@ You can tell the physical address of new memory to the kernel by
> >
> > % echo start_address_of_new_memory > /sys/devices/system/memory/probe
> >
> > -Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
> > -memory range is hot-added. In this case, hotplug script is not called (in
> > -current implementation). You'll have to online memory by yourself.
> > -Please see "How to online memory" in this text.
> > -
> > +Then, [start_address_of_new_memory, start_address_of_new_memory +
> > +memory_block_size] memory range is hot-added. In this case, hotplug script is
> > +not called (in current implementation). You'll have to online memory by
> > +yourself. Please see "How to online memory" in this text.
> >
> >
> > ------------------------------
> > @@ -240,36 +238,36 @@ Please see "How to online memory" in this text.
> >
> > 5.1. State of memory
> > ------------
> > -To see (online/offline) state of memory section, read 'state' file.
> > +To see (online/offline) state of a memory block, read 'state' file.
> >
> > % cat /sys/device/system/memory/memoryXXX/state
> >
> >
> > -If the memory section is online, you'll read "online".
> > -If the memory section is offline, you'll read "offline".
> > +If the memory block is online, you'll read "online".
> > +If the memory block is offline, you'll read "offline".
> >
> >
> > 5.2. How to online memory
> > ------------
> > Even if the memory is hot-added, it is not at ready-to-use state.
> > -For using newly added memory, you have to "online" the memory section.
> > +For using newly added memory, you have to "online" the memory block.
> >
> > -For onlining, you have to write "online" to the section's state file as:
> > +For onlining, you have to write "online" to the memory block's state file as:
> >
> > % echo online > /sys/devices/system/memory/memoryXXX/state
> >
> > -This onlining will not change the ZONE type of the target memory section,
> > -If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
> > +This onlining will not change the ZONE type of the target memory block,
> > +If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
> >
> > % echo online_movable > /sys/devices/system/memory/memoryXXX/state
> > -(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
> > +(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
> >
> > -And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
> > +And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
> >
> > % echo online_kernel > /sys/devices/system/memory/memoryXXX/state
> > -(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
> > +(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
> >
> > -After this, section memoryXXX's state will be 'online' and the amount of
> > +After this, memory block XXX's state will be 'online' and the amount of
> > available memory will be increased.
> >
> > Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
> > @@ -284,22 +282,22 @@ This may be changed in future.
> > 6.1 Memory offline and ZONE_MOVABLE
> > ------------
> > Memory offlining is more complicated than memory online. Because memory offline
> > -has to make the whole memory section be unused, memory offline can fail if
> > -the section includes memory which cannot be freed.
> > +has to make the whole memory block be unused, memory offline can fail if
> > +the memort block includes memory which cannot be freed.
> ^^^^^^
>
>
> >
> > In general, memory offline can use 2 techniques.
> >
> > -(1) reclaim and free all memory in the section.
> > -(2) migrate all pages in the section.
> > +(1) reclaim and free all memory in the memory block.
> > +(2) migrate all pages in the memory block.
> >
> > In the current implementation, Linux's memory offline uses method (2), freeing
> > -all pages in the section by page migration. But not all pages are
> > +all pages in the memory block by page migration. But not all pages are
> > migratable. Under current Linux, migratable pages are anonymous pages and
> > -page caches. For offlining a section by migration, the kernel has to guarantee
> > -that the section contains only migratable pages.
> > +page caches. For offlining a memory block by migration, the kernel has to
> > +guarantee that the memory block contains only migratable pages.
> >
> > -Now, a boot option for making a section which consists of migratable pages is
> > -supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> > +Now, a boot option for making a memory block which consists of migratable pages
> > +is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
> > create ZONE_MOVABLE...a zone which is just used for movable pages.
> > (See also Documentation/kernel-parameters.txt)
> >
> > @@ -315,28 +313,27 @@ creates ZONE_MOVABLE as following.
> > Size of memory for movable pages (for offline) is ZZZZ.
> >
> >
> > -Note) Unfortunately, there is no information to show which section belongs
> > +Note: Unfortunately, there is no information to show which memory block belongs
> > to ZONE_MOVABLE. This is TBD.
> >
> >
> > 6.2. How to offline memory
> > ------------
> > -You can offline a section by using the same sysfs interface that was used in
> > -memory onlining.
> > +You can offline a memory block by using the same sysfs interface that was used
> > +in memory onlining.
> >
> > % echo offline > /sys/devices/system/memory/memoryXXX/state
> >
> > -If offline succeeds, the state of the memory section is changed to be "offline".
> > +If offline succeeds, the state of the memory block is changed to be "offline".
> > If it fails, some error core (like -EBUSY) will be returned by the kernel.
> > -Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
> > -If it doesn't contain 'unmovable' memory, you'll get success.
> > +Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
> > +it. If it doesn't contain 'unmovable' memory, you'll get success.
> >
> > -A section under ZONE_MOVABLE is considered to be able to be offlined easily.
> > -But under some busy state, it may return -EBUSY. Even if a memory section
> > -cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
> > -offline it (or not).
> > -(For example, a page is referred to by some kernel internal call and released
> > - soon.)
> > +A memory block under ZONE_MOVABLE is considered to be able to be offlined
> > +easily. But under some busy state, it may return -EBUSY. Even if a memory
> > +block cannot be offlined due to -EBUSY, you can retry offlining it and may be
> > +able to offline it (or not). (For example, a page is referred to by some kernel
> > +internal call and released soon.)
> >
> > Consideration:
> > Memory hotplug's design direction is to make the possibility of memory offlining
> > @@ -373,11 +370,11 @@ MEMORY_GOING_OFFLINE
> > Generated to begin the process of offlining memory. Allocations are no
> > longer possible from the memory but some of the memory to be offlined
> > is still in use. The callback can be used to free memory known to a
> > - subsystem from the indicated memory section.
> > + subsystem from the indicated memory block.
> >
> > MEMORY_CANCEL_OFFLINE
> > Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
> > - the section that we attempted to offline.
> > + the memory block that we attempted to offline.
> >
> > MEMORY_OFFLINE
> > Generated after offlining memory is complete.
> > @@ -413,8 +410,8 @@ node if necessary.
> > --------------
> > - allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
> > sysctl or new control file.
> > - - showing memory section and physical device relationship.
> > - - showing memory section is under ZONE_MOVABLE or not
> > + - showing memory block and physical device relationship.
> > + - showing memory block is under ZONE_MOVABLE or not
> > - test and make it better memory offlining.
> > - support HugeTLB page migration and offlining.
> > - memmap removing at memory offline.
> > diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> > index bece691..89f752d 100644
> > --- a/drivers/base/memory.c
> > +++ b/drivers/base/memory.c
> > @@ -118,16 +118,6 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
> > return sprintf(buf, "%08lx\n", phys_index);
> > }
> >
> > -static ssize_t show_mem_end_phys_index(struct device *dev,
> > - struct device_attribute *attr, char *buf)
> > -{
> > - struct memory_block *mem = to_memory_block(dev);
> > - unsigned long phys_index;
> > -
> > - phys_index = mem->end_section_nr / sections_per_block;
> > - return sprintf(buf, "%08lx\n", phys_index);
> > -}
> > -
> > /*
> > * Show whether the section of memory is likely to be hot-removable
> > */
> > @@ -384,7 +374,6 @@ static ssize_t show_phys_device(struct device *dev,
> > }
> >
> > static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
> > -static DEVICE_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
> > static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
> > static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
> > static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
> > @@ -529,7 +518,6 @@ struct memory_block *find_memory_block(struct mem_section *section)
> >
> > static struct attribute *memory_memblk_attrs[] = {
> > &dev_attr_phys_index.attr,
> > - &dev_attr_end_phys_index.attr,
> > &dev_attr_state.attr,
> > &dev_attr_phys_device.attr,
> > &dev_attr_removable.attr,
> >
> >
> >
> >
> > .
> >
>
>
Seems we all agree that information about SECTION, e.g. section size,
sections per memory block should be kept as kernel internals, and not
exposed to userspace.
This patch updates Documentation/memory-hotplug.txt to refer to memory
blocks instead of memory sections where appropriate and added a
paragraph to explain that memory blocks are made of memory sections.
The documentation update is mostly provided by Nathan.
Also, as end_phys_index in code is actually not the end section id, but
the end memory block id, which should always be the same as phys_index.
So it is removed here.
Signed-off-by: Li Zhong <[email protected]>
Reviewed-by: Zhang Yanfei <[email protected]>
---
v3: memort->memory, pointed out by Yanfei
Documentation/memory-hotplug.txt | 125 +++++++++++++++++++-------------------
drivers/base/memory.c | 12 ----
2 files changed, 61 insertions(+), 76 deletions(-)
diff --git a/Documentation/memory-hotplug.txt b/Documentation/memory-hotplug.txt
index 58340d5..1aa239f 100644
--- a/Documentation/memory-hotplug.txt
+++ b/Documentation/memory-hotplug.txt
@@ -88,16 +88,21 @@ phase by hand.
1.3. Unit of Memory online/offline operation
------------
-Memory hotplug uses SPARSEMEM memory model. SPARSEMEM divides the whole memory
-into chunks of the same size. The chunk is called a "section". The size of
-a section is architecture dependent. For example, power uses 16MiB, ia64 uses
-1GiB. The unit of online/offline operation is "one section". (see Section 3.)
+Memory hotplug uses SPARSEMEM memory model which allows memory to be divided
+into chunks of the same size. These chunks are called "sections". The size of
+a memory section is architecture dependent. For example, power uses 16MiB, ia64
+uses 1GiB.
-To determine the size of sections, please read this file:
+Memory sections are combined into chunks referred to as "memory blocks". The
+size of a memory block is architecture dependent and represents the logical
+unit upon which memory online/offline operations are to be performed. The
+default size of a memory block is the same as memory section size unless an
+architecture specifies otherwise. (see Section 3.)
+
+To determine the size (in bytes) of a memory block please read this file:
/sys/devices/system/memory/block_size_bytes
-This file shows the size of sections in byte.
-----------------------
2. Kernel Configuration
@@ -123,42 +128,35 @@ config options.
(CONFIG_ACPI_CONTAINER).
This option can be kernel module too.
+
--------------------------------
-4 sysfs files for memory hotplug
+3 sysfs files for memory hotplug
--------------------------------
-All sections have their device information in sysfs. Each section is part of
-a memory block under /sys/devices/system/memory as
+All memory blocks have their device information in sysfs. Each memory block
+is described under /sys/devices/system/memory as
/sys/devices/system/memory/memoryXXX
-(XXX is the section id.)
+(XXX is the memory block id.)
-Now, XXX is defined as (start_address_of_section / section_size) of the first
-section contained in the memory block. The files 'phys_index' and
-'end_phys_index' under each directory report the beginning and end section id's
-for the memory block covered by the sysfs directory. It is expected that all
+For the memory block covered by the sysfs directory. It is expected that all
memory sections in this range are present and no memory holes exist in the
range. Currently there is no way to determine if there is a memory hole, but
the existence of one should not affect the hotplug capabilities of the memory
block.
-For example, assume 1GiB section size. A device for a memory starting at
+For example, assume 1GiB memory block size. A device for a memory starting at
0x100000000 is /sys/device/system/memory/memory4
(0x100000000 / 1Gib = 4)
This device covers address range [0x100000000 ... 0x140000000)
-Under each section, you can see 4 or 5 files, the end_phys_index file being
-a recent addition and not present on older kernels.
+Under each memory block, you can see 4 files:
-/sys/devices/system/memory/memoryXXX/start_phys_index
-/sys/devices/system/memory/memoryXXX/end_phys_index
+/sys/devices/system/memory/memoryXXX/phys_index
/sys/devices/system/memory/memoryXXX/phys_device
/sys/devices/system/memory/memoryXXX/state
/sys/devices/system/memory/memoryXXX/removable
-'phys_index' : read-only and contains section id of the first section
- in the memory block, same as XXX.
-'end_phys_index' : read-only and contains section id of the last section
- in the memory block.
+'phys_index' : read-only and contains memory block id, same as XXX.
'state' : read-write
at read: contains online/offline state of memory.
at write: user can specify "online_kernel",
@@ -185,6 +183,7 @@ For example:
A backlink will also be created:
/sys/devices/system/memory/memory9/node0 -> ../../node/node0
+
--------------------------------
4. Physical memory hot-add phase
--------------------------------
@@ -227,11 +226,10 @@ You can tell the physical address of new memory to the kernel by
% echo start_address_of_new_memory > /sys/devices/system/memory/probe
-Then, [start_address_of_new_memory, start_address_of_new_memory + section_size)
-memory range is hot-added. In this case, hotplug script is not called (in
-current implementation). You'll have to online memory by yourself.
-Please see "How to online memory" in this text.
-
+Then, [start_address_of_new_memory, start_address_of_new_memory +
+memory_block_size] memory range is hot-added. In this case, hotplug script is
+not called (in current implementation). You'll have to online memory by
+yourself. Please see "How to online memory" in this text.
------------------------------
@@ -240,36 +238,36 @@ Please see "How to online memory" in this text.
5.1. State of memory
------------
-To see (online/offline) state of memory section, read 'state' file.
+To see (online/offline) state of a memory block, read 'state' file.
% cat /sys/device/system/memory/memoryXXX/state
-If the memory section is online, you'll read "online".
-If the memory section is offline, you'll read "offline".
+If the memory block is online, you'll read "online".
+If the memory block is offline, you'll read "offline".
5.2. How to online memory
------------
Even if the memory is hot-added, it is not at ready-to-use state.
-For using newly added memory, you have to "online" the memory section.
+For using newly added memory, you have to "online" the memory block.
-For onlining, you have to write "online" to the section's state file as:
+For onlining, you have to write "online" to the memory block's state file as:
% echo online > /sys/devices/system/memory/memoryXXX/state
-This onlining will not change the ZONE type of the target memory section,
-If the memory section is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
+This onlining will not change the ZONE type of the target memory block,
+If the memory block is in ZONE_NORMAL, you can change it to ZONE_MOVABLE:
% echo online_movable > /sys/devices/system/memory/memoryXXX/state
-(NOTE: current limit: this memory section must be adjacent to ZONE_MOVABLE)
+(NOTE: current limit: this memory block must be adjacent to ZONE_MOVABLE)
-And if the memory section is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
+And if the memory block is in ZONE_MOVABLE, you can change it to ZONE_NORMAL:
% echo online_kernel > /sys/devices/system/memory/memoryXXX/state
-(NOTE: current limit: this memory section must be adjacent to ZONE_NORMAL)
+(NOTE: current limit: this memory block must be adjacent to ZONE_NORMAL)
-After this, section memoryXXX's state will be 'online' and the amount of
+After this, memory block XXX's state will be 'online' and the amount of
available memory will be increased.
Currently, newly added memory is added as ZONE_NORMAL (for powerpc, ZONE_DMA).
@@ -284,22 +282,22 @@ This may be changed in future.
6.1 Memory offline and ZONE_MOVABLE
------------
Memory offlining is more complicated than memory online. Because memory offline
-has to make the whole memory section be unused, memory offline can fail if
-the section includes memory which cannot be freed.
+has to make the whole memory block be unused, memory offline can fail if
+the memory block includes memory which cannot be freed.
In general, memory offline can use 2 techniques.
-(1) reclaim and free all memory in the section.
-(2) migrate all pages in the section.
+(1) reclaim and free all memory in the memory block.
+(2) migrate all pages in the memory block.
In the current implementation, Linux's memory offline uses method (2), freeing
-all pages in the section by page migration. But not all pages are
+all pages in the memory block by page migration. But not all pages are
migratable. Under current Linux, migratable pages are anonymous pages and
-page caches. For offlining a section by migration, the kernel has to guarantee
-that the section contains only migratable pages.
+page caches. For offlining a memory block by migration, the kernel has to
+guarantee that the memory block contains only migratable pages.
-Now, a boot option for making a section which consists of migratable pages is
-supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
+Now, a boot option for making a memory block which consists of migratable pages
+is supported. By specifying "kernelcore=" or "movablecore=" boot option, you can
create ZONE_MOVABLE...a zone which is just used for movable pages.
(See also Documentation/kernel-parameters.txt)
@@ -315,28 +313,27 @@ creates ZONE_MOVABLE as following.
Size of memory for movable pages (for offline) is ZZZZ.
-Note) Unfortunately, there is no information to show which section belongs
+Note: Unfortunately, there is no information to show which memory block belongs
to ZONE_MOVABLE. This is TBD.
6.2. How to offline memory
------------
-You can offline a section by using the same sysfs interface that was used in
-memory onlining.
+You can offline a memory block by using the same sysfs interface that was used
+in memory onlining.
% echo offline > /sys/devices/system/memory/memoryXXX/state
-If offline succeeds, the state of the memory section is changed to be "offline".
+If offline succeeds, the state of the memory block is changed to be "offline".
If it fails, some error core (like -EBUSY) will be returned by the kernel.
-Even if a section does not belong to ZONE_MOVABLE, you can try to offline it.
-If it doesn't contain 'unmovable' memory, you'll get success.
+Even if a memory block does not belong to ZONE_MOVABLE, you can try to offline
+it. If it doesn't contain 'unmovable' memory, you'll get success.
-A section under ZONE_MOVABLE is considered to be able to be offlined easily.
-But under some busy state, it may return -EBUSY. Even if a memory section
-cannot be offlined due to -EBUSY, you can retry offlining it and may be able to
-offline it (or not).
-(For example, a page is referred to by some kernel internal call and released
- soon.)
+A memory block under ZONE_MOVABLE is considered to be able to be offlined
+easily. But under some busy state, it may return -EBUSY. Even if a memory
+block cannot be offlined due to -EBUSY, you can retry offlining it and may be
+able to offline it (or not). (For example, a page is referred to by some kernel
+internal call and released soon.)
Consideration:
Memory hotplug's design direction is to make the possibility of memory offlining
@@ -373,11 +370,11 @@ MEMORY_GOING_OFFLINE
Generated to begin the process of offlining memory. Allocations are no
longer possible from the memory but some of the memory to be offlined
is still in use. The callback can be used to free memory known to a
- subsystem from the indicated memory section.
+ subsystem from the indicated memory block.
MEMORY_CANCEL_OFFLINE
Generated if MEMORY_GOING_OFFLINE fails. Memory is available again from
- the section that we attempted to offline.
+ the memory block that we attempted to offline.
MEMORY_OFFLINE
Generated after offlining memory is complete.
@@ -413,8 +410,8 @@ node if necessary.
--------------
- allowing memory hot-add to ZONE_MOVABLE. maybe we need some switch like
sysctl or new control file.
- - showing memory section and physical device relationship.
- - showing memory section is under ZONE_MOVABLE or not
+ - showing memory block and physical device relationship.
+ - showing memory block is under ZONE_MOVABLE or not
- test and make it better memory offlining.
- support HugeTLB page migration and offlining.
- memmap removing at memory offline.
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index bece691..89f752d 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -118,16 +118,6 @@ static ssize_t show_mem_start_phys_index(struct device *dev,
return sprintf(buf, "%08lx\n", phys_index);
}
-static ssize_t show_mem_end_phys_index(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- struct memory_block *mem = to_memory_block(dev);
- unsigned long phys_index;
-
- phys_index = mem->end_section_nr / sections_per_block;
- return sprintf(buf, "%08lx\n", phys_index);
-}
-
/*
* Show whether the section of memory is likely to be hot-removable
*/
@@ -384,7 +374,6 @@ static ssize_t show_phys_device(struct device *dev,
}
static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
-static DEVICE_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
@@ -529,7 +518,6 @@ struct memory_block *find_memory_block(struct mem_section *section)
static struct attribute *memory_memblk_attrs[] = {
&dev_attr_phys_index.attr,
- &dev_attr_end_phys_index.attr,
&dev_attr_state.attr,
&dev_attr_phys_device.attr,
&dev_attr_removable.attr,