============
- ᇂ140차 시작 위치
- start_kernel 1 ~/init/main.c
- vfs_caches_init 925 ~/init/main.c
- mnt_init 3809 ~/fs/dcache.c
- init_mount_tree 5046 ~/fs/namespace.c
- vfs_kern_mount 4217 fs/namespace.c
- mount_fs 1591 fs/namespace.c
- rootfs_mount 2872 // rootfs_mount(&rootfs_fs_type, 0, "rootfs", NULL):
- mount_nodev 625 ~/init/do_mounts.c
- 141주차 함수 호출 구조
- 주석이 잘못 된부분을 발견해서 sysfs_init()를 수정.
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
-
call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
-
call: init_mount_tree()
- get_fs_type(): rootfs 3994 ~/fs/namespace.c
- vfs_kern_mount(): rootfs_fs_type
- call: vfs_kern_mount(): rootfs_fs_type
- alloc_vfsmnt()
- mount_fs(): rootfs_fs_type -> rootfs_mount() 호출
- call: rootfs_mount()
- test_and_set_bit()
- IS_ENABLED()
- mount_nodev(): rootfs_fs_type
- call: mount_nodev(): rootfs_fs_type
- sget()
- call: start_kernel()->vfs_caches_init()
asmlinkage void __init start_kernel(void)
{
char * command_line;
extern const struct kernel_param __start___param[], __stop___param[];
// ATAG,DTB 정보로 사용
...
proc_caches_init();
// sighand_struct, signal_struct, files_struct, fs_struct, mm_struct, vm_area_struct, nsproxy
// 를 사용하기 위한 kmem_cache 할당자 및 percpu list 초기화 수행
buffer_init();
// buffer_head 를 사용하기 위한 kmem_cache 할당자 및 max_buffer_heads 값 초기화 수행
key_init(); // null funtion
security_init(); // null funtion
dbg_late_init(); // null funtion
// totalram_pages: 총 free된 page 수
vfs_caches_init(totalram_pages);
- call: start_kernel()
- vfs_caches_init()
// ARM10C 20151003
// totalram_pages: 총 free된 page 수
void __init vfs_caches_init(unsigned long mempages)
{
unsigned long reserve;
/* Base hash sizes on available memory, with a reserve equal to
150% of current kernel size */
// NOTE:
// mempages 값과 nr_free_pages() 의 값을 정확히 알 수 없음
// 계산된 reserve의 값을 XXX 로 함
// mempages: 총 free된 page 수, nr_free_pages(): 현재의 free pages 수
reserve = min((mempages - nr_free_pages()) * 3/2, mempages - 1);
// reserve: XXX
// mempages: 총 free된 page 수, reserve: XXX
mempages -= reserve;
// mempages: 총 free된 page 수 - XXX
// PATH_MAX: 4096
// SLAB_HWCACHE_ALIGN: 0x00002000UL, SLAB_PANIC: 0x00040000UL
// kmem_cache_create("names_cache", 4096, 0, 0x42000, NULL): kmem_cache#6
names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
// names_cachep: kmem_cache#6
dcache_init();
inode_init();
// mempages: 총 free된 page 수 - XXX
files_init(mempages);
mnt_init();
-
call: start_kernel()
- vfs_caches_init()
-
call: vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
// ARM10C 20151024
void __init mnt_init(void)
{
unsigned u;
int err;
// sizeof(struct mount): 152 bytes, SLAB_HWCACHE_ALIGN: 0x00002000UL, SLAB_PANIC: 0x00040000UL
// kmem_cache_create("mnt_cache", 152, 0, 0x42000, NULL): kmem_cache#2
mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct mount),
0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
// mnt_cache: kmem_cache#2
// sizeof(struct hlist_head): 4 bytes, mhash_entries: 0
// alloc_large_system_hash("Mount-cache", 4, 0, 19, 0, &m_hash_shift, &m_hash_mask, 0, 0): 16kB만큼 할당받은 메모리 주소
mount_hashtable = alloc_large_system_hash("Mount-cache",
sizeof(struct hlist_head),
mhash_entries, 19,
0,
&m_hash_shift, &m_hash_mask, 0, 0);
// mount_hashtable: 16kB만큼 할당받은 메모리 주소
// sizeof(struct hlist_head): 4 bytes, mphash_entries: 0
// alloc_large_system_hash("Mountpoint-cache", 4, 0, 19, 0, &m_hash_shift, &m_hash_mask, 0, 0): 16kB만큼 할당받은 메모리 주소
mountpoint_hashtable = alloc_large_system_hash("Mountpoint-cache",
sizeof(struct hlist_head),
mphash_entries, 19,
0,
&mp_hash_shift, &mp_hash_mask, 0, 0);
// mountpoint_hashtable: 16kB만큼 할당받은 메모리 주소
// mount_hashtable: 16kB만큼 할당받은 메모리 주소, mountpoint_hashtable: 16kB만큼 할당받은 메모리 주소
if (!mount_hashtable || !mountpoint_hashtable)
panic("Failed to allocate mount hash table\n");
// m_hash_mask: 0xFFF
for (u = 0; u <= m_hash_mask; u++)
// u: 0
INIT_HLIST_HEAD(&mount_hashtable[u]);
// INIT_HLIST_HEAD 에서 한일:
// ((&mount_hashtable[0])->first = NULL)
// u: 1...4095 까지 loop 수행
// mp_hash_mask: 0xFFF
for (u = 0; u <= mp_hash_mask; u++)
// u: 0
INIT_HLIST_HEAD(&mountpoint_hashtable[u]);
// INIT_HLIST_HEAD 에서 한일:
// ((&mountpoint_hashtable[0])->first = NULL)
// u: 1...4095 까지 loop 수행
// sysfs_init(): 0
err = sysfs_init();
// err: 0
// err: 0
if (err)
printk(KERN_WARNING "%s: sysfs_init error: %d\n",
__func__, err);
// kobject_create_and_add("fs", NULL): kmem_cache#30-oX (struct kobject)
fs_kobj = kobject_create_and_add("fs", NULL);
// fs_kobj: kmem_cache#30-oX (struct kobject)
// fs_kobj: kmem_cache#30-oX (struct kobject)
if (!fs_kobj)
printk(KERN_WARNING "%s: kobj create error\n", __func__);
init_rootfs();
init_mount_tree();
- call: start_kernel()
- vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
- call: mnt_init()
- kmem_cache_create()
- alloc_large_system_hash() : mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
// ARM10C 20160326
static void __init init_mount_tree(void)
{
struct vfsmount *mnt;
struct mnt_namespace *ns;
struct path root;
struct file_system_type *type;
// get_fs_type("rootfs"): &rootfs_fs_type
type = get_fs_type("rootfs");
// type: &rootfs_fs_type
// get_fs_type 에서 한일:
// "rootfs" 으로 등록된 &rootfs_fs_type 을 찾음
// type: &rootfs_fs_type
if (!type)
panic("Can't find rootfs type");
// type: &rootfs_fs_type
mnt = vfs_kern_mount(type, 0, "rootfs", NULL);
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
- call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
// ARM10C 20160409
// type: &rootfs_fs_type, 0, "rootfs", NULL
struct vfsmount *
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
{
struct mount *mnt;
struct dentry *root;
// type: &rootfs_fs_type
if (!type)
return ERR_PTR(-ENODEV);
// name: "rootfs", alloc_vfsmnt("rootfs"): kmem_cache#2-oX (struct mount)
mnt = alloc_vfsmnt(name);
// mnt: kmem_cache#2-oX (struct mount)
// flags: 0, MS_KERNMOUNT: 0x400000
if (flags & MS_KERNMOUNT)
// mnt->mnt.mnt_flags: (kmem_cache#2-oX (struct mount))->mnt.mnt_flags, MNT_INTERNAL: 0x4000
mnt->mnt.mnt_flags = MNT_INTERNAL;
// mnt->mnt.mnt_flags: (kmem_cache#2-oX (struct mount))->mnt.mnt_flags: 0x4000
// type: &rootfs_fs_type, flags: 0, name: "rootfs", data: NULL
// mount_fs(&rootfs_fs_type, 0, "rootfs", NULL): kmem_cache#5-oX (struct dentry)
root = mount_fs(type, flags, name, data);
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
-
call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
-
call: init_mount_tree()
- get_fs_type(): rootfs 3994 ~/fs/namespace.c
- vfs_kern_mount(): rootfs_fs_type
- call: vfs_kern_mount(): rootfs_fs_type
- alloc_vfsmnt()
- mount_fs(): rootfs_fs_type
// ARM10C 20160416
// type: &rootfs_fs_type, flags: 0, name: "rootfs", data: NULL
struct dentry *
mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
{
struct dentry *root;
struct super_block *sb;
char *secdata = NULL;
// secdata: NULL
// ENOMEM: 12
int error = -ENOMEM;
// error: -12
// data: NULL, type->fs_flags: (&rootfs_fs_type)->fs_flags: 0, FS_BINARY_MOUNTDATA: 2
if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) {
secdata = alloc_secdata();
if (!secdata)
goto out;
error = security_sb_copy_data(data, secdata);
if (error)
goto out_free_secdata;
}
// type->mount: (&rootfs_fs_type)->mount: rootfs_mount
// type: &rootfs_fs_type, flags: 0, name: "rootfs", data: NULL
// rootfs_mount(&rootfs_fs_type, 0, "rootfs", NULL):
root = type->mount(type, flags, name, data);
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
-
call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
-
call: init_mount_tree()
- get_fs_type(): rootfs 3994 ~/fs/namespace.c
- vfs_kern_mount(): rootfs_fs_type
- call: vfs_kern_mount(): rootfs_fs_type
- alloc_vfsmnt()
- mount_fs(): rootfs_fs_type -> rootfs_mount() 호출
rootfs_fs_type 구조체에 .mount는 rootfs_mount 로 정의했다. 따라서 rootfs_mount() 함수를 호출한다.
// ARM10C 20160402
static struct file_system_type rootfs_fs_type = {
.name = "rootfs",
.mount = rootfs_mount,
.kill_sb = kill_litter_super,
};
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
-
call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
-
call: init_mount_tree()
- get_fs_type(): rootfs 3994 ~/fs/namespace.c
- vfs_kern_mount(): rootfs_fs_type
- call: vfs_kern_mount(): rootfs_fs_type
- alloc_vfsmnt()
- mount_fs(): rootfs_fs_type -> rootfs_mount() 호출
// ARM10C 20160416
// type: &rootfs_fs_type, flags: 0, name: "rootfs", data: NULL
static struct dentry *rootfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
static unsigned long once;
void *fill = ramfs_fill_super;
// fill: ramfs_fill_super
// once: 0, test_and_set_bit(0, &once): 0
if (test_and_set_bit(0, &once))
return ERR_PTR(-ENODEV);
// test_and_set_bit 에서 한일:
// once: 1
// CONFIG_TMPFS=y, IS_ENABLED(CONFIG_TMPFS): 1, is_tmpfs: 1
if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs)
// fill: ramfs_fill_super
fill = shmem_fill_super;
// fill: shmem_fill_super
// fs_type: &rootfs_fs_type, flags: 0, data: NULL, fill: shmem_fill_super
return mount_nodev(fs_type, flags, data, fill);
}
mount_nodev()를 실행후 mount_fs()로 돌아간다.
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
-
call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
-
call: init_mount_tree()
- get_fs_type(): rootfs 3994 ~/fs/namespace.c
- vfs_kern_mount(): rootfs_fs_type
- call: vfs_kern_mount(): rootfs_fs_type
- alloc_vfsmnt()
- mount_fs(): rootfs_fs_type -> rootfs_mount() 호출
- call: rootfs_mount()
- test_and_set_bit()
- IS_ENABLED()
- mount_nodev(): rootfs_fs_type
// ARM10C 20160416
// fs_type: &rootfs_fs_type, flags: 0, data: NULL, fill: shmem_fill_super
struct dentry *mount_nodev(struct file_system_type *fs_type,
int flags, void *data,
int (*fill_super)(struct super_block *, void *, int))
{
int error;
// fs_type: &rootfs_fs_type, flags: 0
// sget(&rootfs_fs_type, NULL, set_anon_super, 0, NULL): kmem_cache#25-oX (struct super_block)
struct super_block *s = sget(fs_type, NULL, set_anon_super, flags, NULL);
// s: kmem_cache#25-oX (struct super_block)
// s: kmem_cache#25-oX (struct super_block), IS_ERR(kmem_cache#25-oX (struct super_block)): 0
if (IS_ERR(s))
return ERR_CAST(s);
// s: kmem_cache#25-oX (struct super_block), data: NULL, flags: 0, MS_SILENT: 0x8000
error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
-
call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
-
call: init_mount_tree()
- get_fs_type(): rootfs 3994 ~/fs/namespace.c
- vfs_kern_mount(): rootfs_fs_type
- call: vfs_kern_mount(): rootfs_fs_type
- alloc_vfsmnt()
- mount_fs(): rootfs_fs_type -> rootfs_mount() 호출
- call: rootfs_mount()
- test_and_set_bit()
- IS_ENABLED()
- mount_nodev(): rootfs_fs_type
- call: mount_nodev(): rootfs_fs_type
- sget()
- fill_super()
// ARM10C 20160319
// s: kmem_cache#25-oX (struct super_block), data: NULL, 0
static int fill_super(struct super_block *sb, void *data, int silent)
{
static struct tree_descr files[] = {{""}};
// files[0].name: "", files[0].ops: NULL, files[0].mode: 0
// sb: kmem_cache#25-oX (struct super_block), SECURITYFS_MAGIC: 0x73636673
// simple_fill_super(kmem_cache#25-oX (struct super_block), 0x73636673, files): 0
return simple_fill_super(sb, SECURITYFS_MAGIC, files);
}
simple_fill_super()를 호출하고 그 결과를 mount_nodev()로 반환한다.
- calll: start_kernel()-> vfs_caches_init()
- kmem_cache_create(): names_cache
- dcache_init()
- inode_init()
- files_init()
- mnt_init()
-
call: mnt_init()
- kmem_cache_create(): mnt_cache
- alloc_large_system_hash() : Mount-cache
- alloc_large_system_hash() : Mountpoint-cache
- INIT_HLIST_HEAD() : &mount_hashtable[u]
- INIT_HLIST_HEAD() : &mountpoint_hashtable[u]
- sysfs_init()
- kobject_create_and_add() : fs
- init_rootfs()
- init_mount_tree()
-
call: init_mount_tree()
- get_fs_type(): rootfs 3994 ~/fs/namespace.c
- vfs_kern_mount(): rootfs_fs_type
- call: vfs_kern_mount(): rootfs_fs_type
- alloc_vfsmnt()
- mount_fs(): rootfs_fs_type -> rootfs_mount() 호출
- call: rootfs_mount()
- test_and_set_bit()
- IS_ENABLED()
- mount_nodev(): rootfs_fs_type
- call: mount_nodev(): rootfs_fs_type
- sget()
- fill_super()
- call: fill_super()
- simple_fill_super()
// ARM10C 20160319
// sb: kmem_cache#25-oX (struct super_block), SECURITYFS_MAGIC: 0x73636673, files
int simple_fill_super(struct super_block *s, unsigned long magic,
struct tree_descr *files)
{
struct inode *inode;
struct dentry *root;
struct dentry *dentry;
int i;
// s->s_blocksize: (kmem_cache#25-oX (struct super_block))->s_blocksize, PAGE_CACHE_SIZE: 0x1000
s->s_blocksize = PAGE_CACHE_SIZE;
// s->s_blocksize: (kmem_cache#25-oX (struct super_block))->s_blocksize: 0x1000
// s->s_blocksize_bits: (kmem_cache#25-oX (struct super_block))->s_blocksize_bits, PAGE_CACHE_SHIFT: 12
s->s_blocksize_bits = PAGE_CACHE_SHIFT;
// s->s_blocksize_bits: (kmem_cache#25-oX (struct super_block))->s_blocksize_bits: 12
// s->s_magic: (kmem_cache#25-oX (struct super_block))->s_magic, magic: 0x73636673
s->s_magic = magic;
// s->s_magic: (kmem_cache#25-oX (struct super_block))->s_magic: 0x73636673
// s->s_op: (kmem_cache#25-oX (struct super_block))->s_op
s->s_op = &simple_super_operations;
// s->s_op: (kmem_cache#25-oX (struct super_block))->s_op: &simple_super_operations
// s->s_time_gran: (kmem_cache#25-oX (struct super_block))->s_time_gran
s->s_time_gran = 1;
// s->s_time_gran: (kmem_cache#25-oX (struct super_block))->s_time_gran: 1
// s: kmem_cache#25-oX (struct super_block),
// new_inode(kmem_cache#25-oX (struct super_block)): kmem_cache#4-oX (struct inode)
inode = new_inode(s);
// inode: kmem_cache#4-oX (struct inode)
static int shmem_initxattrs(struct inode *inode,
const struct xattr *xattr_array,
void *fs_info)
{
struct shmem_inode_info *info = SHMEM_I(inode);
const struct xattr *xattr;
struct simple_xattr *new_xattr;
size_t len;
for (xattr = xattr_array; xattr->name != NULL; xattr++) {
new_xattr = simple_xattr_alloc(xattr->value, xattr->value_len);
if (!new_xattr)
return -ENOMEM;
len = strlen(xattr->name) + 1;
new_xattr->name = kmalloc(XATTR_SECURITY_PREFIX_LEN + len,
GFP_KERNEL);
if (!new_xattr->name) {
kfree(new_xattr);
return -ENOMEM;
}
memcpy(new_xattr->name, XATTR_SECURITY_PREFIX,
XATTR_SECURITY_PREFIX_LEN);
memcpy(new_xattr->name + XATTR_SECURITY_PREFIX_LEN,
xattr->name, len);
simple_xattr_list_add(&info->xattrs, new_xattr);
- ᆼᇂᆫ1st log
b4b2640..43e63a7 master -> origin/master
Updating b4b2640..43e63a7
Fast-forward
Reference/Breakdown/009_linux-kernel_20130622.md | 48 +++++++++++++++++-
Reference/Breakdown/Figures/009_cp15.png | Bin 0 -> 35747 bytes
Reference/Breakdown/Figures/009_mva.png | Bin 0 -> 23652 bytes
arch/arm/include/asm/cache.h | 1 +
fs/super.c | 5 +-
include/linux/cred.h | 5 ++
include/linux/exportfs.h | 1 +
include/linux/gfp.h | 1 +
include/linux/kernel.h | 1 +
include/linux/percpu_counter.h | 3 ++
include/linux/rcupdate.h | 6 +++
include/linux/shmem_fs.h | 2 +
include/linux/slab.h | 2 +
include/linux/spinlock.h | 2 +
include/linux/stat.h | 5 ++
include/linux/types.h | 3 ++
include/linux/uidgid.h | 9 ++++
include/uapi/asm-generic/errno-base.h | 1 +
include/uapi/asm-generic/posix_types.h | 2 +
include/uapi/linux/fs.h | 5 ++
include/uapi/linux/stat.h | 7 +++
kernel/cred.c | 3 ++
lib/percpu_counter.c | 2 +
mm/shmem.c | 59 ++++++++++++++++++++++-
24 files changed, 168 insertions(+), 5 deletions(-)
create mode 100644 Reference/Breakdown/Figures/009_cp15.png
create mode 100644 Reference/Breakdown/Figures/009_mva.png