linux-8086.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Juan Perez-Sanchez <lithoxs@gmail.com>
To: linux-8086 <linux-8086@vger.kernel.org>
Subject: [PATCH] Improvements to block device code
Date: Fri, 16 Nov 2012 23:33:34 -0600	[thread overview]
Message-ID: <CAD6VGuby=tno62bSGQzCHkC2s_7M__x+mZG2aEknJ6WmpQmkbg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

Hi,

   Patch 5 of 5

Juan

PREVIOUS OPERATION

1. In file fs/buffer.c, function getblk() never returns NULL. However,
 several functions checks for this result, wasting time and space.

2. In arch/i86/drivers/block/ll_rw_blk.c, function make_request()
makes redundant checks of flags uptodate and dirty. These flags are
checked even before calling ll_rw_blk().

NEW OPERATION

1. The mentioned redundant checks were removed.

2. In file fs/block_dev.c, function blk_rw() was modified to make it
faster and smaller.

OTHER CHANGES

   Code size reduced by 96 bytes.

 The Image builded without errors. The kernel was tested with QEMU and
dioscuri emulators. Also in a PPro pc booting from floppy.

[-- Attachment #2: elksS.patch --]
[-- Type: application/octet-stream, Size: 6641 bytes --]

diff -Nurb elks.orig/arch/i86/drivers/block/ll_rw_blk.c elks/arch/i86/drivers/block/ll_rw_blk.c
--- elks.orig/arch/i86/drivers/block/ll_rw_blk.c	2012-08-18 13:28:59.000000000 -0500
+++ elks/arch/i86/drivers/block/ll_rw_blk.c	2012-10-24 13:57:39.000000000 -0500
@@ -295,10 +295,6 @@
 #endif
 
     case READ:
-	if (buffer_uptodate(bh)) {
-	    unlock_buffer(bh);	/* Hmmph! Already have it */
-	    return;
-	}
 	max_req = NR_REQUEST;	/* reads take precedence */
 	break;
 
@@ -309,10 +305,6 @@
 #endif
 
     case WRITE:
-	if (buffer_clean(bh)) {
-	    unlock_buffer(bh);	/* Hmmph! Nothing to write */
-	    return;
-	}
 	/* We don't allow the write-requests to fill up the
 	 * queue completely:  we want some room for reads,
 	 * as they take precedence. The last third of the
@@ -452,19 +444,10 @@
     if (!dev || !dev->request_fn) {
 	printk("ll_rw_blk: Trying to read nonexistent block-device %s (%lu)\n",
 	       kdevname(bh->b_dev), bh->b_blocknr);
-	goto sorry;
-    }
-
-    /* If there are no pending requests for this device, then we insert
-     * a dummy request for that device.  This will prevent the request
-     * from starting until we have shoved all of the blocks into the
-     * queue, and then we let it rip.  */
-    make_request(major, rw, bh);
-    return;
-
-  sorry:
     bh->b_dirty = 0;
     bh->b_uptodate = 0;
+    } else
+	make_request(major, rw, bh);
     return;
 }
 
diff -Nurb elks.orig/fs/block_dev.c elks/fs/block_dev.c
--- elks.orig/fs/block_dev.c	2012-10-17 12:08:45.000000000 -0500
+++ elks/fs/block_dev.c	2012-11-04 13:05:43.000000000 -0600
@@ -23,24 +23,23 @@
 		  char *buf, size_t count, int wr)
 {
     register struct buffer_head *bh;
-    char *p;
     block_t block;
     kdev_t dev;
-    off_t offset;
+    unsigned int offset;
     size_t chars;
     int written;
 
     written = 0;
     dev = inode->i_rdev;
 
+    while (count > 0) {
+
     /*
      *      Offset to block/offset
      */
-
     block = (block_t) (filp->f_pos >> 10);
-    offset = filp->f_pos & (BLOCK_SIZE - 1);
+	offset = ((unsigned int)filp->f_pos) & (BLOCK_SIZE - 1);
 
-    while (count > 0) {
 	/*
 	 *      Bytes to do
 	 */
@@ -51,50 +50,21 @@
 	 *      Read the block in - use getblk on a write
 	 *      of a whole block to avoid a read of the data.
 	 */
-	bh = (wr == BLOCK_WRITE && chars == BLOCK_SIZE)
-	    ? getblk(dev, block)
-	    : bread(dev, block);
-
-	block++;
+	if(wr == BLOCK_WRITE && chars == BLOCK_SIZE) {
+	    bh = getblk(dev, block);
+	    map_buffer(bh);
+	} else {
+	    bh = bread(dev, block);
 	if (!bh)
 	    return written ? written : -EIO;
+	}
 
-#if 0
-	p = offset + bh->b_data;
-	offset = 0;
-#endif
-
-	filp->f_pos += chars;
-	written += chars;
-	count -= chars;
-	/*
-	 *      What are we doing ?
-	 */
-	map_buffer(bh);
-	p = offset + bh->b_data;
 	if (wr == BLOCK_WRITE) {
 	    /*
 	     *      Alter buffer, mark dirty
 	     */
-	    memcpy_fromfs(p, buf, chars);
+	    memcpy_fromfs(bh->b_data + offset, buf, chars);
 	    bh->b_uptodate = bh->b_dirty = 1;
-	} else {
-	    /*
-	     *      Empty buffer data. Buffer unchanged
-	     */
-	    memcpy_tofs(buf, p, chars);
-	}
-	/*
-	 *      Move on and release buffer
-	 */
-
-#if 0
-	p += chars;
-#endif
-
-	buf += chars;
-	offset = 0;
-	if (wr == BLOCK_WRITE) {
 	    /*
 	     *      Writing: queue physical I/O
 	     */
@@ -104,8 +74,22 @@
 		unmap_brelse(bh);
 		return -EIO;
 	    }
+	} else {
+	    /*
+	     *      Empty buffer data. Buffer unchanged
+	     */
+	    memcpy_tofs(buf, bh->b_data + offset, chars);
 	}
+	/*
+	 *      Move on and release buffer
+	 */
+
 	unmap_brelse(bh);
+
+	buf += chars;
+	filp->f_pos += chars;
+	written += chars;
+	count -= chars;
     }
     return ((wr == BLOCK_WRITE) && !written) ? -ENOSPC : written;
 }
diff -Nurb elks.orig/fs/buffer.c elks/fs/buffer.c
--- elks.orig/fs/buffer.c	2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/buffer.c	2012-10-24 16:32:42.000000000 -0500
@@ -327,17 +327,7 @@
 
 struct buffer_head *bread(kdev_t dev, block_t block)
 {
-#ifdef BLOAT_FS			/* getblk never returns null */
-    register struct buffer_head *bh;
-
-    if (!(bh = getblk(dev, block))) {
-	printk("VFS: bread: READ error on %s\n", kdevname(dev));
-	return NULL;
-    }
-    return readbuf(bh);
-#else
     return readbuf(getblk(dev, block));
-#endif
 }
 
 #if 0
@@ -355,8 +345,9 @@
     if (pos >= filesize)
 	return NULL;
 
-    if (block < 0 || !(bh = getblk(dev, block)))
+    if (block < 0)
 	return NULL;
+    bh = getblk(dev, block);
 
     if (buffer_uptodate(bh))
 	return bh;
@@ -436,9 +427,10 @@
 		bufmem_map[i] = bh;
 		bh->b_data = bufmem[i];
 		bh->b_mapcount++;
+		if(bh->b_uptodate)
 		fmemcpy(get_ds(), (__u16) bh->b_data, _buf_ds,
-			(__u16) (bh->b_num * 0x400), 0x400);
-		debug3("BUFMAP: Buffer %d (block %ld) mapped into L1 slot %d.\n",
+			(__u16) (bh->b_num * BLOCK_SIZE), BLOCK_SIZE);
+		debug3("BUFMAP: Buffer %d (block %d) mapped into L1 slot %d.\n",
 			bh->b_num, bh->b_blocknr, i);
 		return;
 	    }
@@ -455,8 +447,8 @@
 		debug1("BUFMAP: Buffer %d unmapped from L1\n",
 			       bufmem_map[i]->b_num);
 		/* Now unmap it */
-		fmemcpy(_buf_ds, (__u16) (bufmem_map[i]->b_num * 0x400),
-			get_ds(), (__u16) bufmem_map[i]->b_data, 0x400);
+		fmemcpy(_buf_ds, (__u16) (bufmem_map[i]->b_num * BLOCK_SIZE),
+			get_ds(), (__u16) bufmem_map[i]->b_data, BLOCK_SIZE);
 		bufmem_map[i]->b_data = 0;
 		bufmem_map[i] = 0;
 		break;
diff -Nurb elks.orig/fs/minix/bitmap.c elks/fs/minix/bitmap.c
--- elks.orig/fs/minix/bitmap.c	2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/minix/bitmap.c	2012-10-24 14:19:08.000000000 -0500
@@ -136,10 +136,7 @@
     if (j < sb->u.minix_sb.s_firstdatazone || j >= sb->u.minix_sb.s_nzones)
 	return 0;
     /* WARNING: j is not converted, so we have to do it */
-    if (!(bh = getblk(sb->s_dev, (block_t) j))) {
-	printk("mnb: cannot get");
-	return 0;
-    }
+    bh = getblk(sb->s_dev, (block_t) j);
     map_buffer(bh);
     memset(bh->b_data, 0, BLOCK_SIZE);
     mark_buffer_uptodate(bh, 1);
diff -Nurb elks.orig/fs/minix/inode.c elks/fs/minix/inode.c
--- elks.orig/fs/minix/inode.c	2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/minix/inode.c	2012-10-24 14:21:17.000000000 -0500
@@ -377,14 +377,12 @@
 struct buffer_head *minix_getblk(register struct inode *inode,
 				 unsigned short block, int create)
 {
-    struct buffer_head *bh;
     unsigned short blknum;
 
     blknum = _minix_bmap(inode, block, create);
-    if (blknum != 0) {
-	bh = getblk(inode->i_dev, (block_t) blknum);
-	return bh;
-    } else
+    if (blknum != 0)
+	return getblk(inode->i_dev, (block_t) blknum);
+    else
 	return NULL;
 }
 

                 reply	other threads:[~2012-11-17  5:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAD6VGuby=tno62bSGQzCHkC2s_7M__x+mZG2aEknJ6WmpQmkbg@mail.gmail.com' \
    --to=lithoxs@gmail.com \
    --cc=linux-8086@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).