1. 20 May, 2015 4 commits
  2. 14 May, 2015 1 commit
    • Fix build with non-std "python" · a280b53d
      In 5755a6b3 (Basic setup.py / Makefile to build/install/sdist stuff +
      bigfile.so skeleton) we overlooked one thing:
      
          when tailing from setup.py to make level, we forgot to setup the
          PYTHON env variable properly, and that leads to changing building
          with std python.
      
      Look e.g.
      
          $ python3 setup.py build_ext -i
          running build_ext
          python setup.py ll_build_ext --inplace
          ^^^
      
      which is obviously not correct.
      
      Fix it.
      
      The tox setup we have setup for testing with multiple interpreters
      (7af2b2d7 "Tox setup to test things with py27 & py34 and several
      versions of ZODB") did not caught this, because for every python and
      environment versions tox initializes separate virtualenv, in which
      .../bin/python is a link to chosen python, and this way both python and
      my-selected-for-build-python are the same.
      
      Cc: @Tyagov
      Kirill Smelkov committed
  3. 29 Apr, 2015 2 commits
    • bigfile/ram_shmfs: Try to support compiling on older systems · 48defba0
      For example on Debian 7 Wheezy the kernel (linux 3.2) supports holepunching,
      because holepunching was added in linux 2.6.38:
      
          http://git.kernel.org/linus/79124f18b335172e1916075c633745e12dae1dac
      
      but glibc does not provide fallocate mode constants, and compilation fails:
      
          gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -D_GNU_SOURCE -I./include -I./3rdparty/ccan -I./3rdparty/include -I/opt/slapgrid/f2a5f59d0d2b521681b9333ee76a2859/parts/python2.7/include/python2.7 -c bigfile/ram_shmfs.c -o build/temp.linux-x86_64-2.7/bigfile/ram_shmfs.o -std=gnu99 -fplan9-extensions -fvisibility=hidden -Wno-declaration-after-statement -Wno-error=declaration-after-statement
          bigfile/ram_shmfs.c: In function ‘shmfs_drop_memory’:
          bigfile/ram_shmfs.c:135:31: error: ‘FALLOC_FL_PUNCH_HOLE’ undeclared (first use in this function)
          bigfile/ram_shmfs.c:135:31: note: each undeclared identifier is reported only once for each function it appears in
          bigfile/ram_shmfs.c:135:54: error: ‘FALLOC_FL_KEEP_SIZE’ undeclared (first use in this function)
          error: command 'gcc' failed with exit status 1
      
      Try to fix it via fallbacking to provide the needed defines on older systems ourselves.
      
      Cc: Klaus Wölfel <klaus@nexedi.com>
      Cc: Ivan Tyagov <ivan@tyagov.com>
      Kirill Smelkov committed
  4. 15 Apr, 2015 1 commit
    • Fix build with Python that enables -Werror=declaration-after-statement · e0b25398
      In C99 declaration after statement is ok, and we explicitly compile with -std=gnu99.
      
      Python >= 3.4 however adds -Werror=declaration-after-statement even for extension
      modules irregardless of their compilation flags:
      
        https://bugs.python.org/issue21121
      
      and the build fails this way:
      
          building 'wendelin.bigfile._bigfile' extension
          creating build/temp.linux-x86_64-3.4
          creating build/temp.linux-x86_64-3.4/bigfile
          creating build/temp.linux-x86_64-3.4/lib
          gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall
      -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -D_GNU_SOURCE
      -I./include -I./3rdparty/ccan -I./3rdparty/include -I/usr/include/python3.4m -c bigfile/_bigfile.c -o build/temp.linux-x86_64-3.4/bigfile/_bigfile.o
      -std=gnu99 -fplan9-extensions -fvisibility=hidden
          bigfile/_bigfile.c: In function ‘pyfile_new’:
          bigfile/_bigfile.c:679:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
               static char *kw_list[] = {"blksize", NULL};
               ^
          cc1: some warnings being treated as errors
          error: command 'gcc' failed with exit status 1
      
      Ensure we turn off this warning and error because we already rely on compiling in C99 mode.
      
      Reported-and-tested-by: Ivan Tyagov <ivan@tyagov.com>
      Kirill Smelkov committed
  5. 03 Apr, 2015 32 commits
    • wendelin.core v0.1 · 4b6821f4
      Kirill Smelkov committed
    • Demo program that shows how to work with ZBigArrays bigger than RAM in size · 1ee72371
      This shows how to first generate such arrays (in steps, as every
      transaction change should fit in memory), and then gather data from
      whole array using C/Fortran/etc code.
      
      It shows how to compute mean via NumPy's ndarray.mean()
      
      It also shows that e.g. ndarray.var() wants to create temporaries in
      size of original ndarray and that would fail, because it does not fit
      into RAM.
      
      ndarray.var() should not need to create such temporaries in principle -
      all it has to do is to first compute mean, and then compute
      
          sum (Xi - <X>)^2
      
      in a loop.
      
      <X> is scalar, Xi - is just access to original array.
      
      ~~~~
      
      So this also show NumPy can be incrementally improved to avoid creating
      such temporaries, and then it will work.
      Kirill Smelkov committed
    • bigfile: Basic benchmarks · bb9d8bf1
          - for virtual memory subsytem
          - for ZBigFiles
      
      They are not currently great, e.g. for virtmem we have in-kernel
      overhead of page clearing - in perf profiles, for bigfile_mmap compared
      to file_read kernel's clear_page_c raises significantly.
      
      That is the worker for clearing page memory and we currently cannot
      avoid that - any memory obtained from kernel (MAP_ANONYMOUS, mmap(file)
      with hole, etc...) comes pre-initialized to zeros to userspace.
      
      This can be seen in the benchmarks as well: file_readbig differs from
      file_read in only that the latter uses 1 small buffer and the first
      allocates large memory (cleared by kernel + python does the memset).
      
          bigfile/tests/bench_virtmem.py@125::bench_file_mmap_adler32     0.47  (0.86 0.49 0.47)
          bigfile/tests/bench_virtmem.py@126::bench_file_read_adler32     0.69  (1.11 0.71 0.69)
          bigfile/tests/bench_virtmem.py@127::bench_file_readbig_adler32  1.41  (1.70 1.42 1.41)
          bigfile/tests/bench_virtmem.py@128::bench_bigfile_mmap_adler32  1.42  (1.45 1.42 1.51)
      
          bigfile/tests/bench_virtmem.py@130::bench_file_mmap_md5         1.52  (1.91 1.54 1.52)
          bigfile/tests/bench_virtmem.py@131::bench_file_read_md5         1.73  (2.10 1.75 1.73)
          bigfile/tests/bench_virtmem.py@132::bench_file_readbig_md5      2.44  (2.73 2.46 2.44)
          bigfile/tests/bench_virtmem.py@133::bench_bigfile_mmap_md5      2.40  (2.48 2.40 2.53)
      
      There is MAP_UNINITIALIZED which works only for non-mmu targets and only
      if explicitly allowed when configuring kernel (off by default).
      
      There were patches to disable that pages zeroing, as it gives
      significant speedup for people's workloads, e.g. [1,2] but all of them
      did not got merged for security reasons.
      
      [1] http://marc.info/?t=132691315900001&r=1&w=2
      [2] http://thread.gmane.org/gmane.linux.kernel/548926
      
      ~~~~
      
      For ZBigFile - it is the storage who is dominating in profiles.
      Kirill Smelkov committed
    • Prepare to benchmark python code with py.test · bcab1246
      For this, a small wrapper over py.test is developed (to discover/collect
      functions to benchmar, etc) and then it runs such functions several
      times in a boxed enveronment.
      
      Benchmarks should be named bench_*.py
      Kirill Smelkov committed
    • ZBigArray: in-ZODB stored BigArray · 90d32e51
      This is like to BigArray, like ZBigFile is to BigFile (4174b84a
      "bigfile: BigFile backend to store data in ZODB")
      Kirill Smelkov committed
    • BigArray: An ndarray-like on top of BigFile memory mappings · 0c826d5c
      I.e. something like numpy.memmap for numpy.ndarray and OS files. The whole
      bigarray cannot be used as a drop-in replacement for numpy arrays, but BigArray
      _slices_ are real ndarrays and can be used everywhere ndarray can be used,
      including in C/Fortran code. Slice size is limited by mapping-size (=
      address-space size) limit, i.e. to ~ max 127TB on Linux/amd64.
      
      Changes to bigarray memory are changes to bigfile memory mapping and as such
      can be discarded or saved back to bigfile using mapping (= BigFileH) dirty
      discard/writeout interface.
      
      For the same reason the whole amount of changes to memory is limited by amount
      of physical RAM.
      Kirill Smelkov committed
    • bigfile: BigFile backend to store data in ZODB · 4174b84a
      This adds transactionality and with e.g. NEO[1] allows to distribute
      objects to nodes into cluster.
      
      We hook into ZODB two-phase commit process as a separate data manager,
      and synchronize changes to memory, to changes to object only at that
      time.
      
      Alternative would be to get notified on every page change, and mark
      appropriate object as dirty right at that moment.
      
      But I wanted to stay close to filesystem design (we don't get
      notification for every file change from kernel) - that's why it is done
      the first way.
      
      [1] http://www.neoppod.org/
      Kirill Smelkov committed
    • bigfile: BackFile backend to store data in an OS file · b3910de8
      In Python. To demonstrate how backends could be implemented and test
      system on simple things.
      Kirill Smelkov committed
    • bigfile: Python wrapper around virtual memory subsystem · 35eb95c2
      Exposes BigFile - this way users can define BigFile backend in Python.
      
      Also exposed are BigFile handles, and VMA objects which are results of
      mmaping.
      Kirill Smelkov committed
    • Prepare to test python code with py.test · 8ba39a60
      We'll use py.test for unit-testing of Python part.
      Kirill Smelkov committed
    • bigfile/virtmem: Userspace Virtual Memory Manager · 9a293c2d
      Does similar things to what kernel does - users can mmap file parts into
      address space and access them read/write. The manager will be getting
      invoked by hardware/OS kernel for cases when there is no page loaded for
      read, or when a previousle read-only page is being written to.
      
      Additionally to features provided in kernel, it support to be used to
      store back changes in transactional way (see fileh_dirty_writeout()) and
      potentially use huge pages for mappings (though this is currently TODO)
      Kirill Smelkov committed
    • bigfile/file.h: C interface for defining BigFile backends · 9065e2b9
      Users can inherit from BigFile and provide custom ->loadblk() and
      ->storeblk() to load/store file blocks from a database or some other
      storage. The system then could use such files to memory map them into
      user address space (see next patch).
      Kirill Smelkov committed
    • Script to run compiled linux kernel with root fs mounted from host · 76d8f76d
      Useful to debug (via either printk or gdb) the kernel - one can boot it,
      and tweak compile test program on host and be ready to test it inside
      qemu on tested kernel. Another use case is to add tracing printk to
      kernel and to boot it on each iteration. Booting via qemu means the
      workflow is not disrupted as would with rebooting the hardware.
      
      With this tool it was straightforward to find out why mmap-alias through
      mremap does not work for huge pages:
      
      static struct vm_area_struct *vma_to_resize(unsigned long addr,
              unsigned long old_len, unsigned long new_len, unsigned long *p)
      {
              struct mm_struct *mm = current->mm;
              struct vm_area_struct *vma = find_vma(mm, addr);
      
              if (!vma || vma->vm_start > addr)
                      goto Efault;
      
              if (is_vm_hugetlb_page(vma))            <--
                      goto Einval;
      
      mremap_to(...)
      {
              /* lots of checks, then */
              vma_to_resize(...)
      Kirill Smelkov committed
    • bigfile: RAM subsystem · 8c935a5f
      This thing allows to get aliasable RAM from OS kernel and to manage it.
      Currently we get memory from a tmpfs mount, and hugetlbfs should also
      work, but is TODO because hugetlbfs in the kernel needs to be improved.
      
      We need aliasing because we'll need to be able to memory map the same
      page into several places in address space, e.g. for taking two slices
      overlapping slice of the same array at different times.
      
      Comes with test programs that show we aliasing does not work for
      anonymous memory.
      Kirill Smelkov committed
    • bigfile: Stub for virtmem · 77d61533
      This will be the core of virtual memory subsystem. For now we just
      define a structure to describe pages of memory and add utility to
      allocate address space from OS.
      Kirill Smelkov committed
    • Low-level pagefault handler · 6f7d4d64
      We hook into SIGSEGV and handle read/write pagefaults this way.
      
      In this patch there goes stub code that only detects faults and
      determines (in arch specific way) whether fault was for read or write
      and there is a TODO to pass that information to higher level.
      
      It also comes with tests to detect we still crash if we access something
      incorrectly, so people could have coredumps and investigate them.
      Kirill Smelkov committed
    • bigfile/pagemap: specialized {} uint64 -> void * mapping · 45af76e6
      For BigFiles we'll needs to maintain `{} offset-in-file -> void *` mapping. A
      hash or a binary tree could be used there, but since we know files are
      most of the time accessed sequentially and locally in pages-batches, we
      can also organize the mapping in batches of keys.
      
      Specifically offset bits are so divided into parts, that every part
      addresses 1 entry in a table of hardware-page in size. To get to the actual
      value, the system lookups first table by first part of offset, then from
      first table and next part from address - second table, etc.
      
      To clients this looks like a dictionary with get/set/del & clear methods,
      but lookups are O(1) time always, and in contrast to hashes values are
      stored with locality (= adjacent lookups almost always access the same tables).
      Kirill Smelkov committed
    • bigfile/types.h: Type's we'll use · 8114ad6c
      Kirill Smelkov committed
    • Prepare to unit-test C stuff · cd5646af
      We'll be testing C code in a similiar-to-python way - keep test_*.c
      files nearby and compile/executing them as needed.
      
      Tests are run several times in several ways - as plainly compiled and
      also with additional error checkers:
      
       - AddressSanitizer
       - ThreadSanitizer
       - and similiar checkers from Valgrind
      Kirill Smelkov committed
    • lib/mem: Python utilities to zero, set & copy memory · 699b1375
      Like C bzero / memset & memcopy - but work on python buffers. We
      leverage NumPy for doing actual work, and this way NumPy becomes a
      depenency.
      
      Having NumPy as a dependency is ok - we'll for sure need it later as we
      are trying to build out-of-core ndarrays.
      Kirill Smelkov committed
    • lib/utils: Small C utilities we'll use · 3e5e78cd
      Like taking an exact integer log2, upcasting pointers for C-style
      inheritance done in a Plan9 way, and wrappers to functions which should
      never fail.
      Kirill Smelkov committed
    • lib/bug: Small utilities to say there is a warning, or a todo, or a bug on condition · db28e53f
      Modelled by ones used in Linux kernel.
      Kirill Smelkov committed
    • Basic setup.py / Makefile to build/install/sdist stuff + bigfile.so skeleton · 5755a6b3
      It is an early project decision to use gnu99 & Plan9 C extensions, to
      simplify C code.
      
      So far we only build stub wendelin/bigfile/_bigfile.so .
      
      Makefile is introduced because there will be targets which are easier to
      handle at make level. For end users no make knowledge is required -
      usual `python setup.py build|install|...` work, redirecting to make
      where necessary.
      
      As was promised (e870781d "Top-level in-tree import redirector")
      setup.py contains install-time hooks to handle in-tree wendelin.py and
      install it as a module namespace.
      
      For sdist, we just use `git ls-files` info if we are in a checkout.
      Kirill Smelkov committed
    • Basic .gitignore · 0b7b5f6a
      Prepare for building stuff and add commonly produced files to our
      .gitignore .
      Kirill Smelkov committed
    • Start wendelin.bigfile module · 1e92c921
      This will be a module to allow users to program custom file-like
      backends and latter memory-map content of files from the backend.
      
      For now just start the module structure.
      Kirill Smelkov committed
    • Hook in list.h from Linux · a0f940ad
      Unfortunately in CCAN they made separation of list_head into list_head &
      list_node (for better type safety I suppose), but that leads e.g. to
      inablility to insert element in the middle of the list.
      
      We take the code from util-linux.git (v2.25-165-g9138d6f)[1] which claims
      LGPL license for it, with which we are fine.
      
      [1] https://git.kernel.org/cgit/utils/util-linux/util-linux.git/tree/include/list.h?id=v2.25-165-g9138d6f
      Kirill Smelkov committed
    • Hook in CCAN · ea890863
      CCAN[1] is a "Comprehensive C Archive Network" - a collection of useful
      C libraries to use.
      
      Wendelin.core will be a C project in big part, so having CCAN at hand is
      useful.
      
      We hook CCAN as git submodule, without copying it into git repo. Later
      on making source tarball distribution, the code will be injected into
      generated tarball, so there will be no additional dependencies to
      download something from network for end users.
      
      [1] http://ccodearchive.net/
      Kirill Smelkov committed
    • Top-level in-tree import redirector · e870781d
      For working copy checkout we would like to work on the source
      right-away, without putting it under additional wendelin/ (and possibly
      /core/) subdirectories.
      
      Add in-tree modules redirector which tweaks plain-python and
      pkg_resources-based imports so that e.g.
      
          import wendelin.bigarray
      
      while in-tree resolves to
      
          bigarray/__init__.py
      
      In installed state, there will be no such redirector, and code will be
      installed with conventional structure.
      Kirill Smelkov committed
    • Licensing · 66c976ed
      As a first step we want to make sure the code can be used by open-source
      projects without a problem.
      
      So GPLv3+ with wide exception for all open-source licenses.
      Kirill Smelkov committed
    • Start of wendelin.core.git · f155a6d6
      The project to implement Out-of-core NumPy arrays in backward-compatible
      way.
      Kirill Smelkov committed