db: Define PAGESZ, inline mmap() args

laumann
Jan 19, 2024, 5:41 AM
TDOR2JDR2SO7FF5LVBJ4GYQXHK7MPLJQJPZMRO6EIRT6AYQNH6CQC

Dependencies

  • [2] ZYBYX2TB Add new pristine subcommand
  • [3] HUOUNPBG db: replace err() macro with die()

Change contents

  • edit in db.h at line 3
    [2.110]
    [2.110]
    /**
    * The sanakirja database exists to allow the creation of data
    * structures that most naturally lives in memory-mapped files.
    *
    * It is structured around pages, through two traits AllocPage and
    * LoadPage. The assumption is that pages have 4K bytes.
    *
    * There is a Storable macro that types can implement to indicate they
    * can be stored on disk. Implementations should allow for comparing
    * types, getting references from a page to other pages (if they
    * exist).
    */
    #define PAGESZ 4096
  • replacement in db.c at line 66
    [2.1783][2.1783:2001]()
    usize length = 4096;
    int prot = PROT_READ; // memory protection; PROT_{EXEC,READ,WRITE,NONE}
    int flags = MAP_PRIVATE; // determines visibility
    off_t offset = 0;
    addr = mmap(NULL, length, prot, flags, fd, offset);
    [2.1783]
    [2.2001]
    addr = mmap(NULL, PAGESZ, PROT_READ, MAP_PRIVATE, fd, 0);
  • replacement in db.c at line 71
    [2.2072][2.2072:2095]()
    munmap(addr, length);
    [2.2072]
    [2.2095]
    munmap(addr, PAGESZ);
  • replacement in db.c at line 79
    [2.2258][2.2258:2313]()
    addr = mmap(NULL, length, prot, flags, fd, i << 12);
    [2.2258]
    [2.2313]
    addr = mmap(NULL, PAGESZ, PROT_READ, MAP_PRIVATE, fd, i << 12);
  • replacement in db.c at line 83
    [2.2387][2.2387:2411]()
    munmap(addr, length);
    [2.2387]
    [2.2411]
    munmap(addr, PAGESZ);