Skip to content

Commit

Permalink
Fix Linux page size calculation (oshi#1060)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis authored Dec 16, 2019
1 parent fd39349 commit 8ab50c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
4.3.0 (in progress)
================
* [#1057](https://github.com/oshi/oshi/pull/1057): Added Subnet Mask & Prefix Length to NetworkIF. - [@vesyrak](https://github.com/Vesyrak).
* [#1060](https://github.com/oshi/oshi/pull/1057): Fixed Linux page size calculation. - [@dbwiddis](https://github.com/dbwiddis).

4.2.0 (11/9/2019), 4.2.1 (11/14/2019)
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
import java.util.List;
import java.util.function.Supplier;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.jna.platform.linux.LibC; // NOSONAR squid:S1191
import com.sun.jna.platform.linux.LibC.Sysinfo;

import oshi.hardware.VirtualMemory;
import oshi.hardware.common.AbstractGlobalMemory;
import oshi.util.ExecutingCommand;
Expand All @@ -47,8 +41,6 @@
*/
public class LinuxGlobalMemory extends AbstractGlobalMemory {

private static final Logger LOG = LoggerFactory.getLogger(LinuxGlobalMemory.class);

private final Supplier<MemInfo> memInfo = memoize(this::readMemInfo, defaultExpiration());

private final Supplier<Long> pageSize = memoize(this::queryPageSize);
Expand Down Expand Up @@ -76,14 +68,9 @@ public VirtualMemory getVirtualMemory() {
}

private long queryPageSize() {
try {
Sysinfo info = new Sysinfo();
if (0 == LibC.INSTANCE.sysinfo(info)) {
return info.mem_unit;
}
} catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
LOG.debug("Failed to get sysinfo. {}", e);
}
// Ideally we would us sysconf(_SC_PAGESIZE) but the constant is platform
// dependent and would require parsing header files, etc. Since this is only
// read once at startup, command line is a reliable fallback.
return ParseUtil.parseLongOrDefault(ExecutingCommand.getFirstAnswer("getconf PAGE_SIZE"), 4096L);
}

Expand Down

0 comments on commit 8ab50c0

Please sign in to comment.