From: NeilBrown <neilb@suse.de>
To: Lukasz Dorau <lukasz.dorau@intel.com>
Cc: linux-raid@vger.kernel.org, marcin.labun@intel.com,
ed.ciechanowski@intel.com
Subject: Re: [PATCH] Fix serious memory leak
Date: Mon, 19 Sep 2011 13:27:22 +1000 [thread overview]
Message-ID: <20110919132722.04d35708@notabene.brown> (raw)
In-Reply-To: <20110916111913.20840.13403.stgit@gklab-128-085.igk.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3272 bytes --]
On Fri, 16 Sep 2011 13:19:14 +0200 Lukasz Dorau <lukasz.dorau@intel.com>
wrote:
> During reshape function restore_stripes is called periodically
> and every time the buffer stripe_buf (of size raid_disks*chunk_size)
> is allocated but is not freed. It happens also upon successful completion.
> In case of huge arrays it can lead to the seizure of the entire
> system memory (even of the order of gigabytes).
>
> Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
Thanks.
I changed that patch a bit:
- There were two places that freed everything and returned. I changed the
first one to just set 'rv' and 'goto' the last one.
- You set 'rv = 0' twice. Once is enough. I removed the first one.
Thanks,
NeilBrown
> ---
> restripe.c | 43 +++++++++++++++++++++++++++++++------------
> 1 files changed, 31 insertions(+), 12 deletions(-)
>
> diff --git a/restripe.c b/restripe.c
> index 9c83e2e..7cabbd0 100644
> --- a/restripe.c
> +++ b/restripe.c
> @@ -687,6 +687,7 @@ int restore_stripes(int *dest, unsigned long long *offsets,
> char **stripes = malloc(raid_disks * sizeof(char*));
> char **blocks = malloc(raid_disks * sizeof(char*));
> int i;
> + int rv = 0;
>
> int data_disks = raid_disks - (level == 0 ? 0 : level <= 5 ? 1 : 2);
>
> @@ -717,20 +718,26 @@ int restore_stripes(int *dest, unsigned long long *offsets,
> unsigned long long offset;
> int disk, qdisk;
> int syndrome_disks;
> - if (length < len)
> - return -3;
> + if (length < len) {
> + rv = -3;
> + goto abort;
> + }
> for (i = 0; i < data_disks; i++) {
> int disk = geo_map(i, start/chunk_size/data_disks,
> raid_disks, level, layout);
> if (src_buf == NULL) {
> /* read from file */
> - if (lseek64(source,
> - read_offset, 0) != (off64_t)read_offset)
> - return -1;
> + if (lseek64(source, read_offset, 0) !=
> + (off64_t)read_offset) {
> + rv = -1;
> + goto abort;
> + }
> if (read(source,
> stripes[disk],
> - chunk_size) != chunk_size)
> - return -1;
> + chunk_size) != chunk_size) {
> + rv = -1;
> + goto abort;
> + }
> } else {
> /* read from input buffer */
> memcpy(stripes[disk],
> @@ -782,15 +789,27 @@ int restore_stripes(int *dest, unsigned long long *offsets,
> }
> for (i=0; i < raid_disks ; i++)
> if (dest[i] >= 0) {
> - if (lseek64(dest[i], offsets[i]+offset, 0) < 0)
> - return -1;
> - if (write(dest[i], stripes[i], chunk_size) != chunk_size)
> - return -1;
> + if (lseek64(dest[i],
> + offsets[i]+offset, 0) < 0) {
> + rv = -1;
> + goto abort;
> + }
> + if (write(dest[i], stripes[i],
> + chunk_size) != chunk_size) {
> + rv = -1;
> + goto abort;
> + }
> }
> length -= len;
> start += len;
> }
> - return 0;
> + rv = 0;
> +
> +abort:
> + free(stripe_buf);
> + free(stripes);
> + free(blocks);
> + return rv;
> }
>
> #ifdef MAIN
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 190 bytes --]
prev parent reply other threads:[~2011-09-19 3:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-16 11:19 [PATCH] Fix serious memory leak Lukasz Dorau
2011-09-19 3:27 ` NeilBrown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110919132722.04d35708@notabene.brown \
--to=neilb@suse.de \
--cc=ed.ciechanowski@intel.com \
--cc=linux-raid@vger.kernel.org \
--cc=lukasz.dorau@intel.com \
--cc=marcin.labun@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).