Skip to content

Commit 5dcc2fe

Browse files
committed
Mark page cache blocks as DONT_NEED later,
So we are sure we don't need them again.
1 parent 0cf064c commit 5dcc2fe

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

include/osmium/io/detail/pbf_input_format.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ namespace osmium {
133133

134134
*m_offset_ptr += size;
135135

136-
if (m_want_buffered_pages_removed && size > 100) {
137-
// The size check is there to avoid the system call
138-
// when we have only been reading a small number of
139-
// bytes, i.e. for a header.
140-
osmium::io::detail::remove_buffered_pages(m_fd, *m_offset_ptr);
141-
}
142-
143136
return true;
144137
}
145138

@@ -267,6 +260,10 @@ namespace osmium {
267260
} else {
268261
send_to_output_queue(data_blob_parser());
269262
}
263+
264+
if (m_want_buffered_pages_removed) {
265+
osmium::io::detail::remove_buffered_pages(m_fd, *m_offset_ptr);
266+
}
270267
}
271268
}
272269

include/osmium/io/detail/read_write.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ namespace osmium {
272272
#ifdef __linux__
273273
inline void remove_buffered_pages(int fd, std::size_t size) noexcept {
274274
constexpr const std::size_t block_size = 4096;
275-
if (fd > 0 && size > 0) {
275+
// Make sure to keep the last 10 blocks around, so were are
276+
// definitely not removing something which might be needed
277+
// again soon.
278+
if (fd > 0 && size > 10 * block_size) {
279+
size -= 10 * block_size;
276280
::posix_fadvise(fd, 0, (size - 1) & ~(block_size - 1), POSIX_FADV_DONTNEED);
277281
}
278282
#else

0 commit comments

Comments
 (0)