* Removed code duplication by merging destruct_pkt_mbuf and mb_free_ext.

This gets rid of one layer of indirection, too.
  Also, this removed a potential memory leakage, when deleting external memory 
  in destruct_pkt_mbuf. In the case where memory of type EXT_JUMBO9 was
  previously allocated, this would have been wrongly catched by the condition 
  (ext_type & EXT_CLUSTER) != 0.
* Renamed some variables to more human readable style.
* Commented some constants in mbuf.h to make more clear what they indicate and
  to show that they should not be treatet as flags, as it was the case one
  some locations before.
* Removed the EXT_PACKET constant, as it requests the same cache as
  EXT_CLUSTER. EXT_PACKET is a optimizing technique from BSD, where a cache 
  exists holding some preallocated mbuf + cluster memory. Such a thing is not
  implemented in the compat layer, at all. Though EXT_CLUSTER tells more
  clearly what the size of the external data buffer is.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34692 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Colin Günther
2009-12-18 19:18:58 +00:00
parent de86f3421c
commit fafb321062
2 changed files with 31 additions and 53 deletions
@@ -114,11 +114,10 @@ struct mbuf {
(M_PKTHDR|M_RDONLY|M_BCAST|M_MCAST|\
M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_VLANTAG)
#define EXT_CLUSTER 1
#define EXT_PACKET 3
#define EXT_JUMBOP 4
#define EXT_JUMBO9 5
#define EXT_NET_DRV 100
#define EXT_CLUSTER 1 /* 2048 bytes */
#define EXT_JUMBOP 4 /* Page size */
#define EXT_JUMBO9 5 /* 9 * 1024 bytes */
#define EXT_NET_DRV 100 /* custom ext_buf provided by net driver */
#define CSUM_IP 0x0001
#define CSUM_TCP 0x0002
+27 -48
View File
@@ -111,59 +111,39 @@ construct_pkt_mbuf(int how, struct mbuf *memoryBuffer, short type, int flags)
construct_mbuf(memoryBuffer, type, flags);
if (construct_ext_mbuf(memoryBuffer, how) < 0)
return -1;
memoryBuffer->m_ext.ext_type |= EXT_PACKET;
memoryBuffer->m_ext.ext_type = EXT_CLUSTER;
return 0;
}
static void
destruct_pkt_mbuf(struct mbuf *memoryBuffer)
{
object_cache *cache;
if ((memoryBuffer->m_ext.ext_type & EXT_CLUSTER) != 0)
cache = sChunkCache;
else if ((memoryBuffer->m_ext.ext_type & EXT_JUMBO9) != 0)
cache = sJumbo9ChunkCache;
else if ((memoryBuffer->m_ext.ext_type & EXT_JUMBOP) != 0)
cache = sJumboPageSizeCache;
else {
panic("unknown cache");
return;
}
object_cache_free(cache, memoryBuffer->m_ext.ext_buf);
memoryBuffer->m_ext.ext_buf = NULL;
}
struct mbuf *
m_getcl(int how, short type, int flags)
{
struct mbuf *mb =
struct mbuf *memoryBuffer =
(struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how));
if (mb == NULL)
if (memoryBuffer == NULL)
return NULL;
if (construct_pkt_mbuf(how, mb, type, flags) < 0) {
object_cache_free(sMBufCache, mb);
if (construct_pkt_mbuf(how, memoryBuffer, type, flags) < 0) {
object_cache_free(sMBufCache, memoryBuffer);
return NULL;
}
return mb;
return memoryBuffer;
}
static struct mbuf *
_m_get(int how, short type, int flags)
{
struct mbuf *mb =
struct mbuf *memoryBuffer =
(struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how));
if (mb == NULL)
if (memoryBuffer == NULL)
return NULL;
construct_mbuf(mb, type, flags);
construct_mbuf(memoryBuffer, type, flags);
return mb;
return memoryBuffer;
}
@@ -184,16 +164,16 @@ m_gethdr(int how, short type)
struct mbuf *
m_getjcl(int how, short type, int flags, int size)
{
struct mbuf *mb =
struct mbuf *memoryBuffer =
(struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how));
if (mb == NULL)
if (memoryBuffer == NULL)
return NULL;
construct_mbuf(mb, type, flags);
if (construct_ext_sized_mbuf(mb, how, size) < 0) {
object_cache_free(sMBufCache, mb);
construct_mbuf(memoryBuffer, type, flags);
if (construct_ext_sized_mbuf(memoryBuffer, how, size) < 0) {
object_cache_free(sMBufCache, memoryBuffer);
return NULL;
}
return mb;
return memoryBuffer;
}
@@ -234,20 +214,19 @@ mb_free_ext(struct mbuf *memoryBuffer)
panic("unsupported");
*/
if (memoryBuffer->m_ext.ext_type == EXT_PACKET)
destruct_pkt_mbuf(memoryBuffer);
else if (memoryBuffer->m_ext.ext_type == EXT_CLUSTER) {
object_cache_free(sChunkCache, memoryBuffer->m_ext.ext_buf);
memoryBuffer->m_ext.ext_buf = NULL;
} else if (memoryBuffer->m_ext.ext_type == EXT_JUMBO9) {
object_cache_free(sJumbo9ChunkCache, memoryBuffer->m_ext.ext_buf);
memoryBuffer->m_ext.ext_buf = NULL;
} else if (memoryBuffer->m_ext.ext_type == EXT_JUMBOP) {
object_cache_free(sJumboPageSizeCache, memoryBuffer->m_ext.ext_buf);
memoryBuffer->m_ext.ext_buf = NULL;
} else
object_cache *cache = NULL;
if (memoryBuffer->m_ext.ext_type == EXT_CLUSTER)
cache = sChunkCache;
else if (memoryBuffer->m_ext.ext_type == EXT_JUMBO9)
cache = sJumbo9ChunkCache;
else if (memoryBuffer->m_ext.ext_type == EXT_JUMBOP)
cache = sJumboPageSizeCache;
else
panic("unknown type");
object_cache_free(cache, memoryBuffer->m_ext.ext_buf);
memoryBuffer->m_ext.ext_buf = NULL;
object_cache_free(sMBufCache, memoryBuffer);
}