[rfc] sed option `-i' (edit in place)

Denys Vlasenko vda.linux at googlemail.com
Wed Aug 29 11:41:38 UTC 2007


On Monday 27 August 2007 08:04, Johan Adolfsson wrote:
> > -----Original Message-----
> > From: busybox-bounces at busybox.net
> > [mailto:busybox-bounces at busybox.net] On Behalf Of Cristian
> > Ionescu-Idbohrn
> > Sent: den 26 augusti 2007 23:21
> > To: busybox at busybox.net
> > Subject: Re: [rfc] sed option `-i' (edit in place)
> >
> > > Does stock sed do this?
> >
> > No.  GNU sed is doing something similar to bb-sed (or the other way
> > around):
> >
> > ,----
> >
> > | open("lines", O_RDONLY|O_LARGEFILE) = 3
> > | ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfd35068) = -1
> >
> > ENOTTY (Inappropriate ioctl for device)
> >
> > | fstat64(3, {st_mode=S_IFREG|0644, st_size=8, ...}) = 0
> > | gettimeofday({1188158729, 155778}, NULL) = 0
> > | getpid()                                = 19852
> > | open("./sedSTqTlj", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600) = 10
> > | fcntl64(10, F_GETFL)                    = 0x8002 (flags
> >
> > O_RDWR|O_LARGEFILE)
> >
> > | fstat64(10, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
> > | mmap2(NULL, 131072, PROT_READ|PROT_WRITE,
> >
> > MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7dfe000
> >
> > | _llseek(10, 0, [0], SEEK_CUR)           = 0
> > | fchmod(10, 0100644)                     = 0
> > | fchown32(10, 1000, 1000)                = 0
> > | fstat64(3, {st_mode=S_IFREG|0644, st_size=8, ...}) = 0
> > | mmap2(NULL, 131072, PROT_READ|PROT_WRITE,
> >
> > MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7dde000
> >
> > | read(3, "fxx\nbar\n", 131072)           = 8
> > | write(10, "fxx\n", 4)                   = 4
> > | write(10, "bar\n", 4)                   = 4
> > | read(3, "", 131072)                     = 0
> > | close(3)                                = 0
> > | munmap(0xb7dde000, 131072)              = 0
> > | close(10)                               = 0
> > | munmap(0xb7dfe000, 131072)              = 0
> > | rename("./sedSTqTlj", "lines")          = 0
> > | close(1)                                = 0
> > | close(2)                                = 0
> >
> > `----
>
> Wouldn't we get reduced wearing and possibly a general speed up as well,
> if we made sure sed was buffering stuff more and avoiding small writes
> to the filesystem?

Yes, small writes are undesirable, but for different reason: write syscall
overhead can take significant time, and if you pipe gigabytes of data thru
sed, you dont want that.

However, weigh speed gains against possibly bigger code and bigger buffers
(memory consumption).

> Then there shouldn't be much difference in flash wearing compared to a
> copy.

Unless you mounted the fs with O_SYNC, writes are buffered by kernel anyway.
--
vda



More information about the busybox mailing list