Skip to contentSkip to conversation

mem: mark pages as not accessed when reserving VA

PATCH Applied David Marchand 4 participants 5 messages Mar 9, 2020 – Mar 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mem: mark pages as not accessed when reserving VA

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.

---
 lib/librte_eal/common/eal_common_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/eal_common_memory.c +1 -1
index 4a9cc1f19..cc7d54e0c 100644
@@ -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;
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · David Marchand

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.

---
 lib/librte_eal/common/eal_common_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/eal_common_memory.c +0 -0
index 4a9cc1f19..cc7d54e0c 100644

lib/librte_eal/common/eal_common_memory.c eal_get_virtual_area(void *requested_addr, size_t *size, · line 103

Quoted 8 lines
lib/librte_eal/common/eal_common_memory.c +1 -1
@@ -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;

Thanks!
Maxime

Acked-by on v1 1/1
#2 lore raw
In reply to David Marchand
Quoted 10 lines · David Marchand

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.

Quoted 8 lines

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

---

Thanks!

Acked-by on v1 1/1
#3 lore raw
In reply to David Marchand
Quoted 10 lines · David Marchand

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.

Quoted 8 lines

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

---

Signature · 2 lines
Thanks,
Anatoly
author Reviewed-by Maxime Coquelin Acked-by Aaron Conole Acked-by Anatoly Burakov on v1 1/1 Applied
#4 lore raw
In reply to David Marchand
Quoted 11 lines · David Marchand

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.

Quoted 7 lines

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

Applied.

Signature · 1 line
David Marchand