This question already has answers here:
Out-of-order instruction execution: is commit order preserved?
(1 answer)
How does memory reordering help processors and compilers?
(4 answers)
Are loads and stores the only instructions that gets reordered?
(2 answers)
Can memory store be reordered really, in an OoOE processor?
(4 answers)
Closed 2 years ago.
I'm learning multi-thread programming.
But I'm confused with some words that "memory reordering" and "instruction reordering".
My question is that is "memory reordering" equivalent to "instruction reordering"?
If not what's the difference between each.
Related
This question already has answers here:
How to allocate arrays on the heap in Rust 1.0?
(3 answers)
Thread '<main>' has overflowed its stack when allocating a large array using Box
(2 answers)
Performance comparison of a Vec and a boxed slice
(1 answer)
Closed 4 years ago.
I am trying to initialize a large array with shape [[u64; 4096]; 64]. When I try to initialize this array with [[0; 4096]; 64] I get different results depending on how the program is run.
When I run with cargo test I get the following error:
thread '' has overflowed its stack
fatal runtime error: stack overflow
When I run with either cargo run or cargo test --release my program runs as expected. I think this means that the stack is simply not big enough to handle 8 * 64 * 4096 bytes (just over a MB), and that when I run in release or with cargo run a different sized stack is allocated for the program.
Is my assumption about running out of stack correct?
Could I allocate the array to the heap within a Box instead?
Is this the best option?
I would really like look ups for this array to be as fast as possible.
Once you declare a variable in local scope, it is held on the stack. Since your stack capacity is not enough for the variable you declare, then you get a stack overflow error. I suggest to take a quick look at the book's section on the stack and the heap.
In such big sized objects, declaring them inside a Box makes them stored on the heap, which may be the wiser option for you.
This question already has an answer here:
Android : PSS (Proportional Set Size) Calculation
(1 answer)
Closed 7 years ago.
I would like to ask you:
I understand that on Linux, there are process that have shared libreries, and for look this, we can use PSS because this give information about the shared libraries size. And Uss is private dirty memory of a process.
But my question is:
Pss doesn't contains Uss, it's only about the proportionally shared memory;
or
Pss = Uss + proportionally shared memory.
Which interpretation is correct?
Sorry, this question was already answered here:
Android : PSS (Proportional Set Size) Calculation
The "proportional set size" (PSS) of a process is the count of pages
it has in memory, where each page is divided by the number of
processes sharing it. So if a process has 1000 pages all to itself,
and 1000 shared with one other process, its PSS will be 1500
This question already has answers here:
Is there a way to limit the memory, ghci can have?
(2 answers)
Closed 7 years ago.
Here is the problem: sometimes, when playing with GHCI, I end up running an infinite computation by mistake. When this happens, most times, my computer crashes and I'm not even able to interrupt it using Ctrl+C.
I wonder if there is a way to run GHCI (or another interactive console like Hugs) in some mode that allows me to interrupt the program before the memory runs out. Maybe setting a virtual limit for the recursion depth or for the memory used.
(This question may be a duplicated of Is there a way to limit the memory, ghci can have? but this also considers the posibility of a recursion depth limit, not just memory limit.)
You can try using the RTS options to control the garbage collector when starting GHCi. For instance,
ghci +RTS -M100M -RTS Foo.hs
should limit the memory to 100MB. Alternatively, use -Ksize to limit the stack (by default it is limited by 80% of the heap).
This question already has answers here:
Maximum number of threads per process in Linux?
(18 answers)
Changing the limit of maximum number of pthreads by an application
(4 answers)
Closed 8 years ago.
I have about 500 threads that I want them to run simultaneously.
I read that the default glibc allows only about 300 threads to run simultaneously.
How did they got to this number? (I'm on 32 bit system)
The default stack size of a thread on linux is 10MB (or 8 on some). On a 32 bit linux, user space applications have 3GB of memory address space, some used for shared libraries, heap, the code, and other housekeeping, exhausting the address space at about 260 threads(2.6GB memory) is reasonable.
You can probably do with less space for the stack, so create threads with less stack space, e.g.
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 1024*1000*2);
pthread_create(&tid, &attr, threadfunc, NULL);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Linux memory: buffer vs cache
When using command like ps/free to monitor memory on a Linux box, we can see a statistic called buffered memory and another called cached memory. I have searched Internet but cannot find a consistent answer for their differences. Appreciate if anyone could give me any hints.
BTW: I am debugging a program's memory usage pattern, so understanding the concepts are useful for my development.
thanks in advance,
Lin
Buffers are the I/O buffers whereas cached is the page cache.