[blivet:master 05/20] Avoid using Size constant in FileDevice._create().

Anne Mulhern amulhern at redhat.com
Mon Jan 5 12:49:02 UTC 2015





----- Original Message -----
> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> To: "anaconda patch review" <anaconda-patches at lists.fedorahosted.org>
> Sent: Monday, January 5, 2015 2:51:36 AM
> Subject: Re: [blivet:master 05/20] Avoid using Size constant in	FileDevice._create().
> 
> On Tue, 2014-12-23 at 18:42 -0500, mulhern wrote:
> > It makes the code a little bit awkward and busy and the name MiB
> > will conflict with some size constants defined in subsequent patch.
> > New code is an order of magnitude more efficient, which is a bonus.
> > 
> > Signed-off-by: mulhern <amulhern at redhat.com>
> > ---
> >  blivet/devices/file.py | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/blivet/devices/file.py b/blivet/devices/file.py
> > index da231c5..628853d 100644
> > --- a/blivet/devices/file.py
> > +++ b/blivet/devices/file.py
> > @@ -24,7 +24,6 @@ import os
> >  
> >  from .. import util
> >  from ..storage_log import log_method_call
> > -from ..size import Size
> >  
> >  import logging
> >  log = logging.getLogger("blivet")
> > @@ -98,12 +97,11 @@ class FileDevice(StorageDevice):
> >          fd = os.open(self.path, os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
> >          # all this fuss is so we write the zeros 1MiB at a time
> >          zero = "\0"
> > -        MiB = Size("1 MiB")
> > -        count = int(self.size.convertTo(spec="MiB"))
> > -        rem = self.size % MiB
> > +        block_size = 1024 ** 2
> > +        (count, rem) = divmod(int(self.size), block_size)
> >  
> >          for _n in range(count):
> > -            os.write(fd, zero * MiB)
> > +            os.write(fd, zero * block_size)
> Is it really wise to allocate 1 MiB chunk of memory full of zeroes only
> to write it out to a file?
> 
> --
> Vratislav Podzimek
> 
> Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

Nope, it's not. I've extended the patch to hoist zero * block_size
computation above loop.

- mulhern


More information about the anaconda-patches mailing list