mem: mark pages as not accessed when reserving VA

Message ID 20200309145442.28926-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series mem: mark pages as not accessed when reserving VA |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation fail apply issues

Commit Message

David Marchand March 9, 2020, 2:54 p.m. UTC
  When the memory allocator reserves virtual addresses, it still does not
know what they will be used for.
Besides, huge areas are reserved for memory hotplug in multiprocess
setups. But most of the pages are unused in the whole life of the
processes.

Change protection mode to PROT_NONE when only reserving VA.
The memory allocator already switches to the right mode when making use
of it.

It also has the nice effect of getting those pages skipped by the kernel
when calling mlockall() or when a coredump gets generated.

Cc: stable@dpdk.org

Suggested-by: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_eal/common/eal_common_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Maxime Coquelin March 9, 2020, 3:27 p.m. UTC | #1
On 3/9/20 3:54 PM, David Marchand wrote:
> When the memory allocator reserves virtual addresses, it still does not
> know what they will be used for.
> Besides, huge areas are reserved for memory hotplug in multiprocess
> setups. But most of the pages are unused in the whole life of the
> processes.
> 
> Change protection mode to PROT_NONE when only reserving VA.
> The memory allocator already switches to the right mode when making use
> of it.
> 
> It also has the nice effect of getting those pages skipped by the kernel
> when calling mlockall() or when a coredump gets generated.
> 
> Cc: stable@dpdk.org
> 
> Suggested-by: Andrea Arcangeli <aarcange@redhat.com>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/librte_eal/common/eal_common_memory.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
> index 4a9cc1f19..cc7d54e0c 100644
> --- a/lib/librte_eal/common/eal_common_memory.c
> +++ b/lib/librte_eal/common/eal_common_memory.c
> @@ -97,7 +97,7 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
>  			return NULL;
>  		}
>  
> -		mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_READ,
> +		mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_NONE,
>  				mmap_flags, -1, 0);
>  		if (mapped_addr == MAP_FAILED && allow_shrink)
>  			*size -= page_sz;
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks!
Maxime
  
Aaron Conole March 10, 2020, 1:57 p.m. UTC | #2
David Marchand <david.marchand@redhat.com> writes:

> When the memory allocator reserves virtual addresses, it still does not
> know what they will be used for.
> Besides, huge areas are reserved for memory hotplug in multiprocess
> setups. But most of the pages are unused in the whole life of the
> processes.
>
> Change protection mode to PROT_NONE when only reserving VA.
> The memory allocator already switches to the right mode when making use
> of it.
>
> It also has the nice effect of getting those pages skipped by the kernel
> when calling mlockall() or when a coredump gets generated.
>
> Cc: stable@dpdk.org
>
> Suggested-by: Andrea Arcangeli <aarcange@redhat.com>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---

Acked-by: Aaron Conole <aconole@redhat.com>

Thanks!
  
Burakov, Anatoly March 10, 2020, 4:26 p.m. UTC | #3
On 09-Mar-20 2:54 PM, David Marchand wrote:
> When the memory allocator reserves virtual addresses, it still does not
> know what they will be used for.
> Besides, huge areas are reserved for memory hotplug in multiprocess
> setups. But most of the pages are unused in the whole life of the
> processes.
> 
> Change protection mode to PROT_NONE when only reserving VA.
> The memory allocator already switches to the right mode when making use
> of it.
> 
> It also has the nice effect of getting those pages skipped by the kernel
> when calling mlockall() or when a coredump gets generated.
> 
> Cc: stable@dpdk.org
> 
> Suggested-by: Andrea Arcangeli <aarcange@redhat.com>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
David Marchand March 13, 2020, 9:59 a.m. UTC | #4
On Mon, Mar 9, 2020 at 3:55 PM David Marchand <david.marchand@redhat.com> wrote:
>
> When the memory allocator reserves virtual addresses, it still does not
> know what they will be used for.
> Besides, huge areas are reserved for memory hotplug in multiprocess
> setups. But most of the pages are unused in the whole life of the
> processes.
>
> Change protection mode to PROT_NONE when only reserving VA.
> The memory allocator already switches to the right mode when making use
> of it.
>
> It also has the nice effect of getting those pages skipped by the kernel
> when calling mlockall() or when a coredump gets generated.
>
> Cc: stable@dpdk.org
>
> Suggested-by: Andrea Arcangeli <aarcange@redhat.com>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>


Applied.
  

Patch

diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 4a9cc1f19..cc7d54e0c 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -97,7 +97,7 @@  eal_get_virtual_area(void *requested_addr, size_t *size,
 			return NULL;
 		}
 
-		mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_READ,
+		mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_NONE,
 				mmap_flags, -1, 0);
 		if (mapped_addr == MAP_FAILED && allow_shrink)
 			*size -= page_sz;