Skip to content

Commit 0d7c45d

Browse files
Release Managervbraun
Release Manager
authored andcommitted
Trac #21805: Use psutil instead of various hacks
The following modules can mostly replaced by simple calls to `psutil`: * `sage.misc.getusage` * `sage.misc.memory_info` * `sage.misc.darwin_utilities` All usage of these modules is replaced by some simple wrappers around `psutil`. These wrappers are implemented in `sage.misc.getusage`. URL: https://trac.sagemath.org/21805 Reported by: jdemeyer Ticket author(s): Jeroen Demeyer Reviewer(s): Jean-Pierre Flori
2 parents 909d9e1 + 9f629df commit 0d7c45d

File tree

9 files changed

+94
-292
lines changed

9 files changed

+94
-292
lines changed

src/doc/en/reference/misc/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ Miscellaneous Inspection and Development Tools
283283
sage/misc/classgraph
284284
sage/misc/dev_tools
285285
sage/misc/function_mangling
286-
sage/misc/memory_info
287286
sage/misc/rest_index_of_methods
288287

289288
Low-Level Utilities

src/module_list.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,6 @@ def uname_specific(name, value, alternative):
951951

952952
Extension('*', ['sage/misc/*.pyx']),
953953

954-
# Only include darwin_utilities on OS_X >= 10.5
955-
OptionalExtension('sage.misc.darwin_utilities',
956-
sources = ['sage/misc/darwin_memory_usage.c',
957-
'sage/misc/darwin_utilities.pyx'],
958-
condition = (UNAME[0] == "Darwin" and not UNAME[2].startswith('8.'))),
959-
960954
################################
961955
##
962956
## sage.modular

src/sage/interfaces/gap.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,24 +257,28 @@ def get_gap_memory_pool_size():
257257
258258
EXAMPLES::
259259
260-
sage: from sage.interfaces.gap import \
261-
... get_gap_memory_pool_size
260+
sage: from sage.interfaces.gap import get_gap_memory_pool_size
262261
sage: get_gap_memory_pool_size() # random output
263262
1534059315
264263
"""
265264
global gap_memory_pool_size
266265
if gap_memory_pool_size is not None:
267266
return gap_memory_pool_size
268-
from sage.misc.memory_info import MemoryInfo
269-
mem = MemoryInfo()
270-
suggested_size = max(mem.available_swap() // 10,
271-
mem.available_ram() // 50)
267+
268+
import psutil
269+
from sage.misc.getusage import virtual_memory_limit
270+
mem = psutil.virtual_memory()
271+
swap = psutil.swap_memory()
272+
vmax = virtual_memory_limit()
273+
274+
suggested_size = max(swap.free // 10, mem.available // 50)
272275
# Don't eat all address space if the user set ulimit -v
273-
suggested_size = min(suggested_size, mem.virtual_memory_limit()//10)
276+
suggested_size = min(suggested_size, vmax // 10)
274277
# ~220MB is the minimum for long doctests
275278
suggested_size = max(suggested_size, 250 * 1024**2)
276279
return suggested_size
277280

281+
278282
def _get_gap_memory_pool_size_MB():
279283
"""
280284
Return the gap memory pool size suitable for usage on the GAP

src/sage/libs/cypari2/pari_instance.pyx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,11 @@ cdef class PariInstance(PariInstance_auto):
510510
# As a simple heuristic, we set the virtual stack to 1/4 of the
511511
# virtual memory.
512512

513-
from sage.misc.memory_info import MemoryInfo
514-
mem = MemoryInfo()
515-
516513
pari_init_opts(size, maxprime, INIT_DFTm)
517-
518-
sizemax = mem.virtual_memory_limit() // 4
519514

515+
from sage.misc.getusage import virtual_memory_limit
516+
517+
sizemax = virtual_memory_limit() // 4
520518
if CYGWIN_VERSION and CYGWIN_VERSION < (2, 5, 2):
521519
# Cygwin's mmap is broken for large NORESERVE mmaps (>~ 4GB) See
522520
# http://trac.sagemath.org/ticket/20463 So we set the max stack

src/sage/misc/darwin_memory_usage.c

Lines changed: 0 additions & 148 deletions
This file was deleted.

src/sage/misc/darwin_memory_usage.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/sage/misc/darwin_utilities.pyx

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)