Skip to content

Graphviper changes needed for astroviper demonstrator#45

Merged
Jan-Willem merged 3 commits intomainfrom
graphviper-changes-needed-for-astroviper-demonstrator
Mar 19, 2026
Merged

Graphviper changes needed for astroviper demonstrator#45
Jan-Willem merged 3 commits intomainfrom
graphviper-changes-needed-for-astroviper-demonstrator

Conversation

@Jan-Willem
Copy link
Copy Markdown
Member

No description provided.

@Jan-Willem Jan-Willem linked an issue Mar 19, 2026 that may be closed by this pull request
@Jan-Willem Jan-Willem requested a review from Copilot March 19, 2026 16:50
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/toolviper/utils/memory_management.py 0.00% 19 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new toolviper.utils.memory_management module intended to support the “Graphviper / astroviper demonstrator” by providing small helpers for RSS reporting and returning memory to the OS via allocator-specific calls.

Changes:

  • Added get_rss_gb() to report current process RSS via psutil.
  • Added memory_setup() to tune glibc mallopt(M_MMAP_THRESHOLD, ...) on Linux.
  • Added free_memory() to trigger GC and attempt allocator memory release (glibc malloc_trim on Linux; malloc_zone_pressure_relief on macOS).
Comments suppressed due to low confidence (2)

src/toolviper/utils/memory_management.py:40

  • The macOS path calls malloc_zone_pressure_relief(None, 0) without defining argtypes/restype. With ctypes defaults, passing None is likely to raise a conversion TypeError (and the current broad except Exception: pass will silently swallow it), meaning this branch may never actually run. Define the function signature (void*/size_t) and pass a ctypes.c_void_p(0) NULL zone; also consider narrowing the exception handling and/or logging failures so unexpected issues aren't hidden.
            lib = ctypes.CDLL("libSystem.B.dylib")
            # malloc_zone_pressure_relief(zone=NULL, goal=0) asks all zones to
            # release as much memory as possible back to the OS.
            lib.malloc_zone_pressure_relief(None, 0)
        except Exception:
            pass

src/toolviper/utils/memory_management.py:39

  • New memory-management utilities are introduced without tests. Since this repo has unit tests for other toolviper.utils modules, please add tests that validate (via monkeypatching sys.platform/ctypes) that memory_setup()/free_memory() are no-ops or safely handled on unsupported platforms, and that get_rss_gb() returns the expected unit conversion.
    On Linux this calls glibc's mallopt(M_MMAP_THRESHOLD, threshold).
    On macOS the system allocator handles this automatically; the call is skipped.
    """
    import sys, ctypes

    if sys.platform == "linux":
        ctypes.CDLL("libc.so.6").mallopt(-3, threshold)


def free_memory():
    """Return free memory pages to the OS.

    On Linux this calls glibc's malloc_trim(0).
    On macOS, malloc_zone_pressure_relief is used as the closest equivalent.
    """
    import sys, ctypes
    import gc

    gc.collect()
    if sys.platform == "linux":
        ctypes.CDLL("libc.so.6").malloc_trim(0)
    elif sys.platform == "darwin":
        try:
            lib = ctypes.CDLL("libSystem.B.dylib")
            # malloc_zone_pressure_relief(zone=NULL, goal=0) asks all zones to
            # release as much memory as possible back to the OS.
            lib.malloc_zone_pressure_relief(None, 0)
        except Exception:
            pass


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +7

def memory_setup(threshold: int = 131072):
def get_rss_gb():
import psutil, os

return psutil.Process(os.getpid()).memory_info().rss / 1e9
Comment on lines +16 to +19
ctypes.CDLL("libc.so.6").mallopt(-3, threshold)


def free_memory():
Comment on lines +31 to +33
elif sys.platform == "darwin":
try:
lib = ctypes.CDLL("libSystem.B.dylib")
Comment on lines +1 to +4
def get_rss_gb():
import psutil, os

return psutil.Process(os.getpid()).memory_info().rss / 1e9
@Jan-Willem Jan-Willem merged commit f7758f6 into main Mar 19, 2026
18 of 20 checks passed
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.

Changes Needed for AstroVIPER Demonstrator

3 participants