The following patch allows for initializing a gendisk for a
given chunk of memory in a way that cannot fail, instead of having
alloc_gendisk do the kmalloc. This will allow embedding a struct
gendisk in a larger structure, reducing rarely tested error branches.
Other marginal benefits include saving a few CPU cycles with fewer
kmalloc and kfree (not in any critical path though) and perhaps a tad
better cache locality from the gendisk being contiguous with some
related data structures.
Many (all?) users of alloc_gendisk pass a constant maximum
number of partitions and already allocate a struct that the gendisk
and gendisk->part could be embedded in.
Also, since I was editing alloc_disk anyhow, I changed it to
allocate its memory in a single kmalloc. (Same minor benefits: now
the disk partitions are contiguous with the struct gendisk, so perhaps
that may save an occasional cache miss, the allocator is smaller,
etc.).
To me, the important thing is to have an interface for
initializing a struct gendisk in a given chunk of memory that cannot
return failure. As for my implementation choices, I'm happy to
rebuild to suit. Here are couple of notes about those choices.
1. I made this change by making a gendisk.destructor function,
on the theory that some other code might find it useful to
trap gendisk destruction. If that does not sound so useful,
I can change it to use a bit gendisk.flags, so as not to
grow struct gendisk by 4-8 bytes.
2. I made a disk_destructor function to avoid type conversions.
Alternatively, I could just do "disk->destructor = (cast) kfree;",
which should work on all hardware that Linux supports or
probably will, although I don't believe it is absolutely
guaranteed to work by ANSI C. I could also change the argument
that disk->destructor takes to a void* to use kfree without a
cast, which loses a little type checking.
I am running the code now, although I have not really tested
it. This patch is hand editted to remove some unrelated changes, so
patch may report that the line numbers are off slightly.
-- Adam J. Richter __ ______________ 575 Oroville Road adam@yggdrasil.com \ / Milpitas, California 95035 +1 408 309-6081 | g g d r a s i l United States of America "Free Software For The Rest Of Us."
This archive was generated by hypermail 2b29 : Thu Nov 07 2002 - 22:00:42 EST