Skip to content

Commit

Permalink
tun: align write-heavy flow entry members to a cache line
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lrq-max authored and davem330 committed Dec 6, 2018
1 parent 7a35a50 commit 83b1bc1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct tun_flow_entry {
u32 rxhash;
u32 rps_rxhash;
int queue_index;
unsigned long updated;
unsigned long updated ____cacheline_aligned_in_smp;
};

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

0 comments on commit 83b1bc1

Please sign in to comment.