--- Begin Message ---
Subject: |
[PATCH 6/6] grep: do pagesize initialization and buffer allocation earlier |
Date: |
Tue, 7 Jun 2016 01:37:43 -0500 |
* src/grep.c (reset, main): We're going to need pagesize and buffer
initialized anyway, so we might as well do so unconditionally early on
rather than checking on every call to reset().
---
src/grep.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/grep.c b/src/grep.c
index d01bc4f..302e4d7 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -769,16 +769,6 @@ all_zeros (char const *buf, size_t size)
static bool
reset (int fd, struct stat const *st)
{
- if (! pagesize)
- {
- pagesize = getpagesize ();
- if (pagesize == 0 || 2 * pagesize + 1 <= pagesize)
- abort ();
- bufalloc = (ALIGN_TO (INITIAL_BUFSIZE, pagesize)
- + pagesize + sizeof (uword));
- buffer = xmalloc (bufalloc);
- }
-
bufbeg = buflim = ALIGN_TO (buffer + 1, pagesize);
bufbeg[-1] = eolbyte;
bufdesc = fd;
@@ -2252,6 +2242,12 @@ main (int argc, char **argv)
set_program_name (argv[0]);
program_name = argv[0];
+ pagesize = getpagesize ();
+ if (pagesize == 0 || 2 * pagesize + 1 <= pagesize)
+ abort ();
+ bufalloc = (ALIGN_TO (INITIAL_BUFSIZE, pagesize) + pagesize + sizeof
(uword));
+ buffer = xmalloc (bufalloc);
+
keys = NULL;
keycc = 0;
with_filenames = false;
--
2.8.0.rc3
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#23717: [PATCH 6/6] grep: do pagesize initialization and buffer allocation earlier |
Date: |
Sun, 21 Aug 2016 23:28:08 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
Thanks, I see this one was also installed in June and so am closing the bug
report.
I noticed that the old code and the new both have some glitches with respect to
large page sizes, so I installed the attached further patch to fix them. I've
never used grep on a machine with 2 GiB pages, but such beasts exist nowadays
and we might as well make grep safe for them.
0001-grep-minor-tweaks-of-initial-buffer-alloc.patch
Description: Text Data
--- End Message ---