fix mmap error in OSX
parent
3bdc5abeaf
commit
3b56a79f45
|
@ -233,19 +233,20 @@ void OnDiskInvertedLists::prefetch_lists (const long *list_nos, int n) const
|
||||||
|
|
||||||
void OnDiskInvertedLists::do_mmap ()
|
void OnDiskInvertedLists::do_mmap ()
|
||||||
{
|
{
|
||||||
const char *rw_flags = read_only ? "r" : "rw+";
|
const char *rw_flags = read_only ? "r" : "r+";
|
||||||
int prot = read_only ? PROT_READ : PROT_WRITE | PROT_READ;
|
int prot = read_only ? PROT_READ : PROT_WRITE | PROT_READ;
|
||||||
FILE *f = fopen (filename.c_str(), rw_flags);
|
FILE *f = fopen (filename.c_str(), rw_flags);
|
||||||
FAISS_THROW_IF_NOT_FMT (f, "could not open %s in mode %s: %s",
|
FAISS_THROW_IF_NOT_FMT (f, "could not open %s in mode %s: %s",
|
||||||
filename.c_str(), rw_flags, strerror(errno));
|
filename.c_str(), rw_flags, strerror(errno));
|
||||||
|
|
||||||
ptr = (uint8_t*)mmap (nullptr, totsize,
|
uint8_t * ptro = (uint8_t*)mmap (nullptr, totsize,
|
||||||
prot, MAP_SHARED, fileno (f), 0);
|
prot, MAP_SHARED, fileno (f), 0);
|
||||||
|
|
||||||
FAISS_THROW_IF_NOT_FMT (ptr != MAP_FAILED,
|
FAISS_THROW_IF_NOT_FMT (ptro != MAP_FAILED,
|
||||||
"could not mmap %s: %s",
|
"could not mmap %s: %s",
|
||||||
filename.c_str(),
|
filename.c_str(),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
ptr = ptro;
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -334,6 +335,8 @@ OnDiskInvertedLists::OnDiskInvertedLists (
|
||||||
|
|
||||||
OnDiskInvertedLists::OnDiskInvertedLists ():
|
OnDiskInvertedLists::OnDiskInvertedLists ():
|
||||||
InvertedLists (0, 0),
|
InvertedLists (0, 0),
|
||||||
|
totsize (0),
|
||||||
|
ptr (nullptr),
|
||||||
read_only (false),
|
read_only (false),
|
||||||
locks (new LockLevels ()),
|
locks (new LockLevels ()),
|
||||||
pf (new OngoingPrefetch (this))
|
pf (new OngoingPrefetch (this))
|
||||||
|
|
Loading…
Reference in New Issue