From: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
To: Dave Hansen <dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Cc: vda.linux-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org,
menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [RFC][PATCH] flexible array implementation v3
Date: Thu, 23 Jul 2009 11:44:28 -0400 [thread overview]
Message-ID: <4A68855C.1060702@cs.columbia.edu> (raw)
In-Reply-To: <20090722175345.7154C2F2@kernel>
Dave Hansen wrote:
>
> Changes from v2:
> - renamed some of the index functions
> - added preallocation function
> - added flex_array_free_parts() for use with
> statically allocated bases
> - killed append() function
>
> Changes from v1:
> - to vs too typo
> - added __check_part_and_nr() and gave it a warning
> - fixed off-by-one check on __nr_part_ptrs()
> - added FLEX_ARRAY_INIT() macro
> - some kerneldoc comments about the capacity
> with various sized objects
> - comments to note lack of locking semantice
>
> --
>
> Once a structure goes over PAGE_SIZE*2, we see occasional
> allocation failures. Some people have chosen to switch
> over to things like vmalloc() that will let them keep
> array-like access to such a large structures. But,
> vmalloc() has plenty of downsides.
>
> Here's an alternative. I think it's what Andrew was
> suggesting here:
>
> http://lkml.org/lkml/2009/7/2/518
>
> I call it a flexible array. It does all of its work in
> PAGE_SIZE bits, so never does an order>0 allocation.
> The base level has PAGE_SIZE-2*sizeof(int) bytes of
> storage for pointers to the second level. So, with a
> 32-bit arch, you get about 4MB (4183112 bytes) of total
> storage when the objects pack nicely into a page. It
> is half that on 64-bit because the pointers are twice
> the size. There's a table detailing this in the code.
>
> There are kerneldocs for the functions, but here's an
> overview:
>
> flex_array_alloc() - dynamically allocate a base structure
> flex_array_free() - free the array and all of the
> second-level pages
> flex_array_free_parts() - free the second-level pages, but
> not the base (for static bases)
> flex_array_put() - copy into the array at the given index
> flex_array_get() - copy out of the array at the given index
> flex_array_prealloc() - preallocate the second-level pages
> between the given indexes to
> guarantee no allocs will occur at
> put() time.
Probably premature, but -- I wonder if it's worth adding interfaces to:
* copy a range of elements at once (perhaps to/from regular array ?
or userspace ? -- depending on potential users)
* (macro ?) iterate through elements (better have it ready for users
of flex_array before, than convert their code later on)
Oren.
WARNING: multiple messages have this Message-ID (diff)
From: Oren Laadan <orenl@cs.columbia.edu>
To: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: akpm@linux-foundation.org, vda.linux@googlemail.com,
containers@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, menage@google.com
Subject: Re: [RFC][PATCH] flexible array implementation v3
Date: Thu, 23 Jul 2009 11:44:28 -0400 [thread overview]
Message-ID: <4A68855C.1060702@cs.columbia.edu> (raw)
In-Reply-To: <20090722175345.7154C2F2@kernel>
Dave Hansen wrote:
>
> Changes from v2:
> - renamed some of the index functions
> - added preallocation function
> - added flex_array_free_parts() for use with
> statically allocated bases
> - killed append() function
>
> Changes from v1:
> - to vs too typo
> - added __check_part_and_nr() and gave it a warning
> - fixed off-by-one check on __nr_part_ptrs()
> - added FLEX_ARRAY_INIT() macro
> - some kerneldoc comments about the capacity
> with various sized objects
> - comments to note lack of locking semantice
>
> --
>
> Once a structure goes over PAGE_SIZE*2, we see occasional
> allocation failures. Some people have chosen to switch
> over to things like vmalloc() that will let them keep
> array-like access to such a large structures. But,
> vmalloc() has plenty of downsides.
>
> Here's an alternative. I think it's what Andrew was
> suggesting here:
>
> http://lkml.org/lkml/2009/7/2/518
>
> I call it a flexible array. It does all of its work in
> PAGE_SIZE bits, so never does an order>0 allocation.
> The base level has PAGE_SIZE-2*sizeof(int) bytes of
> storage for pointers to the second level. So, with a
> 32-bit arch, you get about 4MB (4183112 bytes) of total
> storage when the objects pack nicely into a page. It
> is half that on 64-bit because the pointers are twice
> the size. There's a table detailing this in the code.
>
> There are kerneldocs for the functions, but here's an
> overview:
>
> flex_array_alloc() - dynamically allocate a base structure
> flex_array_free() - free the array and all of the
> second-level pages
> flex_array_free_parts() - free the second-level pages, but
> not the base (for static bases)
> flex_array_put() - copy into the array at the given index
> flex_array_get() - copy out of the array at the given index
> flex_array_prealloc() - preallocate the second-level pages
> between the given indexes to
> guarantee no allocs will occur at
> put() time.
Probably premature, but -- I wonder if it's worth adding interfaces to:
* copy a range of elements at once (perhaps to/from regular array ?
or userspace ? -- depending on potential users)
* (macro ?) iterate through elements (better have it ready for users
of flex_array before, than convert their code later on)
Oren.
next prev parent reply other threads:[~2009-07-23 15:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 17:53 [RFC][PATCH] flexible array implementation v3 Dave Hansen
2009-07-23 1:44 ` KAMEZAWA Hiroyuki
[not found] ` <20090723104450.e0d421ca.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-07-23 14:05 ` Dave Hansen
2009-07-23 14:05 ` Dave Hansen
2009-07-23 14:48 ` KAMEZAWA Hiroyuki
2009-07-23 14:48 ` KAMEZAWA Hiroyuki
2009-07-23 1:44 ` KAMEZAWA Hiroyuki
2009-07-23 15:44 ` Oren Laadan [this message]
2009-07-23 15:44 ` Oren Laadan
[not found] ` <4A68855C.1060702-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-07-23 16:02 ` Dave Hansen
2009-07-23 16:02 ` Dave Hansen
-- strict thread matches above, loose matches on Subject: below --
2009-07-22 17:53 Dave Hansen
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=4A68855C.1060702@cs.columbia.edu \
--to=orenl-eqauephvms7envbuuze7ea@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=vda.linux-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.