linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alain Knaff <Alain.Knaff@hitchhiker.org.lu>
To: torvalds@transmeta.com, linux-kernel@vger.kernel.org
Cc: viro@math.psu.edu
Subject: Re: Poor floppy performance in kernel 2.4.10
Date: Sat, 27 Oct 2001 17:00:57 +0200	[thread overview]
Message-ID: <200110271500.f9RF0vO01848@hitchhiker.org.lu> (raw)

Appended to this mail is a patch meant to fix the "non-cached floppy"
problem.

The  block_device_operations structure now has a new member:
  can_trust_media_change
If this returns 1, the VFS trusts the driver's check_media_change
function, and skips the call to kill_bdev in blkdev_put. If the driver
provides no such function, it defaults to "don't trust" (i.e. call
kill_bdev)

The floppy driver implements this new function in the following way:
 1. if broken_dcl on a drive is set, can_trust_media_change always
returns false
 2. if broken_dcl is not set, the function initially returns false,
until a disk change signal is seen. From then on, it always returns
true.

Other block devices could implement this by using black or whitelists,
or hardwiring a value.

HOWEVER, even after these changes, the caching problem still wasn't
solved (I confirmed with additional printk's that invalidate_bdev was
indeed no longer called).

Further investigation showed that the real culprit was actually
bdput. This function seems to de-allocate all structures attached to
the block device, including the cache... Ifdeffing it out did indeed
restore cache functionality. However, I understand that this would not
be a proper way to address the problem, as it would certainly cause a
memory leak.

Appended to this mail is the patch (without the debugging printk's,
and with bdput still intact); however in order to make it really work
bdput would need to be changed to not free up the cache, if that is
possible... Any ideas?

Regards,

Alain

diff -ur 2.4.13/linux/drivers/block/floppy.c linux/drivers/block/floppy.c
--- 2.4.13/linux/drivers/block/floppy.c	Sat Oct 27 09:42:34 2001
+++ linux/drivers/block/floppy.c	Sat Oct 27 16:17:33 2001
@@ -741,6 +741,7 @@
 		return UTESTF(FD_DISK_CHANGED);
 	if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80){
 		USETF(FD_VERIFY); /* verify write protection */
+		USETF(FD_DCL_SEEN); /* DCL for this drive has been seen */
 		if (UDRS->maxblock){
 			/* mark it changed */
 			USETF(FD_DISK_CHANGED);
@@ -3901,12 +3902,23 @@
 	return 0;
 }
 
+/* determines whether we can trust media change
+ * answers true if we have seen disk change at least once, and not marked as
+ * broken */
+static int floppy_can_trust_media_change(kdev_t dev)
+{
+	int drive=DRIVE(dev);
+	return (UTESTF(FD_DCL_SEEN) &&
+		((UDP->flags & FD_BROKEN_DCL) == 0));
+}
+
 static struct block_device_operations floppy_fops = {
 	open:			floppy_open,
 	release:		floppy_release,
 	ioctl:			fd_ioctl,
 	check_media_change:	check_floppy_change,
 	revalidate:		floppy_revalidate,
+	can_trust_media_change: floppy_can_trust_media_change
 };
 
 static void __init register_devfs_entries (int drive)
diff -ur 2.4.13/linux/fs/block_dev.c linux/fs/block_dev.c
--- 2.4.13/linux/fs/block_dev.c	Sat Oct 27 09:43:27 2001
+++ linux/fs/block_dev.c	Sat Oct 27 16:18:19 2001
@@ -601,8 +601,12 @@
 		__block_fsync(bd_inode);
 	else if (kind == BDEV_FS)
 		fsync_no_super(rdev);
-	if (!--bdev->bd_openers)
-		kill_bdev(bdev);
+	if (!--bdev->bd_openers) {
+		if(!bdev->bd_op->can_trust_media_change ||
+		   !bdev->bd_op->can_trust_media_change(rdev)) {
+			kill_bdev(bdev);
+		}
+	}
 	if (bdev->bd_op->release)
 		ret = bdev->bd_op->release(bd_inode, NULL);
 	if (!bdev->bd_openers)
diff -ur 2.4.13/linux/include/linux/fd.h linux/include/linux/fd.h
--- 2.4.13/linux/include/linux/fd.h	Fri Aug 13 21:16:16 1999
+++ linux/include/linux/fd.h	Sat Oct 27 13:37:08 2001
@@ -177,7 +177,8 @@
 				 * to clear media change status */
 	FD_UNUSED_BIT,
 	FD_DISK_CHANGED_BIT,	/* disk has been changed since last i/o */
-	FD_DISK_WRITABLE_BIT	/* disk is writable */
+	FD_DISK_WRITABLE_BIT,	/* disk is writable */
+	FD_DCL_SEEN_BIT		/* have we seen DCL? */
 };
 
 #define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
@@ -196,6 +197,7 @@
 #define FD_DISK_NEWCHANGE (1 << FD_DISK_NEWCHANGE_BIT)
 #define FD_DISK_CHANGED (1 << FD_DISK_CHANGED_BIT)
 #define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT)
+#define FD_DCL_SEEN (1 << FD_DCL_SEEN)
 
 	unsigned long spinup_date;
 	unsigned long select_date;
diff -ur 2.4.13/linux/include/linux/fs.h linux/include/linux/fs.h
--- 2.4.13/linux/include/linux/fs.h	Sat Oct 27 11:53:28 2001
+++ linux/include/linux/fs.h	Sat Oct 27 13:05:03 2001
@@ -793,6 +793,7 @@
 	int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
 	int (*check_media_change) (kdev_t);
 	int (*revalidate) (kdev_t);
+	int (*can_trust_media_change) (kdev_t);
 };
 
 /*

             reply	other threads:[~2001-10-27 15:01 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-27 15:00 Alain Knaff [this message]
2001-10-27 15:15 ` Poor floppy performance in kernel 2.4.10 Alexander Viro
2001-10-27 17:12   ` Alain Knaff
2001-10-27 17:42     ` Alexander Viro
2001-10-27 18:00       ` Alain Knaff
2001-10-27 18:13         ` Alexander Viro
2001-10-27 18:26         ` Alexander Viro
2001-10-27 19:02           ` more devfs fun Alexander Viro
2001-10-27 19:16             ` Alexander Viro
2001-10-27 19:50               ` more devfs fun (Piled Higher and Deeper) Alexander Viro
2001-10-27 20:06                 ` Alexander Viro
2001-10-27 21:09                   ` Ryan Cumming
2001-10-27 21:22                     ` Alexander Viro
2001-10-28  1:00                     ` Rik van Riel
2001-10-28  8:45                     ` Richard Gooch
2001-10-28  9:54                       ` Alexander Viro
2001-10-28 12:27                       ` Roman Zippel
2001-10-28 13:16                         ` Alexander Viro
2001-10-28 22:31                       ` Richard Gooch
2001-10-28 23:11                         ` Alexander Viro
2001-10-27 21:01                 ` Alexander Viro
2001-11-06  6:35                 ` Richard Gooch
2001-11-06  7:10                   ` Alexander Viro
2001-11-06  7:14                   ` Richard Gooch
2001-11-06  7:17                     ` Alexander Viro
2001-11-06 20:14                     ` Richard Gooch
2001-10-28 10:06               ` Lorenzo Allegrucci
2001-11-06  5:21               ` Richard Gooch
2001-11-06  5:17             ` more devfs fun Richard Gooch
2001-11-06  5:06           ` Richard Gooch
2001-11-06  7:01         ` Poor floppy performance in kernel 2.4.10 Richard Gooch
2001-11-06  7:03           ` Alexander Viro
2001-12-09  5:38           ` Devfs races with block devices Richard Gooch
2001-11-06  7:19         ` Poor floppy performance in kernel 2.4.10 Richard Gooch
2001-11-06  7:22           ` Alexander Viro
2001-10-27 19:13       ` Alain Knaff
2001-10-27 19:19         ` Alexander Viro
2001-10-27 19:26           ` Alain Knaff
2001-10-28 20:40           ` Alain Knaff
2001-10-28 20:57             ` Peter T. Breuer
2001-10-29  5:38               ` Alain Knaff
2001-10-29  6:07                 ` Alexander Viro
2001-10-29  6:34                   ` Alain Knaff
2001-10-28 21:42             ` Alexander Viro
  -- strict thread matches above, loose matches on Subject: below --
2001-10-21 11:36 Alain Knaff
2001-10-22  9:59 ` Andrea Arcangeli
2001-10-22 10:06   ` Alexander Viro
2001-10-22 14:07 ` Nick LeRoy
2001-10-22 18:28 ` bill davidsen
2001-10-19 16:58 Manfred Spraul
2001-10-17  7:36 Kamil Iskra
2001-10-17 20:45 ` Steve Kieu
2001-10-18 10:11   ` Kamil Iskra
2001-10-18 15:28     ` Andreas Dilger
2001-10-18 15:42       ` Kamil Iskra
2001-10-18 16:17         ` Ville Herva
2001-10-18 16:30           ` Nick LeRoy
2001-10-18 19:57             ` bill davidsen
2001-10-18 20:47               ` Nick LeRoy
2001-10-18 20:05             ` bill davidsen
2001-10-18 20:15               ` Alexander Viro
2001-10-18 16:18       ` Alexander Viro
2001-10-18 17:44         ` Andrea Arcangeli
2001-10-19  7:50           ` Giuliano Pochini
2001-10-19 13:46             ` Andrea Arcangeli
2001-10-19 15:57             ` Linus Torvalds
2001-10-20  4:20               ` Rob Landley

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=200110271500.f9RF0vO01848@hitchhiker.org.lu \
    --to=alain.knaff@hitchhiker.org.lu \
    --cc=alain@linux.lu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    --cc=viro@math.psu.edu \
    /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 NNTP newsgroup(s).