[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.00.0908241343080.5574@chino.kir.corp.google.com>
Date: Mon, 24 Aug 2009 13:50:27 -0700 (PDT)
From: David Rientjes <rientjes@...gle.com>
To: Dave Hansen <dave@...ux.vnet.ibm.com>
cc: Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Subject: Re: [patch 2/4 -mm] flex_array: add flex_array_clear function
On Mon, 24 Aug 2009, Dave Hansen wrote:
> > 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);
> }
>
The idea was to eventually be able to distinguish between
use-uninitialized and use-after-free and flex_array_clear() was a
convenient way of providing an interface to identify the later. So when
an array is fully initialized (or fully cleared after a previous use where
all elements we're used), you couldn't do flex_array_clear() on an element
before flex_array_put() if its part isn't allocated yet with this
implementation.
> 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. :)
>
Hmm, I think being able to increase FLEX_ARRAY_PART_SIZE is eventually
going to become an integral part of the entire library so that it supports
larger number of entries (and order-1 allocations aren't as difficult with
anti-fragmentation), especially for those with larger element sizes.
Otherwise, there's no need for FLEX_ARRAY_PART_SIZE in the first place.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists