Posts

Showing posts with the label allocation

Is the memory block allocated by a thread is on the same affinity as the thread itself until the thread exit?

Is the memory block allocated by a thread is on the same affinity as the thread itself until the thread exit? This is a question about NUMA. For example, in the code below, is the buffer allocated at the local memory of the thread/process throughout its life? for (int th = 0; th < maxThreads; th++) { threads[th] = std::thread([&, th] { int* buffer = new int[1000]; // do something delete buffer; } } Update: to make the question more straightforward, let me ask in this way. If I have 10 simultaneous threads (say, t0 to t9) launched, and within the scope of each threads, it allocates a memory block(say, m0 to m9). Would thread t_n always operates on m_n (n from 0 to 9) before the thread exit, or thread 0 might migrate and operate on memory 9? The memory block in my situation is not very large, usually only a couple of mega-bytes. This will be implementation specific; what is your compiler? ...

Python fork: 'Cannot allocate memory' if process consumes more than 50% avail. memory

Python fork: 'Cannot allocate memory' if process consumes more than 50% avail. memory I encountered a memory allocation problem when forking processes in Python. I know the issue was already discussed in some other posts here, however I couldn't find a good solution in any of them. Here is a sample script illustrating the Problem: import os import psutil import subprocess pid = os.getpid() this_proc = psutil.Process(pid) MAX_MEM = int(psutil.virtual_memory().free*1E-9) # in GB def consume_memory(size): """ Size in GB """ memory_consumer = while get_mem_usage() < size: memory_consumer.append(" "*1000000) # Adding ~1MB return(memory_consumer) def get_mem_usage(): return(this_proc.memory_info()[0]/2.**30) def get_free_mem(): return(psutil.virtual_memory().free/2.**30) if __name__ == "__main__": for i in range(1, MAX_MEM): consumer = consume_memory(i) mem_usage = get_mem_usa...