[Ilugc] Can we access the SWAP SPACE in Python

  • From: arulalant@xxxxxxxxx (Arulalan T)
  • Date: Mon, 10 Oct 2011 11:38:53 +0530

Hai,

2011/10/7 Raja Subramanian <rajasuperman at gmail.com>



Is there any way to store some data in SWAP (but not in RAM) and get the
data from the SWAP partition whenever we need it in Python or C language
?
yup. It may be slower to access the swap area rather than RAM, but it is
much faster than access the data of files which are stored in the hard
disk.

Use mmap to map a file directly into your processes address space. When
you reference the memory address, the kernel will read/write data from the
file using the same mechanisms it uses to swap.  You will bypass all file
IO buffering and have direct access to the files.  This is how all DB
engines
handle IO.  mmap() vs read() will give you a 3 x speedup for IO bound jobs.

Advanced Programming in the Unix Environment by Stevens has a good
example of file copy implemented using mmap.


I couldnt use mmap( ) function in my case, since I am accessing the binary
file like NetCDF, PP, HDF, Grads which contains data
in formats of numpy.float32, numpy.float64 and some meta data also.

These files cant read it as like normal text file object such as
fileobj.readlines( ). i.e. These files are not string type.
So I cant use mmap( ) in this case.




Mechanisms to speed up scientific code:

1. Make fewer passes over your data.  Ideally you want to read the
data once, complete all processing and never have to read it again.
Do not make several passes over data doing a little processing each
time.

2. Use efficient IO like mmap.

3. Use the correct algorithms suitable for your data size and work.

4. Profile your code to understand which step takes the most time.
Then start fine tuning.

5. Run a 64bit OS, you'll sometimes need to use more RAM if you
want faster performance.  It's a trade-off.

6. Code the hot spots in C if you need more speed.


Thanks for above suggestions.

I will use all the above in my project.

-- 
Regards,
Arulalan.T
Project Associate
Centre for Atmospheric Sciences
Indian Institute of Technology Delhi

My Experiments In Gnu/Linux !  : http://tuxcoder.wordpress.com
Kanchi Linux User Group Rocks ! : http://kanchilug.wordpress.com

Other related posts: