grub-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 1/2] disk: Add support for device-specific malloc function


From: Andrei Borzenkov
Subject: Re: [PATCH 1/2] disk: Add support for device-specific malloc function
Date: Mon, 22 Feb 2016 10:57:24 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1

19.02.2016 19:18, Leif Lindholm пишет:
> Some disk types have allocation requirements beyond normal grub_malloc.
> Add a function pointer to grub_disk_t and a wrapper function in
> kern/disk.c making use of that function if available, to enable these
> disk drivers to implement their own malloc.

The problem is not (only) grub_disk_read_small(), but this part in
grub_disk_read:

      if (agglomerate)
        {
          grub_disk_addr_t i;

          err = (disk->dev->read) (disk, transform_sector (disk, sector),
                                   agglomerate << (GRUB_DISK_CACHE_BITS
                                                   + GRUB_DISK_SECTOR_BITS
                                                   - disk->log_sector_size),
                                   buf);

which reads directly into user supplied buffer. May be we can allocate
contiguous cache block here but put pointers to multiple chunks inside
it. Possible implementation is to have second layer of reference counted
memory blocks with cache entries containing pointer + offset into them.

> ---
>  grub-core/kern/disk.c | 13 +++++++++++--
>  include/grub/disk.h   |  5 +++++
>  2 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c
> index 789f8c0..e186586 100644
> --- a/grub-core/kern/disk.c
> +++ b/grub-core/kern/disk.c
> @@ -184,6 +184,15 @@ find_part_sep (const char *name)
>    return NULL;
>  }
>  
> +static void *
> +disk_malloc (struct grub_disk *disk, grub_size_t size)
> +{
> +  if (disk->malloc)
> +    return disk->malloc (disk, size);
> +
> +  return grub_malloc (size);
> +}
> +
>  grub_disk_t
>  grub_disk_open (const char *name)
>  {
> @@ -331,7 +340,7 @@ grub_disk_read_small_real (grub_disk_t disk, 
> grub_disk_addr_t sector,
>      }
>  
>    /* Allocate a temporary buffer.  */
> -  tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
> +  tmp_buf = disk_malloc (disk, GRUB_DISK_SECTOR_SIZE << 
> GRUB_DISK_CACHE_BITS);
>    if (! tmp_buf)
>      return grub_errno;
>  
> @@ -373,7 +382,7 @@ grub_disk_read_small_real (grub_disk_t disk, 
> grub_disk_addr_t sector,
>      num = ((size + offset + (1ULL << (disk->log_sector_size))
>           - 1) >> (disk->log_sector_size));
>  
> -    tmp_buf = grub_malloc (num << disk->log_sector_size);
> +    tmp_buf = disk_malloc (disk, num << disk->log_sector_size);
>      if (!tmp_buf)
>        return grub_errno;
>      
> diff --git a/include/grub/disk.h b/include/grub/disk.h
> index b385af8..0fdd779 100644
> --- a/include/grub/disk.h
> +++ b/include/grub/disk.h
> @@ -111,6 +111,8 @@ typedef void (*grub_disk_read_hook_t) (grub_disk_addr_t 
> sector,
>                                      unsigned offset, unsigned length,
>                                      void *data);
>  
> +typedef void *(*grub_disk_malloc_t) (struct grub_disk *disk, grub_size_t 
> size);
> +
>  /* Disk.  */
>  struct grub_disk
>  {
> @@ -144,6 +146,9 @@ struct grub_disk
>  
>    /* Device-specific data.  */
>    void *data;
> +
> +  /* Device-specific malloc function. */
> +  grub_disk_malloc_t malloc;
>  };
>  typedef struct grub_disk *grub_disk_t;
>  
> 




reply via email to

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