0

If we have an application which has two memory allocations malloc and numa_alloc(1) (assume we have two numa nodes 0 & 1), malloc shall be using memory on node 0 and numa_alloc shall be allocated on node 1.

In this application if we have local varibales like int x, or sem_t tst; where are these local variables allocated; on node 0 or 1 ?

If they get allocated on node 1, is there any way we can restrict all application related allocations need to be done on node 0 and node 1 to be used only for numa allocations ?

valmiki
  • 701
  • 9
  • 24
  • 1
    "where are these local variables allocated; on node 0 or 1?" - Local variable are always allocated on the **stack** of the process/thread which executes the code involving these variables.. – Tsyvarev Dec 31 '19 at 08:44
  • yes, stack is also set of pages, does these pages need to get allocated on node 0 or 1 ? How this decision is made by kernel ? – valmiki Dec 31 '19 at 09:41
  • 1
    Kernel allocates a thread's stack automatically according to the thread's settings. "How this decision is made by kernel?" - If you create a thread with `kthread_create`, then the thread is created on the **current node**. This is explicitly stated in the [description](https://elixir.bootlin.com/linux/v4.19.91/source/include/linux/kthread.h#L26) for a function/macro. If you want to create a thread on specific node, use [kthread_create_on_node](https://elixir.bootlin.com/linux/v4.19.91/source/kernel/kthread.c#L370). – Tsyvarev Dec 31 '19 at 09:48
  • okay lets say kthread_create_on_node is for node 0, if we allocate dynamically memory on node 1 using numa API's will there be any effect on allocation of variables in later functions being called i.e, the new variables will still be allocated on node 0 ? Is there any scenario new variables get allocated on node 1 ? like node 0 ran out of memory for example. – valmiki Jan 02 '20 at 08:53

0 Answers0