Subject: bin/8461: grep mmap()'s too often
To: None <>
From: Andreas Johansson <>
List: netbsd-bugs
Date: 09/21/1999 02:50:50
>Number:         8461
>Category:       bin
>Synopsis:       grep mmap()'s too often
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 21 02:50:01 1999
>Originator:     Andreas Johansson
>Release:        current tarball, 1999-08-03
AlphaPC 164SX, NetBSD current

System: NetBSD ymer 1.4I NetBSD 1.4I (YMER) #16: Fri Aug 13 00:16:51 CEST 1999 ajo@ymer:/usr/src/sys/arch/alpha/compile/YMER alpha

The implementation of grep is very inefficient on my alpha. I've looked at
the code, and it seems that it reads the file data by using mmap() on a
block basis instead of mmap():ing the entire file. mmap is used sort of like
a replacement for read. It seems that (atleast) the mmap implementation on
alpha is very system time consuming and therefore grep takes a lot of system
cpu time. Also, read performance is very poor.

By simply adding #undef HAVE_MMAP to grep.c I've forced grep to use read()
instead of mmap() to read it's data. This increases read performance by about
4 times while still taking much less system cpu time.

time grep something somefile
Simple fix, force grep to use read() instead.
Better fix, mmap() the whole file instead of many small blocks.