* simple memory malloc and free in ip_output.c
@ 2013-12-27 3:16 Guibin(Bill) Tian
2013-12-27 3:24 ` bill4carson
2014-01-02 5:12 ` Mulyadi Santosa
0 siblings, 2 replies; 10+ messages in thread
From: Guibin(Bill) Tian @ 2013-12-27 3:16 UTC (permalink / raw)
To: kernelnewbies
Hi,
I am doing a very simple operation at the method of ip_queue_xmit in
ip_output.c.
The code is very simple.
char *p = kmalloc(48, GFP_KERNEL);
kfree(p);
This will be called every time this method is called.
But the result is that the whole system is not responsive at all. This is a
very simple, not sure what I am doing wrong. Can anybody help?
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131226/3b559310/attachment.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2013-12-27 3:16 simple memory malloc and free in ip_output.c Guibin(Bill) Tian
@ 2013-12-27 3:24 ` bill4carson
2013-12-27 4:21 ` Guibin(Bill) Tian
2014-01-02 5:12 ` Mulyadi Santosa
1 sibling, 1 reply; 10+ messages in thread
From: bill4carson @ 2013-12-27 3:24 UTC (permalink / raw)
To: kernelnewbies
On 2013?12?27? 11:16, Guibin(Bill) Tian wrote:
> Hi,
> I am doing a very simple operation at the method of ip_queue_xmit in ip_output.c.
> The code is very simple.
>
> char *p = kmalloc(48, GFP_KERNEL);
^^^^^^^^
GFP_ATOMIC ?
--
?????????,??????????
--bill
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2013-12-27 3:24 ` bill4carson
@ 2013-12-27 4:21 ` Guibin(Bill) Tian
2013-12-27 5:39 ` Guibin(Bill) Tian
0 siblings, 1 reply; 10+ messages in thread
From: Guibin(Bill) Tian @ 2013-12-27 4:21 UTC (permalink / raw)
To: kernelnewbies
I tried it, still the same thing.
Also, there is another side effect that if I call the two lines of code
above, the internet connection seems to break except to localhost.
On Thu, Dec 26, 2013 at 10:24 PM, bill4carson <bill4carson@gmail.com> wrote:
>
>
> On 2013?12?27? 11:16, Guibin(Bill) Tian wrote:
>
>> Hi,
>> I am doing a very simple operation at the method of ip_queue_xmit in
>> ip_output.c.
>> The code is very simple.
>>
>> char *p = kmalloc(48, GFP_KERNEL);
>>
> ^^^^^^^^
> GFP_ATOMIC ?
> --
> ?????????,??????????
>
> --bill
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131226/4775133e/attachment.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2013-12-27 4:21 ` Guibin(Bill) Tian
@ 2013-12-27 5:39 ` Guibin(Bill) Tian
2013-12-27 7:02 ` Anand Moon
0 siblings, 1 reply; 10+ messages in thread
From: Guibin(Bill) Tian @ 2013-12-27 5:39 UTC (permalink / raw)
To: kernelnewbies
It does work in your way, thanks Carson
On Thursday, December 26, 2013, Guibin(Bill) Tian wrote:
> I tried it, still the same thing.
> Also, there is another side effect that if I call the two lines of code
> above, the internet connection seems to break except to localhost.
>
>
> On Thu, Dec 26, 2013 at 10:24 PM, bill4carson <bill4carson at gmail.com<javascript:_e({}, 'cvml', 'bill4carson@gmail.com');>
> > wrote:
>
>>
>>
>> On 2013?12?27? 11:16, Guibin(Bill) Tian wrote:
>>
>>> Hi,
>>> I am doing a very simple operation at the method of ip_queue_xmit in
>>> ip_output.c.
>>> The code is very simple.
>>>
>>> char *p = kmalloc(48, GFP_KERNEL);
>>>
>> ^^^^^^^^
>> GFP_ATOMIC ?
>> --
>> ?????????,??????????
>>
>> --bill
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131227/8c26bcbe/attachment.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2013-12-27 5:39 ` Guibin(Bill) Tian
@ 2013-12-27 7:02 ` Anand Moon
0 siblings, 0 replies; 10+ messages in thread
From: Anand Moon @ 2013-12-27 7:02 UTC (permalink / raw)
To: kernelnewbies
Hi,
ip_queue_xmit will get called for every packet send, so frequent allocation and free of memory can be a problem for slab allocator.
If you need only 48 bytes of memory in a function you can chose to use array.
-Anand Moon
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.14 (GNU/Linux)
jA0EAwMCYq3dHqTzwcVgyRxC1j+oLxS8Yw92EIeKln+x3eAWzd7mM/pUluRo
=0RYk
-----END PGP MESSAGE-----
On Friday, December 27, 2013 11:11 AM, Guibin(Bill) Tian <gbtian@gmail.com> wrote:
It does work in your way, thanks Carson?
On Thursday, December 26, 2013, Guibin(Bill) Tian wrote:
I tried it, still the same thing.?
>Also, there is another side effect that if I call the two lines of code above, the internet connection seems to break except to localhost.?
>
>
>
>On Thu, Dec 26, 2013 at 10:24 PM, bill4carson <bill4carson@gmail.com> wrote:
>
>
>>
>>On 2013?12?27? 11:16, Guibin(Bill) Tian wrote:
>>
>>Hi,
>>>I am doing a very simple operation at the method of ip_queue_xmit in ip_output.c.
>>>The code is very simple.
>>>
>>>char *p = kmalloc(48, GFP_KERNEL);
>>>
? ? ? ? ? ? ? ? ? ? ? ? ?^^^^^^^^
>>? ? ? ? ? ? ? ? ? ? ? ? GFP_ATOMIC ?
>>--
>>?????????,??????????
>>
>>--bill
>>
>
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131226/e27a6158/attachment-0001.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2013-12-27 3:16 simple memory malloc and free in ip_output.c Guibin(Bill) Tian
2013-12-27 3:24 ` bill4carson
@ 2014-01-02 5:12 ` Mulyadi Santosa
2014-01-02 5:41 ` Valdis.Kletnieks at vt.edu
1 sibling, 1 reply; 10+ messages in thread
From: Mulyadi Santosa @ 2014-01-02 5:12 UTC (permalink / raw)
To: kernelnewbies
On Fri, Dec 27, 2013 at 10:16 AM, Guibin(Bill) Tian <gbtian@gmail.com> wrote:
> Hi,
> I am doing a very simple operation at the method of ip_queue_xmit in
> ip_output.c.
> The code is very simple.
>
> char *p = kmalloc(48, GFP_KERNEL);
> kfree(p);
>
> This will be called every time this method is called.
>
> But the result is that the whole system is not responsive at all. This is a
> very simple, not sure what I am doing wrong. Can anybody help?
Other than what others have said, IMHO it is better to avoid such
rapid alloc/free, assuming your code fragment is running on every
packet reception/sending.
Instead, I suggest to allocate the memory before the ip_queue_xmit and
use-reuse it inside ip_queue_xmit.
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2014-01-02 5:12 ` Mulyadi Santosa
@ 2014-01-02 5:41 ` Valdis.Kletnieks at vt.edu
2014-01-02 6:15 ` Mulyadi Santosa
0 siblings, 1 reply; 10+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2014-01-02 5:41 UTC (permalink / raw)
To: kernelnewbies
On Thu, 02 Jan 2014 12:12:49 +0700, Mulyadi Santosa said:
> Other than what others have said, IMHO it is better to avoid such
> rapid alloc/free, assuming your code fragment is running on every
> packet reception/sending.
>
> Instead, I suggest to allocate the memory before the ip_queue_xmit and
> use-reuse it inside ip_queue_xmit.
Be careful with re-entrancy issues - you'll want a separate instance of memory
for all possible concurrent callers of ip_queue_xmit (you may need one per
active interface, because you can e transmitting packets on multiple interfaces
at the same time).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140102/711f1a02/attachment.bin
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2014-01-02 5:41 ` Valdis.Kletnieks at vt.edu
@ 2014-01-02 6:15 ` Mulyadi Santosa
2014-01-02 17:42 ` Guibin(Bill) Tian
0 siblings, 1 reply; 10+ messages in thread
From: Mulyadi Santosa @ 2014-01-02 6:15 UTC (permalink / raw)
To: kernelnewbies
On Thu, Jan 2, 2014 at 12:41 PM, <Valdis.Kletnieks@vt.edu> wrote:
> On Thu, 02 Jan 2014 12:12:49 +0700, Mulyadi Santosa said:
>
>> Other than what others have said, IMHO it is better to avoid such
>> rapid alloc/free, assuming your code fragment is running on every
>> packet reception/sending.
>>
>> Instead, I suggest to allocate the memory before the ip_queue_xmit and
>> use-reuse it inside ip_queue_xmit.
>
> Be careful with re-entrancy issues - you'll want a separate instance of memory
> for all possible concurrent callers of ip_queue_xmit (you may need one per
> active interface, because you can e transmitting packets on multiple interfaces
> at the same time).
Ah yes, you're correct Valdis. Thanks for note.
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2014-01-02 6:15 ` Mulyadi Santosa
@ 2014-01-02 17:42 ` Guibin(Bill) Tian
2014-01-07 11:27 ` Mulyadi Santosa
0 siblings, 1 reply; 10+ messages in thread
From: Guibin(Bill) Tian @ 2014-01-02 17:42 UTC (permalink / raw)
To: kernelnewbies
Thank you sirs. But in fact, I don't alloc/free for every packet. I did
exactly as what you said---reuse.
I am a little confused why GFP_ATOMIC can work but GFP_KERNEL will cause
the system to panic. Does it because that GFP_KERNEL can sleep in kmalloc,
then ip_xmit_queue will be held or something? But anyway, GFP_ATOMIC works
perfectly.
On Thu, Jan 2, 2014 at 1:15 AM, Mulyadi Santosa
<mulyadi.santosa@gmail.com>wrote:
> On Thu, Jan 2, 2014 at 12:41 PM, <Valdis.Kletnieks@vt.edu> wrote:
> > On Thu, 02 Jan 2014 12:12:49 +0700, Mulyadi Santosa said:
> >
> >> Other than what others have said, IMHO it is better to avoid such
> >> rapid alloc/free, assuming your code fragment is running on every
> >> packet reception/sending.
> >>
> >> Instead, I suggest to allocate the memory before the ip_queue_xmit and
> >> use-reuse it inside ip_queue_xmit.
> >
> > Be careful with re-entrancy issues - you'll want a separate instance of
> memory
> > for all possible concurrent callers of ip_queue_xmit (you may need one
> per
> > active interface, because you can e transmitting packets on multiple
> interfaces
> > at the same time).
>
> Ah yes, you're correct Valdis. Thanks for note.
>
>
>
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140102/4e4cd4dd/attachment.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* simple memory malloc and free in ip_output.c
2014-01-02 17:42 ` Guibin(Bill) Tian
@ 2014-01-07 11:27 ` Mulyadi Santosa
0 siblings, 0 replies; 10+ messages in thread
From: Mulyadi Santosa @ 2014-01-07 11:27 UTC (permalink / raw)
To: kernelnewbies
On Fri, Jan 3, 2014 at 12:42 AM, Guibin(Bill) Tian <gbtian@gmail.com> wrote:
> Thank you sirs. But in fact, I don't alloc/free for every packet. I did
> exactly as what you said---reuse.
>
> I am a little confused why GFP_ATOMIC can work but GFP_KERNEL will cause the
> system to panic. Does it because that GFP_KERNEL can sleep in kmalloc, then
> ip_xmit_queue will be held or something? But anyway, GFP_ATOMIC works
> perfectly.
yup, you nailed it. gfp_kernel sleeps, while ip_xmit_queue is in
interrupt context.
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-01-07 11:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-27 3:16 simple memory malloc and free in ip_output.c Guibin(Bill) Tian
2013-12-27 3:24 ` bill4carson
2013-12-27 4:21 ` Guibin(Bill) Tian
2013-12-27 5:39 ` Guibin(Bill) Tian
2013-12-27 7:02 ` Anand Moon
2014-01-02 5:12 ` Mulyadi Santosa
2014-01-02 5:41 ` Valdis.Kletnieks at vt.edu
2014-01-02 6:15 ` Mulyadi Santosa
2014-01-02 17:42 ` Guibin(Bill) Tian
2014-01-07 11:27 ` Mulyadi Santosa
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.