Skip to content

Commit 83b1bc1

Browse files
lrq-maxdavem330
authored andcommitted
tun: align write-heavy flow entry members to a cache line
tun flow entry 'updated' fields are written when receive every packet. Thus if a flow is receiving packets from a particular flow entry, it'll cause false-sharing with all the other who has looked it up, so move it in its own cache line and update 'queue_index' and 'update' field only when they are changed to reduce the cache false-sharing. Signed-off-by: Zhang Yu <[email protected]> Signed-off-by: Wang Li <[email protected]> Signed-off-by: Li RongQing <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7a35a50 commit 83b1bc1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/net/tun.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ struct tun_flow_entry {
201201
u32 rxhash;
202202
u32 rps_rxhash;
203203
int queue_index;
204-
unsigned long updated;
204+
unsigned long updated ____cacheline_aligned_in_smp;
205205
};
206206

207207
#define TUN_NUM_FLOW_ENTRIES 1024
@@ -539,8 +539,10 @@ static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
539539
e = tun_flow_find(head, rxhash);
540540
if (likely(e)) {
541541
/* TODO: keep queueing to old queue until it's empty? */
542-
e->queue_index = queue_index;
543-
e->updated = jiffies;
542+
if (e->queue_index != queue_index)
543+
e->queue_index = queue_index;
544+
if (e->updated != jiffies)
545+
e->updated = jiffies;
544546
sock_rps_record_flow_hash(e->rps_rxhash);
545547
} else {
546548
spin_lock_bh(&tun->lock);

0 commit comments

Comments
 (0)