File tree 1 file changed +9
-11
lines changed
1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -258,23 +258,21 @@ struct text_region FindNodeTextRegion() {
258
258
259
259
#if defined(__linux__)
260
260
bool IsTransparentHugePagesEnabled () {
261
- std::ifstream ifs;
262
-
263
261
// File format reference:
264
262
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/huge_memory.c?id=13391c60da3308ed9980de0168f74cce6c62ac1d#n163
265
- ifs.open (" /sys/kernel/mm/transparent_hugepage/enabled" );
266
- if (!ifs) {
263
+ const char * filename = " /sys/kernel/mm/transparent_hugepage/enabled" ;
264
+ std::ifstream config_stream (filename, std::ios::in);
265
+ if (!config_stream.good ()) {
267
266
PrintWarning (" could not open /sys/kernel/mm/transparent_hugepage/enabled" );
268
267
return false ;
269
268
}
270
269
271
- std::string always, madvise;
272
- if (ifs.is_open ()) {
273
- ifs >> always >> madvise;
274
- }
275
- ifs.close ();
276
-
277
- return always == " [always]" || madvise == " [madvise]" ;
270
+ std::string token;
271
+ config_stream >> token;
272
+ if (" [always]" == token) return true ;
273
+ config_stream >> token;
274
+ if (" [madvise]" == token) return true ;
275
+ return false ;
278
276
}
279
277
#elif defined(__FreeBSD__)
280
278
bool IsSuperPagesEnabled () {
You can’t perform that action at this time.
0 commit comments