lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] lwip does not ack retransmissions


From: Jonathan Larmour
Subject: Re: [lwip-users] lwip does not ack retransmissions
Date: Wed, 28 Jan 2009 05:42:38 +0000
User-agent: Mozilla Thunderbird 1.0.8-1.1.fc4 (X11/20060501)

john bougs wrote:

Had to change the macro name to ALLOC_PBUF_POOL, and the second call to
use (q).... but it worked.

Great!

 From an efficiency view point this works a
little better, but not much.  Sometimes the TCP_QUEUE_OOSEQ = 0 creates
a bunch of traffic, but they both take about the same time to resolve
the issue ...200-400ms.

Yes, if this code is used, I wouldn't expect it to resolve the issue any faster than if TCP_QUEUE_OOSEQ == 0. But having TCP_QUEUE_OOSEQ==1 may make the problem appear less frequently in the first place and recover faster if we didn't quite run out of pbufs, and now it won't stall in such a bad way.

I understand what happening now so am much happier.  I will submit the
request tomorrow.  Thank you for your help.

Since you say it works, and exactly the typos which I made :-), I think I'm brave enough to check it in (with a few trivial tidies). I've attached the patch I'm checking in.

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine
Index: CHANGELOG
===================================================================
RCS file: /sources/lwip/lwip/CHANGELOG,v
retrieving revision 1.330
diff -u -5 -p -r1.330 CHANGELOG
--- CHANGELOG   19 Dec 2008 18:16:50 -0000      1.330
+++ CHANGELOG   28 Jan 2009 05:40:16 -0000
@@ -54,10 +54,14 @@ HISTORY
     Added option to limit loopback packets for each netifs.
 
 
   ++ Bugfixes:
 
+  2009-01-28 Jonathan Larmour
+  * pbuf.c: reclaim pbufs from TCP out-of-sequence segments if we run
+    out of pool pbufs.
+
   2008-12-19 Simon Goldschmidt
   * many files: patch #6699: fixed some warnings on platform where sizeof(int) 
== 2 
 
   2008-12-10 Tamas Somogyi, Frédéric Bernon
   * sockets.c: fixed bug #25051: lwip_recvfrom problem with udp: fromaddr and
Index: src/core/pbuf.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/pbuf.c,v
retrieving revision 1.130
diff -u -5 -p -r1.130 pbuf.c
--- src/core/pbuf.c     30 Sep 2008 13:40:41 -0000      1.130
+++ src/core/pbuf.c     28 Jan 2009 05:40:16 -0000
@@ -68,18 +68,57 @@
 #include "lwip/mem.h"
 #include "lwip/memp.h"
 #include "lwip/pbuf.h"
 #include "lwip/sys.h"
 #include "arch/perf.h"
+#if TCP_QUEUE_OOSEQ
+#include "lwip/tcp.h"
+#endif
 
 #include <string.h>
 
 #define SIZEOF_STRUCT_PBUF        LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
 /* Since the pool is created in memp, PBUF_POOL_BUFSIZE will be automatically
    aligned there. Therefore, PBUF_POOL_BUFSIZE_ALIGNED can be used here. */
 #define PBUF_POOL_BUFSIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE)
 
+#if TCP_QUEUE_OOSEQ
+#define ALLOC_POOL_PBUF(p) do { (p) = alloc_pool_pbuf(); } while (0)
+#else
+#define ALLOC_POOL_PBUF(p) do { (p) = memp_malloc(MEMP_PBUF_POOL); } while (0)
+#endif
+
+
+#if TCP_QUEUE_OOSEQ
+/**
+ * Attempt to reclaim some memory from queued out-of-sequence TCP segments
+ * if we run out of pool pbufs. It's better to give priority to new packets
+ * if we're running out.
+ *
+ * @return the allocated pbuf.
+ */
+static struct pbuf *
+alloc_pool_pbuf(void)
+{
+  struct tcp_pcb *pcb;
+  struct pbuf *p;
+
+retry:
+  p = memp_malloc(MEMP_PBUF_POOL);
+  if (NULL == p) {
+    for (pcb=tcp_active_pcbs; NULL != pcb; pcb = pcb->next) {
+      if (NULL != pcb->ooseq) {
+        tcp_segs_free(pcb->ooseq);
+        pcb->ooseq = NULL;
+        goto retry;
+      }
+    }
+  }
+  return p;
+}
+#endif /* TCP_QUEUE_OOSEQ */
+
 /**
  * Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
  *
  * The actual memory allocated for the pbuf is determined by the
  * layer at which the pbuf is allocated and the requested size
@@ -140,11 +179,11 @@ pbuf_alloc(pbuf_layer layer, u16_t lengt
   }
 
   switch (type) {
   case PBUF_POOL:
     /* allocate head of pbuf chain into p */
-      p = memp_malloc(MEMP_PBUF_POOL);
+    ALLOC_POOL_PBUF(p);
     LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 3, ("pbuf_alloc: allocated pbuf 
%p\n", (void *)p));
     if (p == NULL) {
       return NULL;
     }
     p->type = type;
@@ -170,11 +209,11 @@ pbuf_alloc(pbuf_layer layer, u16_t lengt
     r = p;
     /* remaining length to be allocated */
     rem_len = length - p->len;
     /* any remaining pbufs to be allocated? */
     while (rem_len > 0) {
-      q = memp_malloc(MEMP_PBUF_POOL);
+      ALLOC_POOL_PBUF(q);
       if (q == NULL) {
         /* free chain so far allocated */
         pbuf_free(p);
         /* bail out unsuccesfully */
         return NULL;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]