Skip to content

Commit 1f20a57

Browse files
alobakinChristoph Hellwig
authored andcommitted
page_pool: make sure frag API fields don't span between cachelines
After commit 5027ec1 ("net: page_pool: split the page_pool_params into fast and slow") that made &page_pool contain only "hot" params at the start, cacheline boundary chops frag API fields group in the middle again. To not bother with this each time fast params get expanded or shrunk, let's just align them to `4 * sizeof(long)`, the closest upper pow-2 to their actual size (2 longs + 1 int). This ensures 16-byte alignment for the 32-bit architectures and 32-byte alignment for the 64-bit ones, excluding unnecessary false-sharing. ::page_state_hold_cnt is used quite intensively on hotpath no matter if frag API is used, so move it to the newly created hole in the first cacheline. Signed-off-by: Alexander Lobakin <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent ea01fa7 commit 1f20a57

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

include/net/page_pool/types.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,22 @@ struct page_pool {
130130
struct page_pool_params_fast p;
131131

132132
int cpuid;
133+
u32 pages_state_hold_cnt;
133134
bool has_init_callback;
134135

136+
/* The following block must stay within one cacheline. On 32-bit
137+
* systems, sizeof(long) == sizeof(int), so that the block size is
138+
* ``3 * sizeof(long)``. On 64-bit systems, the actual size is
139+
* ``2 * sizeof(long) + sizeof(int)``. The closest pow-2 to both of
140+
* them is ``4 * sizeof(long)``, so just use that one for simplicity.
141+
* Having it aligned to a cacheline boundary may be excessive and
142+
* doesn't bring any good.
143+
*/
144+
__cacheline_group_begin(frag) __aligned(4 * sizeof(long));
135145
long frag_users;
136146
struct page *frag_page;
137147
unsigned int frag_offset;
138-
u32 pages_state_hold_cnt;
148+
__cacheline_group_end(frag);
139149

140150
struct delayed_work release_dw;
141151
void (*disconnect)(void *pool);

net/core/page_pool.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,22 @@ static void page_pool_producer_unlock(struct page_pool *pool,
172172
spin_unlock_bh(&pool->ring.producer_lock);
173173
}
174174

175+
static void page_pool_struct_check(void)
176+
{
177+
CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_users);
178+
CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_page);
179+
CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_offset);
180+
CACHELINE_ASSERT_GROUP_SIZE(struct page_pool, frag, 4 * sizeof(long));
181+
}
182+
175183
static int page_pool_init(struct page_pool *pool,
176184
const struct page_pool_params *params,
177185
int cpuid)
178186
{
179187
unsigned int ring_qsize = 1024; /* Default */
180188

189+
page_pool_struct_check();
190+
181191
memcpy(&pool->p, &params->fast, sizeof(pool->p));
182192
memcpy(&pool->slow, &params->slow, sizeof(pool->slow));
183193

0 commit comments

Comments
 (0)