From: Kent Overstreet <kmo@daterainc.com>
To: Tejun Heo <tj@kernel.org>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Stephen Rothwell <sfr@canb.auug.org.au>,
Fengguang Wu <fengguang.wu@intel.com>
Subject: Re: [PATCH] idr: Document ida tree sections
Date: Tue, 13 Aug 2013 15:33:11 -0700 [thread overview]
Message-ID: <20130813223311.GB12069@kmo-pixel> (raw)
In-Reply-To: <20130809145756.GL20515@mtj.dyndns.org>
On Fri, Aug 09, 2013 at 10:57:56AM -0400, Tejun Heo wrote:
> Hello,
>
> On Wed, Aug 07, 2013 at 01:51:17PM -0700, Kent Overstreet wrote:
> > + * So if the max section size is 64k, that's ~4096 sections, with 8 byte
> > + * pointers that's a little over 32k for the pointers to sections.
> > + *
> > + * That means max size sections are order 4 page allocations.
>
> Order 4 allocations for common data structure doesn't really sound
> like a good idea to me. It's gonna work fine on relatively large
> machines but suck on mobile / small embedded devices, many of which
> are still struggling with 32bit address space and compaction may not
> be enabled. It just doens't make sense to me to impose 64k
> allocations from low level library function like ida.
Would this be an acceptable solution?
>From 483cfa0c809b7dc3b0abad93407468f273416578 Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kmo@daterainc.com>
Date: Tue, 13 Aug 2013 15:31:20 -0700
Subject: [PATCH] ida: Use order 2 allocations when COMPACTION=n
And fall back to vmalloc for the array of pointers to sections so we can
still allocate up to INT_MAX ids.
diff --git a/lib/idr.c b/lib/idr.c
index 02a221c..3bffb52 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -21,16 +21,20 @@
#include <linux/export.h>
#include <linux/idr.h>
#include <linux/kernel.h>
+#include <linux/mm.h>
#include <linux/percpu.h>
#include <linux/rcupdate.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/spinlock.h>
+#include <linux/vmalloc.h>
static void kgfree(void *ptr, size_t size)
{
- if (size < PAGE_SIZE)
+ if (is_vmalloc_addr(ptr))
+ vfree(ptr);
+ else if (size < PAGE_SIZE)
kfree(ptr);
else
free_pages((unsigned long) ptr, get_order(size));
@@ -102,7 +106,14 @@ static void *kgalloc(size_t size, gfp_t gfp)
*/
#define IDA_TREE_ARY BITS_PER_LONG
-#define IDA_SECTION_SIZE (64UL << 10)
+
+/* Max section size, in bytes */
+#ifdef CONFIG_COMPACTION
+#define IDA_SECTION_SIZE (64UL << 10) /* order 4 page allocation */
+#else
+#define IDA_SECTION_SIZE (16UL << 10) /* order 2 */
+#endif
+
#define IDA_NODES_PER_SECTION (IDA_SECTION_SIZE / sizeof(unsigned long))
static inline unsigned long *ida_index_to_node(struct ida *ida, unsigned node)
@@ -251,8 +262,15 @@ again:
if (ida->nodes >= IDA_NODES_PER_SECTION &&
is_power_of_2(cur_sections)) {
- sections = kgalloc(cur_sections * 2 * sizeof(unsigned long *),
- __GFP_ZERO|gfp);
+ size_t bytes = cur_sections * 2 * sizeof(unsigned long *);
+
+ if (bytes <= IDA_SECTION_SIZE)
+ sections = kgalloc(bytes, __GFP_ZERO|gfp);
+ else if (gfp & GFP_KERNEL)
+ sections = vzalloc(bytes);
+ else
+ sections = NULL;
+
if (!sections)
goto err;
}
next prev parent reply other threads:[~2013-08-13 22:33 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-07 17:34 IDA/IDR rewrite, percpu ida Kent Overstreet
2013-08-07 17:34 ` [PATCH 03/10] idr: Rewrite ida Kent Overstreet
2013-08-07 20:22 ` Tejun Heo
2013-08-07 20:51 ` [PATCH] idr: Document ida tree sections Kent Overstreet
2013-08-09 14:57 ` Tejun Heo
2013-08-13 22:13 ` Kent Overstreet
2013-08-13 22:19 ` Tejun Heo
2013-08-13 22:27 ` Kent Overstreet
2013-08-13 22:44 ` Tejun Heo
2013-08-13 22:59 ` Kent Overstreet
2013-08-13 23:22 ` Tejun Heo
2013-08-13 23:51 ` Kent Overstreet
2013-08-13 23:59 ` Tejun Heo
2013-08-15 0:04 ` Kent Overstreet
2013-08-15 0:22 ` Tejun Heo
2013-08-13 22:33 ` Kent Overstreet [this message]
2013-08-07 17:34 ` [PATCH 04/10] idr: Percpu ida Kent Overstreet
2013-08-07 17:56 ` Christoph Lameter
2013-08-07 18:33 ` Kent Overstreet
2013-08-07 19:40 ` Christoph Lameter
2013-08-07 19:57 ` [PATCH] idr: Use this_cpu_ptr() for percpu_ida Kent Overstreet
2013-08-08 14:32 ` Christoph Lameter
2013-08-20 21:19 ` Nicholas A. Bellinger
2013-08-20 21:29 ` Andrew Morton
2013-08-21 2:01 ` Kent Overstreet
2013-08-21 2:07 ` Tejun Heo
2013-08-21 2:31 ` Kent Overstreet
2013-08-21 11:59 ` Tejun Heo
2013-08-21 21:09 ` Kent Overstreet
2013-08-21 21:16 ` Tejun Heo
2013-08-21 21:24 ` Kent Overstreet
2013-08-21 21:31 ` Tejun Heo
2013-08-21 14:32 ` Christoph Lameter
2013-08-21 17:49 ` Nicholas A. Bellinger
2013-08-21 20:49 ` Andrew Morton
2013-08-22 16:44 ` Christoph Lameter
2013-08-22 16:56 ` Jens Axboe
2013-08-07 17:46 ` [PATCH 05/10] idr: Kill old deprecated idr interfaces Kent Overstreet
2013-08-07 17:46 ` [PATCH 06/10] idr: Rename idr_get_next() -> idr_find_next() Kent Overstreet
2013-08-07 17:46 ` [PATCH 08/10] idr: Reimplement idr on top of ida/radix trees Kent Overstreet
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=20130813223311.GB12069@kmo-pixel \
--to=kmo@daterainc.com \
--cc=akpm@linux-foundation.org \
--cc=fengguang.wu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sfr@canb.auug.org.au \
--cc=tj@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox