The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Michał Nazarewicz" <m.nazarewicz@samsung.com>
To: me@felipebalbi.com
Cc: linux-usb@vger.kernel.org,
	David Brownell <dbrownell@users.sourceforge.net>,
	gregkh@suse.de, linux-kernel@vger.kernel.org,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>
Subject: Re: [PATCH] USB: f_mass_storage: dynamic buffers for better alignment
Date: Mon, 15 Mar 2010 20:20:08 +0100	[thread overview]
Message-ID: <op.u9minutl7p4s8u@pikus> (raw)
In-Reply-To: <20100315181020.GD3857@gandalf>

> On Mon, Mar 15, 2010 at 11:09:55AM +0100, Michal Nazarewicz wrote:
>> "Static" buffers in fsg_buffhd structure (ie. fields which are arrays
>> rather then pointers to dynamically allocated memory) are not aligned
>> to any "big" power of two which may lead to poor DMA performance

On Mon, 15 Mar 2010 19:10:21 +0100, Felipe Balbi <me@felipebalbi.com> wrote:
> not so true as you can add __attribute__ ((aligned(32))) to those.

I admit, I haven't thought about that.  Some fields rearrangement
could help avoid some padding but yes, it can be done.

However, there is one more thing I've had in mind.  Each buffer
is 4 pages (16 KiB) and there are two such buffers in struct
fsg_common therefore the whole size of the structure is
9 pages (> 32 KiB).

I've been simply concerned about using kamlloc() for such big
structures so in the end decided to split it into 3 allocations.

Maybe I'm overeating though?  Or maybe vmalloc() would solve those
problems?  But then again, vmalloc() could degrade DMA performance
on systems w/o scatter-gather.

What do you think?

>>  	bh = common->buffhds;
>> -	i = FSG_NUM_BUFFERS - 1;
>> -	do {
>> +	i = FSG_NUM_BUFFERS;
>> +	for (i = FSG_NUM_BUFFERS;; ++bh) {

> something like
>
> for (i = 0; i < FSG_NUM_BUFFERS; i++, ++bh) {
>
> wouldn't it do it ??

I admit I'm a bit addicted to "downwards to zero" loops and avoiding
checking of the condition prior to the first iteration.  (As such I
often use do-while where others would use for.)

Besides counting to zero is not really an issue here.  I didn't
particularly fancy the "bh[-1]" that have to be used if the break
is not inside the loop, ie:

	bh = common->buffhds;
	rc = -ENOMEM;
	for (i = FSG_NUM_BUFFERS; i--; ++bh) {
		bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
		if (unlikely(!bh->buf))
			goto error_release;
		bh->next = bh + 1;
	}
	bh[-1].next = common->buffhds;

Note also that the last bh->next is assigned twice.

So personally I'd still stick with my version but since
readability is important how about:

	bh = common->buffhds;
	rc = -ENOMEM;
	i = FSG_NUM_BUFFERS;
	for(;;) {
		bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
		if (unlikely(!bh->buf))
			goto error_release;
		if (!--i)
			break;
		bh->next = bh + 1;
		++bh;
	}
	bh->next = common->buffhds;

What do you think?

-- 
Best regards,                                           _     _
  .o. | Liege of Serenely Enlightened Majesty of       o' \,=./ `o
  ..o | Computer Science,  Michał "mina86" Nazarewicz     (o o)
  ooo +---[mina86@mina86.com]---[mina86@jabber.org]---ooO--(_)--Ooo--

  reply	other threads:[~2010-03-15 19:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-15 10:09 [PATCH] USB: f_mass_storage: dynamic buffers for better alignment Michal Nazarewicz
2010-03-15 18:10 ` Felipe Balbi
2010-03-15 19:20   ` Michał Nazarewicz [this message]
2010-03-15 19:28     ` Felipe Balbi
2010-03-15 19:43       ` Michał Nazarewicz
2010-03-15 20:28         ` Michal Nazarewicz
2010-03-15 20:38         ` [PATCHv3] " Michal Nazarewicz

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=op.u9minutl7p4s8u@pikus \
    --to=m.nazarewicz@samsung.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=gregkh@suse.de \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=me@felipebalbi.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