aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/aoe/aoedev.c
diff options
context:
space:
mode:
authorEd L. Cashin <ecashin@coraid.com>2008-02-08 07:20:05 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:32 -0500
commit9bb237b6a670fa7a6af3adc65231b1f6fda44510 (patch)
tree6e30e57f3d79e28e8be92f8685037998c16d42da /drivers/block/aoe/aoedev.c
parent262bf54144ebcb78cd0d057d2705dc5fb7bba7ac (diff)
aoe: dynamically allocate a capped number of skbs when necessary
What this Patch Does Even before this recent series of 12 patches to 2.6.22-rc4, the aoe driver was reusing a small set of skbs that were allocated once and were only used for outbound AoE commands. The network layer cannot be allowed to put_page on the data that is still associated with a bio we haven't returned to the block layer, so the aoe driver (even before the patch under discussion) is still the owner of skbs that have been handed to the network layer for transmission. We need to keep track of these skbs so that we can free them, but by tracking them, we can also easily re-use them. The new patch was a response to the behavior of certain network drivers. We cannot reuse an skb that the network driver still has in its transmit ring. Network drivers can defer transmit ring cleanup and then use the state in the skb to determine how many data segments to clean up in its transmit ring. The tg3 driver is one driver that behaves in this way. When the network driver defers cleanup of its transmit ring, the aoe driver can find itself in a situation where it would like to send an AoE command, and the AoE target is ready for more work, but the network driver still has all of the pre-allocated skbs. In that case, the new patch just calls alloc_skb, as you'd expect. We don't want to get carried away, though. We try not to do excessive allocation in the write path, so we cap the number of skbs we dynamically allocate. Probably calling it a "dynamic pool" is misleading. We were already trying to use a small fixed-size set of pre-allocated skbs before this patch, and this patch just provides a little headroom (with a ceiling, though) to accomodate network drivers that hang onto skbs, by allocating when needed. The d->skbpool_hd list of allocated skbs is necessary so that we can free them later. We didn't notice the need for this headroom until AoE targets got fast enough. Alternatives If the network layer never did a put_page on the pages in the bio's we get from the block layer, then it would be possible for us to hand skbs to the network layer and forget about them, allowing the network layer to free skbs itself (and thereby calling our own skb->destructor callback function if we needed that). In that case we could get rid of the pre-allocated skbs and also the d->skbpool_hd, instead just calling alloc_skb every time we wanted to transmit a packet. The slab allocator would effectively maintain the list of skbs. Besides a loss of CPU cache locality, the main concern with that approach the danger that it would increase the likelihood of deadlock when VM is trying to free pages by writing dirty data from the page cache through the aoe driver out to persistent storage on an AoE device. Right now we have a situation where we have pre-allocation that corresponds to how much we use, which seems ideal. Of course, there's still the separate issue of receiving the packets that tell us that a write has successfully completed on the AoE target. When memory is low and VM is using AoE to flush dirty data to free up pages, it would be perfect if there were a way for us to register a fast callback that could recognize write command completion responses. But I don't think the current problems with the receive side of the situation are a justification for exacerbating the problem on the transmit side. Signed-off-by: Ed L. Cashin <ecashin@coraid.com> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/aoe/aoedev.c')
-rw-r--r--drivers/block/aoe/aoedev.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index e26f6f4a28a2..839a964906ce 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -7,11 +7,13 @@
7#include <linux/hdreg.h> 7#include <linux/hdreg.h>
8#include <linux/blkdev.h> 8#include <linux/blkdev.h>
9#include <linux/netdevice.h> 9#include <linux/netdevice.h>
10#include <linux/delay.h>
10#include "aoe.h" 11#include "aoe.h"
11 12
12static void dummy_timer(ulong); 13static void dummy_timer(ulong);
13static void aoedev_freedev(struct aoedev *); 14static void aoedev_freedev(struct aoedev *);
14static void freetgt(struct aoetgt *t); 15static void freetgt(struct aoedev *d, struct aoetgt *t);
16static void skbpoolfree(struct aoedev *d);
15 17
16static struct aoedev *devlist; 18static struct aoedev *devlist;
17static spinlock_t devlist_lock; 19static spinlock_t devlist_lock;
@@ -125,9 +127,10 @@ aoedev_freedev(struct aoedev *d)
125 t = d->targets; 127 t = d->targets;
126 e = t + NTARGETS; 128 e = t + NTARGETS;
127 for (; t < e && *t; t++) 129 for (; t < e && *t; t++)
128 freetgt(*t); 130 freetgt(d, *t);
129 if (d->bufpool) 131 if (d->bufpool)
130 mempool_destroy(d->bufpool); 132 mempool_destroy(d->bufpool);
133 skbpoolfree(d);
131 kfree(d); 134 kfree(d);
132} 135}
133 136
@@ -176,6 +179,43 @@ aoedev_flush(const char __user *str, size_t cnt)
176 return 0; 179 return 0;
177} 180}
178 181
182/* I'm not really sure that this is a realistic problem, but if the
183network driver goes gonzo let's just leak memory after complaining. */
184static void
185skbfree(struct sk_buff *skb)
186{
187 enum { Sms = 100, Tms = 3*1000};
188 int i = Tms / Sms;
189
190 if (skb == NULL)
191 return;
192 while (atomic_read(&skb_shinfo(skb)->dataref) != 1 && i-- > 0)
193 msleep(Sms);
194 if (i <= 0) {
195 printk(KERN_ERR
196 "aoe: %s holds ref: %s\n",
197 skb->dev ? skb->dev->name : "netif",
198 "cannot free skb -- memory leaked.");
199 return;
200 }
201 skb_shinfo(skb)->nr_frags = skb->data_len = 0;
202 skb_trim(skb, 0);
203 dev_kfree_skb(skb);
204}
205
206static void
207skbpoolfree(struct aoedev *d)
208{
209 struct sk_buff *skb;
210
211 while ((skb = d->skbpool_hd)) {
212 d->skbpool_hd = skb->next;
213 skb->next = NULL;
214 skbfree(skb);
215 }
216 d->skbpool_tl = NULL;
217}
218
179/* find it or malloc it */ 219/* find it or malloc it */
180struct aoedev * 220struct aoedev *
181aoedev_by_sysminor_m(ulong sysminor) 221aoedev_by_sysminor_m(ulong sysminor)
@@ -215,16 +255,14 @@ aoedev_by_sysminor_m(ulong sysminor)
215} 255}
216 256
217static void 257static void
218freetgt(struct aoetgt *t) 258freetgt(struct aoedev *d, struct aoetgt *t)
219{ 259{
220 struct frame *f, *e; 260 struct frame *f, *e;
221 261
222 f = t->frames; 262 f = t->frames;
223 e = f + t->nframes; 263 e = f + t->nframes;
224 for (; f < e; f++) { 264 for (; f < e; f++)
225 skb_shinfo(f->skb)->nr_frags = 0; 265 skbfree(f->skb);
226 dev_kfree_skb(f->skb);
227 }
228 kfree(t->frames); 266 kfree(t->frames);
229 kfree(t); 267 kfree(t);
230} 268}