home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!swrinde!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!agate!doc.ic.ac.uk!pipex!demon!cix.compulink.co.uk!tbunce
- Newsgroups: comp.lang.perl
- From: tbunce@cix.compulink.co.uk (Tim Bunce)
- Subject: Memory allocation during @ary = <>;
- Reply-To: tbunce@cix.compulink.co.uk
- Date: Tue, 26 Jan 1993 21:59:00 +0000
- Message-ID: <memo.897439@cix.compulink.co.uk>
- Sender: usenet@demon.co.uk
- Lines: 65
-
-
- While tinkering with a large script to improve it's performance
- I started using trace(1) in the sun to watch the system calls.
-
- The perl code reads in a large (>100k) text file, manipulates it,
- then writes it all back out again. Using trace -c to count the system
- calls I found:
-
- 275 brk
- 180 read
- 161 write
- etc
-
- The reads and writes are ok (perl does it's i/o in 4096 bytes blocks)
- but 275 calls to brk (re malloc for those not familiar) seemed a little
- excessive.
-
- The following is an extract from the trace output (data shown as dots):
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 brk (0x276bb0) = 0
- 21:08:16 brk (0x279bb0) = 0
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 brk (0x27cbb0) = 0
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 brk (0x27fbb0) = 0
- 21:08:16 brk (0x282bb0) = 0
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 brk (0x285bb0) = 0
- 21:08:16 brk (0x288bb0) = 0
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 brk (0x28bbb0) = 0
- 21:08:16 brk (0x28fbb0) = 0
- 21:08:16 read (3, "..................................".., 4096) = 4096
- 21:08:16 brk (0x293bb0) = 0
- etc etc
-
- Notice that after a while perl is calling brk() for almost every read, Ouch!
- I presume here that perl is calling malloc() and malloc() is calling brk()
- because it has no spare memory.
-
- I had hoped to improve performance by allocating lots of memory for a
- temporary variable and then freeing that memory before the read. This
- did not seem to affect the brk()'s, I presume the memory was not really
- free()'d. (I've tried many ways to allocate and free the memory.)
-
- Is there a better solution? Is there a way to change the read ahead size
- from 4096? Given a virtual memory i/o system such as SunOS >4.1, a means
- of setting a larger read size should be very beneficial. Perl 5 perhaps :-)
-
- Regards,
- Tim Bunce.
- tbunce@cix.compulink.co.uk
-