diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-16 13:06:39 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-16 13:06:39 -0500 |
commit | 9cfc86249f32d984339c6d1f8a1fd1326989b3b8 (patch) | |
tree | 56428d319483f54949de8d9d0a5b3f715287ed91 /lib/genalloc.c | |
parent | f42647acc4eab1befa9e290691ed7a40f9a7d3cc (diff) | |
parent | 243797f59b748f679ab88d456fcc4f92236d724b (diff) |
Merge branch 'akpm'
* akpm: (173 commits)
genalloc: use bitmap_find_next_zero_area
ia64: use bitmap_find_next_zero_area
sparc: use bitmap_find_next_zero_area
mlx4: use bitmap_find_next_zero_area
isp1362-hcd: use bitmap_find_next_zero_area
iommu-helper: use bitmap library
bitmap: introduce bitmap_set, bitmap_clear, bitmap_find_next_zero_area
qnx4: use hweight8
qnx4fs: remove remains of the (defunct) write support
resource: constify arg to resource_size() and resource_type()
gru: send cross partition interrupts using the gru
gru: function to generate chipset IPI values
gru: update driver version number
gru: improve GRU TLB dropin statistics
gru: fix GRU interrupt race at deallocate
gru: add hugepage support
gru: fix bug in allocation of kernel contexts
gru: update GRU structures to match latest hardware spec
gru: check for correct GRU chiplet assignment
gru: remove stray local_irq_enable
...
Diffstat (limited to 'lib/genalloc.c')
-rw-r--r-- | lib/genalloc.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/lib/genalloc.c b/lib/genalloc.c index eed2bdb865e7..e67f97495dd5 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/bitmap.h> | ||
14 | #include <linux/genalloc.h> | 15 | #include <linux/genalloc.h> |
15 | 16 | ||
16 | 17 | ||
@@ -114,7 +115,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) | |||
114 | struct gen_pool_chunk *chunk; | 115 | struct gen_pool_chunk *chunk; |
115 | unsigned long addr, flags; | 116 | unsigned long addr, flags; |
116 | int order = pool->min_alloc_order; | 117 | int order = pool->min_alloc_order; |
117 | int nbits, bit, start_bit, end_bit; | 118 | int nbits, start_bit, end_bit; |
118 | 119 | ||
119 | if (size == 0) | 120 | if (size == 0) |
120 | return 0; | 121 | return 0; |
@@ -129,29 +130,19 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) | |||
129 | end_bit -= nbits + 1; | 130 | end_bit -= nbits + 1; |
130 | 131 | ||
131 | spin_lock_irqsave(&chunk->lock, flags); | 132 | spin_lock_irqsave(&chunk->lock, flags); |
132 | bit = -1; | 133 | start_bit = bitmap_find_next_zero_area(chunk->bits, end_bit, 0, |
133 | while (bit + 1 < end_bit) { | 134 | nbits, 0); |
134 | bit = find_next_zero_bit(chunk->bits, end_bit, bit + 1); | 135 | if (start_bit >= end_bit) { |
135 | if (bit >= end_bit) | ||
136 | break; | ||
137 | |||
138 | start_bit = bit; | ||
139 | if (nbits > 1) { | ||
140 | bit = find_next_bit(chunk->bits, bit + nbits, | ||
141 | bit + 1); | ||
142 | if (bit - start_bit < nbits) | ||
143 | continue; | ||
144 | } | ||
145 | |||
146 | addr = chunk->start_addr + | ||
147 | ((unsigned long)start_bit << order); | ||
148 | while (nbits--) | ||
149 | __set_bit(start_bit++, chunk->bits); | ||
150 | spin_unlock_irqrestore(&chunk->lock, flags); | 136 | spin_unlock_irqrestore(&chunk->lock, flags); |
151 | read_unlock(&pool->lock); | 137 | continue; |
152 | return addr; | ||
153 | } | 138 | } |
139 | |||
140 | addr = chunk->start_addr + ((unsigned long)start_bit << order); | ||
141 | |||
142 | bitmap_set(chunk->bits, start_bit, nbits); | ||
154 | spin_unlock_irqrestore(&chunk->lock, flags); | 143 | spin_unlock_irqrestore(&chunk->lock, flags); |
144 | read_unlock(&pool->lock); | ||
145 | return addr; | ||
155 | } | 146 | } |
156 | read_unlock(&pool->lock); | 147 | read_unlock(&pool->lock); |
157 | return 0; | 148 | return 0; |