LINUX自启动线程学习笔记

由于嵌入式处理器的性能不够,希望尽量能减少不必要的启动进程。对处理器启动进程进行了学习,了解哪些相关介绍判断哪些必须保留的线程。·

当前我使用的LINUX 系统启动后的线程

# ps
PID   USER     COMMAND1 root     init  //启动部分的和GRUB相关2 root     [kthreadd]内核线程主节点,用于生成进程,主要用于管理硬件。3 root     [rcu_gp]//读取复制跟新管理间后续接收4 root     [rcu_par_gp]//读取复制跟新管理间后续接收5 root     [kworker/0:0-mm_]//内核0工作线程占位符,语法间后面介绍6 root     [kworker/0:0H]//内核0工作线程占位符7 root     [kworker/u4:0-ev]//和前面类似,不过未绑定cpu8 root     [mm_percpu_wq]//关于每个 CPU 工作队列线程的内存管理真内核维护者列表中的神秘消息9 root     [ksoftirqd/0]//一种在常规处理程序之外处理硬件中断请求的方法 CPU010 root     [rcu_sched]//读取复制更新计划程序,用于在写入器和读取器之间同步数据。这是有关 RCU 的最新信息11 root     [rcu_bh]//作为上述rcu_sched的表亲,它在 RCU 子系统中提供了宽限期。12 root     [migration/0]//跨内核分配进程。每个内核一个这样的进程。13 root     [cpuhp/0]//支持在系统中物理添加和删除 CPU 的进程 内核0。14 root     [cpuhp/1]//支持在系统中物理添加和删除 CPU 的进程 内核1。15 root     [migration/1]//和前面类似只是内核为1 16 root     [ksoftirqd/1]//和前面类似只是内核为1 17 root     [kworker/1:0-rcu]//和前面类似只是内核为1 18 root     [kworker/1:0H]//和前面类似只是内核为1 19 root     [kdevtmpfs]//此线程填充并维护设备节点树20 root     [oom_reaper]//在内存分配路径上,当内存不足的时候会触发kswapd、或者内存规整,极端情况会触发OOM,来获取更多内存。21 root     [writeback]//处理对块设备的缓慢写入22 root     [kcompactd0]//kcompactd是一个内核规整的后台进程,内存压缩23 root     [crypto]//为内核加密模块提供 API 接口24 root     [kblockd]//检查 I/O 管道中的拥塞25 root     [watchdogd]//看门狗26 root     [kworker/1:1-mm_]//和前面类似只是内核为1 27 root     [kworker/0:1-eve]//和前面类似只是内核为1 28 root     [kswapd0]//页面回收kswapd内核线程29 root     [kworker/u5:0]//和前面类似,不过未绑定cpu55 root     [spi0]//SPI0 接口进程56 root     [spi2]//SPI2 接口进程72 root     /sbin/syslogd -n  //远程系统日志守护进程。76 root     /sbin/klogd -n   //内核日志守护进程87 root     -/bin/sh   //脚本进程89 root     [kworker/u4:1]

一些定义介绍

GRUB

GRUB 是一个用于加载和管理系统启动的完整程序。它是 Linux 发行版中最常见的引导程序(bootloader)。引导程序是计算机启动时运行的第一个软件。它加载 操作系统的内核,然后再由内核初始化操作系统的其他部分(包括 Shell、显示管理器、桌面环境 等等)。

OOM

原文连接
Linux内核为了提高内存的使用效率采用过度分配内存(over-commit memory)的办法,造成物理内存过度紧张进而触发OOM机制来杀死一些进程回收内存。

Syslog系统日志:

Syslog设备依据两个重要的文件:/etc/syslogd(守护进程)和/etc/syslog.conf配置文件,习惯上,多数syslog信息被写到/var/adm或/var/log目录下的信息文件中(messages.*)。一个典型的syslog纪录包括生成程序的名字和一个文本信息。它还包括一个设备和一个优先级范围(但不在日之中出现)。
syslogd不仅仅是记录kernel log的服务,还能记录user space中的日志。

syslogd是Linux下的一个记录日志文件服务。新版本叫做rsyslogd。

syslogd有一系列的子服务,例如mail、auth、cron、kern等等,这些子服务提供日志记录的功能,。当程序要记录log时,可以直接调用这些子服务将日志记录到设定的地方。

特殊进程

一文了解Linux下2号进程的kthreadd
Linux下有3个特殊的进程,idle进程(PID = 0), init进程(PID = 1)和kthreadd(PID = 2)

  • idle进程由系统自动创建, 运行在内核态

idle进程其pid=0,其前身是系统创建的第一个进程,也是唯一一个没有通过fork或者kernel_thread产生的进程。完成加载系统后,演变为进程调度、交换

  • init进程由idle通过kernel_thread创建,在内核空间完成初始化后, 加载init程序, 并最终用户空间

由0进程创建,完成系统的初始化. 是系统中所有其它用户进程的祖先进程

Linux中的所有进程都是有init进程创建并运行的。首先Linux内核启动,然后在用户空间中启动init进程,再启动其他系统进程。在系统启动完成完成后,init将变为守护进程监视系统其他进程。

  • kthreadd进程由idle通过kernel_thread创建,并始终运行在内核空间, 负责所有内核线程的调度和管理

它的任务就是管理和调度其他内核线程kernel_thread, 会循环执行一个kthreadd的函数,该函数的作用就是运行kthread_create_list全局链表中维护的kthread, 当我们调用kernel_thread创建的内核线程会被加入到此链表中,因此所有的内核线程都是直接或者间接的以kthreadd为父进程

RCU 相关知识

什么是RCU?是Read,Copy-Update的缩写,意指读-复制更新。是一种同步机制。其将同步开销的非对称分布发挥到逻辑极限(我简单理解位线程进程中的数据同步控制机制)。是在2002年引入在Linux内核中的。大家应该都知道内核同步机制中的像各种锁机制、信号量、内存屏障啥的,但为啥会引入一个叫读复制更新这么个同步机制呢?它有啥优点,或者说它的应用场景是什么?

考虑一个问题,我们知道,在路由器上,会有很多线程去查找路由表数据,但是更新路由表数据的情况却不多。像这种情况下我们如何做多同步?上面说的几种同步机制都不是很好的选择,这时RCU就派上用场了,具体原因下文会解释。所以,RCU主要应用在那种,读线程多,而写线程唯一的情况,同时需要保证数据一致性。搞明白了这个道理,我们来分析一下RCU。

在RCU的实现过程中,我们主要解决以下问题:

1,在读取过程中,另外一个线程删除了一个节点。删除线程可以把这个节点从链表中移除,但它不能直接销毁这个节点,必须等到所有的读取线程读取完成以后,才进行销毁操作。RCU中把这个过程称为宽限期(Grace period)。

2,在读取过程中,另外一个线程插入了一个新节点,而读线程读到了这个节点,那么需要保证读到的这个节点是完整的。这里涉及到了发布-订阅机制(Publish-Subscribe Mechanism)。

3, 保证读取链表的完整性。新增或者删除一个节点,不至于导致遍历一个链表从中间断开。但是RCU并不保证一定能读到新增的节点或者不读到要被删除的节点。

KWORKER进程

什么是 kworker 进程?
“kworker” 是 Linux 内核的工作线程,用于异步处理工作队列中的任务。这些任务包括处理硬件中断、文件系统事件、管理系统内存等。你可能会看到多个 kworker 进程,每个进程的名称后面都有一个数字,如 “kworker/0:1”、“kworker/1:2” 等。这个数字表示了 kworker 是在哪个 CPU 核心上运行的以及任务的顺序。

kworker 进程为什么会占用大量 CPU?
正常情况下,kworker 进程的 CPU 占用率应该是相对较低的。但是,在一些情况下,你可能会发现 kworker 进程占用了大量的 CPU。这可能是因为系统中有大量的底层任务需要处理,这些任务可能包括硬件中断、文件系统操作、内存管理等。

可能的原因包括:

硬件问题: 有时,某些硬件设备会产生大量的中断,导致 kworker 线程的 CPU 占用率提高。这可能是硬件故障或者驱动程序错误导致的。
I/O 等待: 如果系统中有大量的磁盘 I/O 操作,kworker 线程可能会被频繁唤醒来处理这些操作,从而导致高 CPU 占用。
内存压力: 如果系统内存使用率高,可能会导致频繁的内存回收操作,这也会导致 kworker 线程的 CPU 占用率提高。

我们需要找出是什么导致 kworker 高 CPU 占用。我们可以使用一些系统诊断工具,如 perf、iostat、vmstat 等,来找出问题的根源。根据问题的具体原因,我们可以采取相应的措施来解决问题。

深入理解 Linux 中的 kworker 进程

According to kernel.org, the syntax is kworker/%u:%d%s (cpu, id, priority). The u designates a special CPU, the unbound cpu, meaning that the kthread is currently unbound.

The workqueue workers which have negative nice value have ‘H’ postfixed to their names.

根据 kernel.org,语法是 kworker/%u:%d%s (cpu, id, priority)。u 表示一个特殊的 CPU,即未绑定的 cpu,这意味着 kthread 当前处于未绑定状态。如果该worker的nice小于0,说明它的优先级很高,所以就加了H属性。
源介绍

一个比较详细的进程说明

ditto:同上的意思
All Processes

All Processes
These are the processes running on a default install of Ubuntu Server 18.04.4. The only non-default I took was to run sshd so I could log in and get this list.ps -ef
/sbin/init maybe-ubiquity the one true process to start them all the maybe-ubiquity part is from GRUB
[kthreadd] kernel thread master for spawning off processes largely to manage hardware. Kthread processes are shown in [square brackets].
[kworker/0:0H] a kernel worker thread placeholder
[mm_percpu_wq] wow! really not a lot about the memory management per cpu work queue thread, other than cryptic messages in the kernel maintainers list
[ksoftirqd/0] a way of handling hardware interrupt requests outside a regular handler
[rcu_sched] the Read Copy Update scheduler that synchronizes data across writer and readers. Here’s the latest on RCU
[rcu_bh] a cousin of the rcu_sched above, it provides grace periods in the RCU subsystem.
[migration/0] Distributes processes across cores. One such process per core. [watchdog/0] Checks to ensure the system’s still running, and reboots if hung, hopefully.
[cpuhp/0] Process that supports physically adding and removing CPUs from the system.
[cpuhp/1] lscpu says this machine has 4 cores, so these one-per-core kernel threads are repeated with different /n suffixes
[watchdog/1] ditto
[migration/1] ditto
[ksoftirqd/1] ditto
[kworker/1:0H] ditto
[cpuhp/2] ditto
[watchdog/2] ditto
[migration/2] ditto
[ksoftirqd/2] ditto
[kworker/2:0H] ditto
[cpuhp/3] ditto
[watchdog/3] ditto
[migration/3] ditto
[ksoftirqd/3] ditto
[kworker/3:0H] ditto
[kdevtmpfs] this thread populates and maintains a device node tree
[netns] this maintains the network namespace
[rcu_tasks_kthre] clearly a part of the Read Copy Update subsystem, but I’ll be hanged if I can find ANYTHING about this thread on the web.
[kauditd] the kernel thread responsible for auditing security events
[kworker/1:1] another kernel thread placeholder, see above
[khungtaskd] looks for hung tasks every two minutes
[oom_reaper] cleans up processes that are Out Of Memory.
[writeback] handles slow writes to block devices
[kcompactd0] handles background memory compaction
[ksmd] kernel samepage merging daemon, used by the KVM hypervisor.
[khugepaged] keeps track of huge virtual memory pages efficiently
[crypto] provides an API interface to the kernel crypto module
[kintegrityd] checks the integrity of block devices by writing/reading data to and from them.
[kblockd] checks for congestion in I/O pipes
[kworker/3:1] another generic kernel thread, see above.
[kworker/2:1] ditto
[ata_sff] handles ATA Small Form Factor interfaces
[md] handles multiple device interfaces, e.g. RAID arrays
[edac-poller] handles memory error detection and correction
[devfreq_wq] apparently allows for the reuse of frequently-used kernel workqueues
[watchdogd] probably has something to do with the watchdog thread. This is another one with almost no documentation.
[kswapd0] The manager of virtual memory. An ancient and venerable subsystem.
[kworker/u33:0] Another generic kernel thread ready to be used. See above.
[ecryptfs-kthrea] This encrypts and decrypts data passing out to the filesystem.
[kthrotld] Controls bandwidth on a request queue by throttling requests
[acpi_thermal_pm] Provides an API interface to the ACPI to provider thermal management
[ipv6_addrconf] handles the IPv6 configuration workqueue
[kstrp] the Kernel Stream Processor
[kworker/2:2] another worker thread placeholder, see the first one above
[charger_manager] about what you’d expect: a battery charger manager
[scsi_eh_0] Linux boxes almost never have SCSI disks anymore. This is the handles errors from other types of disks that appear as SCSI
[scsi_tmf_0] handles disk Task Mangement Functions
[scsi_eh_1] same as above for the next disk
[scsi_tmf_1] ditto
[scsi_eh_2] ditto
[scsi_tmf_2] ditto
[scsi_eh_3] ditto
[scsi_tmf_3] ditto
[scsi_eh_4] ditto
[scsi_tmf_4] ditto
[scsi_eh_5] ditto
[scsi_tmf_5] ditto
[e1000e] Handles the Intel Gigabit Ethernet devices
[i915/signal:0] Handles the Intel i915 Graphics drivers
[i915/signal:1] ditto
[i915/signal:2] ditto
[kworker/3:1H] another placeholder thread
[raid5wq] Probably a RAID5 driver, can’t find any info on it.
[jbd2/sda2-8] Updates the filesystem journal
[ext4-rsv-conver] Handles writeback conversion work from the ext4 filesystem.
[kworker/0:1H] another placeholder thread
[kworker/1:1H] another placeholder thread
[kworker/2:1H] another placeholder thread
/lib/systemd/systemd-journald and into userland! this is the process that collects logging data
[iscsi_eh] Can’t find much info on this one either, probably the iSCSI error handler
/sbin/lvmetad -f The Logical Volume Manager metadata caching process
[ib-comp-wq] Found one reference to it in the kernel mailing list. It has to do with the InfiniBand driver, and it’s now cpu-bound
[ib-comp-unb-wq] Dealing with the InfiniBand WorkQueue
[ib_mcast] Handling InfiniBand Multicast groups
[ib_nl_sa_wq] No info on this one, either. Some InfiniBand WorkQueue
[rdma_cm] Remote Direct Memory Access, usually part of InfiniBand
/lib/systemd/systemd-udevd The part of systemd that handles devices coming and going
/lib/systemd/systemd-timesyncd The systemd way of synchronizing the system clock to an external timekeeper. The supposedly better replacement for ntpd.
[irq/27-mei_me] One of the daemons that handles IRQ interrupts
/lib/systemd/systemd-networkd The part of the systemd juggernaut that handles networking
/lib/systemd/systemd-resolved The systemd Domain Name Service resolution manager
/usr/sbin/atd -f One of the few old-timers left: The at daemon that handles one-time delayed job execution
/usr/bin/lxcfs /var/lib/lxcfs/ Manages filesystems for fuse containers
/usr/sbin/rsyslogd -n The remote system logger daemon.
/usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers Handles changes to the systemd-networkd
/usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only The Dbus message bus daemon without which there would be no systemd functionality
/usr/sbin/cron -f An old subsystem I’ve used for decades: the cron daemon for regularly scheduled tasks
/usr/lib/accountsservice/accounts-daemon Provides Dbus interface to modifiying account information
/usr/sbin/thermald --no-daemon --dbus-enable The user-land deamon to monitor the system’s heat
/lib/systemd/systemd-logind About what it appears it handles the login process. Gone are the gettys.
/usr/sbin/irqbalance --foreground Distributes IRQs among the processors
/usr/lib/policykit-1/polkitd --no-debug Facilitates letting unprivileged processes talk to privileged ones.
/usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal Keeps the system from shutting down while software is being updated
/bin/login -p -- The actual login process that manages a user login
[loop0] Not much information about this either. Possibly a loopback filesystem thread?
[kworker/0:6] another placeholder thread
[kworker/0:7] ditto
/usr/lib/snapd/snapd The runner for the Snap packages
/lib/systemd/systemd --user The user-land heart of systemd
(sd-pam) a helper process for the Pluggable Authentication Module system
-bash What I’m using now, the Bourne-again Shell
/usr/sbin/sshd -D The Secure Shell server process
[kworker/1:2] another placeholder thread
[kworker/3:2] ditto
[kworker/u32:0] ditto
[kworker/u32:2] ditto
[kworker/u32:1] ditto
[kworker/1:0] ditto
[kworker/3:0] ditto
ps -ef List the status of all processes

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/579071.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Duboo-入门到学废【上篇】

目录 1🥞.什么是duboo 2🌭.架构图 3.🍿快速入门 4.🧇浅浅理解 1.什么是duboo🤶🤶🤶 Dubbo是一个由阿里巴巴开发的基于Java的开源RPC框架。它提供了高性能、透明化的远程方法调用&#xff0…

JWT 单点登录探析:原理、用途与安全实践

JWT 单点登录探析:原理、用途与安全实践 什么是 JWT? JWT (JSON Web Token) 是目前最流行的跨域认证解决方案,是一种基于 Token 的认证授权机制。 从 JWT 的全称可以看出,JWT 本身也是 Token&#xff0c…

给WordPress网站添加返回顶部按钮

给WordPress网站底部添加一个按钮,点它就可以现实快速返回到顶部。有两种方法可以现实,一种是通过安装相关插件来实现。另外一种方式就是以纯属代码的方式来实现。 给WordPress网站底部添加一个按钮,点它就可以现实快速返回到顶部。有两种方…

操作系统 面试第一弹

1. 进程和线程的区别 进程(Process)和线程(Thread)是操作系统中的重要概念,它们表示执行中的程序的不同执行单元。下面是它们的区别: 定义:进程是一个独立的执行环境,具有独立的内存…

【深度学习】DataComp论文,数据集介绍,大数据模型的数据集介绍

参考: https://laion.ai/blog/datacomp/ 论文:https://arxiv.org/abs/2304.14108 文章目录 论文报告的一些内容datacomp-1B 数据质量比lainon2B要好不同规模数据有多少数据数据处理数据来源 论文报告的一些内容 摘要 多模态数据集是近期如CLIP、Stable …

TCP服务器的演变过程:IO多路复用机制select实现TCP服务器

IO多路复用机制select实现TCP服务器 一、前言二、新增使用API函数2.1、select()函数2.2、FD_*系列函数 三、实现步骤四、完整代码五、TCP客户端5.1、自己实现一个TCP客户端5.2、Windows下可以使用NetAssist的网络助手工具 小结 一、前言 手把手教你从0开始编写TCP服务器程序&a…

洛谷——【数据结构1-2】二叉树

文章目录 题目【深基16.例1】淘汰赛题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1基本思路:代码 【深基16.例3】二叉树深度题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1基本思路:代码 [USACO3.4] 美国血统 American Heritage题目描…

算符优先语法分析设计原理与实现

前言: 作者的词法分析程序以及算符优先语法分析设计程序仓库链接 1、目标任务 **[实验项目] **以专题 1 词法分析程序的输出为语法分析的输入,实现算符优先分析算法,完成以下描述算术表达式的算符优先文法的算符优先分析过程。 G[E]:E→E…

Spark编程实验三:Spark SQL编程

目录 一、目的与要求 二、实验内容 三、实验步骤 1、Spark SQL基本操作 2、编程实现将RDD转换为DataFrame 3、编程实现利用DataFrame读写MySQL的数据 四、结果分析与实验体会 一、目的与要求 1、通过实验掌握Spark SQL的基本编程方法; 2、熟悉RDD到DataFram…

代码随想录算法训练营第二十七天 | 回溯算法part4

力扣题目 用时&#xff1a;未知 1、93.复原IP地址 2、78.子集 3、90.子集II 力扣题目记录 93.复原IP地址 这个题和上一个题差不多&#xff0c;只是4段数字&#xff0c;只有三个句点&#xff0c;所以第四段要单独处理判断子串是否合法 class Solution { private:vector<s…

Qt/QML编程学习之心得:实现一个图片浏览器(十八)

QML中有个重要控件,经常使用就是image,通常可以用它来显示一张图片。如果想结合openfiledialog来让image显示图片,也就是做一个简易的图片浏览器,怎么弄呢? DefaultFileDialog.qml: import QtQuick 2.0 import QtQuick.Dialogs 1.0FileDialog {id: fileDialogtitle: &qu…

2024免费的数据恢复软件EasyRecovery14自己操作就能恢复的方法

而今天小编为大家还是带来了同系列软件easyrecovery14&#xff0c;这是easyrecovery数据恢复软件中的技术员版本&#xff0c;不仅包含家庭版和专业版的所有功能&#xff0c;而且还旨在简化技术人员的数据恢复过程。软件拥有强大的数据恢复功能&#xff0c;支持使用的恢复场景有…

KNN与KD树博客总结

目录 总结小结&#xff1a; 总结 原始篇&#xff1a;KNN算法及其优缺点算法思想改进篇&#xff1a;KD树&#xff08;KNN的plus版算法实现第一篇&#xff1a;平衡二叉树的构建&#xff08;递归算法实现第二篇&#xff1a;KD树的构建&#xff08;递归算法实现第三篇&#xff1a;…

CentOS 7 设置网络

CentOS 7 设置网络 正常情况 ①登陆进去之后使用下面的命令修改文件 echo ONBOOTyes >> /etc/sysconfig/network-scripts/ifcfg-ens33②如果是虚拟机重启后使用如下命令进行查看IP地址 ip addr注&#xff1a;到这里如果显示有两部分&#xff0c;则代表网络设置成功&a…

华为设备VRP系统管理

为了满足企业业务对网络的需求&#xff0c;网络设备中的系统文件需要不断进行升级。另外&#xff0c;网络设备中的配置文件也需要时常进行备份&#xff0c;以防设备故障或其他灾害给业务带来损害。在升级和备份系统文件或配置文件时&#xff0c;经常会使用FTP和TFTP来传输文件。…

服务器系统时间不同步如何处理

在分布式计算环境中&#xff0c;服务器系统时间的同步至关重要。然而&#xff0c;由于各种原因&#xff0c;服务器系统时间不同步的问题时有发生,这可能会导致严重的问题&#xff0c;如日志不准确、证书验证失败等。下面我们可以一起探讨下造成服务器系统时间不同的原因以及解决…

【Vue2+3入门到实战】(5)Vue基础之Computed计算属性 详细示例

目录 一、今日学习目标1.computed计算属性 二、computed计算属性1.概念2.语法3.注意4.案例5.代码准备 三、computed计算属性 VS methods方法1.computed计算属性2.methods计算属性3.计算属性的优势4.总结 四、计算属性的完整写法五、综合案例-成绩案例六、Computed计算属性总结 …

【测试开发】测试分类相关知识

文章目录 目录 文章目录 前言 一、测试分类 1.按照测试对象划分&#xff1a; 界面测试&#xff1a; 可靠性测试&#xff1a; 容错性测试&#xff1a; 文档测试 &#xff1a; 兼容性测试 &#xff1a; 易用性测试 &#xff1a; 安装卸载测试 &#xff1a; 安全测试 &#xff1a;…

揭秘Pod状态与生命周期管理的秘密(中)

上一篇文章中主要介绍了Pod的基础概念与使用、删除。本文将带你一起学习Pod的几种容器(Init、Pause) 点击 这里 可以查看所有相关文章。 Init 容器 本文讲解 Init 容器的基本概念&#xff0c;这是一种专用的容器&#xff0c;在应用程序容器启动之前运行&#xff0c;用来包含…

Spring Boot 3.2 新特性之 HTTP Interface

SpringBoot 3.2引入了新的 HTTP interface 用于http接口调用&#xff0c;采用了类似 openfeign 的风格。 具体的代码参照 示例项目 https://github.com/qihaiyan/springcamp/tree/master/spring-http-interface 一、概述 HTTP Interface 是一个类似于 openfeign 的同步接口调…