std::bad_alloc error

417 views
Skip to first unread message

Abhay Gupta

unread,
Dec 27, 2014, 1:03:31 PM12/27/14
to ns-3-...@googlegroups.com
Hello,

I am trying to generate more than 20000000 (200 million) udp packets by using UdpClientHelper class. But, after about 100 million packets, I am getting std::bad_alloc error. I am running the same program on other PC and it is running without any error. What can be the possible cause of this error? I have done  a lot of googling and ran it under debugger (gdb). Debugger gives error -

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Program received signal SIGABRT, Aborted.
0xb7fdd424 in __kernel_vsyscall ()
(gdb) bt
#0  0xb7fdd424 in __kernel_vsyscall ()
#1  0xb4265e0f in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0xb4269455 in __GI_abort () at abort.c:91
#3  0xb44f513d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#4  0xb44f2ed3 in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#5  0xb44f2f0f in std::terminate() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#6  0xb44f305e in __cxa_throw () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#7  0xb44f367f in operator new(unsigned int) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#8  0xb7a170fc in __gnu_cxx::new_allocator<ns3::Ptr<ns3::Packet> >::allocate (this=0x809d6c4, __n=128)
    at /usr/include/c++/4.6/ext/new_allocator.h:92
#9  0xb66eac9f in std::_Deque_base<ns3::Ptr<ns3::Packet>, std::allocator<ns3::Ptr<ns3::Packet> > >::_M_allocate_node (this=0x809d6c4)
    at /usr/include/c++/4.6/bits/stl_deque.h:525
#10 0xb66ea268 in std::deque<ns3::Ptr<ns3::Packet>, std::allocator<ns3::Ptr<ns3::Packet> > >::_M_push_back_aux (this=0x809d6c4, __t=...)
    at /usr/include/c++/4.6/bits/deque.tcc:427
#11 0xb66e975a in std::deque<ns3::Ptr<ns3::Packet>, std::allocator<ns3::Ptr<ns3::Packet> > >::push_back (this=0x809d6c4, __x=...)
    at /usr/include/c++/4.6/bits/stl_deque.h:1371
#12 0xb66e8ccc in std::queue<ns3::Ptr<ns3::Packet>, std::deque<ns3::Ptr<ns3::Packet>, std::allocator<ns3::Ptr<ns3::Packet> > > >::push (
    this=0x809d6c4, __x=...) at /usr/include/c++/4.6/bits/stl_queue.h:212
#13 0xb5a3925e in ns3::DropTailQueue::DoEnqueue (this=0x809d680, p=...) at ../src/network/utils/drop-tail-queue.cc:103
#14 0xb5aa41e5 in ns3::Queue::Enqueue (this=0x809d680, p=...) at ../src/network/utils/queue.cc:69
#15 0xb6403e67 in ns3::PointToPointNetDevice::Send (this=0x809d570, packet=..., dest=..., protocolNumber=2048)
    at ../src/point-to-point/model/point-to-point-net-device.cc:509
#16 0xb6679433 in ns3::Ipv4Interface::Send (this=0x80a0360, p=..., dest=...) at ../src/internet/model/ipv4-interface.cc:283
#17 0xb6689290 in ns3::Ipv4L3Protocol::SendRealOut (this=0x809e040, route=..., packet=..., ipHeader=...)
    at ../src/internet/model/ipv4-l3-protocol.cc:834
#18 0xb66868dc in ns3::Ipv4L3Protocol::Send (this=0x809e040, packet=..., source=..., destination=..., protocol=17 '\021', route=...)
    at ../src/internet/model/ipv4-l3-protocol.cc:678
#19 0xb66b5998 in ns3::MemPtrCallbackImpl<ns3::Ptr<ns3::Ipv4>, void (ns3::Ipv4::*)(ns3::Ptr<ns3::Packet>, ns3::Ipv4Address, ns3::Ipv4Address, unsigned char, ns3::Ptr<ns3::Ipv4Route>), void, ns3::Ptr<ns3::Packet>, ns3::Ipv4Address, ns3::Ipv4Address, unsigned char, ns3::Ptr<ns3::Ipv4Route>, ns3::empty, ns3::empty, ns3::empty, ns3::empty>::operator() (this=0x809e650, a1=..., a2=..., a3=..., a4=17 '\021', a5=...)
    at ./ns3/callback.h:394
#20 0xb6ea4483 in ns3::Callback<void, ns3::Ptr<ns3::Packet>, ns3::Ipv4Address, ns3::Ipv4Address, unsigned char, ns3::Ptr<ns3::Ipv4Route>, ns3::empty, ns3::empty, ns3::empty, ns3::empty>::operator() (this=0x809f3b4, a1=..., a2=..., a3=..., a4=17 '\021', a5=...) at ./ns3/callback.h:1077
#21 0xb66b0fd8 in ns3::UdpL4Protocol::Send (this=0x809f388, packet=..., saddr=..., daddr=..., sport=49153, dport=9000, route=...)
    at ../src/internet/model/udp-l4-protocol.cc:453
#22 0xb66e2cd0 in ns3::UdpSocketImpl::DoSendTo (this=0x80a1288, p=..., dest=..., port=9000) at ../src/internet/model/udp-socket-impl.cc:635
#23 0xb66e0f6e in ns3::UdpSocketImpl::DoSendTo (this=0x80a1288, p=..., address=...) at ../src/internet/model/udp-socket-impl.cc:456
#24 0xb66e0745 in ns3::UdpSocketImpl::DoSend (this=0x80a1288, p=...) at ../src/internet/model/udp-socket-impl.cc:420
#25 0xb66e016c in ns3::UdpSocketImpl::Send (this=0x80a1288, p=..., flags=0) at ../src/internet/model/udp-socket-impl.cc:389
#26 0xb5a27a7d in ns3::Socket::Send (this=0x80a1288, p=...) at ../src/network/model/socket.cc:137
\




It (debugger)does not give any location of error. After googling, I found, this problem may come either due to huge memory allocation or memory leak. In ns3, i feel, there is no cause for memory leak. Same program is running fine on other PC having same configuration and same ns3 framework, so, error may not be due to huge memory allocation. Please help to find out this error.


I have attached my code.

thank you.

abhay





udpPacket.cc

Tommaso Pecorella

unread,
Dec 28, 2014, 6:16:24 AM12/28/14
to ns-3-...@googlegroups.com
Hi,

it may be the HD space. Nowadays the physical RAM is enlarged by virtual memory and swap files, so the two PC may have different available memory. Moreover, in the PC hanging you may ave other processes using memory, like Eclipse, a browser, etc.

As a side note, I'd avoid generating so many packets in so few time, it's unrealistic. The "app" usually waits until the current block of data has been sent before transmitting more. You can explore different system to do that, and I'd point some. However, my connection is really bad today, so... have fun coding!

Cheers,

T.

pdbarnes

unread,
Jan 29, 2015, 6:43:30 PM1/29/15
to ns-3-...@googlegroups.com
Hello Abhay,

When I try to build your script the compiler complains because you have an undefined type OnuLoad:

PrintLoad(const OnuLoad& onuTrafficLoad) //callback

which you connect to a trace source "Load4Onu" in UdpClient, which doesn't exist:

UdpClientHelper client2 (i.GetAddress (1),serverPort);
ApplicationContainer clientApp2 = client2.Install (nodes.Get (0));
clientApp2
.Get(0)->TraceConnectWithoutContext ("Load4Onu", MakeCallback(&PrintLoad)); //jitendra

In fact UdpClient has no Trace sources.  Perhaps the out of memory error is in the OnuLoad implementation?

If you look at UdpClient::Send() it's clear it only creates one packet at a time, so there shouldn't be any memory consumption there.

Peter
Reply all
Reply to author
Forward
0 new messages