[CRIU] [PATCH] rst-malloc: return aligned pointers to sizeof(void *) (v4)
Andrew Vagin
avagin at virtuozzo.com
Sat Feb 6 16:23:58 PST 2016
On Sat, Feb 06, 2016 at 08:39:44PM +0300, Pavel Emelyanov wrote:
> On 02/05/2016 09:09 PM, Andrey Vagin wrote:
> > From: Andrew Vagin <avagin at virtuozzo.com>
> >
> > Stas found that if we don't align a pointer,
> > futex and atomic operations can fail.
> >
> > v2: don't hard-code the size of void *
> > v3: add a function to allocate memory without gaps with
> > a privious slice. It's used to allocate arrays.
> > v4: don't change rst_mem_cpos
> >
> > Cc: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
> > Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
>
> I'm OK with the patch. Will there be another one that actually
> makes use of the new rst_mem_alloc_cont() routine?
The second patch does this.
>
> > ---
> > include/rst-malloc.h | 1 +
> > rst-malloc.c | 20 +++++++++++++++++++-
> > 2 files changed, 20 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/rst-malloc.h b/include/rst-malloc.h
> > index 8c48f27..f205622 100644
> > --- a/include/rst-malloc.h
> > +++ b/include/rst-malloc.h
> > @@ -58,6 +58,7 @@ extern void *rst_mem_remap_ptr(unsigned long pos, int type);
> > * last object can be freed (pop-ed from buffer).
> > */
> > extern void *rst_mem_alloc(unsigned long size, int type);
> > +extern void *rst_mem_alloc_cont(unsigned long size, int type);
> > extern void rst_mem_free_last(int type);
> > /*
> > * Routines to remap SHREMAP and PRIVATE into restorer address space
> > diff --git a/rst-malloc.c b/rst-malloc.c
> > index 14e0b41..3556980 100644
> > --- a/rst-malloc.c
> > +++ b/rst-malloc.c
> > @@ -138,7 +138,7 @@ void *rst_mem_remap_ptr(unsigned long pos, int type)
> > return t->buf + pos;
> > }
> >
> > -void *rst_mem_alloc(unsigned long size, int type)
> > +static void *__rst_mem_alloc(unsigned long size, int type)
> > {
> > struct rst_mem_type_s *t = &rst_mems[type];
> > void *ret;
> > @@ -158,6 +158,24 @@ void *rst_mem_alloc(unsigned long size, int type)
> > return ret;
> > }
> >
> > +void *rst_mem_alloc(unsigned long size, int type)
> > +{
> > + struct rst_mem_type_s *t = &rst_mems[type];
> > +
> > + t->free_mem = (void *) round_up((unsigned long)t->free_mem, sizeof(void *));
> > +
> > + return __rst_mem_alloc(size, type);
> > +}
> > +
> > +/* Allocate memory without gaps with a previous slice */
> > +void *rst_mem_alloc_cont(unsigned long size, int type)
> > +{
> > + struct rst_mem_type_s *t = &rst_mems[type];
> > + BUG_ON(!t->remapable);
> > +
> > + return __rst_mem_alloc(size, type);
> > +}
> > +
> > void rst_mem_free_last(int type)
> > {
> > struct rst_mem_type_s *t = &rst_mems[type];
> >
>
More information about the CRIU
mailing list