code: func (db *DB) mmap(minsz int) error {
  	db.mmaplock.Lock()
  	defer db.mmaplock.Unlock()
  
  	info, err := db.file.Stat()
  	if err != nil {
  		return fmt.Errorf("mmap stat error: %s", err)
  	} else if int(info.Size()) < db.pageSize*2 {
  		return fmt.Errorf("file size too small")
  	}
  
  	// Ensure the size is at least the minimum size.
  	var size = int(info.Size())
  	if size < minsz {
  		size = minsz
  	}
  	size, err = db.mmapSize(size)
  	if err != nil {
  		return err
  	}
  
  	// Dereference all mmap references before unmapping.
  	if db.rwtx != nil {
  		db.rwtx.root.dereference()
  	}
  
  	// Unmap existing data before continuing.
  	if err := db.munmap(); err != nil {
  		return err
  	}
  
  	// Memory-map the data file as a byte slice.
  	if err := mmap(db, size); err != nil {
  		return err
  	}
  
  	// Save references to the meta pages.
  	db.meta0 = db.page(0).meta()
  	db.meta1 = db.page(1).meta()
  
  	// Validate the meta pages. We only return an error if both meta pages fail
  	// validation, since meta0 failing validation means that it wasn't saved
  	// properly -- but we can recover using meta1. And vice-versa.
  	err0 := db.meta0.validate()
  	err1 := db.meta1.validate()
  	if err0 != nil && err1 != nil {
  		return err0
  	}
  
  	return nil
  }
docs: // mmap opens the underlying memory-mapped file and initializes the meta references.
  // minsz is the minimum size that the new mmap can be.