From: Ben Gras Date: Wed, 6 Feb 2008 15:05:57 +0000 (+0000) Subject: Optimization in searching for new zones to allocate contributed X-Git-Tag: v3.1.4~300 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doxygen.png?a=commitdiff_plain;h=2876d5c4bab705a198d1bb08123b6d513cc27714;p=minix.git Optimization in searching for new zones to allocate contributed by Jens de Smit. --- diff --git a/servers/mfs/inode.c b/servers/mfs/inode.c index 1601bf2f2..690c83f2a 100644 --- a/servers/mfs/inode.c +++ b/servers/mfs/inode.c @@ -14,6 +14,9 @@ * old_icopy: copy to/from in-core inode struct and disk inode (V1.x) * new_icopy: copy to/from in-core inode struct and disk inode (V2.x) * dup_inode: indicate that someone else is using an inode table entry + * + * Updates: + * 2007-06-01: jfdsmit@gmail.com added i_zsearch initialization */ #include "fs.h" @@ -204,6 +207,7 @@ int numb; /* inode number (ANSI: may not be unshort) */ rip->i_count = 1; if (dev != NO_DEV) rw_inode(rip, READING); /* get inode from disk */ rip->i_update = 0; /* all the times are initially up-to-date */ + rip->i_zsearch = NO_ZONE; /* no zones searched for yet */ if ((rip->i_mode & I_TYPE) == I_NAMED_PIPE) rip->i_pipe = I_PIPE; else diff --git a/servers/mfs/inode.h b/servers/mfs/inode.h index 10e78271a..4fb80fc6d 100644 --- a/servers/mfs/inode.h +++ b/servers/mfs/inode.h @@ -6,6 +6,9 @@ * disk; the second part holds fields not present on the disk. * The disk inode part is also declared in "type.h" as 'd1_inode' for V1 * file systems and 'd2_inode' for V2 file systems. + * + * Updates: + * 2007-01-06: jfdsmit@gmail.com added i_zsearch */ #include "queue.h" @@ -30,6 +33,7 @@ EXTERN struct inode { struct super_block *i_sp; /* pointer to super block for inode's device */ char i_dirt; /* CLEAN or DIRTY */ char i_pipe; /* set to I_PIPE if pipe */ + bit_t i_zsearch; /* where to start search for new zones */ char i_mountpoint; /* true if mounted on */ diff --git a/servers/mfs/write.c b/servers/mfs/write.c index c51cb0c79..638dc2c9c 100644 --- a/servers/mfs/write.c +++ b/servers/mfs/write.c @@ -6,6 +6,9 @@ * do_write: call read_write to perform the WRITE system call * clear_zone: erase a zone in the middle of a file * new_block: acquire a new block + * + * Updates: + * 2007-06-01: jfdsmit@gmail.com added i_zsearch optimalization */ #include "fs.h" @@ -287,18 +290,20 @@ off_t position; /* file pointer */ /* Is another block available in the current zone? */ if ( (b = read_map(rip, position)) == NO_BLOCK) { - /* Choose first zone if possible. */ - /* Lose if the file is nonempty but the first zone number is NO_ZONE - * corresponding to a zone full of zeros. It would be better to - * search near the last real zone. - */ - if (rip->i_zone[0] == NO_ZONE) { - sp = rip->i_sp; - z = sp->s_firstdatazone; + if (rip->i_zsearch == NO_ZONE) { + /* First search for this file. Start looking from + * the file's first data zone to prevent fragmentation + */ + if ( (z = rip->i_zone[0]) == NO_ZONE) { + /* no first zone for file either */ + z = rip->i_sp->s_firstdatazone; /* let alloc_zone decide */ + } } else { - z = rip->i_zone[0]; /* hunt near first zone */ + /* searched before, start from last find */ + z = rip->i_zsearch; } if ( (z = alloc_zone(rip->i_dev, z)) == NO_ZONE) return(NIL_BUF); + rip->i_zsearch = z; /* store for next lookup */ if ( (r = write_map(rip, position, z, 0)) != OK) { free_zone(rip->i_dev, z); err_code = r;