bin/54276: pread/pwrite patches for libc db functions
Dan Nelson
dnelson at allantgroup.com
Wed Jul 9 13:20:21 PDT 2003
>Number: 54276
>Category: bin
>Synopsis: pread/pwrite patches for libc db functions
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Wed Jul 09 13:20:18 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Dan Nelson
>Release: FreeBSD 5.1-CURRENT i386
>Organization:
The Allant Group
>Environment:
System: FreeBSD dan.emsphone.com 5.1-CURRENT FreeBSD 5.1-CURRENT #276: Fri Jun 27 16:21:53 CDT 2003 dan at dan.emsphone.com:/usr/src/sys/i386/compile/DANSMP i386
>Description:
The following patch replaces an lseek+read/write combo with a single
pread/pwrite, cutting the number of syscalls by 1/2.
All db I/O gets funnelled though mpool_get and mpool_write so these are
the only functions that need changing. I've been running with this
patch for 3 years and had forgotten about it :) Tested against >100mb
btree indexes.
>How-To-Repeat:
>Fix:
Index: mpool.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/db/mpool/mpool.c,v
retrieving revision 1.10
diff -u -p -r1.10 mpool.c
--- mpool.c 22 Mar 2002 21:52:01 -0000 1.10
+++ mpool.c 29 Mar 2002 18:42:00 -0000
@@ -207,9 +207,7 @@ mpool_get(mp, pgno, flags)
++mp->pageread;
#endif
off = mp->pagesize * pgno;
- if (lseek(mp->fd, off, SEEK_SET) != off)
- return (NULL);
- if ((nr = _read(mp->fd, bp->page, mp->pagesize)) != mp->pagesize) {
+ if ((nr = pread(mp->fd, bp->page, mp->pagesize, off)) != mp->pagesize) {
if (nr >= 0)
errno = EFTYPE;
return (NULL);
@@ -381,9 +379,7 @@ mpool_write(mp, bp)
(mp->pgout)(mp->pgcookie, bp->pgno, bp->page);
off = mp->pagesize * bp->pgno;
- if (lseek(mp->fd, off, SEEK_SET) != off)
- return (RET_ERROR);
- if (_write(mp->fd, bp->page, mp->pagesize) != mp->pagesize)
+ if (pwrite(mp->fd, bp->page, mp->pagesize, off) != mp->pagesize)
return (RET_ERROR);
bp->flags &= ~MPOOL_DIRTY;
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list