View Javadoc
1   /*
2    * Copyright 2020-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware.platform.unix.aix;
6   
7   import java.util.function.Supplier;
8   
9   import com.sun.jna.platform.unix.aix.Perfstat.perfstat_memory_total_t;
10  
11  import oshi.annotation.concurrent.ThreadSafe;
12  import oshi.hardware.common.AbstractVirtualMemory;
13  
14  /**
15   * Memory obtained by perfstat_memory_total_t
16   */
17  @ThreadSafe
18  final class AixVirtualMemory extends AbstractVirtualMemory {
19  
20      // Memoized perfstat from GlobalMemory
21      private final Supplier<perfstat_memory_total_t> perfstatMem;
22  
23      // AIX has multiple page size units, but for purposes of "pages" in perfstat,
24      // the docs specify 4KB pages so we hardcode this
25      private static final long PAGESIZE = 4096L;
26  
27      /**
28       * Constructor for SolarisVirtualMemory.
29       *
30       * @param perfstatMem The memoized perfstat data from the global memory class
31       */
32      AixVirtualMemory(Supplier<perfstat_memory_total_t> perfstatMem) {
33          this.perfstatMem = perfstatMem;
34      }
35  
36      @Override
37      public long getSwapUsed() {
38          perfstat_memory_total_t perfstat = perfstatMem.get();
39          return (perfstat.pgsp_total - perfstat.pgsp_free) * PAGESIZE;
40      }
41  
42      @Override
43      public long getSwapTotal() {
44          return perfstatMem.get().pgsp_total * PAGESIZE;
45      }
46  
47      @Override
48      public long getVirtualMax() {
49          return perfstatMem.get().virt_total * PAGESIZE;
50      }
51  
52      @Override
53      public long getVirtualInUse() {
54          return perfstatMem.get().virt_active * PAGESIZE;
55      }
56  
57      @Override
58      public long getSwapPagesIn() {
59          return perfstatMem.get().pgspins;
60      }
61  
62      @Override
63      public long getSwapPagesOut() {
64          return perfstatMem.get().pgspouts;
65      }
66  }