jjww 发表于 2003-6-15 16:43:31

__init什么意思?

http://www.moses.uklinux.net/patches/lki-3.html
The inode cache subsystem is initialised when inode_init() function is called from init/main.c:start_kernel(). The function is marked as __init, which means its code is thrown away later on. It is passed a single argument - the number of physical pages on the system. This is so that the inode cache can configure itself depending on how much memory is available, i.e. create a larger hashtable if there is enough memory.

__init意味该函数在后来被丢弃,怎么理解?后来是指什么阶段?

xdwjack 发表于 2003-6-15 21:07:25

也就是说,凡是带有__init的函数,只是在系统初始化的时候使用,在系统初始化结束以后,永远不使用这个函数.直到下一次重新启动计算机,再一次进行系统初始化的时候,才会再一次用到.

jjww 发表于 2003-6-15 21:34:54

thx.

Dragonfly 发表于 2003-6-15 23:11:53

and thus after using all this routines, linux can remove them and save some mem. that is why we can see
"Freeing unused kernel memory: xxxk freed"

jjww 发表于 2003-6-16 09:18:42

恩,但是我不知道kernel释放这些初始化内存的控制路径在什么位置?另外,释放的是什么空间呢?函数体的空间?是不是通过__init定义的函数在编译的时候把这种函数都放在在".text.init"会话区(section)里,在kernel启动完毕后,把整个sectiond都删除呢?
我想这个section也是属于kernel的文本image,删除了能节约多少空间,能不能用上这些空间?

Dragonfly 发表于 2003-6-16 09:39:01

free_initmem() in arch/xx/mm/init.c

i think even 100kb mem is useful at some situations.

jjww 发表于 2003-6-16 09:42:07

那__init是放在kernel image的最后部分了,这样释放后__end才又可能减小,对吗?

Dragonfly 发表于 2003-6-16 09:55:29

qjfx or ULK have intro. i forget.

my brain only has 640k and becomes smaller and smaller now.

coldwind 发表于 2003-6-16 20:19:35

是的,bss段

Dragonfly 发表于 2003-6-16 22:56:12

o, thx

jjww 发表于 2003-6-17 08:37:17

bss段不是存放没有初始化的数据吗?还可以存放函数体?

jjww 发表于 2003-6-17 08:47:39

include/linux/init.h

#define __init                __attribute__ ((__section__ (".text.init")))
#define __exit                __attribute__ ((unused, __section__(".text.exit")))
#define __initdata        __attribute__ ((__section__ (".data.init")))
#define __exitdata        __attribute__ ((unused, __section__ (".data.exit")))
#define __initsetup        __attribute__ ((unused,__section__ (".setup.init")))
#define __init_call        __attribute__ ((unused,__section__ (".initcall.init")))
#define __exit_call        __attribute__ ((unused,__section__ (".exitcall.exit")))
请大家一并看看这几个定义,
代码注释: Mark functions and data as being only used at initialization or exit time.

Dragonfly 发表于 2003-6-17 08:59:50

so there are in different seg?
hehe, should check some doc to know this.

coldwind 发表于 2003-6-17 16:37:27

o,sorry, I was confused

Dragonfly 发表于 2003-6-17 22:03:01

i remember books have this. but i forget again. my main memory is so small that, i always have to swap out most of the knowledge i had learned. sigh!
页: [1] 2
查看完整版本: __init什么意思?