1 Reply Latest reply on Apr 23, 2009 5:11 AM by 524300

    BerkeleyDB-4.7.25 with the option O_DIRECT and  Invalid argument


      I am quite new to Berkeley DB.
      I have been trying to test BerkeleyDB-4.7.25 with the option O_DIRECT.
      I have compiled it for 64bits Linux (2.6.26 ) with the BDB options enable-o_direct enable-cxx

      I have set the DB_CONFIG to read
      set_flags DB_DIRECT_DB

      In C++ code the database is open (database file type is BTREE) properly (no errors).
      The open gets executed properly and the O_DIRECT flag is passed.
      After having done a bunch of puts into the DB,
      an error gets generated saying:

      read: ... ..., 4096 Invalid ....

      if the pagesize get set to set_pagesize(1024)


      read ... , 1024 Invalid ....

      if pagesize is set to 512
      read: 0x7fa4c526b1a0, 512: Invalid argument

      All of that does not happen if a patch submitted in 2007 is applied

      Question, please:

      Is there any way to use DB_DIRECT_DB with success (4.7.25) on without the need to apply that patch ?
      Am I missing something ?

      Thanks a lot for your help,

        • 1. Re: BerkeleyDB-4.7.25 with the option O_DIRECT and  Invalid argument
          That patch is required. After discussion with the openldap developers, Oracle decided not to integrate this change with Berkeley DB. Firstly, in general we don't know at compile time what Linux kernel will be used at runtime, so while it may be reasonable in many cases to make a build-time assumption about the virtual memory page size, we can't do so in all cases. Further, as far as we know, there is no easy way to work out at runtime what alignment is required.

          Lastly, even if we could work out the right page size, it is not clear how useful this really is anyway, since it is wasting quite a lot of space in the Berkeley DB cache in order to save space in the Linux filesystem cache. This is due to Berkeley DB's layout of data structures in shared memory, which is something we have considered changing so that buffers are naturally aligned to page boundaries, but that is a large piece of work that is not currently scheduled.

          The advice we have had is that setting swappiness to zero on Linux is usually a better solution that trying to make Berkeley DB use O_DIRECT. See http://kerneltrap.org/node/3000 for details and discussion.

          Michael Cahill, Oracle Berkeley DB.