linux SYSCTL的原理分析

2021-08-19 01:37:25 字數 2833 閱讀 4194

需要開啟核心選項config_proc_sysctl

fs/proc/root.c

void __init proc_root_init(void)

#ifdef config_proc_sysctl

extern int proc_sys_init(void);

extern void sysctl_head_put(struct ctl_table_header *);

#else

static inline void proc_sys_init(void)

static inline void sysctl_head_put(struct ctl_table_header *head)

#endif

proc-$(config_proc_sysctl)    += proc_sysctl.o

fs/proc/proc_sysctl.c

int __init proc_sys_init(void)

kernel/sysctl.c

#ifdef  

config_sysctl

int __init sysctl_init(void)

#endif /* config_sysctl */

因此可以看出,config_sysctl實際上是在/proc/sys目錄下多加一些入口

config_sysctl  配置選項

以前sysctl命令是通過sysctl系統呼叫實現的,不過新實現的都是通過直接讀寫proc檔案系統實現的

sysctl系統呼叫的實現:

kernel/sysctl_binary.c

syscall_define1(sysctl, struct __sysctl_args __user *, args)

compat_syscall_define1(sysctl, struct compat_sysctl_args __user *, args)

static ssize_t

do_sysctl

(int __user *args_name, int nlen,

void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)

#ifdef config_sysctl_syscall

binary_sysctl()

#else /* config_sysctl_syscall */

static ssize_t binary_sysctl(const int *name, int nlen,

void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)

#endif /* config_sysctl_syscall */

static const struct bin_table *get_sysctl(const int *name, int nlen, char *path)

因此sysctl系統呼叫需要config_sysctl_syscall開啟,這個系統呼叫只是把傳進來的name根據bin_root_table表轉化為/proc/sys

下面的路徑,然後讀寫這些檔案實現的,而

sysctl_init()則是在/proc/sys下面加入很多入口

可以看出

sysctl系統呼叫也只是轉化了一下路徑而已,最終還是得操作/proc/sys下面的檔案。

kernel/sysctl_binary.c中可以看到支援的配置目錄:

static const struct bin_table

bin_root_table

= ,    

//proc/sys/kernel

,,            

//proc/sys/net

/* ctl_proc not used */

,/* ctl_debug "debug" no longer used */,,

,/* ctl_cpu not used */

/* ctl_arlan "arlan" no longer used */,,

,{}};static const struct bin_table

bin_kern_table

= ,,/* kern_osrev not used */

,/* kern_securemask not used */

/* kern_prof not used */,,

,,,,

,/* kern_nametrans not used */

/* kern_ppc_htabreclaim not used */

/* kern_ppc_zeropaged not used */,,

,,/* kern_ppc_l2cr "l2cr" no longer used */

/* kern_rtsignr not used */

/* kern_rtsigmax not used */,,

,/* kern_msgpool not used*/,,

,,,,

,,,,

,,,,

/* kern_tainted "tainted" no longer used */,,

,,,,

,,,,

,/* kern_hz_timer "hz_timer" no longer used */,,

,,/* kern_acpi_video_flags "acpi_video_flags" no longer used */,,

,,,{}

}

ConcurrentHashMap原理分析

hashtable是乙個執行緒安全的類,它使用synchronized來鎖住整張hash表來實現執行緒安全,即每次鎖住整張表讓執行緒獨佔。concurrenthashmap允許多個修改操作併發進行,其關鍵在於使用了鎖分離技術。它使用了多個鎖來控制對hash表的不同部分進行的修改。concurrent...

JWT(Json Web Token)認證原理分析

目錄 優點 1 資料庫不需要儲存token,所以伺服器的 io 操作會減少 沒有io寫操作 2 客戶端存token,伺服器只儲存簽發與校驗演算法,執行效率高 3 簽發與校驗演算法在多個伺服器上可以直接統一,所以jwt認證規則下,伺服器做集群非常便捷 突破點 1 token必須要有多個部分組成,有能反...

mysql亂碼原理 MySQL中亂碼原理分析

問題描述 假定建立資料庫時採用的是utf8編碼方式 create database huangweiyi default character set utf8 經常在windows的cmd視窗中插入帶有中文的記錄到mysql表中時會出現插入錯誤,或者在查詢mysql中資料顯示是出現亂碼 首先插入中文...