Defer skb allocation -- add destroy buffers function for virtio]
Subsystems (3)
PATCH v2 1/4 Defer skb allocation -- add destroy buffers function for virtio]
Sorry, forgot to CC all.
Thanks
Shirley
Quoted 7 lines · Shirley Ma
Hello Michael,
Quoted 3 lines · Michael S. Tsirkin
No, this code would be in virtio net.
destroy would simply be the virtqueue API that returns data pointer.
Quoted 7 lines
Since
virtio_netdoesn't maintain the descriptors of vring, to return the data pointer from vq destroy will go throughvq->vring.num. It's a little expensive. Since it's shutdown code, it might be OK.Rusty,
How do you think? If I change the code something like this, not tested.
Yes, this is basically what I had in mind.
Looks slightly easier to understand than callbacks to me. But far from critical of course.
Quoted 22 lines
+static void *vring_destroy_bufs(struct virtqueue
*_vq, void (*destroy)(void *))(quoted diff) +19
-0+{ + struct vring_virtqueue *vq = to_vvq(_vq); + unsigned int i; + + START_USE(vq); + + for (i = 0; i < vq->vring.num; i++) { + if (vq->data[i]) { + /* detach_buf clears data, so grab it now. */ + detach_buf(vq, i); + END_USED(vq); + return vq->data[i]; + } + } + /* That should have freed everything. */ + BUG_ON(vq->num_free != vq->vring.num); + END_USED(vq); + return NULL; +}
Review
Quoted 10 lines
(quoted diff) +9
-0+static void virtnet_free_bufs(struct virtqueue *rvq) +{ + void *buf; + for (;;) { + buf = rvq->destroy(rvq); + if (!buf) { + BUG_ON(vi->num != 0); + return; + } else {
Since we have return above, you can put the following code in the outer block and reduce nesting (without "else").
Quoted 15 lines
(quoted diff) +11
-0+ if (vi->mergeable_rx_bufs || vi->big_packets) + struct page *page, *next; + + for (page = buf; page; page = next) { + next = (struct page *)page->private; *)page->private; + __free_pages(page, 0); + } else + kfree_skb(buf); + } + --vi->num; +}Thanks
Shirley