[9/9] memalloc: allocate memory in reverse

Message ID 914a5f584be81d6c129b35bc8e358774854d8960.1528749451.git.anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series mem: reduce memory fragmentation |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Burakov, Anatoly June 11, 2018, 8:55 p.m. UTC
  Currently, all hugepages are allocated from lower VA address to
higher VA address, while malloc heap allocates from higher VA
address to lower VA address. This results in heap fragmentation
over time due to multiple reserves leaving small space below the
allocated elements.

Fix this by allocating VA memory from the top, thereby reducing
fragmentation and lowering overall memory usage.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Burakov, Anatoly July 24, 2018, 10:10 a.m. UTC | #1
On 11-Jun-18 9:55 PM, Anatoly Burakov wrote:
> Currently, all hugepages are allocated from lower VA address to
> higher VA address, while malloc heap allocates from higher VA
> address to lower VA address. This results in heap fragmentation
> over time due to multiple reserves leaving small space below the
> allocated elements.
> 
> Fix this by allocating VA memory from the top, thereby reducing
> fragmentation and lowering overall memory usage.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>   lib/librte_eal/linuxapp/eal/eal_memalloc.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> index 8c11f98c9..d35fb52c4 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> @@ -682,7 +682,8 @@ alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
>   	need = wa->n_segs;
>   
>   	/* try finding space in memseg list */
> -	cur_idx = rte_fbarray_find_next_n_free(&cur_msl->memseg_arr, 0, need);
> +	cur_idx = rte_fbarray_find_prev_n_free(&cur_msl->memseg_arr,
> +			cur_msl->memseg_arr.len - 1, need);
>   	if (cur_idx < 0)
>   		return 0;
>   	start_idx = cur_idx;
> 

Hi Thomas,

We have discovered a few regressions in virtio/vhost use cases due to 
this patch. Virtio expects to map all segments starting from 0 address, 
and this patch breaks that assumption.

Can we revert this for 18.08? It will be reintroduced in 18.11 along 
with fixes for virtio/vhost fixes to account for this change.
  
Thomas Monjalon July 24, 2018, 10:24 a.m. UTC | #2
24/07/2018 12:10, Burakov, Anatoly:
> On 11-Jun-18 9:55 PM, Anatoly Burakov wrote:
> > Currently, all hugepages are allocated from lower VA address to
> > higher VA address, while malloc heap allocates from higher VA
> > address to lower VA address. This results in heap fragmentation
> > over time due to multiple reserves leaving small space below the
> > allocated elements.
> > 
> > Fix this by allocating VA memory from the top, thereby reducing
> > fragmentation and lowering overall memory usage.
> > 
> > Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> > ---
> >   lib/librte_eal/linuxapp/eal/eal_memalloc.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> > index 8c11f98c9..d35fb52c4 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> > @@ -682,7 +682,8 @@ alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
> >   	need = wa->n_segs;
> >   
> >   	/* try finding space in memseg list */
> > -	cur_idx = rte_fbarray_find_next_n_free(&cur_msl->memseg_arr, 0, need);
> > +	cur_idx = rte_fbarray_find_prev_n_free(&cur_msl->memseg_arr,
> > +			cur_msl->memseg_arr.len - 1, need);
> >   	if (cur_idx < 0)
> >   		return 0;
> >   	start_idx = cur_idx;
> > 
> 
> Hi Thomas,
> 
> We have discovered a few regressions in virtio/vhost use cases due to 
> this patch. Virtio expects to map all segments starting from 0 address, 
> and this patch breaks that assumption.
> 
> Can we revert this for 18.08? It will be reintroduced in 18.11 along 
> with fixes for virtio/vhost fixes to account for this change.

Yes, please send the patch with explanations.
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index 8c11f98c9..d35fb52c4 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -682,7 +682,8 @@  alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	need = wa->n_segs;
 
 	/* try finding space in memseg list */
-	cur_idx = rte_fbarray_find_next_n_free(&cur_msl->memseg_arr, 0, need);
+	cur_idx = rte_fbarray_find_prev_n_free(&cur_msl->memseg_arr,
+			cur_msl->memseg_arr.len - 1, need);
 	if (cur_idx < 0)
 		return 0;
 	start_idx = cur_idx;