question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory allocation for buffers

See original GitHub issue

With the current implementation of buffers.py one can request a buffersize which doesn’t fit in the memory provided but because of numpys implementation of np.zeros() the memory is not allocated before it is actually used. But because the buffer is meant to be filled completely (otherwise one could just use a smaller buffer) the computer will finally run out of memory and start to swap heavily. Because there are only smaller parts of the buffer that are accessed at once (minibatches) the system will just swap the necessary pages in and out of memory. At that moment the progress of the run is most likely lost and one has to start a new run with a smaller buffer.

I would recommend using np.ones instead, as it will allocate the buffer at the beginning and fail if there is not enough memory provided by the system. The only issue is that there is no clear error description in the case where the system memory is exceeded but python gets simply killed by the OS with a SIGKILL. Maybe one could catch that command?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
ndormanncommented, May 29, 2020

oh too slow

2reactions
PartiallyTypedcommented, May 29, 2020

This should work:

import psutil

import psutil
mem = psutil.virtual_memory()
# svmem(total=17179869184, available=7359184896, percent=57.2, used=9309233152, free=2441043968, active=4924092416, inactive=4230881280, wired=4385140736)
mem.available
# 7359184896

import numpy as np
x = np.empty(1000000000)
x.nbytes
# 8000000000
assert x.nbytes < mem.available
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# AssertionError
Read more comments on GitHub >

github_iconTop Results From Across the Web

C buffer memory allocation - Stack Overflow
The file has 6144 bytes (stored correctly in lSize) but the size of my buffer is only 4 bytes, therefore only the MZ...
Read more >
Buffer Allocation and Initialization
The amount of memory to allocate for a fielded buffer depends on the maximum number of fields the buffer will contain and the...
Read more >
Memory and buffer management - USENIX
The lwIP implementation has dynamic buffer and memory allocation mechanisms where memory for holding connection state and packets is dynamically allocated ...
Read more >
Buffer Allocation
NvSciBufArray: Memory used to store a group of units, where each unit represents data of various basic types like int, float etc. •...
Read more >
3.6. Buffer allocation and usage
Provides to MPI a buffer in the user's memory to be used for buffering outgoing messages. The buffer is used only by messages...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found