func (m *arenaManager) unloadArena(aid int) error {
	if m.arenas[aid-m.baseAid] == nil {
		return nil
	}
	if err := m.arenas[aid-m.baseAid].Unmap(); err != nil {
		return fmt.Errorf("error in unmap :: %w", err)
	}
	m.inMem--
	m.arenas[aid-m.baseAid] = nil
	return nil
}
unloadArena will remove the arena from memory.
package bigqueue
import (
	"fmt"
	"path"
	"strconv"
	"syscall"
	"github.com/grandecola/mmap"
)
const (
	cArenaFileSuffix = "_arena.dat"
)
type arenaManager struct {
	dir       string
	conf      *bqConfig
	md        *metadata
	baseAid   int
	arenas    []*mmap.File
	inMem     int
	fullPath  []byte
}
func newArenaManager(dir string, conf *bqConfig, md *metadata) (*arenaManager, error) {
	headAid, _ := md.getHead()
	tailAid, _ := md.getTail()
	numArenas := tailAid + 1 - headAid
	arenas := make([]*mmap.File, numArenas)
	am := &arenaManager{
		dir:     path.Clean(dir),
		conf:    conf,
		md:      md,
		baseAid: headAid,
		arenas:  arenas,
	}
	if err := am.loadArena(tailAid); err != nil {
		return nil, err
	}
	return am, nil
}
func (m *arenaManager) getArena(aid int) (*mmap.File, error) {
	relAid := aid - m.baseAid
	if relAid == len(m.arenas) {
		m.arenas = append(m.arenas, nil)
	}
	aa := m.arenas[relAid]
	if aa != nil {
		return aa, nil
	}
	if err := m.ensureEnoughMem(); err != nil {
		return nil, err
	}
	if err := m.loadArena(aid); err != nil {
		return nil, err
	}
	return m.arenas[aid], nil
}
func (m *arenaManager) ensureEnoughMem() error {
	if m.conf.maxInMemArenas == 0 {
		return nil
	}
	if m.inMem < m.conf.maxInMemArenas {
		return nil
	}
	tailAid, _ := m.md.getTail()
	curAid := m.baseAid + len(m.arenas)
	for m.conf.maxInMemArenas-m.inMem <= 0 {
		curAid--
		if curAid < 0 {
			panic("not enough memory to hold arenas in memory")
		}
		if curAid == tailAid {
			continue
		}
		if err := m.unloadArena(curAid); err != nil {
			return err
		}
	}
	return nil
}
func (m *arenaManager) loadArena(aid int) error {
	if m.arenas[aid-m.baseAid] != nil {
		return nil
	}
	m.fullPath = append(m.fullPath[:0], m.dir...)
	m.fullPath = append(m.fullPath, '/')
	m.fullPath = strconv.AppendInt(m.fullPath, int64(aid), 10)
	m.fullPath = append(m.fullPath, cArenaFileSuffix...)
	aa, err := newArena(string(m.fullPath), m.conf.arenaSize)
	if err != nil {
		return err
	}
	m.inMem++
	m.arenas[aid-m.baseAid] = aa
	return nil
}