QAD patch to speed up lilo

Keith Owens (kaos@melbpc.org.au)
Wed, 21 Feb 1996 18:04:02 +0000


Running lilo 0.16 on two machines (one SCSI, one IDE), both 1.3.54 ELF,
there was a big difference between run times. Turns out that the
geometry code for SCSI does a lot more calls to last_dev which does a
complete scan of /dev every time, sloooow!

Quick and dirty patch to last_dev to remember the last
parent/major/increment result and return the same result if the next
call is for the same parameters. Cuts readdir/stat calls down by 90%.

diff -ur lilo/geometry.c lilo-0.16.new/geometry.c
--- lilo/geometry.c Sun Feb 26 12:41:59 1995
+++ lilo-0.16.new/geometry.c Wed Feb 21 17:38:14 1996
@@ -10,6 +10,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <limits.h>
+#include <malloc.h>
#include <sys/stat.h>
#include <sys/ioctl.h>

@@ -158,6 +159,17 @@
ST_BUF st,*walk;
int max,this;
int fd;
+ static char *prev_parent = NULL;
+ static int prev_major = -1, prev_increment = -1, prev_max = -1;
+
+ if (prev_parent && strcmp(parent, prev_parent) == 0 &&
+ major == prev_major && increment == prev_increment)
+ return(prev_max);
+
+ if (prev_parent) {
+ free(prev_parent);
+ prev_parent = NULL;
+ }

st.next = next;
max = 0;
@@ -188,6 +200,13 @@
}
}
(void) closedir(dp);
+ prev_parent = malloc(strlen(parent)+1);
+ if (prev_parent) {
+ strcpy(prev_parent, parent);
+ prev_major = major;
+ prev_increment = increment;
+ prev_max = max;
+ }
return max;
}