Skip to content

Commit 5baf5ca

Browse files
committed
Cleanup.
1 parent 58c0d99 commit 5baf5ca

File tree

4 files changed

+10
-31
lines changed

4 files changed

+10
-31
lines changed

src/common/io.cc

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,32 +172,21 @@ std::size_t GetPageSize() {
172172
#if defined(_MSC_VER)
173173
SYSTEM_INFO sys_info;
174174
GetSystemInfo(&sys_info);
175-
// During testing, `sys_info.dwPageSize` is of size 4096 while `dwAllocationGranularity` is of size 65536.
175+
// During testing, `sys_info.dwPageSize` is of size 4096 while `dwAllocationGranularity` is of
176+
// size 65536.
176177
return sys_info.dwAllocationGranularity;
177178
#else
178179
return getpagesize();
179180
#endif
180181
}
181182

182-
std::size_t PadPageForMmap(std::size_t file_bytes, dmlc::Stream* fo) {
183-
decltype(file_bytes) page_size = GetPageSize();
184-
CHECK(page_size != 0 && page_size % 2 == 0) << "Failed to get page size on the current system.";
185-
CHECK_NE(file_bytes, 0) << "Empty page encountered.";
186-
auto n_pages = file_bytes / page_size + !!(file_bytes % page_size != 0);
187-
auto padded = n_pages * page_size;
188-
auto padding = padded - file_bytes;
189-
std::vector<std::uint8_t> padding_bytes(padding, 0);
190-
// fo->Write(padding_bytes.data(), padding_bytes.size());
191-
return file_bytes;
192-
}
193-
194183
struct PrivateMmapStream::MMAPFile {
195184
#if defined(_MSC_VER)
196-
HANDLE fd{ INVALID_HANDLE_VALUE };
185+
HANDLE fd{INVALID_HANDLE_VALUE};
197186
#else
198-
std::int32_t fd {0};
187+
std::int32_t fd{0};
199188
#endif
200-
char* base_ptr{ nullptr };
189+
char* base_ptr{nullptr};
201190
std::size_t base_size{0};
202191
std::string path;
203192
};
@@ -255,7 +244,7 @@ char* PrivateMmapStream::Open(std::string path, bool read_only, std::size_t offs
255244
CHECK_NE(ptr, MAP_FAILED) << "Failed to map: " << path << ". " << strerror(errno);
256245
#endif // defined(__linux__)
257246

258-
handle_.reset(new MMAPFile{ fd, ptr, view_size, std::move(path) });
247+
handle_.reset(new MMAPFile{fd, ptr, view_size, std::move(path)});
259248
ptr += (offset - view_start);
260249
return ptr;
261250
}
@@ -272,7 +261,8 @@ PrivateMmapStream::~PrivateMmapStream() {
272261
#else
273262
CHECK_NE(munmap(handle_->base_ptr, handle_->base_size), -1)
274263
<< "Faled to munmap." << handle_->path << ". " << strerror(errno);
275-
CHECK_NE(close(handle_->fd), -1) << "Faled to close: " << handle_->path << ". " << strerror(errno);
264+
CHECK_NE(close(handle_->fd), -1)
265+
<< "Faled to close: " << handle_->path << ". " << strerror(errno);
276266
#endif
277267
}
278268
} // namespace common

src/common/io.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,6 @@ inline std::string ReadAll(std::string const &path) {
130130
}
131131

132132
std::size_t GetPageSize();
133-
/**
134-
* @brief Pad the output file for a page to make it mmap compatible.
135-
*
136-
* @param file_bytes The size of the output file
137-
* @param fo Stream used to write the file.
138-
*
139-
* @return The file size after being padded.
140-
*/
141-
std::size_t PadPageForMmap(std::size_t file_bytes, dmlc::Stream* fo);
142133

143134
/**
144135
* @brief Private mmap file, copy-on-write. File must be properly aligned by `PadPageForMmap()`.

src/data/sparse_page_source.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,11 @@ class SparsePageSourceImpl : public BatchIteratorImpl<S> {
174174
}
175175

176176
auto bytes = fmt->Write(*page_, fo.get());
177-
auto padded = common::PadPageForMmap(bytes, fo.get());
178177

179178
timer.Stop();
180179
LOG(INFO) << static_cast<double>(bytes) / 1024.0 / 1024.0 << " MB written in "
181180
<< timer.ElapsedSeconds() << " seconds.";
182-
cache_info_->Push(padded);
181+
cache_info_->Push(bytes);
183182
}
184183

185184
virtual void Fetch() = 0;

tests/cpp/common/test_io.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ TEST(IO, PrivateMmapStream) {
111111
fo->Write(data.data(), data.size() * sizeof(T));
112112

113113
std::size_t bytes = sizeof(std::uint64_t) + data.size() * sizeof(T);
114-
auto padded = common::PadPageForMmap(bytes, fo.get());
115-
offset.push_back(padded);
114+
offset.push_back(bytes);
116115

117116
batches.emplace_back(std::move(data));
118117
}

0 commit comments

Comments
 (0)