public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <dave@linux.vnet.ibm.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: Re: [patch 2/4 -mm] flex_array: add flex_array_clear function
Date: Mon, 24 Aug 2009 13:38:40 -0700	[thread overview]
Message-ID: <1251146320.22398.8051.camel@nimitz> (raw)
In-Reply-To: <alpine.DEB.2.00.0908241323360.5574@chino.kir.corp.google.com>

On Mon, 2009-08-24 at 13:29 -0700, David Rientjes wrote:
> On Mon, 24 Aug 2009, Dave Hansen wrote:
> 
> > My only worry about this is that it's largely a copy-and-paste of
> > flex_array_put().  If we had a function that just returned a pointer to
> > 'dst', we could use that in both cases.  
> > 
> > Couldn't we implement the above with just:
> > 
> > int flex_array_clear(struct flex_array *fa, unsigned int element_nr)
> > {
> > 	return flex_array_put(fa, element_nr, &empty_zero_page);
> > }
> > 
> 
> Sure, if you never increase FLEX_ARRAY_PART_SIZE.  Otherwise, doing
> 
> static char zero_part[FLEX_ARRAY_PART_SIZE] = {
> 	[0 ... FLEX_ARRAY_PART_SIZE - 1] = 0
> };
> 
> and using flex_array_put(fa, element_nr, &zero_part) would work although 
> you're trading off cleaner, yet not more efficient, code at the cost of 
> FLEX_ARRAY_PART_SIZE wasted memory and memcpy() being slower than 
> memset().

Yeah, that's true.  How about using the get() function?

int flex_array_clear(struct flex_array *fa, unsigned int element_nr)
{
	void *element = flex_array_get(fa, element_nr);
	memset(element, FLEX_ARRAY_FREE, fa->element_size);
}

It'll keep us from having to keep around a zero'd element. 

But, I guess we could also do:

	struct flex_array_part *zero_part = empty_zero_page;

And use a BUILD_BUG_ON(FLEX_ARRAY_PART_SIZE > PAGE_SIZE).  But the whole
point of this was to have elements that are smaller than PAGE_SIZE.
Having that as a constraint doesn't seem too bad. :)

-- Dave


  reply	other threads:[~2009-08-24 20:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-21 23:21 [patch 1/4 -mm] flex_array: convert element_nr formals to unsigned David Rientjes
2009-08-21 23:21 ` [patch 2/4 -mm] flex_array: add flex_array_clear function David Rientjes
2009-08-24 15:41   ` Dave Hansen
2009-08-24 20:29     ` David Rientjes
2009-08-24 20:38       ` Dave Hansen [this message]
2009-08-24 20:50         ` David Rientjes
2009-08-24 21:28           ` Dave Hansen
2009-08-24 22:32             ` David Rientjes
2009-08-21 23:21 ` [patch 3/4 -mm] flex_array: poison free elements David Rientjes
2009-08-24 15:56   ` Dave Hansen
2009-08-24 20:41     ` David Rientjes
2009-08-24 21:16       ` Dave Hansen
2009-08-24 22:40         ` David Rientjes
2009-08-24 21:42       ` Dave Hansen
2009-08-24 22:44         ` David Rientjes
2009-09-08 22:26           ` David Rientjes
2009-09-09  2:05             ` Li Zefan
2009-09-09  3:18               ` David Rientjes
2009-09-09  3:31                 ` Li Zefan
2009-09-09  3:41                   ` David Rientjes
2009-09-09  3:45                     ` Li Zefan
2009-09-09  4:15                       ` David Rientjes
2009-09-09 15:28             ` Dave Hansen
2009-09-09 19:18               ` David Rientjes
2009-09-09 19:22                 ` Dave Hansen
2009-09-09 19:34                   ` David Rientjes
2009-08-21 23:21 ` [patch 4/4 -mm] flex_array: add flex_array_shrink function David Rientjes
2009-08-21 23:49   ` Andrew Morton
2009-08-22  0:02     ` Randy Dunlap
2009-08-22 21:28     ` David Rientjes

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=1251146320.22398.8051.camel@nimitz \
    --to=dave@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rientjes@google.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