From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Travis Subject: Re: [patch 02/41] cpu alloc: The allocator Date: Wed, 04 Jun 2008 07:48:34 -0700 Message-ID: <4846AB42.5070402@sgi.com> References: <20080530035620.587204923@sgi.com> <20080530040011.084909898@sgi.com> <20080529215833.469c3cbe.akpm@linux-foundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from relay2.sgi.com ([192.48.171.30]:41676 "EHLO relay.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753342AbYFDOsh (ORCPT ); Wed, 4 Jun 2008 10:48:37 -0400 In-Reply-To: <20080529215833.469c3cbe.akpm@linux-foundation.org> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Andrew Morton Cc: Christoph Lameter , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, David Miller , Eric Dumazet , Peter Zijlstra , Rusty Russell Andrew Morton wrote: ... >> +/* >> + * Mark an object as used in the cpu_alloc_map >> + * >> + * Must hold cpu_alloc_map_lock >> + */ >> +static void set_map(int start, int length) >> +{ >> + while (length-- > 0) >> + __set_bit(start++, cpu_alloc_map); >> +} > > bitmap_fill()? > >> +/* >> + * Mark an area as freed. >> + * >> + * Must hold cpu_alloc_map_lock >> + */ >> +static void clear_map(int start, int length) >> +{ >> + while (length-- > 0) >> + __clear_bit(start++, cpu_alloc_map); >> +} > > bitmap_zero()? ... >> +void *cpu_alloc(unsigned long size, gfp_t gfpflags, unsigned long align) >> +{ >> + unsigned long start; >> + int units = size_to_units(size); >> + void *ptr; >> + int first; >> + unsigned long flags; >> + >> + if (!size) >> + return ZERO_SIZE_PTR; > > OK, so we reuse ZERO_SIZE_PTR from kmalloc. > >> + spin_lock_irqsave(&cpu_alloc_map_lock, flags); >> + >> + first = 1; >> + start = first_free; >> + >> + for ( ; ; ) { >> + >> + start = find_next_zero_bit(cpu_alloc_map, UNITS, start); >> + if (start >= UNITS) >> + goto out_of_memory; >> + >> + if (first) >> + first_free = start; >> + >> + /* >> + * Check alignment and that there is enough space after >> + * the starting unit. >> + */ >> + if (start % (align / UNIT_SIZE) == 0 && >> + find_next_bit(cpu_alloc_map, UNITS, start + 1) >> + >= start + units) >> + break; >> + start++; >> + first = 0; >> + } > > This is kinda bitmap_find_free_region(), only bitmap_find_free_region() > isn't quite strong enough. > > Generally I think it would have been better if you had added new > primitives to the bitmap library (or enhanced existing ones) and used > them here, rather than implementing private functionality. Hi Andrew, I've sort of inherited this now... So are you suggesting that we add new bitmap primitives to: bitmap_fill_offset(bitmap, start, nbits) /* start at bitmap[start] */ bitmap_zero_offset(bitmap, start, nbits) bitmap_find_free_area(bitmap, nbits, size, align) /* size not order */ Thanks, Mike