Commit 98b23c87 authored by Evgeny Savinov's avatar Evgeny Savinov Committed by Matthijs Douze

Use madvice instead of iteration over data (#503)

parent e4ef2eff
...@@ -223,7 +223,17 @@ int OnDiskInvertedLists::OngoingPrefetch::global_cs = 0; ...@@ -223,7 +223,17 @@ int OnDiskInvertedLists::OngoingPrefetch::global_cs = 0;
void OnDiskInvertedLists::prefetch_lists (const long *list_nos, int n) const void OnDiskInvertedLists::prefetch_lists (const long *list_nos, int n) const
{ {
pf->prefetch_lists (list_nos, n); if (use_madvise) {
for (int i = 0; i < n; ++i) {
const auto list_no = list_nos[i];
const auto size = list_size(list_no);
madvise((void *) get_ids(list_no), size * sizeof(Index::idx_t), MADV_WILLNEED);
madvise((void *) get_codes(list_no), size * code_size, MADV_WILLNEED);
}
} else {
pf->prefetch_lists (list_nos, n);
}
} }
...@@ -327,6 +337,7 @@ OnDiskInvertedLists::OnDiskInvertedLists ( ...@@ -327,6 +337,7 @@ OnDiskInvertedLists::OnDiskInvertedLists (
totsize (0), totsize (0),
ptr (nullptr), ptr (nullptr),
read_only (false), read_only (false),
use_madvise (false),
locks (new LockLevels ()), locks (new LockLevels ()),
pf (new OngoingPrefetch (this)) pf (new OngoingPrefetch (this))
{ {
...@@ -340,6 +351,7 @@ OnDiskInvertedLists::OnDiskInvertedLists (): ...@@ -340,6 +351,7 @@ OnDiskInvertedLists::OnDiskInvertedLists ():
totsize (0), totsize (0),
ptr (nullptr), ptr (nullptr),
read_only (false), read_only (false),
use_madvise (false),
locks (new LockLevels ()), locks (new LockLevels ()),
pf (new OngoingPrefetch (this)) pf (new OngoingPrefetch (this))
{ {
......
...@@ -73,7 +73,8 @@ struct OnDiskInvertedLists: InvertedLists { ...@@ -73,7 +73,8 @@ struct OnDiskInvertedLists: InvertedLists {
size_t totsize; size_t totsize;
uint8_t *ptr; // mmap base pointer uint8_t *ptr; // mmap base pointer
bool read_only; /// are inverted lists mapped read-only bool read_only; /// are inverted lists mapped read-only
bool use_madvise; // use madvice for prefetching
OnDiskInvertedLists (size_t nlist, size_t code_size, OnDiskInvertedLists (size_t nlist, size_t code_size,
const char *filename); const char *filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment