linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhi Yong Wu <zwu.kernel@gmail.com>
To: kreijack@inwind.it
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	jbacik@fusionio.com, dave@jikos.cz, linuxram@linux.vnet.ibm.com,
	Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Subject: Re: [PATCH v2 2/2] btrfs-progs: Fix up memory leakage
Date: Wed, 26 Sep 2012 10:58:26 +0800	[thread overview]
Message-ID: <CAEH94LirayD_NB2KW5q5KSZ3nVTJLYpi23D_ioGwcKmn0WyDVw@mail.gmail.com> (raw)
In-Reply-To: <5061E676.8080203@libero.it>

On Wed, Sep 26, 2012 at 1:14 AM, Goffredo Baroncelli <kreijack@libero.it> wrote:
> On 09/25/2012 12:14 PM, David Sterba wrote:
>>
>> On Tue, Sep 25, 2012 at 10:02:16AM +0800, zwu.kernel@gmail.com wrote:
>>>
>>> From: Zhi Yong Wu<wuzhy@linux.vnet.ibm.com>
>>>
>>>    Some code pathes forget to free memory on exit.
>>
>>
>> Same as with the fd's, kernel will free all memory for us at exit().
>
>
> I strongly disagree with this approach. The callee often don't know what
> happen after and before the call. The same is true for the programmer,
> because the code is quite often updated by several people. A clean exit() is
> the right thing to do as general rule. I don't see any valid reason (in the
> btrfs context) to do otherwise.
>
> Relying on the exit() for a proper clean-up increase the likelihood of bug
> when the code evolves (see my patch   [RESPOST][BTRFS-PROGS][PATCH]
> btrfs_read_dev_super(): uninitialized variable for an example of what means
> an incorrect deallocation of resource).
>
>
>> If there's lots of memory allocated, it may be even faster to leave the
>> unallocation process to kernel as it will do it in one go, while the
>> application would unnecessarily free it chunk by chunk.
>
>
> May be I am wrong, but I don't think that the increase of speed of the btrfs
> "command" is even measurable relying on exit instead of free()-ing each
> chunk of memory one at time.... The same should be true for the
> open()/close()

I fully agree with you. In one same function, i find that some code
path free system sources,
while other code path doesn't. This is one nice way.

>
> My 2¢
>
> BR
> G.Baroncelli
>
>>
>> david
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>>
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> .
>>
>



-- 
Regards,

Zhi Yong Wu

  reply	other threads:[~2012-09-26  2:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-25  2:02 [resend][PATCH v2 0/2] btrfs-progs: some bugfixes zwu.kernel
2012-09-25  2:02 ` [PATCH v2 1/2] btrfs-progs: Close file descriptor on exit zwu.kernel
2012-09-25 10:12   ` David Sterba
2012-09-25 13:58     ` Zhi Yong Wu
2012-09-25  2:02 ` [PATCH v2 2/2] btrfs-progs: Fix up memory leakage zwu.kernel
2012-09-25 10:14   ` David Sterba
2012-09-25 14:03     ` Zhi Yong Wu
2012-09-25 17:14     ` Goffredo Baroncelli
2012-09-26  2:58       ` Zhi Yong Wu [this message]
2012-09-26 21:13       ` Goffredo Baroncelli
  -- strict thread matches above, loose matches on Subject: below --
2012-09-05  9:21 [PATCH v2 0/2] btrfs-progs: some bugfixes Zhi Yong Wu
2012-09-05  9:21 ` [PATCH v2 2/2] btrfs-progs: Fix up memory leakage Zhi Yong Wu

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=CAEH94LirayD_NB2KW5q5KSZ3nVTJLYpi23D_ioGwcKmn0WyDVw@mail.gmail.com \
    --to=zwu.kernel@gmail.com \
    --cc=dave@jikos.cz \
    --cc=jbacik@fusionio.com \
    --cc=kreijack@inwind.it \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxram@linux.vnet.ibm.com \
    --cc=wuzhy@linux.vnet.ibm.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).