tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: GSoC 2017 Project "Make Anita support multiple virtual machine systems"



Christos Zoulas wrote:
> >2. Line nos. 125-132 (the function definition for make_dense_image) define
> >a function for creating a file of given file size. Was there any advantage
> >(as in speed etc.) for choosing to write your own function instead of
> >something like
> ><code>
> >ret =
> >os.spawnvp(os.P_WAIT,'dd',['dd','if=/dev/zero','of=/home/utkarsh/new.img','bs=1MiB','count=10'])
> >if not ret:
> >    print("image created!")
> ></code>
> >We could get the block size, count and filename from the user, just like
> >the original function and the user name from the environment variable USER.
> 
> Yes, I agree I think using dd is better.

One reason for not using dd is that it can only create files that are
a multiple of the block size given by the "bs" argument, so you would
have to choose a block size that the file size is divisible by.  That
would complicate things, and if the desired file size happens to be a
prime number of sectors, you would have to choose a block size of a
single sector, which would be inefficient compared to the 64k block
size used by the current Python code.

As for "get the block size [..] from the user, just like the original
function", the current code does not get the block size from the user,
but uses a fixed block size of 64k.  I don't think the user should be
burdened with choosing a block size.

The Python version also issues about half the number of system calls,
since it only needs to write() the file, not read() /dev/zero.  And it
avoids a fork() and exec(), as well as any possible portability issues
due to differences between the dd implementations on different host
operating systems.  For example, the "MiB" unit used in the example is
not supported by the POSIX standard for dd, nor by NetBSD's
implementation.
-- 
Andreas Gustafsson, gson%gson.org@localhost


Home | Main Index | Thread Index | Old Index