编辑
2024-01-11
记录知识
0

git提交建议

git commit一直没有一个规范,但是经常翻阅大型仓库例如linux kernel的都能感觉到commit是有一定规范的。为了让自己提交代码更合规点,这里整理了规范和一些注意事项(不一定正确哦),如下分享

我的模板

Module: SubModule: Brief description of the patch ################################################################################# # Reference: https://www.kernel.org/doc/html/v5.4/process/submitting-patches.html # Notice: # 1. Only one problem was solved. # 2. Full description and justification # 3. Only one problem per patch # # Example 1: # Module: SubModule: Brief description of the patch # # Example 2: # Module: SubModule: Brief description of the patch # # Detailed description (if desired) # # Example 3: # [PATCH] Foo: Fix these things # or # [PATCH v2] Foo: Fix these things better # or # [PATCH v3 0/2] comedi: Fix these things # [PATCH v3 1/2] comedi: Fix the first thing # [PATCH v3 2/2] comedi: Fix the second thing #################################################################################

上述是.gitmessage文件,这个文件需要在自己的目录~/.gitmessage
为了使得这个模板生效,可以git config --global commit.template ~/.gitmessage
这样,以后提交就可以按照这个模板了。

介绍内核补丁提交

vim设置

vim ~/.vimrc

filetype plugin indent on syntax on set title set tabstop=8 set softtabstop=8 set shiftwidth=8 set noexpandtab

命令如下
:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
update-alternatives --config editor

mutt设置

apt install esmtp touch ~/.esmtprc chmod g-rwx ~/.esmtprc chmod o-rwx ~/.esmtprc vim ~/.esmtprc identity "tangfengweny@gmail.com" hostname smtp.gmail.com:587 username "tangfengweny@gmail.com" password "邮箱密码" starttls required set sendmail="/usr/bin/esmtp" set envelope_from=yes set from="tangfeng <tangfengweny@gmail.com>" set use_from=yes set edit_headers=yes

git设置

vim ~/.gitconfig [user] name = tangfeng email = tangfengweny@example.com

更新内核

git fetch origin git rebase origin/yourbranch

checkpatch

apt-get install codespell python-ply python-git vim .git/hooks/post-commit #!/bin/sh exec git show --format=email HEAD | ./scripts/checkpatch.pl --strict --codespell chmod a+x .git/hooks/post-commit

这样提交时就默认检查补丁规范了./scripts/checkpatch.pl --strict --codespell

提交

确保提交的commit信息用 git log --oneline 能够清晰了解补丁内容

发送

了解对应提交的maintainer
git show HEAD | perl scripts/get_maintainer.pl --separator , -- nokeywords --nogit --nogit-fallback --norolestats 如果是特定文件 perl scripts/get_maintainer.pl --separator , --nokeywords --nogit -- nogit-fallback --norolestats -f drivers/staging/vt6655/baseband.c
不要直接把补丁发送到邮件列表,要先制作一封特殊的邮件。如下 git format-patch -o /tmp/ HEAD^ 先发给自己 mutt -H /tmp/0001-*.patch 也可以git发送

vim .gitconfig [sendemail] smtpserver = /usr/bin/esmtp git send-email --annotate HEAD^

对补丁进行版本控制

git format-patch --subject-prefix="PATCH v2"
如果需要对补丁额外修改,应该在补丁下添加---,然后开始解释,git工具会忽略---下面的内容 然后在补充内容后面加剪刀符>8-----8<这样文本会更加清晰 如下:

Signed-off-by: Your Name <my.email@gmail.com> --- Changes since v2: * Made commit message more clear * Corrected grammer in code comment * Used new API instead of depreciated API >8------------------------------------------------------8< drivers/staging/csr/bh.c

这里---下面的是补充的内容

制作补丁集

补丁集也就是对所有提交补丁的汇总,如下
git format-patch -n --subject-prefix="PATCH vY" --cover-letter
最后发送补丁集
git send-email --to <发给谁> --cc <addresses from get_maintainer.pl output> /tmp/*.patch
可以先--dry-run在本地实验后在发送
git send-email --to <发给谁> --cc <addresses from get_maintainer.pl output> -dry-run /tmp/*.patch

参考链接

https://kernelnewbies.org/FirstKernelPatch
https://kernelnewbies.org/PatchPhilosophy

编辑
2024-01-09
记录知识
0

了解/proc/vmstat

nr_free_pages 2596184 # 系统可用的页数 对应MemFree nr_zone_inactive_anon 489528 # 未活跃的页数 对应Inactive(anon) nr_zone_active_anon 599 # 对应Active(anon) nr_zone_inactive_file 516396 # 对应 Inactive(file) nr_zone_active_file 235058 # Active(file) nr_zone_unevictable 71526 # Unevictable nr_zone_write_pending 149 # dirty+writeback+unstable pages nr_mlock 8 # Mlocked nr_bounce 0 # Bounce nr_zspages 0 # allocated in zsmalloc nr_free_cma 0 # cma numa_hit 4634064 # allocated in intended node numa_miss 0 # allocated in non intended node numa_foreign 0 # was intended here, hit elsewhere numa_interleave 2880 # interleaver preferred this zone numa_local 4634064 # allocation from local node numa_other 0 # allocation from other node nr_inactive_anon 489528 # nr_zone_inactive_anon nr_active_anon 599 # nr_zone_active_anon nr_inactive_file 516396 # nr_zone_inactive_file nr_active_file 235058 # nr_zone_active_file nr_unevictable 71526 # nr_zone_unevictable nr_slab_reclaimable 32813 # SReclaimable nr_slab_unreclaimable 26640 # SUnreclaim nr_isolated_anon 0 # Temporary isolated pages from anon lru nr_isolated_file 0 # Temporary isolated pages from file lru workingset_nodes 0 workingset_refault_anon 0 workingset_refault_file 0 workingset_activate_anon 0 workingset_activate_file 0 workingset_restore_anon 0 workingset_restore_file 0 workingset_nodereclaim 0 nr_anon_pages 470838 # AnonPages nr_mapped 196874 # Mapped nr_file_pages 842283 # 文件缓存页 nr_dirty 149 # 脏页数 nr_writeback 0 # 回写页数 nr_writeback_temp 0 # WritebackTmp 文件系统的临时回写 nr_shmem 92614 # Shmem nr_shmem_hugepages 0 # ShmemHugePages nr_shmem_pmdmapped 0 # ShmemPmdMapped nr_file_hugepages 0 # FileHugePages nr_file_pmdmapped 0 # FilePmdMapped nr_anon_transparent_hugepages 0 # AnonHugePages nr_vmscan_write 0 # LRU内存回收写入页数 nr_vmscan_immediate_reclaim 0 # 优先回收的页数 nr_dirtied 515721 # page dirtyings since bootup nr_written 346168 # page dirtyings since bootup nr_kernel_misc_reclaimable 0 # reclaimable non-slab kernel pages nr_foll_pin_acquired 0 # via: pin_user_page(), gup flag: FOLL_PIN nr_foll_pin_released 0 # pages returned via unpin_user_page() nr_kernel_stack 12992 # KernelStack,kb单位 nr_page_table_pages 6858 # PageTables nr_swapcached 0 # swap cached nr_dirty_threshold 660577 # 脏页触发系统回写的阈值 nr_dirty_background_threshold 329885 # 脏页触发后台回写的阈值 pgpgin 2541198 # 从启动到现在读入的内存页数 pgpgout 1421761 # 从启动到现在换出的内存页数 pswpin 0 # 从启动到现在读入的交换分区页数 pswpout 0 # 从启动到现在换出的交换分区页数 pgalloc_dma 512 # 从启动到现在DMA存储区分配的页数 pgalloc_dma32 513 # 从启动到现在DMA 32位的存储区分配的页数 pgalloc_normal 4756880 # 从启动到现在普通存储区分配的页数 pgalloc_movable 0 # 可移除内存区 allocstall_dma 0 allocstall_dma32 0 allocstall_normal 0 allocstall_movable 0 pgskip_dma 0 pgskip_dma32 0 pgskip_normal 0 pgskip_movable 0 pgfree 7356348 # 从启动到现在释放的页数 pgactivate 365485 # 从启动到现在激活的页数 pgdeactivate 0 # 从启动到现在去激活的页数 pglazyfree 2336 pgfault 2896643 # 从启动到现在二级页面错误数 pgmajfault 6079 # 从启动到现在一级页面错误数 pglazyfreed 0 pgrefill 0 pgreuse 429609 # 不太理解,这里解释https://lkml.kernel.org/lkml/CAHk-=wgchPHqevEZ1radW1vLHKGGSaq_SCVHKgxHmQt70OSSfg@mail.gmail.com/ pgsteal_kswapd 0 pgsteal_direct 0 pgscan_kswapd 0 pgscan_direct 0 pgscan_direct_throttle 0 pgscan_anon 0 pgscan_file 0 pgsteal_anon 0 pgsteal_file 0 zone_reclaim_failed 0 pginodesteal 0 slabs_scanned 0 kswapd_inodesteal 0 kswapd_low_wmark_hit_quickly 0 kswapd_high_wmark_hit_quickly 0 pageoutrun 0 pgrotated 2 # 从启动到现在轮换的页面数 drop_pagecache 0 drop_slab 0 oom_kill 0 numa_pte_updates 0 numa_huge_pte_updates 0 numa_hint_faults 0 numa_hint_faults_local 0 numa_pages_migrated 0 pgmigrate_success 0 pgmigrate_fail 0 thp_migration_success 0 thp_migration_fail 0 thp_migration_split 0 compact_migrate_scanned 0 compact_free_scanned 0 compact_isolated 0 compact_stall 0 compact_fail 0 compact_success 0 compact_daemon_wake 0 compact_daemon_migrate_scanned 0 compact_daemon_free_scanned 0 htlb_buddy_alloc_success 0 htlb_buddy_alloc_fail 0 unevictable_pgs_culled 538811 unevictable_pgs_scanned 423920 unevictable_pgs_rescued 424015 unevictable_pgs_mlocked 202 unevictable_pgs_munlocked 194 unevictable_pgs_cleared 0 unevictable_pgs_stranded 0 thp_fault_alloc 0 thp_fault_fallback 0 thp_fault_fallback_charge 0 thp_collapse_alloc 0 thp_collapse_alloc_failed 0 thp_file_alloc 0 thp_file_fallback 0 thp_file_fallback_charge 0 thp_file_mapped 0 thp_split_page 0 thp_split_page_failed 0 thp_deferred_split_page 0 thp_split_pmd 0 thp_split_pud 0 thp_zero_page_alloc 0 thp_zero_page_alloc_failed 0 thp_swpout 0 thp_swpout_fallback 0 balloon_inflate 0 balloon_deflate 0 balloon_migrate 0 swap_ra 0 swap_ra_hit 0 direct_map_level2_splits 113 direct_map_level3_splits 2 nr_unstable 0

可以发现vmstat里面包含了很多的内存名词和信息,这些都是平时完全不知道的,要把内存这款了解透,得慢慢接触这些代码,配置和慢慢实践。上面分析vmstat过程中,很多不知道的,就没有细究了。因为还没那个功底去细究

编辑
2024-01-09
记录知识
0

了解/proc/meminfo

MemTotal: 16002428 kB # 内核和系统可以使用的内存大小 MemFree: 12692524 kB # 系统尚未使用的内存 MemAvailable: 14358188 kB # free+可以被回收的内存大小 Buffers: 64908 kB # 块设备的缓存页 Cached: 1990844 kB # 磁盘或文件系统的内存缓存 SwapCached: 0 kB # 交换分区的内存缓存 Active: 955104 kB # 最近比较活跃的内存,可回收的 Inactive: 1851012 kB # 不活跃的内存 Active(anon): 2160 kB # cache里面的匿名的活跃内存 Inactive(anon): 928056 kB # cache里面的匿名的不活跃内存 Active(file): 952944 kB # cache里面的活跃内存 Inactive(file): 922956 kB # cache里面的不活跃内存 Unevictable: 188200 kB # 被内核认为无法回收的内存 Mlocked: 0 kB # mlock锁住的内存 SwapTotal: 902700 kB # swap的内存 SwapFree: 902700 kB # swap的可用内存 Dirty: 0 kB # 等待回写的脏页 Dirty+NFS_Unstable+Writeback=脏页 Writeback: 0 kB # 正在回写的脏页 AnonPages: 938576 kB # 匿名页 Mapped: 434276 kB # 被映射的页,例如库,二进制,mmap过的 Shmem: 191716 kB # 共享内存或tmpfs或devtmpfs KReclaimable: 100012 kB # 内核可被回收的内存 Slab: 202148 kB # SReclaimable+SUnreclaim SReclaimable: 100012 kB # slab中可以被回收的内存 SUnreclaim: 102136 kB # slab中不可以被回收的内存 KernelStack: 9904 kB # 给用户线程分配的内核栈消耗的页 PageTables: 16356 kB # 页表占用内存,内存占用越多使用的页表就越多 NFS_Unstable: 0 kB # 给nfs 服务的缓存 Bounce: 0 kB # 给块设备的bounce buffers WritebackTmp: 0 kB # 给用户文件系统FUSE的临时回写内存 CommitLimit: 8903912 kB # 提交虚拟内存的最大大小,也就是虚拟内存的最大申请内存值 Committed_AS: 4856984 kB # 当前系统的虚拟内存分配量 VmallocTotal: 34359738367 kB # 可用于vmalloc申请的内存大小 VmallocUsed: 33552 kB # 已用的虚拟内存大小 VmallocChunk: 0 kB # 虚拟内存最大的连续块 Percpu: 8896 kB # 给percpu机制申请器使用的内存 HardwareCorrupted: 0 kB # 内核察觉出内存出错的大小计数 AnonHugePages: 2048 kB # 给用户空间的匿名大页 ShmemHugePages: 0 kB # 给shmem和tmpfs的大页 ShmemPmdMapped: 0 kB # 已映射过的shmem大页 FileHugePages: 0 kB # 映射文件的大页 FilePmdMapped: 0 kB # 已映射过的文件的大页 HugePages_Total: 0 # 总共大页内存大小 HugePages_Free: 0 # 剩余的大页大小 HugePages_Rsvd: 0 # 预申请的大页,也就是申请了没有的 HugePages_Surp: 0 # 大页池的剩余 Hugepagesize: 2048 kB # 大页大小 Hugetlb: 0 kB # Hugetlbfs 的大页使用清除 DirectMap4k: 235016 kB # 可以映射4k页面的数量 DirectMap2M: 4624384 kB # 可以映射2M页面的数量 DirectMap1G: 11534336 kB # 可以映射1G页面的数量

参考链接

https://www.kernel.org/doc/Documentation/filesystems/proc.rst http://linuxperf.com/?p=142 http://www.javashuo.com/article/p-dgjqhxgd-nc.html
编辑
2024-01-09
记录知识
0

repo简易搭建

随着git项目越来越多,每次环境部署的时候,不可能一个一个去clone仓库,这样太费事了。为了偷懒,我借鉴了android的repo机制,这样可以自行对自己的git仓库搭建一个简单的repo,之后使用这个repo就能方便的管理多个git仓库了。

克隆repo

git clone https://gerrit.googlesource.com/git-repo

由于repo会把repo url默认到

https://gerrit.googlesource.com/git-repo。

这里需要本地git地址。也可修改成gitlab地址。如下

REPO_URL = 'http://ip/git-repo.git'

repo设置

git init --bare manifests.git git clone /root/work2/git/manifests.git vim manifests.git <?xml version="1.0" encoding="UTF-8"?> <manifest> <remote fetch="ssh://root@172.25.130.31/root/work2/git" name="origin"/> <default remote="origin" revision="master" sync-j="4"/> <project name="test1" path="test1"/> <project name="test2" path="test2"/> <project name="test3" path="test3"/> </manifest> git add . && git commit -m "first commit" && git push

这里通过编写xml,设置远端的git仓库为root@172.25.130.31/root/work2/git, 远端的分支名字为origin,默认的remote为origin,版本分支为master,一共三个工程,分别为test1 test2 test3,并在本地创建同样的目录名字。

这样即可编写一个最简单的manifests.xml。后续可以使用这个xml来管理整个git仓库

拉repo仓库

repo init -u root@172.25.130.31:/root/work2/git/manifests.git repo sync

此时可以看到三个仓库被正常的拉取

[root@localhost 3]# ls test1 test2 test3

设置快照

在repo不断更新的过程中,可以生成快照,实际上就是生成一个xml文件,它保持了当时的repo状态,可供其他人使用。

这个类似于git tag。当需要整体出一个版本的时候,可以直接生成快照。

repo manifest -r -o tag_v1.0.xml <?xml version="1.0" encoding="UTF-8"?> <manifest> <remote fetch="ssh://root@172.25.130.31/root/work2/git" name="origin"/> <default remote="origin" revision="master" sync-j="4"/> <project dest-branch="master" name="test1" revision="831a146ccf46fe060c74f15354e9d68c3e0afbcb" upstream="master"/> <project dest-branch="master" name="test2" revision="829b53cce4538d5ae5919bc42bea7254bc1dcd9b" upstream="master"/> <project dest-branch="master" name="test3" revision="750f8d272da0b85a7bb7c42427fe9f0c72d416be" upstream="master"/> </manifest>

这里就比较显而易见了,快照保持了每个分支的分支信息,commit信息和上游信息

基本使用

查看分支状态

repo status

为某个分支创建新的branch

repo start bug_1.2 test1

上面这个命令等同于

git checkout -b bug_1.4

查看分支信息

repo branch

查看所有分支的diff

repo diff

manifests仓库的xml解释

标准头

默认的xml头

<?xml version="1.0" encoding="UTF-8"?>

顶层manifest元素

<manifest> </manifest>

remote元素

<remote /> name 这里的name是git remote的那个远程名字,默认是origin。如果是git的remote是其他的,这里填写对应即可 fetch 这里是git的地址,如果是ssh可以是:ssh://root@172.25.130.31/root/work2/git 如果是http或者git,就是github/gitlab上的地址 pushurl 这里是push的地址,当指定该属性的时候,这个值会和<project>标签中的name属性拼成完整的push url路径,这样当我们使用git push命令的时候,就会使用该url。如果不指定该属性,则pushurl和fetch一样。 revision 这里是默认的git branch名字。可以是master或者其他

default 元素

<default /> remote 这里是remote设置的名字,代表repo拉的分支默认使用哪个remote上的 revision 当一个<project>不指定revision的时候使用该值 dest-branch 默认创建的本地分支,如果不指定,就是revision默认创建的分支 sync-j repo sync的并行数目 sync-c 如果设置为true,则只同步指定的分支(revision 属性指定),而不是所有的ref内容 sync-s 如果设置为true,则会同步git的子项目 sync-tags

project 元素

<project /> name: 这里是工程名也就是哪个仓库 ${remote_fetch}/${project_name}.git path: 显式声明的存放文件路径 remote: 这里指定的远程分支名字 revision: 这里指定需要获取的git提交点,可以是master, refs/heads/master, tag或者SHA-1值。如果不设置的话,默认下载当前project,当前分支上的最新代码。 upstream: 在哪个git分支可以找到一个SHA1。用于同步revision锁定的manifest(-c 模式

include 元素

xml可以直接include子xml。通过如下方式 <manifest> <include name="default.xml" /> </manifest>

linkfile和copyfile属性

<project name="test1" path="test1"> <linkfile dest="Readme" src="Readme"/> <copyfile dest="Readme.md1" src="Readme.md"/> </project>

在project下面设置可以设置软连接和拷贝。实际上等效于如下

ln -s test1/Readme Readme cp test1/Readme.md Readme.md1 ``` ## 参考链接 ``` https://gerrit-googlesource.proxy.ustclug.org/git-repo https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.md ```
编辑
2024-01-09
记录知识
0

ssh记录

记录一下ssh相关配置,随时查询用

免密登录

ssh-keygen -C name@mail.com ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip

别名登录

ssh-keygen ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip vim ~/.ssh/config Host tf HostName 172.25.80.123 Port 22 User root IdentityFile ~/.ssh/id_rsa ssh tf

ssh登录慢

  1. 使用root权限修改ssh的配置文件

vim /etc/ssh/sshd_config

增加一行记录:UseDNS no

  1. 关闭GSSAPI

发现:Next authentication method: gssapi-with-mic

vim /etc/ssh/sshd_config

vim /etc/ssh/ssh_config

修改GSSAPIAuthentication参数为no

远程备份

dd if=/dev/mmcblk1p4 | ssh root@ip dd of=~/backup.img

tar cvzf - package_dir/ | ssh root@ip "cd ~/backup ;cat >backup_file.tar.gz"

Root登录

/etc/ssh/sshd_config PermitRootLogin yes

allocation request failed on channel 0

mount devpts /dev/pts -t devpts

删除hosts

ssh-keygen -f "~/.ssh/known_hosts" -R ip

no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

~/.ssh/config Host * KexAlgorithms +diffie-hellman-group1-sha1

tcp转发

AllowTcpForwarding 默认yes,可以no关闭

tun转发

PermitTunnel 是否允许 tun 设备转发。可用值如下: "yes", "point-to-point", "ethernet", "no"(默认) "yes"同时蕴含着"point-to-point"和"ethernet"