From owner-freebsd-hackers Sun Apr 16 11:23:37 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by hub.freebsd.org (Postfix) with ESMTP id ED15137B721 for ; Sun, 16 Apr 2000 11:23:34 -0700 (PDT) (envelope-from dillon@apollo.backplane.com) Received: (from dillon@localhost) by apollo.backplane.com (8.9.3/8.9.1) id LAA87432; Sun, 16 Apr 2000 11:23:32 -0700 (PDT) (envelope-from dillon) Date: Sun, 16 Apr 2000 11:23:32 -0700 (PDT) From: Matthew Dillon Message-Id: <200004161823.LAA87432@apollo.backplane.com> To: Anatoly Vorobey Cc: hackers@FreeBSD.ORG Subject: Re: memory in the kernel References: <20000416123037.A24869@happy.checkpoint.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG :I have to malloc a lot of memory in the kernel, hence a few :questions: : :1. The data must be absolutely present at all times, no page :faults or locking mechanisms, etc. Does that mean :I should use kmem_alloc_wired() or am I misunderstanding its purpose? :Does it make sense to alloc less than a pageful or is the rest simply :going to be wasted? : :2. Unfortunately, I need to realloc a lot as data is dynamic and I :don't know sizes beforehand. How do I do that? Do I malloc a new :region, copy manually and release the old one? : :Thanks a lot in advance, :Anatoly. : :-- :Anatoly Vorobey, At the moment all kernel memory is wired, so just use the kernel malloc() function. Create your own malloc area (see other kernel source modules on how to do that, it's trivial). There is no kernel realloc(). Even if there were using realloc or a malloc-copy-free-old scheme can lead to severe fragmentation if you aren't careful. If you can possibly avoid it, try to figure out the size of your structures before hand or even move to using a linked list rather then an array. Otherwise the only way to do a realloc-like thing is to malloc the larger object, copy the old data, and then free the original object. -Matt Matthew Dillon To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message