diff mbox series

[5/8] hugetlb: document the demote sysfs interfaces

Message ID 20210816224953.157796-6-mike.kravetz@oracle.com (mailing list archive)
State New
Headers show
Series hugetlb: add demote/split page functionality | expand

Commit Message

Mike Kravetz Aug. 16, 2021, 10:49 p.m. UTC
Describe demote and demote_size interfaces.

Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 Documentation/admin-guide/mm/hugetlbpage.rst | 29 ++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

Comments

Andrew Morton Aug. 16, 2021, 11:28 p.m. UTC | #1
On Mon, 16 Aug 2021 15:49:50 -0700 Mike Kravetz <mike.kravetz@oracle.com> wrote:

> Describe demote and demote_size interfaces.
> 
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
>  Documentation/admin-guide/mm/hugetlbpage.rst | 29 ++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
> index 8abaeb144e44..902059a0257b 100644
> --- a/Documentation/admin-guide/mm/hugetlbpage.rst
> +++ b/Documentation/admin-guide/mm/hugetlbpage.rst
> @@ -234,8 +234,12 @@ will exist, of the form::
>  
>  	hugepages-${size}kB
>  
> -Inside each of these directories, the same set of files will exist::
> +Inside each of these directories, the set of files contained in ``/proc``
> +will exist.  In addition, two additional interfaces for demoting huge
> +pages will exist::
>  
> +        demote
> +        demote_size
>  	nr_hugepages
>  	nr_hugepages_mempolicy
>  	nr_overcommit_hugepages
> @@ -243,7 +247,28 @@ Inside each of these directories, the same set of files will exist::
>  	resv_hugepages
>  	surplus_hugepages
>  
> -which function as described above for the default huge page-sized case.
> +The demote interfaces provide the ability to split a huge page into
> +smaller huge pages.  For example, the x86 architecture supports both
> +1GB and 2MB huge pages sizes.  A 1GB huge page can be split into 512
> +2MB huge pages.  The demote interfaces are:
> +
> +demote_size
> +        is the size of demoted pages.  When a page is demoted a corresponding
> +        number of huge pages of demote_size will be created.  For huge pages
> +        of the smallest supported size (2MB on x86), demote_size will be the
> +        system page size (PAGE_SIZE).  If demote_size is the system page size
> +        then demoting a page will simply free the huge page.  demote_size is
> +        a read only interface.
> +
> +demote
> +        is used to demote a number of huge pages.  A user with root privileges
> +        can write to this file.  It may not be possible to demote the
> +        requested number of huge pages.  To determine how many pages were
> +        actually demoted, compare the value of nr_hugepages before and after
> +        writing to the demote interface.  demote is a write only interface.
> +
> +The interfaces which are the same as in ``/proc`` function as described
> +above for the default huge page-sized case.

Are these new demote interfaces duplicated in /proc? 
Documentation/admin-guide/mm/hugetlbpage.rst says "The ``/proc``
interfaces discussed above have been retained for backwards
compatibility.", so new interfaces need not appear in /proc?
Mike Kravetz Aug. 17, 2021, 1:04 a.m. UTC | #2
On 8/16/21 4:28 PM, Andrew Morton wrote:
> On Mon, 16 Aug 2021 15:49:50 -0700 Mike Kravetz <mike.kravetz@oracle.com> wrote:
> 
>> Describe demote and demote_size interfaces.
>>
>> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
>> ---
>>  Documentation/admin-guide/mm/hugetlbpage.rst | 29 ++++++++++++++++++--
>>  1 file changed, 27 insertions(+), 2 deletions(-)
>>
>> diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
>> index 8abaeb144e44..902059a0257b 100644
>> --- a/Documentation/admin-guide/mm/hugetlbpage.rst
>> +++ b/Documentation/admin-guide/mm/hugetlbpage.rst
>> @@ -234,8 +234,12 @@ will exist, of the form::
>>  
>>  	hugepages-${size}kB
>>  
>> -Inside each of these directories, the same set of files will exist::
>> +Inside each of these directories, the set of files contained in ``/proc``
>> +will exist.  In addition, two additional interfaces for demoting huge
>> +pages will exist::
>>  
>> +        demote
>> +        demote_size
>>  	nr_hugepages
>>  	nr_hugepages_mempolicy
>>  	nr_overcommit_hugepages
>> @@ -243,7 +247,28 @@ Inside each of these directories, the same set of files will exist::
>>  	resv_hugepages
>>  	surplus_hugepages
>>  
>> -which function as described above for the default huge page-sized case.
>> +The demote interfaces provide the ability to split a huge page into
>> +smaller huge pages.  For example, the x86 architecture supports both
>> +1GB and 2MB huge pages sizes.  A 1GB huge page can be split into 512
>> +2MB huge pages.  The demote interfaces are:
>> +
>> +demote_size
>> +        is the size of demoted pages.  When a page is demoted a corresponding
>> +        number of huge pages of demote_size will be created.  For huge pages
>> +        of the smallest supported size (2MB on x86), demote_size will be the
>> +        system page size (PAGE_SIZE).  If demote_size is the system page size
>> +        then demoting a page will simply free the huge page.  demote_size is
>> +        a read only interface.
>> +
>> +demote
>> +        is used to demote a number of huge pages.  A user with root privileges
>> +        can write to this file.  It may not be possible to demote the
>> +        requested number of huge pages.  To determine how many pages were
>> +        actually demoted, compare the value of nr_hugepages before and after
>> +        writing to the demote interface.  demote is a write only interface.
>> +
>> +The interfaces which are the same as in ``/proc`` function as described
>> +above for the default huge page-sized case.
> 
> Are these new demote interfaces duplicated in /proc? 
> Documentation/admin-guide/mm/hugetlbpage.rst says "The ``/proc``
> interfaces discussed above have been retained for backwards
> compatibility.", so new interfaces need not appear in /proc?
> 

The new demote interfaces are only in sysfs, they are not /proc.
Aneesh Kumar K.V Sept. 21, 2021, 1:52 p.m. UTC | #3
Mike Kravetz <mike.kravetz@oracle.com> writes:

> Describe demote and demote_size interfaces.
>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
>  Documentation/admin-guide/mm/hugetlbpage.rst | 29 ++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
> index 8abaeb144e44..902059a0257b 100644
> --- a/Documentation/admin-guide/mm/hugetlbpage.rst
> +++ b/Documentation/admin-guide/mm/hugetlbpage.rst
> @@ -234,8 +234,12 @@ will exist, of the form::
>  
>  	hugepages-${size}kB
>  
> -Inside each of these directories, the same set of files will exist::
> +Inside each of these directories, the set of files contained in ``/proc``
> +will exist.  In addition, two additional interfaces for demoting huge
> +pages will exist::
>  
> +        demote
> +        demote_size
>  	nr_hugepages
>  	nr_hugepages_mempolicy
>  	nr_overcommit_hugepages
> @@ -243,7 +247,28 @@ Inside each of these directories, the same set of files will exist::
>  	resv_hugepages
>  	surplus_hugepages
>  
> -which function as described above for the default huge page-sized case.
> +The demote interfaces provide the ability to split a huge page into
> +smaller huge pages.  For example, the x86 architecture supports both
> +1GB and 2MB huge pages sizes.  A 1GB huge page can be split into 512
> +2MB huge pages.  The demote interfaces are:
> +
> +demote_size
> +        is the size of demoted pages.  When a page is demoted a corresponding
> +        number of huge pages of demote_size will be created.  For huge pages
> +        of the smallest supported size (2MB on x86), demote_size will be the
> +        system page size (PAGE_SIZE).  If demote_size is the system page size
> +        then demoting a page will simply free the huge page.  demote_size is
> +        a read only interface.

That is an alternate interface for nr_hugepages. Will it be better to
return EINVAL on write to 'demote' file below
/sys/kernel/mm/hugepages/hugepages-2048kB ?

Or may be not expose demote possibility within 2M hugepage directory at all?


> +
> +demote
> +        is used to demote a number of huge pages.  A user with root privileges
> +        can write to this file.  It may not be possible to demote the
> +        requested number of huge pages.  To determine how many pages were
> +        actually demoted, compare the value of nr_hugepages before and after
> +        writing to the demote interface.  demote is a write only interface.
> +
> +The interfaces which are the same as in ``/proc`` function as described
> +above for the default huge page-sized case.
>  
>  .. _mem_policy_and_hp_alloc:
>  
> -- 
> 2.31.1
Mike Kravetz Sept. 21, 2021, 5:17 p.m. UTC | #4
On 9/21/21 6:52 AM, Aneesh Kumar K.V wrote:
> Mike Kravetz <mike.kravetz@oracle.com> writes:
> 
>> Describe demote and demote_size interfaces.
>>
>> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
>> ---
>>  Documentation/admin-guide/mm/hugetlbpage.rst | 29 ++++++++++++++++++--
>>  1 file changed, 27 insertions(+), 2 deletions(-)
>>
>> diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
>> index 8abaeb144e44..902059a0257b 100644
>> --- a/Documentation/admin-guide/mm/hugetlbpage.rst
>> +++ b/Documentation/admin-guide/mm/hugetlbpage.rst
>> @@ -234,8 +234,12 @@ will exist, of the form::
>>  
>>  	hugepages-${size}kB
>>  
>> -Inside each of these directories, the same set of files will exist::
>> +Inside each of these directories, the set of files contained in ``/proc``
>> +will exist.  In addition, two additional interfaces for demoting huge
>> +pages will exist::
>>  
>> +        demote
>> +        demote_size
>>  	nr_hugepages
>>  	nr_hugepages_mempolicy
>>  	nr_overcommit_hugepages
>> @@ -243,7 +247,28 @@ Inside each of these directories, the same set of files will exist::
>>  	resv_hugepages
>>  	surplus_hugepages
>>  
>> -which function as described above for the default huge page-sized case.
>> +The demote interfaces provide the ability to split a huge page into
>> +smaller huge pages.  For example, the x86 architecture supports both
>> +1GB and 2MB huge pages sizes.  A 1GB huge page can be split into 512
>> +2MB huge pages.  The demote interfaces are:
>> +
>> +demote_size
>> +        is the size of demoted pages.  When a page is demoted a corresponding
>> +        number of huge pages of demote_size will be created.  For huge pages
>> +        of the smallest supported size (2MB on x86), demote_size will be the
>> +        system page size (PAGE_SIZE).  If demote_size is the system page size
>> +        then demoting a page will simply free the huge page.  demote_size is
>> +        a read only interface.
> 
> That is an alternate interface for nr_hugepages. Will it be better to
> return EINVAL on write to 'demote' file below
> /sys/kernel/mm/hugepages/hugepages-2048kB ?
> 
> Or may be not expose demote possibility within 2M hugepage directory at all?
> 

Thanks for taking a look Aneesh!

You are right. If demote_size is PAGE_SIZE, then demote is just an
alternative to freeing huge pages via the nr_hugepages interface.
So, why even provide such an interface?
It certainly would be easy to just not display demote interfaces for the
smallest huge page size.

Based on other feedback, I am also making demote_size writable.  It
makes little sense on x86 with only two huge page sizes.  However, it
might be useful on other architectures with more sizes.  demote_size can
only be a valid huge page size.  Before your comment, I was going to
allow setting demote_size to PAGE_SIZE.  Perhaps, that should not be
allowed.

Thanks for the suggestion,  I think removing support for demote_size ==
PAGE_SIZE will make the code simpler.
diff mbox series

Patch

diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
index 8abaeb144e44..902059a0257b 100644
--- a/Documentation/admin-guide/mm/hugetlbpage.rst
+++ b/Documentation/admin-guide/mm/hugetlbpage.rst
@@ -234,8 +234,12 @@  will exist, of the form::
 
 	hugepages-${size}kB
 
-Inside each of these directories, the same set of files will exist::
+Inside each of these directories, the set of files contained in ``/proc``
+will exist.  In addition, two additional interfaces for demoting huge
+pages will exist::
 
+        demote
+        demote_size
 	nr_hugepages
 	nr_hugepages_mempolicy
 	nr_overcommit_hugepages
@@ -243,7 +247,28 @@  Inside each of these directories, the same set of files will exist::
 	resv_hugepages
 	surplus_hugepages
 
-which function as described above for the default huge page-sized case.
+The demote interfaces provide the ability to split a huge page into
+smaller huge pages.  For example, the x86 architecture supports both
+1GB and 2MB huge pages sizes.  A 1GB huge page can be split into 512
+2MB huge pages.  The demote interfaces are:
+
+demote_size
+        is the size of demoted pages.  When a page is demoted a corresponding
+        number of huge pages of demote_size will be created.  For huge pages
+        of the smallest supported size (2MB on x86), demote_size will be the
+        system page size (PAGE_SIZE).  If demote_size is the system page size
+        then demoting a page will simply free the huge page.  demote_size is
+        a read only interface.
+
+demote
+        is used to demote a number of huge pages.  A user with root privileges
+        can write to this file.  It may not be possible to demote the
+        requested number of huge pages.  To determine how many pages were
+        actually demoted, compare the value of nr_hugepages before and after
+        writing to the demote interface.  demote is a write only interface.
+
+The interfaces which are the same as in ``/proc`` function as described
+above for the default huge page-sized case.
 
 .. _mem_policy_and_hp_alloc: