Skip to content

Allow explicit populate of mmap - #4923

Merged
generall merged 11 commits into
devfrom
allow-explicit-populate-of-mmap
Sep 14, 2024
Merged

generall merged 11 commits into
devfrom
allow-explicit-populate-of-mmap

Conversation

@generall

@generall generall commented Aug 19, 2024 •

Copy link
Copy Markdown
Member
  • Instead of in-ram + mmap we can just force mmap in ram with populate
  • Should solve double memory usage of experimental vector storage along with cold start and OOM problems
  • required benchmarks

@generall
generall requested a review from xzfc August 19, 2024 18:43
@generall

Copy link
Copy Markdown
Member Author

image

@generall

Copy link
Copy Markdown
Member Author

depends on #4943

Comment thread lib/collection/src/config.rs Resolved
@generall generall changed the title [WIP] Allow explicit populate of mmap Allow explicit populate of mmap Sep 11, 2024
@generall
generall requested a review from timvisee September 11, 2024 10:18
@generall
generall force-pushed the allow-explicit-populate-of-mmap branch from b80b82b to 78f6b57 Compare September 11, 2024 17:20
Comment on lines +124 to +129
log::warn!(
"Failed to populate mmap{separator}{path:?} to cache: {err}",
separator = separator,
path = path,
err = err
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit:

Suggested change
log::warn!(
"Failed to populate mmap{separator}{path:?} to cache: {err}",
separator = separator,
path = path,
err = err
);
log::warn!(
"Failed to populate mmap{separator}{path:?} to cache: {err}"
);

Also, It was already before this PR, but I don't think this separator logic works as expected. If path is None, it will print this: Failed to populate mmap"" to cache: …. Maybe it should be like this:

let path = path.map_or_else(|| "".to_string(), |path| format!(" {path:?}"));
…
log::warn!("Failed to populate mmap{path} to cache: {err}");

Comment thread lib/common/memory/src/madvise.rs Outdated

fn populate(&self) -> io::Result<()> {
#[cfg(target_os = "linux")]
self.advise(memmap2::Advice::PopulateRead)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option requires Linux 5.14+. Some long-term supported distros (e.g. RHEL 8 and Ubuntu 20.04) still have older kernels. Maybe it would make sense to check beforehand if it is supported and fallback to the loop implementation if it isn't. Quote from madvise(2):

madvise(0, 0, advice) will return zero iff advice is supported by the kernel and can be relied on to probe for support.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check could be like this:

fn populate_read_is_supported() -> bool {
    use std::sync::OnceLock;
    static IS_SUPPORTED: OnceLock<bool> = OnceLock::new();
    *IS_SUPPORTED.get_or_init(|| unsafe {
        libc::madvise(std::ptr::null_mut(), 0, Advice::PopulateRead as libc::c_int) == 0
    })
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're running 5.14 (at least) in the cloud I don't think we should care too much about older versions.

We can, but I prefer to keep things simpler.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases we do use an older kernel version. So, lets follow your suggestion with the runtime check.

@xzfc I've tagged you in Slack where we've discussed this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recap: we still have older versions somewhere.

And even if we didn't, performing this tiny check shouldn't complicate things much, since we already have the fallback code for non-Linux systems.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented that in the last commit to this PR. It uses a new mmap2::Advise::is_supported() method added in https://www.github.com/RazrFalcon/memmap2-rs/pull/122.

@xzfc
xzfc force-pushed the allow-explicit-populate-of-mmap branch 2 times, most recently from 72466d8 to 5c3912d Compare September 12, 2024 20:06

@timvisee timvisee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming the open review comments get resolved

@generall
generall merged commit e8d5cfc into dev Sep 14, 2024
@generall
generall deleted the allow-explicit-populate-of-mmap branch September 14, 2024 18:53
@timvisee timvisee mentioned this pull request Sep 16, 2024
6 tasks done
Comment thread Cargo.toml
Comment on lines +252 to +253
# Temporary patch until memmap2 0.9.5 is released.
memmap2 = { git = "https://github.com/RazrFalcon/memmap2-rs" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We bump this to the latest release in #5085.

timvisee pushed a commit that referenced this pull request Sep 17, 2024
* expose mmap populate

* expose mmap populate in open_read_mmap

* FOR TEST, REVERSE IT: make InRamChunkedMmap default

* enable populate advise on unix

* fix clippy

* unix -> linux

* Update lib/collection/src/config.rs

* clippy fixes

* resolve conflicts

* fmt

* Runtime check for PopulateRead

---------

Co-authored-by: xzfc <[email protected]>
@timvisee timvisee mentioned this pull request Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants