mlx4_core: restore optimal ICM memory allocation
Subsystems (3)
PATCH v2 1/1 mlx4_core: restore optimal ICM memory allocation
Commit 1383cb8103bb ("mlx4_core: allocate ICM memory in page size chunks") brought two regressions caught in our regression suite.
The big one is an additional cost of 256 bytes of overhead per 4096 bytes, or 6.25 % which is unacceptable since ICM can be pretty large.
This comes from having to allocate one struct mlx4_icm_chunk (256 bytes) per MLX4_TABLE_CHUNK, which the buggy commit shrank to 4KB (instead of prior 256KB)
Note that mlx4_alloc_icm() is already able to try high order allocations and fallback to low-order allocations under high memory pressure.
Most of these allocations happen right after boot time, when we get plenty of non fragmented memory, there is really no point being so pessimistic and break huge pages into order-0 ones just for fun.
We only have to tweak gfp_mask a bit, to help falling back faster, without risking OOM killings.
Second regression is an KASAN fault, that will need further investigations.
--- drivers/net/ethernet/mellanox/mlx4/icm.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx4/icm.c +12 -6
@@ -43,12 +43,13 @@#include "fw.h" /* -* We allocate in page size (default 4KB on many archs) chunks to avoid high -* order memory allocations in fragmented/high usage memory situation. +* We allocate in as big chunks as we can, up to a maximum of 256 KB +* per chunk. Note that the chunks are not necessarily in contiguous +* physical memory. */ enum { -MLX4_ICM_ALLOC_SIZE =PAGE_SIZE , -MLX4_TABLE_CHUNK_SIZE =PAGE_SIZE , +MLX4_ICM_ALLOC_SIZE =1 <<18 , +MLX4_TABLE_CHUNK_SIZE =1 <<18 , };static void mlx4_free_icm_pages (struct mlx4_dev *dev,struct mlx4_icm_chunk *chunk)
@@ -135,6 +136,7 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,struct mlx4_icm *icm;struct mlx4_icm_chunk *chunk =NULL ;int cur_order; +gfp_t mask;int ret;/* We use sg_set_buf for coherent allocs, which assumes low memory */
@@ -178,13 +180,17 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,while (1 << cur_order > npages) --cur_order; + mask = gfp_mask; +if (cur_order) + mask &= ~__GFP_DIRECT_RECLAIM; +if (coherent) ret =mlx4_alloc_icm_coherent (&dev->persist->pdev->dev, &chunk->mem[chunk->npages], - cur_order, gfp_mask); + cur_order, mask);else ret =mlx4_alloc_icm_pages (&chunk->mem[chunk->npages], - cur_order, gfp_mask, + cur_order, mask, dev->numa_node);if (ret) {
Signature · 1 line
2.17.0.921.gf22659ad46-goog
Quoted 9 lines · Eric Dumazet
Commit
1383cb8103bb("mlx4_core: allocate ICM memory in page size chunks") brought two regressions caught in our regression suite.The big one is an additional cost of 256 bytes of overhead per 4096 bytes, or 6.25 % which is unacceptable since ICM can be pretty large.
This comes from having to allocate one struct
mlx4_icm_chunk(256 bytes) perMLX4_TABLE_CHUNK, which the buggy commit shrank to 4KB (instead of prior 256KB)
It would be great if you could share the test case that triggered the KASAN report in your environment. Our QA has been running intensive tests using 8KB or 4KB chunk size configuration for some time, no one has reported memory corruption issues so far, given that we are not running the latest upstream kernel.
IMO, it's worthwhile to find out the root cause and fix the problem.
Quoted 10 lines
Note that
mlx4_alloc_icm()is already able to try high order allocations and fallback to low-order allocations under high memory pressure.Most of these allocations happen right after boot time, when we get plenty of non fragmented memory, there is really no point being so pessimistic and break huge pages into order-0 ones just for fun.
We only have to tweak
gfp_maska bit, to help falling back faster, without risking OOM killings.
Just FYI, out of memory wasn't our original concern. We didn't encounter OOM killings.
Quoted 65 lines
Second regression is an KASAN fault, that will need further investigations.
Fixes 1383cb8103bb ("mlx4_core: allocate ICM memory in page size chunks")Signed-off-by Eric Dumazet <[email protected]>Acked-by Tariq Toukan <[email protected]>Cc John Sperbeck <[email protected]>Cc Tarick Bedeir <[email protected]>Cc Qing Huang <[email protected]>Cc Daniel Jurgens <[email protected]>Cc Zhu Yanjun <[email protected]>--- drivers/net/ethernet/mellanox/mlx4/icm.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)drivers/net/ethernet/mellanox/mlx4/icm.c +12
-6@@ -43,12 +43,13 @@#include "fw.h" /* -* We allocate in page size (default 4KB on many archs) chunks to avoid high -* order memory allocations in fragmented/high usage memory situation. +* We allocate in as big chunks as we can, up to a maximum of 256 KB +* per chunk. Note that the chunks are not necessarily in contiguous +* physical memory. */ enum { -MLX4_ICM_ALLOC_SIZE =PAGE_SIZE , -MLX4_TABLE_CHUNK_SIZE =PAGE_SIZE , +MLX4_ICM_ALLOC_SIZE =1 <<18 , +MLX4_TABLE_CHUNK_SIZE =1 <<18 , };static void mlx4_free_icm_pages (struct mlx4_dev *dev,struct mlx4_icm_chunk *chunk)@@ -135,6 +136,7 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,struct mlx4_icm *icm;struct mlx4_icm_chunk *chunk =NULL ;int cur_order; +gfp_t mask;int ret;/* We use sg_set_buf for coherent allocs, which assumes low memory */ @@ -178,13 +180,17 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,while (1 << cur_order > npages) --cur_order; + mask = gfp_mask; +if (cur_order) + mask &= ~__GFP_DIRECT_RECLAIM; +if (coherent) ret =mlx4_alloc_icm_coherent (&dev->persist->pdev->dev, &chunk->mem[chunk->npages], - cur_order, gfp_mask); + cur_order, mask);else ret =mlx4_alloc_icm_pages (&chunk->mem[chunk->npages], - cur_order, gfp_mask, + cur_order, mask, dev->numa_node);if (ret) {
Quoted 9 lines · Qing Huang
It would be great if you could share the test case that triggered the KASAN report in your environment. Our QA has been running intensive tests using 8KB or 4KB chunk size configuration for some time, no one has reported memory corruption issues so far, given that we are not running the latest upstream kernel.
IMO, it's worthwhile to find out the root cause and fix the problem.
Do not worry, we are working on this minor problem.
We do not use KASAN on production hosts, quite obviously.
The memory waste is the major problem really.
From: Eric Dumazet <[email protected]>
Date: Thu, 31 May 2018 05:52:24 -0700
Quoted 17 lines
Commit
1383cb8103bb("mlx4_core: allocate ICM memory in page size chunks") brought two regressions caught in our regression suite.The big one is an additional cost of 256 bytes of overhead per 4096 bytes, or 6.25 % which is unacceptable since ICM can be pretty large.
This comes from having to allocate one struct
mlx4_icm_chunk(256 bytes) perMLX4_TABLE_CHUNK, which the buggy commit shrank to 4KB (instead of prior 256KB)Note that
mlx4_alloc_icm()is already able to try high order allocations and fallback to low-order allocations under high memory pressure.Most of these allocations happen right after boot time, when we get plenty of non fragmented memory, there is really no point being so pessimistic and break huge pages into order-0 ones just for fun.
Quoted 8 lines
We only have to tweak
gfp_maska bit, to help falling back faster, without risking OOM killings.Second regression is an KASAN fault, that will need further investigations.
Fixes 1383cb8103bb ("mlx4_core: allocate ICM memory in page size chunks")Signed-off-by Eric Dumazet <[email protected]>Acked-by Tariq Toukan <[email protected]>
Applied, thanks Eric.