{"id":447,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:40","modified_gmt":"2020-08-22T20:26:40","slug":"this-is-the-page-title-toplevel-280","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=447","title":{"rendered":"Unloading a Module"},"content":{"rendered":"\n<title>Unloading a Module<\/title>\n<p>\nModules can be removed using the <font face=\"helvetica\">rmmod<\/font> command but demand loaded modules\nare automatically removed from the system by <tt>kerneld<\/tt> when they are no longer being used.\nEvery time its idle timer expires, <tt>kerneld<\/tt> makes a system call requesting that\nall unused demand loaded modules are removed from the system.\nThe timer&#8217;s value is set when you start <tt>kerneld<\/tt>; my <tt>kerneld<\/tt> checks every\n180 seconds.\nSo, for example, if you mount an <tt>iso9660<\/tt> CD ROM and your <tt>iso9660<\/tt> filesystem\nis a loadable module, then shortly after the CD ROM is unmounted, the <tt>iso9660<\/tt>\nmodule will be removed from the <glossary>kernel<\/glossary>.\n<p>\nA module cannot be unloaded so long as other components of the kernel are depending\non it.For example, you cannot unload the <tt>VFAT<\/tt> module if you have one or\nmore <tt>VFAT<\/tt> file systems mounted.\nIf you look at the output of <font face=\"helvetica\">lsmod<\/font>, you will see that each module has\na count associated with it.\nFor example:\n<pre>\nModule:        #pages:  Used by:\nmsdos              5                  1\nvfat               4                  1 (autoclean)\nfat                6    [vfat msdos]  2 (autoclean)\n<\/pre>\n<p>\nThe count is the number of kernel entities that are dependent on this module.\nIn the above example, the <tt>vfat<\/tt> and <tt>msdos<\/tt> modules are both dependent on\nthe <tt>fat<\/tt> module and so it has a count of 2.\nBoth the <tt>vfat<\/tt> and <tt>msdos<\/tt> modules have 1 dependent, which is a mounted\nfile system.\nIf I were to load another <tt>VFAT<\/tt> file system then the <tt>vfat<\/tt> module&#8217;s\ncount would become 2.\nA module&#8217;s count is held in the first longword of its image.\n<p>\nThis field is slightly overloaded as it also holds the <tt>AUTOCLEAN<\/tt> and <tt>VISITED<\/tt>\nflags.\nBoth of these flags are used for demand loaded modules.\nThese modules are marked as <tt>AUTOCLEAN<\/tt> so that the system can recognize\nwhich ones it may automatically unload.\nThe <tt>VISITED<\/tt> flag marks the\nmodule as in use by one or more other system components; it is set whenever another\ncomponent makes use of the module.\nEach time the system is asked by <tt>kerneld<\/tt> to remove unused demand loaded modules\nit looks through all of the modules in the system for likely candidates.\nIt only looks at modules marked as <tt>AUTOCLEAN<\/tt> and in the state <tt>RUNNING<\/tt>.\nIf the candidate has its <tt>VISITED<\/tt> flag cleared then it will remove the\nmodule, otherwise it will clear the <tt>VISITED<\/tt> flag and go on to look at the next\nmodule in the system.\n<p>\nAssuming that a module can be unloaded, its cleanup routine is called to allow\nit to free up the kernel resources that it has allocated.\n<p>\nThe <tt>module<\/tt> data structure is marked as <tt>DELETED<\/tt> and it is unlinked\nfrom the list of kernel modules.\nAny other modules that it is dependent on have their reference lists modified\nso that they no longer have it as a dependent.\nAll of the kernel memory that the module needed is deallocated.\n<p>\n","protected":false},"excerpt":{"rendered":"<p>Unloading a Module Modules can be removed using the rmmod command but demand loaded modules are automatically removed from the system by kerneld when they are no longer being used. Every time its idle timer expires, kerneld makes a system &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=447\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-447","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=447"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/447\/revisions"}],"predecessor-version":[{"id":771,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/447\/revisions\/771"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}