Re: [PATCH] ida: fix up bitmap size calculation

From: Tejun Heo
Date: Thu Sep 02 2010 - 13:20:09 EST


Hello,

On 09/02/2010 07:00 PM, Namhyung Kim wrote:
> ida chunk should consist of 128 bytes (= 1024 bits) by definition
> but because of wrong calculation of IDA_BITMAP_LONGS it only contained
> 992 on 32-bit machines, 960 on 64-bit machines. Fix it.
>
> Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxx>
> ---
> include/linux/idr.h | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/idr.h b/include/linux/idr.h
> index e968db7..13c7296 100644
> --- a/include/linux/idr.h
> +++ b/include/linux/idr.h
> @@ -119,8 +119,8 @@ void idr_init(struct idr *idp);
> * pointer isn't necessary.
> */
> #define IDA_CHUNK_SIZE 128 /* 128 bytes per chunk */
> -#define IDA_BITMAP_LONGS (128 / sizeof(long) - 1)
> -#define IDA_BITMAP_BITS (IDA_BITMAP_LONGS * sizeof(long) * 8)
> +#define IDA_BITMAP_LONGS (IDA_CHUNK_SIZE / sizeof(long))
> +#define IDA_BITMAP_BITS (IDA_CHUNK_SIZE * 8)

The -1 when calculating IDA_BITMAP_LONGS is intentional. Please see
below.

struct ida_bitmap {
long nr_busy;
unsigned long bitmap[IDA_BITMAP_LONGS];
};

With the -1, sizeof(struct ida_bitmap) becomes 128 bytes but if you
remove the -1, it becomes 132 bytes. Because ida_bitmap doesn't use
dedicated slab (doesn't make sense as it's not a very hot data
structure), with 132 bytes, it's gonna be allocated from 256 byte slot
wasting ~50% of memory. Adding a comment there to clarify why -1 is
there would be nice tho.

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/