bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH 5/6] libpager: Fix overallocating pagemap


From: Samuel Thibault
Subject: Re: [PATCH 5/6] libpager: Fix overallocating pagemap
Date: Fri, 7 May 2021 00:04:45 +0200
User-agent: NeoMutt/20170609 (1.8.3)

Sergey Bugaev, le jeu. 06 mai 2021 15:56:30 +0300, a ecrit:
> The code tried to round up the allocation size to a multiple of page size.
> But we actually allocate newsize * sizeof (*p->pagemap) bytes, not newsize
> bytes, which meant allocations were sizeof (*p->pagemap) times larger than
> they needed to be.

Indeed, applied, thanks!

> ---
>  libpager/pagemap.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/libpager/pagemap.c b/libpager/pagemap.c
> index 63c5f44d..1570c75b 100644
> --- a/libpager/pagemap.c
> +++ b/libpager/pagemap.c
> @@ -17,21 +17,22 @@
>  
>  #include "priv.h"
>  #include <string.h>
> -  
> +
>  /* Grow the pagemap of pager P as necessary to deal with address OFF */
>  error_t
>  _pager_pagemap_resize (struct pager *p, vm_address_t off)
>  {
>    error_t err = 0;
> -  
> +
>    off /= __vm_page_size;
>  
>    if (p->pagemapsize < off)
>      {
>        void *newaddr;
> -      vm_size_t newsize = round_page (off);
> +      vm_size_t newsize = round_page (off * sizeof (*p->pagemap))
> +                                          / sizeof (*p->pagemap);
>  
> -      newaddr = mmap (0, newsize * sizeof (*p->pagemap), 
> +      newaddr = mmap (0, newsize * sizeof (*p->pagemap),
>                     PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
>        err = (newaddr == (void *) -1) ? errno : 0;
>        if (! err)
> -- 
> 2.31.1
> 
> 



reply via email to

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