2002-03-19 16:18:54

by chiranjeevi vaka

[permalink] [raw]
Subject: using kmalloc

Hi,

I am getting some problems with kmalloc. If I tried to
allocate more than certain memory then the system is
hanging while booting with the changed kernel. Can you
suggest me how to come out this situation. Can't I
allocate as much I want when I want to allocate in the
kernel.


Thank you,
Chiranjeevi

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/


2002-03-19 16:33:57

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: using kmalloc

Em Tue, Mar 19, 2002 at 08:18:31AM -0800, chiranjeevi vaka escreveu:

> I am getting some problems with kmalloc. If I tried to allocate more than
> certain memory then the system is hanging while booting with the changed
> kernel. Can you suggest me how to come out this situation. Can't I allocate
> as much I want when I want to allocate in the kernel.

try vmalloc, kmalloc is limited, AFAIK, to 128 KiB and even that is difficult
to get after some time.

- Arnaldo

2002-03-19 17:30:11

by Victor Yodaiken

[permalink] [raw]
Subject: Re: using kmalloc

On Tue, Mar 19, 2002 at 01:41:36PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Tue, Mar 19, 2002 at 08:18:31AM -0800, chiranjeevi vaka escreveu:
>
> > I am getting some problems with kmalloc. If I tried to allocate more than
> > certain memory then the system is hanging while booting with the changed
> > kernel. Can you suggest me how to come out this situation. Can't I allocate
> > as much I want when I want to allocate in the kernel.
>
> try vmalloc, kmalloc is limited, AFAIK, to 128 KiB and even that is difficult
> to get after some time.

Apparently, kmalloc semantics changed at some point
so it does not ever return error.


--
---------------------------------------------------------
Victor Yodaiken
Finite State Machine Labs: The RTLinux Company.
http://www.fsmlabs.com http://www.rtlinux.com

2002-03-19 19:27:28

by chiranjeevi vaka

[permalink] [raw]
Subject: Re: using kmalloc

Hi jim,
I am trying to get something around 600 to 1000 bytes
using kmalloc. This one is for some changes in TCP/IP
stack. I am trying to implement a new kernel data
structure in tcp layer. So can you suggest me what
functionality to use to come out of that hanging.


thanks.
--- James Washer <[email protected]> wrote:
>
> How much memory are you trying to get? Also.. is
> this for a module, or a
> builtin function/driver/whatever?
> - jim
>
> chiranjeevi vaka
> <[email protected]>@vger.kernel.org on
> 03/19/2002
> 08:18:31 AM
>
> Sent by: [email protected]
>
>
> To: [email protected]
> cc:
> Subject: using kmalloc
>
>
>
> Hi,
>
> I am getting some problems with kmalloc. If I tried
> to
> allocate more than certain memory then the system is
> hanging while booting with the changed kernel. Can
> you
> suggest me how to come out this situation. Can't I
> allocate as much I want when I want to allocate in
> the
> kernel.
>
>
> Thank you,
> Chiranjeevi
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - live college hoops coverage
> http://sports.yahoo.com/
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at
> http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
>
>


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/

2002-03-19 19:39:48

by Tommy Reynolds

[permalink] [raw]
Subject: Re: using kmalloc

Uttered "chiranjeevi vaka" <[email protected]>, spoke thus:

> I am trying to get something around 600 to 1000 bytes
> using kmalloc. This one is for some changes in TCP/IP
> stack. I am trying to implement a new kernel data
> structure in tcp layer. So can you suggest me what
> functionality to use to come out of that hanging.

Be sure to use "kmalloc( 1000, GFP_ATOMIC )" if you don't want to block waiting
for the memory. Check for a NULL result, because you might not be able to get
the memory.


Attachments:
(No filename) (197.00 B)

2002-03-20 05:53:08

by Dan Maas

[permalink] [raw]
Subject: Re: using kmalloc

> I am getting some problems with kmalloc. If I tried to
> allocate more than certain memory then the system is
> hanging while booting with the changed kernel. Can you
> suggest me how to come out this situation. Can't I
> allocate as much I want when I want to allocate in the
> kernel.

kmalloc() allocates physically-contiguous pages of memory. Due to
fragmentation, more than 64KB-128KB of contiguous pages might not be
available, and hence kmalloc() will fail.

To allocate more memory, use vmalloc(), which allocates and maps physically
disjoint pages into a virtually-contiguous region. Be careful when doing DMA
to a vmalloc() area, since it is not physically contiguous and exists only
in the kernel's virtual memory map... Also I believe vmalloc()ed memory is
only accessible from (the context of) the process in which it was allocated
(?).

Regards,
Dan

2002-03-20 10:12:21

by Alan

[permalink] [raw]
Subject: Re: using kmalloc

> To allocate more memory, use vmalloc(), which allocates and maps physically
> disjoint pages into a virtually-contiguous region. Be careful when doing DMA
> to a vmalloc() area, since it is not physically contiguous and exists only
> in the kernel's virtual memory map... Also I believe vmalloc()ed memory is
> only accessible from (the context of) the process in which it was allocated
> (?).

vmalloc memory is accessible everywhere. You can't allocate it during
interrupts or tasklets, and you will get deadlocks if you allocate it in the
write out path of a file system/disk driver.

Alan

2002-03-20 11:48:58

by Jan Hudec

[permalink] [raw]
Subject: Re: using kmalloc

> kmalloc() allocates physically-contiguous pages of memory. Due to
> fragmentation, more than 64KB-128KB of contiguous pages might not be
> available, and hence kmalloc() will fail.

kmalloc allocates from generic slab caches. They come in sizes of powers
of 2 from 32B to 128KiB. The largest has slabs 128KiB large (on i386 at least).
Pages are allocated via __get_free_pages, so they have to be continuous.

However if you allocate namy instances of some structure, it's best to create
a kmem cache and allocate via kmem_cache_alloc (since it does not round the
requested size up to a power of two).

--------------------------------------------------------------------------------
- Jan Hudec `Bulb' <[email protected]>