Skip to content

Commit e9275f5

Browse files
Zoltan Kissdavem330
Zoltan Kiss
authored andcommitted
xen-netback: Aggregate TX unmap operations
Unmapping causes TLB flushing, therefore we should make it in the largest possible batches. However we shouldn't starve the guest for too long. So if the guest has space for at least two big packets and we don't have at least a quarter ring to unmap, delay it for at most 1 milisec. Signed-off-by: Zoltan Kiss <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0935078 commit e9275f5

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

drivers/net/xen-netback/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ struct xenvif {
137137
u16 dealloc_ring[MAX_PENDING_REQS];
138138
struct task_struct *dealloc_task;
139139
wait_queue_head_t dealloc_wq;
140+
struct timer_list dealloc_delay;
141+
bool dealloc_delay_timed_out;
140142

141143
/* Use kthread for guest RX */
142144
struct task_struct *task;

drivers/net/xen-netback/interface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
408408
.desc = i };
409409
vif->grant_tx_handle[i] = NETBACK_INVALID_HANDLE;
410410
}
411+
init_timer(&vif->dealloc_delay);
411412

412413
/*
413414
* Initialise a dummy MAC address. We choose the numerically
@@ -556,6 +557,7 @@ void xenvif_disconnect(struct xenvif *vif)
556557
}
557558

558559
if (vif->dealloc_task) {
560+
del_timer_sync(&vif->dealloc_delay);
559561
kthread_stop(vif->dealloc_task);
560562
vif->dealloc_task = NULL;
561563
}

drivers/net/xen-netback/netback.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ static inline pending_ring_idx_t pending_index(unsigned i)
133133
return i & (MAX_PENDING_REQS-1);
134134
}
135135

136+
static inline pending_ring_idx_t nr_free_slots(struct xen_netif_tx_back_ring *ring)
137+
{
138+
return ring->nr_ents - (ring->sring->req_prod - ring->rsp_prod_pvt);
139+
}
140+
136141
bool xenvif_rx_ring_slots_available(struct xenvif *vif, int needed)
137142
{
138143
RING_IDX prod, cons;
@@ -1716,9 +1721,36 @@ static inline int tx_work_todo(struct xenvif *vif)
17161721
return 0;
17171722
}
17181723

1724+
static void xenvif_dealloc_delay(unsigned long data)
1725+
{
1726+
struct xenvif *vif = (struct xenvif *)data;
1727+
1728+
vif->dealloc_delay_timed_out = true;
1729+
wake_up(&vif->dealloc_wq);
1730+
}
1731+
17191732
static inline bool tx_dealloc_work_todo(struct xenvif *vif)
17201733
{
1721-
return vif->dealloc_cons != vif->dealloc_prod;
1734+
if (vif->dealloc_cons != vif->dealloc_prod) {
1735+
if ((nr_free_slots(&vif->tx) > 2 * XEN_NETBK_LEGACY_SLOTS_MAX) &&
1736+
(vif->dealloc_prod - vif->dealloc_cons < MAX_PENDING_REQS / 4) &&
1737+
!vif->dealloc_delay_timed_out) {
1738+
if (!timer_pending(&vif->dealloc_delay)) {
1739+
vif->dealloc_delay.function =
1740+
xenvif_dealloc_delay;
1741+
vif->dealloc_delay.data = (unsigned long)vif;
1742+
mod_timer(&vif->dealloc_delay,
1743+
jiffies + msecs_to_jiffies(1));
1744+
1745+
}
1746+
return false;
1747+
}
1748+
del_timer_sync(&vif->dealloc_delay);
1749+
vif->dealloc_delay_timed_out = false;
1750+
return true;
1751+
}
1752+
1753+
return false;
17221754
}
17231755

17241756
void xenvif_unmap_frontend_rings(struct xenvif *vif)

0 commit comments

Comments
 (0)