The init.d autofs script runs a check for "maps within maps"
(actually mountpoints within mountpoints) which it does by looping over
all knownmaps and grepping for a start-of-line match in both directions
(ie: 2 greps).
I was testing some things on a system with 39 maps and was surprised
to find the autofs script took 38 seconds to report on required
reloads. Testing showed that there were ~3000 runs of grep called by
this piece of code.
It is possible to do the same test with internal case statements.
This removes ~3000 calls to grep (I have another system with 49 map, so
it gets nearly 5000...). With this fix applied the autofs script ran in
one quarter of the time.
--- autofs-4.1.4/samples/rc.autofs.in 2006-08-22 14:48:51.000000000 +0100
+++ autofs.enhance 2006-08-22 14:49:51.000000000 +0100
@@ -233,11 +233,21 @@
# another map or another map, maps on top of it.
for knownmap in $knownmaps
do
- if [ "`echo $dir/ | grep ^$knownmap`" != "" \
- -o "`echo $knownmap | grep ^$dir/`" != "" \]
- then
- continue 2
- fi
+# This gets run for all maps on all maps, so is O(n^2)
+# This means 3500 external grep calls for 38 map entries,
+# which is slow. case statements make it much faster.
+#
+# if [ "`echo $dir/ | grep ^$knownmap`" != "" \
+# -o "`echo $knownmap | grep ^$dir/`" != "" \]
+# then
+# continue 2
+# fi
+ case "$dir/" in
+ $knownmap*) continue 2 ;;
+ esac
+ case "$knownmap" in
+ $dir/*) continue 2 ;;
+ esac
done
if [ ! -z "$dir" -a ! -z "$map" \
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs