help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] [PATCH] memory: Handle heap allocation failures wit


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] [PATCH] memory: Handle heap allocation failures without aborting
Date: Sat, 29 Dec 2012 15:12:29 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

Il 29/12/2012 00:42, Holger Hans Peter Freyther ha scritto:
> From: Holger Hans Peter Freyther <address@hidden>
> 
> _gst_heap_sbrk/heap_sbrk_internal will return NULL on allocation
> failures and set errno to ENOMEM but the morecore method assumed
> that MMAP_FAILED (PTR -1) would be returned. Make it consistent.
> 
> This way I can allocate up to 1.4gb of virtual address space until
> I run into GC scalability issues.
> ---
>  libgst/ChangeLog |    6 ++++++
>  libgst/alloc.c   |    6 ++++--
>  libgst/heap.c    |   11 +++--------
>  3 files changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/libgst/ChangeLog b/libgst/ChangeLog
> index 2ba7b05..1923813 100644
> --- a/libgst/ChangeLog
> +++ b/libgst/ChangeLog
> @@ -1,3 +1,9 @@
> +2012-12-29  Holger Hans Peter Freyther  <address@hidden>
> +
> +     * libgst/alloc.c: _gst_heap_sbrk returns NULL and not MMAP_FAILED
> +     on allocation failure.
> +     * libgst/heap.c: Return NULL on allocation failure.
> +
>  2012-09-09  Paolo Bonzini  <address@hidden>
>  
>       * libgst/sysdep/posix/events.c: Register the fd with gst
> diff --git a/libgst/alloc.c b/libgst/alloc.c
> index 86810d2..cdead03 100644
> --- a/libgst/alloc.c
> +++ b/libgst/alloc.c
> @@ -671,6 +671,8 @@ heap_system_alloc (heap_data *h, size_t sz)
>  #endif
>  
>    mem = (heap_block *) morecore (sz);
> +  if (!mem)
> +     nomemory(1);
>    mem->mmap_block = 0;
>    mem->size = sz;
>  
> @@ -700,7 +702,7 @@ morecore (size_t size)
>      {
>        char *ptr = _gst_heap_sbrk (current_heap, size);
>  
> -      if (ptr != (PTR) -1)
> +      if (ptr != NULL)
>       {
>            if (((intptr_t) ptr & (pagesize - 1)) > 0)
>              {
> @@ -710,7 +712,7 @@ morecore (size_t size)
>             ptr = _gst_heap_sbrk (current_heap, size);
>              }
>  
> -          if (ptr != (PTR) -1)
> +          if (ptr != NULL)
>           return (ptr);
>       }
>  
> diff --git a/libgst/heap.c b/libgst/heap.c
> index 1f64fb2..929389f 100644
> --- a/libgst/heap.c
> +++ b/libgst/heap.c
> @@ -220,14 +220,9 @@ heap_sbrk_internal (struct heap * hdp,
>      {
>        if (hdp->breakval - hdp->base + size > hdp->areasize)
>          {
> -          if (hdp->breakval - hdp->base == hdp->areasize);
> -            {
> -              /* FIXME: a library should never exit!  */
> -              fprintf (stderr, "gst: out of memory allocating %d bytes\n",
> -                       size);
> -              exit (1);
> -            }
> -          size = hdp->areasize - (hdp->breakval - hdp->base);
> +          /* this heap is full? */
> +          errno = ENOMEM;
> +          return NULL;
>          }
>  
>        moveto = PAGE_ALIGN (hdp->breakval + size);
> 

Applied, thanks!

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]