Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Oct 2003 10:01:14 +0930
From:      Greg 'groggy' Lehey <grog@FreeBSD.org>
To:        Poul-Henning Kamp <phk@phk.freebsd.dk>
Cc:        Mark Valentine <mark@valentine.me.uk>
Subject:   Re: Alignment of disk-I/O from userland.
Message-ID:  <20031007003114.GF47054@wantadilla.lemis.com>
In-Reply-To: <26939.1065479790@critter.freebsd.dk> <21229.1065441969@critter.freebsd.dk>
References:  <200310062220.h96MK7PI061345@dotar.thuvia.org> <26939.1065479790@critter.freebsd.dk> <21229.1065441969@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help

--rWhLK7VZz0iBluhq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Monday,  6 October 2003 at 14:06:09 +0200, Poul-Henning Kamp wrote:
>
> Some disk controllers require that the memory buffer for a DMA
> transfer be aligned on a particular bounday, typically four bytes,
> but in some cases larger than that.
>
> This program, in other words, would be a problem for some of our
> disk controllers:
>
> 	#include <stdlib.h>
>
> 	int
> 	main(int argc, char **argv)
> 	{
> 		char *p;
>
> 		p = malloc(8192);	/* page aligned */
> 		read (0, p + 1, 2048);	/* not */
> 	}

This kind of code is explicitly allowed in K&R 2 (page 170 et seq).

> Most code which does disk I/O from userland uses malloc'ed buffers for
> the sectors and the alignment comes for free, but we currently have
> no requirement that it be so.
>
> How much code (apart from newfs(8)!) would we break by enforcing a
> minimum alignment of for instance 16 bytes on disk-I/O requests
> from userland ?

Quite possibly a lot of third party code over which we have no
control.  I'm thinking of ibcs2 and Linux stuff, for example.

> It would be a trivial matter to do the "bounce-buffering" somewhere
> along the road, but I am not convinced it is the right thing to do
> because all of sudden some requests would take a performance hit to
> do a copy and some would not...

I think the bounce buffering is necessary, but should be an emergency
measure.  It could generate a console message, for example.

On Tuesday,  7 October 2003 at  0:36:30 +0200, Poul-Henning Kamp wrote:
>
> If shitty code breaks, I don't care.  We're trying to raise the
> standard in and with FreeBSD, we're not trying to lower the bar
> to make any visual basic programmer pass.

That depends on whether the programmer is a FreeBSD developer or a
user.  I agree that our own code should be aligned correctly.  I don't
think it's reasonable to expect all users to adhere to a higher coding
standard than they would for, say, Linux.  It's not difficult to cater
for them, and if you like we can still tell them off when they do it,
but I think the code should work nevertheless.  People who get bitten
by this "bug" won't see the clean design intentions behind it.
They'll just know that FreeBSD is broken.

Greg
--
See complete headers for address and phone numbers.

--rWhLK7VZz0iBluhq
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (FreeBSD)

iD8DBQE/gglSIubykFB6QiMRAjl+AJ9oYwEvWYvXVyR/TbjWZFe28bLilwCfeLBH
KYVKdvQvOLv0gVX1O/D1p4s=
=T/Eq
-----END PGP SIGNATURE-----

--rWhLK7VZz0iBluhq--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031007003114.GF47054>