win-pvdrivers

changeset 69:a41314faf255

xennet: only allocate as much memory as needed for linearization, not a whole page
author Andy Grover <andy.grover@oracle.com>
date Wed Dec 19 13:01:04 2007 -0800 (2007-12-19)
parents 7ae8e22810a3
children 0d06cc4c5fc9
files xennet/xennet.c
line diff
     1.1 --- a/xennet/xennet.c	Wed Dec 19 11:23:47 2007 -0800
     1.2 +++ b/xennet/xennet.c	Wed Dec 19 13:01:04 2007 -0800
     1.3 @@ -187,7 +187,6 @@ static NDIS_STATUS
     1.4  XenNet_TxBufferGC(struct xennet_info *xi)
     1.5  {
     1.6    RING_IDX cons, prod;
     1.7 -
     1.8    unsigned short id;
     1.9    PNDIS_PACKET pkt;
    1.10    PMDL pmdl;
    1.11 @@ -214,7 +213,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
    1.12  
    1.13        /* free linearized data page */
    1.14        pmdl = *(PMDL *)pkt->MiniportReservedEx;
    1.15 -      MmFreePagesFromMdl(pmdl);
    1.16 +      NdisFreeMemory(MmGetMdlVirtualAddress(pmdl), 0, 0);
    1.17        IoFreeMdl(pmdl);
    1.18  
    1.19        xi->stat_tx_ok++;
    1.20 @@ -1019,6 +1018,7 @@ XenNet_ReturnPacket(
    1.21  PMDL
    1.22  XenNet_Linearize(PNDIS_PACKET Packet)
    1.23  {
    1.24 +  NDIS_STATUS status;
    1.25    PMDL pmdl;
    1.26    char *start;
    1.27    PNDIS_BUFFER buffer;
    1.28 @@ -1026,17 +1026,24 @@ XenNet_Linearize(PNDIS_PACKET Packet)
    1.29    UINT buff_len;
    1.30    UINT tot_buff_len;
    1.31  
    1.32 -  pmdl = AllocatePage();
    1.33 +  NdisGetFirstBufferFromPacketSafe(Packet, &buffer, &buff_va, &buff_len,
    1.34 +    &tot_buff_len, NormalPagePriority);
    1.35 +  ASSERT(tot_buff_len <= XN_MAX_PKT_SIZE);
    1.36  
    1.37 -  start = MmGetSystemAddressForMdlSafe(pmdl, NormalPagePriority);
    1.38 -  if (!start)
    1.39 +  status = NdisAllocateMemoryWithTag(&start, tot_buff_len, XENNET_POOL_TAG);
    1.40 +  if (!NT_SUCCESS(status))
    1.41    {
    1.42 +    KdPrint(("Could not allocate memory for linearization\n"));
    1.43      return NULL;
    1.44    }
    1.45 -
    1.46 -  NdisGetFirstBufferFromPacketSafe(Packet, &buffer, &buff_va, &buff_len,
    1.47 -    &tot_buff_len, NormalPagePriority);
    1.48 -  ASSERT(tot_buff_len <= PAGE_SIZE);
    1.49 +  pmdl = IoAllocateMdl(start, tot_buff_len, FALSE, FALSE, FALSE);
    1.50 +  if (!pmdl)
    1.51 +  {
    1.52 +    KdPrint(("Could not allocate MDL for linearization\n"));
    1.53 +    NdisFreeMemory(start, 0, 0);
    1.54 +    return NULL;
    1.55 +  }
    1.56 +  MmBuildMdlForNonPagedPool(pmdl);
    1.57  
    1.58    while (buffer)
    1.59    {
    1.60 @@ -1094,7 +1101,7 @@ XenNet_SendPackets(
    1.61        *MmGetMdlPfnArray(pmdl),
    1.62        TRUE);
    1.63      xi->grant_tx_ref[id] = tx->gref;
    1.64 -    tx->offset = 0;
    1.65 +    tx->offset = (uint16_t)MmGetMdlByteOffset(pmdl);
    1.66      tx->size = (UINT16)pkt_size;
    1.67      tx->flags = NETTXF_csum_blank;
    1.68