From owner-freebsd-arch@FreeBSD.ORG Mon Oct 6 05:06:17 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 920CA16A4BF for ; Mon, 6 Oct 2003 05:06:17 -0700 (PDT) Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 780D243FE5 for ; Mon, 6 Oct 2003 05:06:16 -0700 (PDT) (envelope-from phk@phk.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.9/8.12.9) with ESMTP id h96C692B021230 for ; Mon, 6 Oct 2003 14:06:10 +0200 (CEST) (envelope-from phk@phk.freebsd.dk) To: arch@freebsd.org From: Poul-Henning Kamp Date: Mon, 06 Oct 2003 14:06:09 +0200 Message-ID: <21229.1065441969@critter.freebsd.dk> Subject: Alignment of disk-I/O from userland. X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Oct 2003 12:06:17 -0000 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. If a userland program does a read or write on a disk device (/dev/ad0 for instance), we do some VM swizzle in physio and the request is in essence a zero-copy thing directly into the process' pages, and as an sideeffect of this, the pointer passed to the device driver has the same offset into a page as the users request (the lower 12 bits on i386). That means that userland programs can send down I/O requests which are not properly aligned. This program, in other words, would be a problem for some of our disk controllers: #include int main(int argc, char **argv) { char *p; p = malloc(8192); /* page aligned */ read (0, p + 1, 2048); /* not */ } 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 ? 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... Qualified, informed input requested. No Bikesheds please. Poul-Henning -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.