Subject: Re: bin/8681: grep may bomb out with "memory exhausted"
To: None <richard.earnshaw@arm.com>
From: R. C. Dowdeswell <elric@mabelode.imrryr.org>
List: netbsd-bugs
Date: 10/28/1999 03:28:55
On 941105063 seconds since the Beginning of the UNIX epoch
Richard Earnshaw wrote:
>
>
>elric@mabelode.imrryr.org said:
>> Why not mmap(2) the file MAP_SHARED and PROT_READ.  It's not like grep
>> is going to modify the pages, and shared pages shouldn't be counted
>> towards memory usage as they are only backed on disk.
>
>I haven't looked at the code, but it's probably to avoid having to 
>special-case <stdin>.

They already use HAVE_MMAP, so they must already special case stdin.
But that does bring up an interesting point, that the read(2)/write(2)
method must be fixed regardless of whether one could play games
with how mmap(2) is invoked.

I do still think that a solution should be found, not a workaround.
I ran the experiment on my system which seemed okay, but then I
have a fair bit of memory.  I'd hate to see how grep thrashes a
system with little memory if you accidentally grep the `wrong'
file.  I really don't think that grep should need to eat that much
memory to efficiently deal with files that have no newline.

 == Roland Dowdeswell                      http://www.Imrryr.ORG/~elric/  ==
 == The Unofficial NetBSD Web Pages        http://www.Imrryr.ORG/NetBSD/  ==
 == The NetBSD Project                            http://www.NetBSD.ORG/  ==