Message ID | 5f3fc9a9-9a22-ccc3-5971-9783b60807bc@virtuozzo.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] mm: Allocate shrinker_map on appropriate NUMA node | expand |
On Fri 31-01-20 18:00:51, Kirill Tkhai wrote: [...] > @@ -333,8 +333,9 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, > /* Not yet online memcg */ > if (!old) > return 0; > - > - new = kvmalloc(sizeof(*new) + size, GFP_KERNEL); > + /* See comment in alloc_mem_cgroup_per_node_info()*/ > + tmp = node_state(nid, N_NORMAL_MEMORY) ? nid : NUMA_NO_NODE; > + new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, tmp); > if (!new) > return -ENOMEM; I do not think this is a good pattern to copy. Why cannot you simply use kvmalloc_node with the given node? The allocator should fallback to the closest node if the given one doesn't have any memory.
On 31.01.2020 18:47, Michal Hocko wrote: > On Fri 31-01-20 18:00:51, Kirill Tkhai wrote: > [...] >> @@ -333,8 +333,9 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, >> /* Not yet online memcg */ >> if (!old) >> return 0; >> - >> - new = kvmalloc(sizeof(*new) + size, GFP_KERNEL); >> + /* See comment in alloc_mem_cgroup_per_node_info()*/ >> + tmp = node_state(nid, N_NORMAL_MEMORY) ? nid : NUMA_NO_NODE; >> + new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, tmp); >> if (!new) >> return -ENOMEM; > > I do not think this is a good pattern to copy. Why cannot you simply use > kvmalloc_node with the given node? The allocator should fallback to the > closest node if the given one doesn't have any memory. Hm, why isn't the same scheme used in alloc_mem_cgroup_per_node_info() then? Kirill
On Fri 31-01-20 18:49:24, Kirill Tkhai wrote: > On 31.01.2020 18:47, Michal Hocko wrote: > > On Fri 31-01-20 18:00:51, Kirill Tkhai wrote: > > [...] > >> @@ -333,8 +333,9 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, > >> /* Not yet online memcg */ > >> if (!old) > >> return 0; > >> - > >> - new = kvmalloc(sizeof(*new) + size, GFP_KERNEL); > >> + /* See comment in alloc_mem_cgroup_per_node_info()*/ > >> + tmp = node_state(nid, N_NORMAL_MEMORY) ? nid : NUMA_NO_NODE; > >> + new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, tmp); > >> if (!new) > >> return -ENOMEM; > > > > I do not think this is a good pattern to copy. Why cannot you simply use > > kvmalloc_node with the given node? The allocator should fallback to the > > closest node if the given one doesn't have any memory. > > Hm, why isn't the same scheme used in alloc_mem_cgroup_per_node_info() then? Dunno, it's an old code. Probably worth cleaning up.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6f6dc8712e39..20700ad25373 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -323,7 +323,7 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, int size, int old_size) { struct memcg_shrinker_map *new, *old; - int nid; + int nid, tmp; lockdep_assert_held(&memcg_shrinker_map_mutex); @@ -333,8 +333,9 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, /* Not yet online memcg */ if (!old) return 0; - - new = kvmalloc(sizeof(*new) + size, GFP_KERNEL); + /* See comment in alloc_mem_cgroup_per_node_info()*/ + tmp = node_state(nid, N_NORMAL_MEMORY) ? nid : NUMA_NO_NODE; + new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, tmp); if (!new) return -ENOMEM; @@ -370,7 +371,7 @@ static void memcg_free_shrinker_maps(struct mem_cgroup *memcg) static int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) { struct memcg_shrinker_map *map; - int nid, size, ret = 0; + int nid, size, tmp, ret = 0; if (mem_cgroup_is_root(memcg)) return 0; @@ -378,7 +379,9 @@ static int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) mutex_lock(&memcg_shrinker_map_mutex); size = memcg_shrinker_map_size; for_each_node(nid) { - map = kvzalloc(sizeof(*map) + size, GFP_KERNEL); + /* See comment in alloc_mem_cgroup_per_node_info()*/ + tmp = node_state(nid, N_NORMAL_MEMORY) ? nid : NUMA_NO_NODE; + map = kvzalloc_node(sizeof(*map) + size, GFP_KERNEL, tmp); if (!map) { memcg_free_shrinker_maps(memcg); ret = -ENOMEM;