Skip to content

Commit 313a3e5

Browse files
committed
Check env var OSMIUM_CLEAN_PAGE_CACHE_AFTER_READ
Read OSMIUM_CLEAN_PAGE_CACHE_AFTER_READ to decide whether the page cache should be cleaned by calling fadvise DONT_NEED after reading blocks from an OSM file. Allowed values are "no" and "yes". If set to anything else or not set at all the implementation does what it thinks best, currently it clears the page cache.
1 parent 8a000cf commit 313a3e5

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

include/osmium/io/compression.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace osmium {
9393
std::atomic<std::size_t> m_file_size{0};
9494
std::atomic<std::size_t> m_offset{0};
9595

96-
std::atomic_bool m_want_buffered_pages_removed{true};
96+
std::atomic_bool m_want_buffered_pages_removed{false};
9797

9898
public:
9999

include/osmium/io/reader.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ namespace osmium {
330330
std::promise<osmium::io::Header> header_promise;
331331
m_header_future = header_promise.get_future();
332332

333+
const auto cpc = osmium::config::clean_page_cache_after_read();
334+
if (cpc >= 0) {
335+
m_decompressor->set_want_buffered_pages_removed(true);
336+
}
337+
333338
const int fd_for_parser = m_decompressor->is_real() ? -1 : m_fd;
334339
m_thread = osmium::thread::thread_handler{parser_thread, std::ref(*m_pool), fd_for_parser, std::ref(m_creator),
335340
std::ref(m_input_queue), std::ref(m_osmdata_queue),

include/osmium/util/config.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ namespace osmium {
103103
return value;
104104
}
105105

106+
inline int8_t clean_page_cache_after_read() noexcept {
107+
const char* env = osmium::detail::getenv_wrapper("OSMIUM_CLEAN_PAGE_CACHE_AFTER_READ");
108+
if (env) {
109+
if (!strcasecmp(env, "yes")) {
110+
return 1;
111+
}
112+
if (!strcasecmp(env, "no")) {
113+
return -1;
114+
}
115+
}
116+
return 0;
117+
}
118+
106119
} // namespace config
107120

108121
} // namespace osmium

0 commit comments

Comments
 (0)