Speeding up FAT operations

Jukka Tapani Santala (e75644@UWasa.Fi)
Tue, 15 Sep 1998 19:57:38 +0300 (EET DST)


I'm using egcs-1.0.3 release and Linux 2.1.120 kernel on Pentium II at the
moment. Every now and then I feel the need to hunt for the most obiviously
inefficient bit of code in Linux kernel, which usually falls within the
domain of FAT filesystem drivers... which, I guess, isn't all Linux's
fault ;) However, my current pet-peewe is the fat_smap() function in
fs/fat/cache.c - caches are supposed to speed up things, but with lines
like...

cluster = sector/sb->cluster_size;
offset = sector % sb->cluster_size;

...my computer seems to be wasting most of it's time doing integer divide
on numbers that my recollection from the FAT days should be replaceable
by simple bit-operations (Okay, this may have something to do with the
fact that the FPU is otherwise pre-occupied). Geeze, even int
i=sb->cluster_size>>1; cluster=sector; while(i>>1) cluster=cluster>>1;
offset=sector&(sb->cluster_size-1); yields better result. I'm probably
missing a technique to do away with that loop entirely, but taking the
shift-value ahead of time into a static variable in appropriate place is
the real trick...

The reason I'm not presenting a patch to do this at this time is because
kernel stuff isn't really my usual playground, and so I'm wondering if
there actually is a reason this is done the "hard way" currently or all
places the change would reflect to. Also, by posting this instead I hope
other people take cases like this into account (Multiplication and
especially division is very expensive operation even when done in
integer, which is exactly why most measures dealt with in lowe-level code
are powers of 2) and won't change the behaviour back to earlier in the
next patch ;) I can only guess at how many similiar places there are in the
code.

-Donwulff

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