Skip to content

Separate RSS from the private/footprint memory shown by graphical system monitors - #3082

Merged
dbwiddis merged 16 commits into
oshi:masterfrom
dyorgio:macos-memory-footprint
Mar 10, 2026
Merged

dbwiddis merged 16 commits into
oshi:masterfrom
dyorgio:macos-memory-footprint

Conversation

@dyorgio

@dyorgio dyorgio commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Add getMemoryFootprint method on OSProcess class.

The objective is get a memory size value like in end user task manager.

In linux and Windows RSS value appears to be ok, but on macOS values showed in "Activity Monitor" are very different of it.

Summary by CodeRabbit

  • New Features

    • Per-process memory split into Resident and Private (footprint) values across platforms; Windows exposes both private and total working set. Added sorting by private memory and a Private memory column in process views. Old RSS-based metric retained for compatibility but deprecated.
  • Tests

    • Updated tests to assert both resident and private memory values.
  • Documentation

    • Changelog and download snapshots updated to 6.11.0-SNAPSHOT.

@coderabbitai

coderabbitai Bot commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Add explicit resident vs. private resident memory APIs (getResidentMemory(), getPrivateResidentMemory()), deprecate getResidentSetSize() (delegates), propagate separate fields through platform implementations, update Windows perf/registry counters, tests, UI, and bump snapshot/version to 6.11.0-SNAPSHOT.

Changes

Cohort / File(s) Summary
Core interface
oshi-core/src/main/java/oshi/software/os/OSProcess.java
Add getResidentMemory() and getPrivateResidentMemory() (defaulting to resident); deprecate getResidentSetSize() (delegates); update Javadoc and header year.
Sorting / OS utilities
oshi-core/src/main/java/oshi/software/os/OperatingSystem.java
Switch RSS comparator to getResidentMemory(); add comparator for private/footprint memory (descending) using getPrivateResidentMemory().
macOS FFM schema
oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystem.java
Add RI_PHYS_FOOTPRINT PathElement for ri_phys_footprint.
macOS FFM implementation
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
Add memoryFootprint field; rename RSS getter to getResidentMemory(); add getPrivateResidentMemory(); prefer ri_phys_footprint over RSS when present.
macOS JVM implementation
oshi-core/src/main/java/oshi/software/os/mac/MacOSProcess.java
Add memoryFootprint field; rename getResidentSetSize()→getResidentMemory(); add getPrivateResidentMemory(); populate from RUsage V2 footprint when available.
Windows perf & registry
oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformation.java, oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
Expose both total and private working set counters; update enum, PerfCounterBlock ctor, fields and getters to carry workingSetSize and privateWorkingSetSize; update call sites.
Windows process class
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
Replace residentSetSize with workingSetSize and privateWorkingSetSize; add getResidentMemory() and getPrivateResidentMemory(); mark getResidentSetSize() deprecated and delegate to private value.
Linux process
oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
Add privateResidentMemory and getPrivateResidentMemory(); rename getResidentSetSize()→getResidentMemory(); parse /proc/[pid]/statm to compute resident and private resident memory with RSS fallback.
Other UNIX variants
oshi-core/src/main/java/oshi/software/os/unix/...
AixOSProcess.java, FreeBsdOSProcess.java, OpenBsdOSProcess.java, SolarisOSProcess.java
Rename getResidentSetSize()→getResidentMemory(); Solaris adds residentSetSizePrivate and getPrivateResidentMemory() population.
Tests & UI output
oshi-core/src/test/java/..., oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java, CHANGELOG.md
Update tests to assert getResidentMemory() and getPrivateResidentMemory(); add Private memory column to outputs/UI; add CHANGELOG entry for PR #3082.
Build & docs versioning
pom.xml, oshi-core/pom.xml, oshi-core-java11/pom.xml, oshi-core-java25/pom.xml, oshi-dist/pom.xml, oshi-demo/pom.xml, README.md, src/site/markdown/index.md
Bump snapshot/version references from 6.10.1-SNAPSHOT to 6.11.0-SNAPSHOT and update download links.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant OS as OperatingSystem
    participant Proc as OSProcess
    participant Native as Native/Platform

    Client->>OS: request process list / sort by footprint
    OS->>Proc: getPrivateResidentMemory()
    alt platform provides private value
        Proc-->>OS: privateResidentMemory (private working set / footprint)
    else fallback to resident
        Proc->>Proc: getResidentMemory()
        Proc-->>OS: residentMemory (RSS)
    end
    alt macOS FFM path
        Proc->>Native: read ri_phys_footprint (RUSAGE_INFO_V2)
        Native-->>Proc: ri_phys_footprint or RSS fallback
        Proc-->>OS: memoryFootprint
    end
    OS-->>Client: return sorted process list
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through bytes and native trace,
Found footprints hidden in each place,
RSS or phys when true,
Private counts now show the view,
🥕 cheers to PR three-oh-eight-two

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.49% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main objective: separating resident memory (RSS) from private/footprint memory measurements. The changes introduce getResidentMemory() and getPrivateResidentMemory() across all platforms with platform-specific implementations, directly addressing the title's goal of distinguishing these two memory metrics for graphical system monitors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Mar 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.30%. Comparing base (86879d6) to head (91d9038).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...core/src/main/java/oshi/software/os/OSProcess.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3082      +/-   ##
==========================================
+ Coverage   84.58%   85.30%   +0.72%     
==========================================
  Files          33       33              
  Lines        1466     1470       +4     
  Branches      216      216              
==========================================
+ Hits         1240     1254      +14     
+ Misses        131      118      -13     
- Partials       95       98       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java`:
- Line 170: The field declaration "private lgon memoryFootprint;" uses an
invalid type token "lgon"; update the type to the correct Java primitive "long"
for the field "memoryFootprint" in the MacOSProcessFFM class so it reads
"private long memoryFootprint;" and rebuild to ensure compilation succeeds.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f623b9c and 91d240f.

📒 Files selected for processing (1)
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java (1)

531-532: Memory footprint fallback/override flow looks correct.

Using RSS as default (Line 531-Line 532) and overriding with ri_phys_footprint when available (Line 557), then exposing via getMemoryFootprint() (Line 354-Line 357), is a good compatibility pattern.

Also applies to: 552-558, 354-357

@dbwiddis

dbwiddis commented Mar 5, 2026

Copy link
Copy Markdown
Member

Thanks for this PR!

Code-wise, it's ready to merge, but I want to discuss what we currently display and how we name it.

I changed the Javadoc for your new method to describe what it actually measures (footprint) rather than what you describe (the OS display).

However, on Windows, we already display this "footprint" value (the Private Bytes / Working Set - Private value), rather than just Working Set Size (WSS) which is the closer analog to RSS.

Current end users probably already use the existing RSS method to recreate "Task Manager" displays (just look at the oshi-demo project) so we can't really change that to be more accurate on macOS without breaking expectations, and I expect users of top and friends would still want to see the RSS value!

We also should consider the true Linux footprint, possibly Proportional Set Size (/proc/<pid>/smaps_rollup) as a closer "footprint" analog.

Here's the landscape:

"What does this process cost the system?" (Footprint) "What physical pages are resident?" (RSS)
macOS phys_footprint (Activity Monitor "Memory" column) ri_resident_size (traditional RSS)
Windows Private Bytes / Private Working Set Working Set Size
Linux PSS (/proc/<pid>/smaps_rollup) RSS (/proc/<pid>/stat)
Unix ? ?
current OSHI getResidentSetSize() Windows (Private WS) macOS (RSS), Linux (RSS)

So we have an inconsistency today: Windows users already get the "footprint" style value from getResidentSetSize(), while macOS and Linux users get the traditional RSS.

I think the right path forward is:

  1. Add getResidentMemory() to return true RSS consistently on all platforms (keep existing "RSS" implementations on *nix, but change Windows to Working Set Size).
  2. Extend getMemoryFootprint() (as proposed in this PR) to all platforms — returning the "what does the OS charge this process" value (macOS phys_footprint, Windows Private Bytes (current Windows RSS implementation), Linux PSS).
  3. Deprecate getResidentSetSize() due to its ambiguity.
    • Internally redirect to one of the two above methods to preserve existing behavior.
    • In the javadoc, redirect to a newly named method getDisplayedMemoryUsage() (or some better name) that fills the purpose of what you proposed in your earlier javadoc which changes the macOS behavior (and possibly Linux).
    • This new method (intended for end users to match OS process displays) would be the new main entry point intended for end users for the new changed but accurate behavior.

This gives users two clearly distinct methods with consistent cross-platform semantics, and the names actually describe what they return. Plus they have a common entry point for those who want to match their UI displays (which may differ from top or ps outputs).

Open Question: On Linux, PSS is the best "footprint" analog but requires reading smaps_rollup, which has a performance cost and may need elevated permissions. We may want to fall back to RssAnon + VmSwap from /proc/<pid>/status as a cheaper alternative, or just document the limitation.

Happy to merge this PR now and address these questions in a follow-on PR, or if you want to do the redesign in this PR we can handle that as well. Let me know what you think.

@dyorgio

dyorgio commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @dbwiddis, I did some research in Gnome System Monitor source and get this:

Captura de Tela 2026-03-06 às 17 56 53

What do you think?

@dbwiddis

dbwiddis commented Mar 6, 2026 •

Copy link
Copy Markdown
Member

What do you think?

Looks pretty accurate to me! Is that "resident" - "shared"? (Edit: yes it is, from gnome source code proc_mem.resident - proc_mem.share)

@dbwiddis

dbwiddis commented Mar 6, 2026

Copy link
Copy Markdown
Member

Summarizing:

  • we clearly have two different memory outputs on Win/Mac/Linux, a UI/manager value (your original javadoc) and RSS (what comes from ps or top)
  • current RSS is inconsistent
  • we need to make both values available. open to naming ideas.
  • we should deprecate RSS while keeping its current interpretation, suggesting either of the alternatives

@dbwiddis

dbwiddis commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

Proposed New Method Names/Javadoc description:

getResidentMemory(): Returns the total amount of physical memory (RAM) currently mapped to the process's address space. This value represents the Resident Set Size (RSS) and includes both private memory and memory shared with other processes (such as shared libraries). This aligns with the reporting behavior of standard command-line utilities like ps and top.

  • @return The resident set size in bytes.

getPrivateResidentMemory(): Returns an estimate of the portion of physical memory (RAM) uniquely attributed to this process. This metric excludes shared libraries and other memory segments mapped by multiple processes, providing a more accurate representation of the process's individual impact on system resources. This value aligns with the primary "Memory" column in graphical system monitors, such as Windows Task Manager, macOS Activity Monitor, and the GNOME System Monitor.

  • @return The private or "footprint" resident memory in bytes.

OS implementations:

OS getResidentMemory() (RSS) getPrivateResidentMemory()
Windows WorkingSetSize (Total physical) PrivateWorkingSet (Task Manager "Memory")
macOS resident_size (Mach task info) phys_footprint (Activity Monitor "Memory")
Linux VmRSS (from /proc/[pid]/status) USS (Unique Set Size) or RSS - Shared
FreeBSD ki_rssize (from kinfo_proc) PRES (Private Resident pages via procstat)
Solaris pr_rssize (from prusage_t) pr_rssize - pr_shmsize (Private RSS)
AIX resident_size (RSS) svmon -P [pid] -O filtertype=working
OpenBSD p_vm_rssize (Total Resident) ps DSIZ or RSS - TSIZ (Data Size)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
oshi-core/src/test/java/oshi/software/os/OperatingSystemTest.java (1)

129-132: Add the deprecated-accessor compatibility assertion here.

These assertions cover the new APIs, but the fragile part of this PR is the old getResidentSetSize() contract: Windows should still map it to private resident memory, while other platforms should keep delegating to resident memory. A small assertion here would catch regressions in that compatibility layer.

🧪 Suggested test addition
         assertThat("Current running process resident set size should be 0 or higher", proc.getResidentMemory(),
                 is(greaterThanOrEqualTo(0L)));
         assertThat("Current running process private resident memory size should be 0 or higher",
                 proc.getPrivateResidentMemory(), is(greaterThanOrEqualTo(0L)));
+        if (Platform.isWindows()) {
+            assertThat("Deprecated RSS accessor should preserve Windows private-working-set semantics",
+                    proc.getResidentSetSize(), is(proc.getPrivateResidentMemory()));
+        } else {
+            assertThat("Deprecated RSS accessor should delegate to resident memory on non-Windows platforms",
+                    proc.getResidentSetSize(), is(proc.getResidentMemory()));
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/test/java/oshi/software/os/OperatingSystemTest.java` around
lines 129 - 132, Add a compatibility assertion for the deprecated
getResidentSetSize() to ensure Windows still maps it to private resident memory
while other OSes map it to resident memory: after the existing assertions on
proc.getResidentMemory() and proc.getPrivateResidentMemory(), detect Windows
(e.g., System.getProperty("os.name").toLowerCase().contains("win")) and assert
proc.getResidentSetSize() == proc.getPrivateResidentMemory() on Windows,
otherwise assert proc.getResidentSetSize() == proc.getResidentMemory();
reference proc, getResidentSetSize(), getResidentMemory(), and
getPrivateResidentMemory() when adding the assertion in OperatingSystemTest.
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java (1)

118-118: Rename the first working-set list to match PRIVATEBYTES.

Now that this path carries both private and total working set, the current locals are easy to misread: the first constructor argument still comes from PRIVATEBYTES, but its name looks like the total working set. Renaming it to privateWorkingSetSizeList would make the mapping much safer to maintain.

♻️ Suggested cleanup
-        List<Long> workingSetSizeList = valueMap.get(ProcessPerformanceProperty.PRIVATEBYTES);
+        List<Long> privateWorkingSetSizeList = valueMap.get(ProcessPerformanceProperty.PRIVATEBYTES);
         List<Long> workingSetList = valueMap.get(ProcessPerformanceProperty.WORKINGSETBYTES);
@@
                 processMap.put(pid,
                         new PerfCounterBlock(instances.get(inst), ppidList.get(inst).intValue(),
-                                priorityList.get(inst).intValue(), workingSetSizeList.get(inst),
+                                priorityList.get(inst).intValue(), privateWorkingSetSizeList.get(inst),
                                 workingSetList.get(inst), ctime, upTime, ioReadList.get(inst), ioWriteList.get(inst),
                                 pageFaultsList.get(inst).intValue()));

Also applies to: 137-140

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java`
at line 118, Rename the local variable workingSetList (from
ProcessPerformanceData.java where it's assigned from
ProcessPerformanceProperty.PRIVATEBYTES) to privateWorkingSetSizeList and update
all its subsequent references (including the constructor call arguments around
lines 137-140) so it is not confused with the total working set list obtained
from ProcessPerformanceProperty.WORKINGSETBYTES; ensure the renamed identifier
is used consistently where the PRIVATEBYTES-sourced list is passed to the
ProcessPerformanceData constructor and any other usages in this scope.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core/src/main/java/oshi/software/os/OSProcess.java`:
- Around line 181-222: OSProcess must remain source-compatible: make
getResidentSetSize() the abstract contract and convert getResidentMemory() and
getPrivateResidentMemory() to default implementations delegating to it;
specifically, remove the new abstract getResidentMemory() and instead add a
default getResidentMemory() that returns getResidentSetSize(), keep
getPrivateResidentMemory() as a default returning getResidentMemory(), and
preserve the `@Deprecated` annotation on getResidentSetSize() so existing
implementations compile unchanged while callers can migrate to the new names.

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java`:
- Around line 207-215: The override of getResidentSetSize() in WindowsOSProcess
currently lacks the `@Deprecated` annotation, so callers typed as WindowsOSProcess
won’t get deprecation warnings; add the `@Deprecated` annotation to the
WindowsOSProcess.getResidentSetSize() method (which delegates to
getPrivateResidentMemory()) to match the parent interface and preserve the
deprecation signal.

---

Nitpick comments:
In
`@oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java`:
- Line 118: Rename the local variable workingSetList (from
ProcessPerformanceData.java where it's assigned from
ProcessPerformanceProperty.PRIVATEBYTES) to privateWorkingSetSizeList and update
all its subsequent references (including the constructor call arguments around
lines 137-140) so it is not confused with the total working set list obtained
from ProcessPerformanceProperty.WORKINGSETBYTES; ensure the renamed identifier
is used consistently where the PRIVATEBYTES-sourced list is passed to the
ProcessPerformanceData constructor and any other usages in this scope.

In `@oshi-core/src/test/java/oshi/software/os/OperatingSystemTest.java`:
- Around line 129-132: Add a compatibility assertion for the deprecated
getResidentSetSize() to ensure Windows still maps it to private resident memory
while other OSes map it to resident memory: after the existing assertions on
proc.getResidentMemory() and proc.getPrivateResidentMemory(), detect Windows
(e.g., System.getProperty("os.name").toLowerCase().contains("win")) and assert
proc.getResidentSetSize() == proc.getPrivateResidentMemory() on Windows,
otherwise assert proc.getResidentSetSize() == proc.getResidentMemory();
reference proc, getResidentSetSize(), getResidentMemory(), and
getPrivateResidentMemory() when adding the assertion in OperatingSystemTest.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 073b1e8e-8f01-42d3-83cd-d0078fdada3a

📥 Commits

Reviewing files that changed from the base of the PR and between 060ded8 and 8fa27c9.

📒 Files selected for processing (13)
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformation.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/OSProcess.java
  • oshi-core/src/main/java/oshi/software/os/OperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/aix/AixOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/test/java/oshi/software/os/OperatingSystemTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, macos-latest

@dbwiddis
dbwiddis force-pushed the macos-memory-footprint branch 2 times, most recently from 6749baa to bf36ecd Compare March 9, 2026 21:35

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java`:
- Around line 390-401: The fallback branch in LinuxOSProcess (where
statmFields.length <= 2) sets residentSetSize but leaves privateResidentMemory
unchanged; update that branch to initialize privateResidentMemory as the
conservative fallback equal to residentSetSize (i.e., set privateResidentMemory
= residentSetSize) so callers get an upper-bound value when /proc/[pid]/statm
lacks shared-page info; adjust the block that reads ProcPidStat.RSS and computes
residentSetSize to also assign privateResidentMemory accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99352cb0-7da7-4eb9-874a-5aaf1bc817c5

📥 Commits

Reviewing files that changed from the base of the PR and between 8fa27c9 and bf36ecd.

📒 Files selected for processing (6)
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformation.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core/src/test/java/oshi/software/os/OperatingSystemTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformation.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
🔇 Additional comments (8)
oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java (2)

87-87: LGTM!

New field added to track private resident memory separately from total resident set size.


212-220: LGTM!

The new memory accessors are correctly implemented. getResidentMemory() returns the total RSS, while getPrivateResidentMemory() returns the private (non-shared) portion. This aligns with the PR objectives to expose both metrics with clear, distinct names.

oshi-core/src/test/java/oshi/software/os/OperatingSystemTest.java (1)

129-139: LGTM!

The test assertions correctly validate the new memory APIs and verify the backward-compatible behavior of the deprecated getResidentSetSize() method across platforms. The platform-specific expectations align with the PR objectives where Windows returns private memory and other platforms return RSS for backward compatibility.

oshi-core/src/test/java/oshi/SystemInfoTest.java (1)

335-342: LGTM!

The output format is correctly updated to display both resident and private memory values. The column alignment between the header and format string is consistent, and the new getResidentMemory() and getPrivateResidentMemory() methods are used appropriately.

oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java (4)

117-140: LGTM! Perf counter method updated consistently.

The changes mirror the registry-based method, retrieving both WORKINGSETPRIVATE and WORKINGSET values and passing them to the constructor. The variable naming (privateWorkingSetList, workingSetList) is clear and consistent with existing patterns.


150-174: LGTM! Clean field separation for memory metrics.

The PerfCounterBlock now correctly encapsulates both:

  • privateWorkingSetSize - aligns with Windows Task Manager's "Memory" (footprint)
  • workingSetSize - represents true RSS (total physical memory mapped)

The immutable pattern is maintained with final private fields.


71-79: LGTM! Constructor call correctly updated for dual memory metrics.

The WORKINGSETPRIVATE (private working set / footprint) and WORKINGSET (total working set / RSS) constants are properly defined in the ProcessPerformanceProperty enum and correctly used here to align with the cross-platform memory API design.


197-209: New getters properly expose dual memory metrics.

The renamed/new getter methods getPrivateWorkingSetSize() and getWorkingSetSize() correctly replace the previous getResidentSetSize() method on the internal PerfCounterBlock class. The Javadoc correctly indicates that workingSetSize represents RSS. All consumers in WindowsOSProcess.updateAttributes() have been updated to use the new getters.

@dbwiddis
dbwiddis force-pushed the macos-memory-footprint branch from bf36ecd to 8a1cb1a Compare March 9, 2026 23:58
@dbwiddis dbwiddis changed the title Introduce OSProcess.getMemoryFootprint method. Separate RSS from the private/footprint memory shown by graphical system monitors Mar 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java (1)

390-402: Guard against potential underflow when shared > resident.

The calculation (resident - shared) * pageSize at line 398 assumes resident >= shared. While this should hold under normal kernel accounting (shared pages are a subset of resident pages), edge cases or kernel bugs could potentially cause shared > resident, resulting in a negative value.

Consider clamping to zero to ensure non-negative results:

♻️ Proposed defensive fix
             long resident = ParseUtil.parseLongOrDefault(statmFields[1], 0L);
             long shared = ParseUtil.parseLongOrDefault(statmFields[2], 0L);
             long pageSize = LinuxOperatingSystem.getPageSize();
             this.residentSetSize = resident * pageSize;
-            this.privateResidentMemory = (resident - shared) * pageSize;
+            this.privateResidentMemory = Math.max(0L, resident - shared) * pageSize;

Also, the fallback path now correctly initializes privateResidentMemory = residentSetSize (line 401), addressing the concern from the previous review.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java` around
lines 390 - 402, In LinuxOSProcess where /proc/[pid]/statm is parsed (the block
computing residentSetSize and privateResidentMemory), guard against underflow
when computing (resident - shared): compute privateResidentMemory from the
non-negative difference (clamp resident - shared to zero) before multiplying by
pageSize so privateResidentMemory cannot become negative; keep residentSetSize
calculation unchanged and ensure you use the same long types (resident, shared,
pageSize) when performing the clamp.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 4: Update the CHANGELOG entry to mention that getResidentSetSize() is now
deprecated and users should migrate to getResidentMemory() and
getPrivateResidentMemory(); locate the existing bullet that introduces
getResidentMemory() and getPrivateResidentMemory() (the line referencing PR
`#3082`) and append a concise deprecation note stating that getResidentSetSize()
is ambiguous across platforms and will be deprecated, and recommend the two new
methods as replacements.
- Line 3: Change the "##### New Features" heading to a second-level heading so
it increments correctly from the top-level title: replace the string "##### New
Features" with "## New Features" in CHANGELOG.md to fix the MD001 heading-level
violation and match the document's heading structure.

---

Nitpick comments:
In `@oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java`:
- Around line 390-402: In LinuxOSProcess where /proc/[pid]/statm is parsed (the
block computing residentSetSize and privateResidentMemory), guard against
underflow when computing (resident - shared): compute privateResidentMemory from
the non-negative difference (clamp resident - shared to zero) before multiplying
by pageSize so privateResidentMemory cannot become negative; keep
residentSetSize calculation unchanged and ensure you use the same long types
(resident, shared, pageSize) when performing the clamp.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d8dd69fd-bea6-41b6-b176-248c8a0152c0

📥 Commits

Reviewing files that changed from the base of the PR and between bf36ecd and 8a1cb1a.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • README.md
  • oshi-core-java11/pom.xml
  • oshi-core-java25/pom.xml
  • oshi-core/pom.xml
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcess.java
  • oshi-demo/pom.xml
  • oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java
  • oshi-dist/pom.xml
  • pom.xml
  • src/site/markdown/index.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🪛 markdownlint-cli2 (0.21.0)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (18)
oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java (3)

43-45: LGTM!

The column definitions are well-structured. The 10 columns match the 10 width percentages, and the widths sum to 1.0. The addition of separate "RSS" (total resident) and "Memory" (private resident) columns aligns with the PR's goal of exposing both memory metrics clearly.


138-140: LGTM!

The sorting logic correctly uses getPrivateResidentMemory() to match the "Memory" column display. The default fallback to getResidentMemory() on platforms without explicit implementations ensures consistent behavior.


167-172: LGTM!

The data population correctly maps to the column definitions:

  • Index 6 → "RSS" using getResidentMemory()
  • Index 7 → "Memory" using getPrivateResidentMemory()
  • Index 8 → "% Memory" calculated from private resident memory
  • Index 9 → "Process Name"

The percentage calculation appropriately uses private resident memory to reflect the process's individual memory footprint relative to total system memory.

oshi-core-java25/pom.xml (1)

8-8: LGTM!

Parent version bump to 6.11.0-SNAPSHOT is consistent with the coordinated multi-module version update.

oshi-core-java11/pom.xml (1)

8-8: LGTM!

Parent version bump aligns with the coordinated 6.11.0-SNAPSHOT release across all modules.

src/site/markdown/index.md (1)

53-55: LGTM!

SNAPSHOT download links correctly updated to 6.11.0-SNAPSHOT for all three module variants (JDK8, JPMS, FFM).

oshi-demo/pom.xml (1)

8-8: LGTM!

Parent version bump is consistent with the project-wide 6.11.0-SNAPSHOT update.

README.md (1)

53-55: LGTM!

SNAPSHOT download links updated consistently with the site documentation (index.md).

pom.xml (1)

7-7: LGTM!

Root POM version bump to 6.11.0-SNAPSHOT correctly establishes the baseline for all child modules.

oshi-core/pom.xml (1)

8-8: LGTM!

Parent version bump aligns oshi-core with the 6.11.0-SNAPSHOT release containing the new memory footprint API.

oshi-dist/pom.xml (1)

8-8: LGTM!

Parent version bump ensures distribution packaging aligns with the 6.11.0-SNAPSHOT release.

oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcess.java (4)

81-81: LGTM!

The new residentSetSizePrivate field aligns with the broader API changes introducing separate resident memory metrics across platforms.


200-207: LGTM!

The API changes correctly implement the new memory semantics:

  • getResidentMemory() returns the existing residentSetSize (true RSS)
  • getPrivateResidentMemory() returns the new residentSetSizePrivate field

This aligns with the cross-platform API design documented in OSProcess.java context snippet 1.


403-421: Formatting-only changes in switch block.

These are indentation/formatting changes with no behavioral impact. The switch logic correctly maps Solaris process state characters to the State enum.


371-371: The multiplication by 1024 is correct.

Oracle Solaris documentation confirms that psinfo_t.pr_rssizepriv is measured in kilobytes, so the conversion to bytes via multiplication by 1024 is accurate. The existing comment at line 368 ("These are in KB, multiply") correctly applies to this field.

oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java (3)

87-87: LGTM!

The new privateResidentMemory field aligns with the broader API changes and matches the naming convention used in the macOS implementation.


213-220: LGTM!

The API changes correctly implement the new memory semantics:

  • getResidentMemory() returns residentSetSize (true RSS)
  • getPrivateResidentMemory() returns privateResidentMemory (computed from statm)

This aligns with the interface contract in OSProcess.java and matches other platform implementations.


358-358: LGTM!

Reading /proc/[pid]/statm is appropriate for obtaining the resident and shared page counts needed to compute private memory.

Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
@dbwiddis
dbwiddis force-pushed the macos-memory-footprint branch from 8a1cb1a to 7b99010 Compare March 10, 2026 00:12
@dbwiddis
dbwiddis force-pushed the macos-memory-footprint branch from 72e2828 to 91d9038 Compare March 10, 2026 01:35
@dbwiddis
dbwiddis merged commit 9ae3c62 into oshi:master Mar 10, 2026
14 checks passed
@dyorgio

dyorgio commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@dbwiddis thank you so much, you are a code machine :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants