From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aXlN7-00032p-U2 for mharc-grub-devel@gnu.org; Mon, 22 Feb 2016 02:57:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXlN5-000306-MJ for grub-devel@gnu.org; Mon, 22 Feb 2016 02:57:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXlN2-0006ag-7t for grub-devel@gnu.org; Mon, 22 Feb 2016 02:57:31 -0500 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]:34321) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXlN1-0006ab-R6 for grub-devel@gnu.org; Mon, 22 Feb 2016 02:57:28 -0500 Received: by mail-lf0-x234.google.com with SMTP id j78so88215892lfb.1 for ; Sun, 21 Feb 2016 23:57:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=YyNnz5Yx+KdI9ZCksCY3wDNZfomPtMSvkte82jfoHfc=; b=QnZdLehLv03Uu+B+etBRNbIdfTsZYKK08+bK8RmAmTNUcIdUfnI0/tJPz4bQ69oo/s d6IotNo7PhFgq5bvqQeVhoHZ7KwmQzqKPClYUkKWZIsdHlZ/MSfDDqnZmgj8CYGGvn09 z5x9s0F8MgHe+BxJFU/gqCwMRqfhDivfv/Wx+J4LDgLOfO0MSiUbtJxvWVtiSIOLbAUc VaCnbOf3KXcg9Id+urF9ng2LFc1GjncqKuQluMDRIH5VtQmJPAdQg28bYoGUkSAqu7IY dw5zmmpOJXNIpoI3QPFEmSuwhzPIkGEDIdf9NywGE9uaUpzkq5CsGiT/xafh+HP/tADN bqhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=YyNnz5Yx+KdI9ZCksCY3wDNZfomPtMSvkte82jfoHfc=; b=LJ/HybQ5+UkTpnPcCxAXxSK4QYlnC91580csW8e1b734/D6amceyqUIQiKLV3y1vFO NN9Odr19j1HqUQa74GWBrO5wUhAk8emZGDNRfVsMUjYv4l6TR1hYPbzclg1usiHnysVN lJ7y/i5HfqxjhtO5CnQUX8k2OY4xsoOoEapSex1JQMUTbE8kY2d/4PBMjCONRzkvbU0j vrGRXYvWRGBbcAntRpj6xul3HA5PQv8RQjLMsQgQXD0HMUiFWQ9ic7iTggnFKyDAZXCD kltScoLpWBsM49vsB//YsOzfCXoNtyXXeyeDaAbY1AbXa1y8piaJq6FKD1pHQ1QdwmQN zg3Q== X-Gm-Message-State: AG10YORCzcx8bPM7rNnOcsJmDm3+sc5BYYJv19z1gZgWJcIbUQxibD3ReA5ZpfhGbwgpgg== X-Received: by 10.25.28.209 with SMTP id c200mr7997991lfc.29.1456127846965; Sun, 21 Feb 2016 23:57:26 -0800 (PST) Received: from [192.168.1.41] (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id cc7sm3085207lbd.11.2016.02.21.23.57.25 for (version=TLSv1/SSLv3 cipher=OTHER); Sun, 21 Feb 2016 23:57:25 -0800 (PST) Subject: Re: [PATCH 1/2] disk: Add support for device-specific malloc function To: grub-devel@gnu.org References: <1455898714-25127-1-git-send-email-leif.lindholm@linaro.org> <1455898714-25127-2-git-send-email-leif.lindholm@linaro.org> From: Andrei Borzenkov X-Enigmail-Draft-Status: N1110 Message-ID: <56CABF64.7020003@gmail.com> 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 MIME-Version: 1.0 In-Reply-To: <1455898714-25127-2-git-send-email-leif.lindholm@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::234 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2016 07:57:32 -0000 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; > >