[PATCH] IB/mthca: Handle context tables smaller than our chunk size

When creating a table in context memory where the table is smaller
than our chunk size, we don't want to allocate and map a full chunk.
Instead, allocate just enough memory to cover the table.

This can be pretty simple because all tables are a power-of-2 size, so
either the table is a multiple of the chunk size, or it's smaller than
one chunk.

Signed-off-by: Roland Dreier <rolandd@cisco.com>

authored by

Roland Dreier and committed by
Roland Dreier
d20a4019 c04bc3d1

+6 -1
+6 -1
drivers/infiniband/hw/mthca/mthca_memfree.c
··· 286 { 287 struct mthca_icm_table *table; 288 int num_icm; 289 int i; 290 u8 status; 291 ··· 307 table->icm[i] = NULL; 308 309 for (i = 0; i * MTHCA_TABLE_CHUNK_SIZE < reserved * obj_size; ++i) { 310 - table->icm[i] = mthca_alloc_icm(dev, MTHCA_TABLE_CHUNK_SIZE >> PAGE_SHIFT, 311 (use_lowmem ? GFP_KERNEL : GFP_HIGHUSER) | 312 __GFP_NOWARN); 313 if (!table->icm[i])
··· 286 { 287 struct mthca_icm_table *table; 288 int num_icm; 289 + unsigned chunk_size; 290 int i; 291 u8 status; 292 ··· 306 table->icm[i] = NULL; 307 308 for (i = 0; i * MTHCA_TABLE_CHUNK_SIZE < reserved * obj_size; ++i) { 309 + chunk_size = MTHCA_TABLE_CHUNK_SIZE; 310 + if ((i + 1) * MTHCA_TABLE_CHUNK_SIZE > nobj * obj_size) 311 + chunk_size = nobj * obj_size - i * MTHCA_TABLE_CHUNK_SIZE; 312 + 313 + table->icm[i] = mthca_alloc_icm(dev, chunk_size >> PAGE_SHIFT, 314 (use_lowmem ? GFP_KERNEL : GFP_HIGHUSER) | 315 __GFP_NOWARN); 316 if (!table->icm[i])