Optimization in searching for new zones to allocate contributed

by Jens de Smit.
This commit is contained in:
Ben Gras 2008-02-06 15:05:57 +00:00
parent cd89066f9a
commit 2876d5c4ba
3 changed files with 22 additions and 9 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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;