-
Notifications
You must be signed in to change notification settings - Fork 7
Select mmap madvise by index type: MADV_RANDOM for DiskSeismic, not a global hugepage default #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chishui
merged 1 commit into
opensearch-project:main
from
zirui-song-18:mmap-advise-per-index-type
Sep 14, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| #include "nsparse/utils/mmap_file.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <cstring> | ||
| #include <filesystem> | ||
| #include <fstream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace nsparse { | ||
| namespace { | ||
|
|
||
| using AccessPattern = MmapFile::AccessPattern; | ||
|
|
||
| // The per-type default: DiskSeismic (point lookups of ~k' small inline blocks) | ||
| // must suppress readahead with MADV_RANDOM, while the scanned shared forward | ||
| // index collapses to huge pages. A regression here silently reinstates the | ||
| // ~860x read amplification that makes per_block look slower than shared. | ||
| TEST(MmapFileAdvise, DefaultsByAccessPattern) { | ||
| EXPECT_EQ(MmapFile::resolve_advise(AccessPattern::kPointLookup, nullptr), | ||
| "random"); | ||
| EXPECT_EQ(MmapFile::resolve_advise(AccessPattern::kScan, nullptr), | ||
| "hugepage"); | ||
| } | ||
|
|
||
| // NSPARSE_MMAP_ADVISE overrides the per-type default, for either pattern. | ||
| TEST(MmapFileAdvise, EnvOverridesEitherPattern) { | ||
| for (const char* env : {"hugepage", "random", "normal", "hugetlb"}) { | ||
| EXPECT_EQ(MmapFile::resolve_advise(AccessPattern::kPointLookup, env), | ||
| env); | ||
| EXPECT_EQ(MmapFile::resolve_advise(AccessPattern::kScan, env), env); | ||
| } | ||
| } | ||
|
|
||
| // An empty env var (set but "") is treated as unset, not as an override that | ||
| // would silently force the "hugepage" fallback and undo DiskSeismic's default. | ||
| TEST(MmapFileAdvise, EmptyEnvIsTreatedAsUnset) { | ||
| EXPECT_EQ(MmapFile::resolve_advise(AccessPattern::kPointLookup, ""), | ||
| "random"); | ||
| EXPECT_EQ(MmapFile::resolve_advise(AccessPattern::kScan, ""), "hugepage"); | ||
| } | ||
|
|
||
| // The access-pattern hint is advisory: the mapping returns the file's bytes | ||
| // unchanged under either pattern. | ||
| TEST(MmapFileAdvise, MapsSameBytesUnderEitherPattern) { | ||
| const std::filesystem::path path = | ||
| std::filesystem::temp_directory_path() / "nsparse_mmap_advise_test.bin"; | ||
| std::vector<uint8_t> payload(8192); | ||
| for (size_t i = 0; i < payload.size(); ++i) { | ||
| payload[i] = static_cast<uint8_t>(i * 7 + 1); | ||
| } | ||
| { | ||
| std::ofstream out(path, std::ios::binary | std::ios::trunc); | ||
| out.write(reinterpret_cast<const char*>(payload.data()), | ||
| static_cast<std::streamsize>(payload.size())); | ||
| } | ||
|
|
||
| for (const AccessPattern access : | ||
| {AccessPattern::kPointLookup, AccessPattern::kScan}) { | ||
| MmapFile file(path.string(), access); | ||
| ASSERT_EQ(file.size(), payload.size()); | ||
| ASSERT_NE(file.data(), nullptr); | ||
| EXPECT_EQ(std::memcmp(file.data(), payload.data(), payload.size()), 0); | ||
| } | ||
|
|
||
| std::error_code ignored; | ||
| std::filesystem::remove(path, ignored); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace nsparse |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previous logic is: for all indices, no madvise is called, now you change to only set disk seismic index to random