From owner-freebsd-hackers@FreeBSD.ORG Fri Sep 22 01:58:01 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AA86F16A49E; Fri, 22 Sep 2006 01:58:01 +0000 (UTC) (envelope-from admin@intron.ac) Received: from intron.ac (unknown [210.51.165.237]) by mx1.FreeBSD.org (Postfix) with ESMTP id 48B1743D7C; Fri, 22 Sep 2006 01:57:56 +0000 (GMT) (envelope-from admin@intron.ac) Received: from localhost (localhost [127.0.0.1]) (uid 1003) by intron.ac with local; Fri, 22 Sep 2006 09:57:55 +0800 id 0010E408.45134323.00004A36 References: <200609212136.18850.jhb@freebsd.org> In-Reply-To: <200609212136.18850.jhb@freebsd.org> From: "Intron is my alias on the Internet" To: John Baldwin Date: Fri, 22 Sep 2006 09:57:55 +0800 Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312"; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Cc: freebsd-hackers@freebsd.org Subject: Re: A Bug in linker_reference_module() ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Sep 2006 01:58:01 -0000 John Baldwin wrote: > On Thursday 21 September 2006 14:12, Intron is my alias on the Internet wrote: >> Please have a look at the function linker_reference_module() in >> /sys/kern/kern_linker.c of 7.0-CURRENT. If the module is loaded on demand, >> why not increase its reference counter after loading? In my opinion, >> linker_reference_module() behaves differently from linker_load_file(). > > This is because a new kld loaded via linker_load_module() starts off > with a refcount of 1. Thus, if you do: > > linker_reference_module(...); > ... > linker_release_module(...); > > Then with the current code the release_module() call drops the reference > count to 0 and the module is unloaded. This is the desired operation for > reference_module/release_module. This model is commonly used in the kernel. > For example, when creating a credential, one just does 'crget()' and later > a 'crfree()' to free it instead of doing 'crget(); crhold()' to create one. This model is a little confusing. If a module is loaded on demand as dependency, its reference counter is set to 1. And if the module is loaded by kldload(2), its reference counter is also set to 1, though in fact no other loaded module depends on it. Although this "shift" model can work correctly, I want to know whether there's a more reasonable way, such as setting up an auto-unloadable flag. ------------------------------------------------------------------------ From Beijing, China