一。可见性
内存分为主内存和线程内存,当线程开始时会把主内存需要的数据放到线程内存里,但线程内存的数据不会直接返回给主内存,这导致了多线程的情况下,对一个 数据不能做到即使反馈。
二。volatile
它可以用来修饰成员变量和静态成员变量,他可以避免线程从自己的工作缓存中查找变量的值,必须到主存中获取 它的值,线程操作 volatile 变量都是直接操作主存。
三。指令重排
JVM 会在不影响正确性的前提下,可以调整语句的执行顺序,这种特性称之为『指令重排』,多线程下『指令重排』会影响正确性。
volatile 修饰的变量,可以禁用指令重排。
被volatile修饰的变量在其读操作时产生读屏障,之后的代码不会排在其之前,在写操作时,其它代码不能排到它之后。
四。cas
cas全称为compareAndSet 比较并交换,是一个原子操作,在类unsafe在的方法。
cas必须和volatile配合。
cas特点:
CREATE TABLE EMP (EMPNO int NOT NULL, ENAME VARCHAR(10), JOB VARCHAR(9), MGR int, HIREDATE DATETIME, SAL int, COMM int, DEPTNO int) INSERT INTO EMP VALUES (7369, 'SMITH', 'CLERK', 7902, '12/17/1980', 800, NULL, 20) INSERT INTO EMP VALUES (7499, 'ALLEN', 'SALESMAN', 7698, '2/20/1981', 1600, 300, 30) INSERT INTO EMP VALUES (7521, 'WARD', 'SALESMAN', 7698, '2/22/1981', 1250, 500, 30) INSERT INTO EMP VALUES (7566, 'JONES', 'MANAGER', 7839, '4/2/1981', 2975, NULL, 20) INSERT INTO EMP VALUES (7654, 'MARTIN', 'SALESMAN', 7698, '9/28/1981', 1250, 1400, 30) INSERT INTO EMP VALUES (7698, 'BLAKE', 'MANAGER', 7839, '5/1/1981', 2850, NULL, 30) INSERT INTO EMP VALUES (7782, 'CLARK', 'MANAGER', 7839, '6/9/1981', 2450, NULL, 10) INSERT INTO EMP VALUES (7788, 'SCOTT', 'ANALYST', 7566, '12/9/1982', 3000, NULL, 20) INSERT INTO EMP VALUES (7839, 'KING', 'PRESIDENT', NULL, '11/17/1981', 5000, NULL, 10) INSERT INTO EMP VALUES (7844, 'TURNER', 'SALESMAN', 7698, '9/8/1981', 1500, 0, 30) INSERT INTO EMP VALUES (7876, 'ADAMS', 'CLERK', 7788, '1/12/1983',1100, NULL, 20) INSERT INTO EMP VALUES (7900, 'JAMES', 'CLERK', 7698, '12/3/1981', 950, NULL, 30) INSERT INTO EMP VALUES (7902, 'FORD', 'ANALYST', 7566, '12/3/1981', 3000, NULL, 20) INSERT INTO EMP VALUES (7934, 'MILLER', 'CLERK', 7782, '1/23/1982', 1300, NULL, 10) CREATE TABLE DEPT (DEPTNO integer, DNAME VARCHAR(14), LOC VARCHAR(13) ) INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK') INSERT INTO DEPT VALUES (20, 'RESEARCH', 'DALLAS') INSERT INTO DEPT VALUES (30, 'SALES', 'CHICAGO') INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON') CREATE TABLE T1 (ID INTEGER) INSERT INTO T1 VALUES (1) CREATE TABLE T10 (ID INTEGER) INSERT INTO T10 VALUES (1) INSERT INTO T10 VALUES (2) INSERT INTO T10 VALUES (3) INSERT INTO T10 VALUES (4) INSERT INTO T10 VALUES (5) INSERT INTO T10 VALUES (6) INSERT INTO T10 VALUES (7) INSERT INTO T10 VALUES (8) INSERT INTO T10 VALUES (9) INSERT INTO T10 VALUES (10) CREATE TABLE T100 (ID INTEGER) INSERT INTO T100 VALUES (1) INSERT INTO T100 VALUES (2) INSERT INTO T100 VALUES (3) INSERT INTO T100 VALUES (4) INSERT INTO T100 VALUES (5) INSERT INTO T100 VALUES (6) INSERT INTO T100 VALUES (7) INSERT INTO T100 VALUES (8) INSERT INTO T100 VALUES (9) INSERT INTO T100 VALUES (10) INSERT INTO T100 VALUES (11) INSERT INTO T100 VALUES (12) INSERT INTO T100 VALUES (13) INSERT INTO T100 VALUES (14) INSERT INTO T100 VALUES (15) INSERT INTO T100 VALUES (16) INSERT INTO T100 VALUES (17) INSERT INTO T100 VALUES (18) INSERT INTO T100 VALUES (19) INSERT INTO T100 VALUES (20) INSERT INTO T100 VALUES (21) INSERT INTO T100 VALUES (22) INSERT INTO T100 VALUES (23) INSERT INTO T100 VALUES (24) INSERT INTO T100 VALUES (25) INSERT INTO T100 VALUES (26) INSERT INTO T100 VALUES (27) INSERT INTO T100 VALUES (28) INSERT INTO T100 VALUES (29) INSERT INTO T100 VALUES (30) INSERT INTO T100 VALUES (31) INSERT INTO T100 VALUES (32) INSERT INTO T100 VALUES (33) INSERT INTO T100 VALUES (34) INSERT INTO T100 VALUES (35) INSERT INTO T100 VALUES (36) INSERT INTO T100 VALUES (37) INSERT INTO T100 VALUES (38) INSERT INTO T100 VALUES (39) INSERT INTO T100 VALUES (40) INSERT INTO T100 VALUES (41) INSERT INTO T100 VALUES (42) INSERT INTO T100 VALUES (43) INSERT INTO T100 VALUES (44) INSERT INTO T100 VALUES (45) INSERT INTO T100 VALUES (46) INSERT INTO T100 VALUES (47) INSERT INTO T100 VALUES (48) INSERT INTO T100 VALUES (49) INSERT INTO T100 VALUES (50) INSERT INTO T100 VALUES (51) INSERT INTO T100 VALUES (52) INSERT INTO T100 VALUES (53) INSERT INTO T100 VALUES (54) INSERT INTO T100 VALUES (55) INSERT INTO T100 VALUES (56) INSERT INTO T100 VALUES (57) INSERT INTO T100 VALUES (58) INSERT INTO T100 VALUES (59) INSERT INTO T100 VALUES (60) INSERT INTO T100 VALUES (61) INSERT INTO T100 VALUES (62) INSERT INTO T100 VALUES (63) INSERT INTO T100 VALUES (64) INSERT INTO T100 VALUES (65) INSERT INTO T100 VALUES (66) INSERT INTO T100 VALUES (67) INSERT INTO T100 VALUES (68) INSERT INTO T100 VALUES (69) INSERT INTO T100 VALUES (70) INSERT INTO T100 VALUES (71) INSERT INTO T100 VALUES (72) INSERT INTO T100 VALUES (73) INSERT INTO T100 VALUES (74) INSERT INTO T100 VALUES (75) INSERT INTO T100 VALUES (76) INSERT INTO T100 VALUES (77) INSERT INTO T100 VALUES (78) INSERT INTO T100 VALUES (79) INSERT INTO T100 VALUES (80) INSERT INTO T100 VALUES (81) INSERT INTO T100 VALUES (82) INSERT INTO T100 VALUES (83) INSERT INTO T100 VALUES (84) INSERT INTO T100 VALUES (85) INSERT INTO T100 VALUES (86) INSERT INTO T100 VALUES (87) INSERT INTO T100 VALUES (88) INSERT INTO T100 VALUES (89) INSERT INTO T100 VALUES (90) INSERT INTO T100 VALUES (91) INSERT INTO T100 VALUES (92) INSERT INTO T100 VALUES (93) INSERT INTO T100 VALUES (94) INSERT INTO T100 VALUES (95) INSERT INTO T100 VALUES (96) INSERT INTO T100 VALUES (97) INSERT INTO T100 VALUES (98) INSERT INTO T100 VALUES (99) INSERT INTO T100 VALUES (100) DB2MySQLOraclePostqestsql_cookbook · master · examples / SQL Cookbook · GitLab (oreilly.
sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt-get update sudo apt-get install gcc-7sudo apt-get install g++-7 配置:将gcc7,g++7作为默认选项
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100sudo update-alternatives --config gccsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100sudo update-alternatives --config g++
初学者学习Linux系统地址转换时,如果只是学习理论,又或者研读代码,那可能感觉比较枯燥。此时如果可以利用某些工具实际观察一下地址转换的过程,那可能会给枯燥的内核学习带来些微的乐趣。crash tool是一款内核调试工具,常用来分析内核崩溃问题。我们可以手动触发内核崩溃,然后借用该工具来分析当时系统的运行情况,当然也包括内存的运行情况。
本文基于ARMv8 AArch64 (简称ARM64)架构,Linux 4.14内核来讲述。首先回顾一下内存访问的相关知识点。
1、ARM内存访问的硬件架构
ARM有MMU部件,现代操作系统一般都会启用MMU来访问内存。启用MMU之后,多进程就有了可能,每个进程可以维护各自私有的虚拟地址空间,无需关心物理内存布局。
2、虚拟地址空间到物理地址空间的映射
虚拟地址到物理地址的映射是通过查表的机制来实现,下图是一种典型的地址映射布局。内核空间地址的高16位(bit[63:48])为全1,其转换表的基地址存放在TTBR1_EL1寄存器中;用户空间地址的高16位(bit[63:48])为全0,其转换表的基地址存放在TTBR0_EL0寄存器中。
除了高16位外,剩下的48位,也并不全用作虚拟地址空间,使用多少位是可以配置的,比如Linux系统的内核一般做如下配置,表示有39位虚拟地址空间。
CONFIG_ARM64_VA_BITS=39
39位虚拟地址空间,内核空间范围为0xFFFFFF80_00000000 ~ 0xFFFFFFFF_FFFFFFFF,用户空间范围为0x00000000_00000000 ~ 0x0000007F_FFFFFFFF。
3、转换表的格式
转换表有4个级别,level 0 ~ level 3。
如下图所示,当bit[1:0]为2b'11时,表示该表项是Table descriptor,指向下一级转换表的地址。而当 bit[1:0]为2b'01时,表示Block entry,不指向下一级转换表,而是直接输出block address。当表项处于level 3时,即使bit[1:0]为2b'11,也不再指向下一级转换表,而是输出block address。
4、地址转换的过程
如下图所示,以39位虚拟地址为例,来了解地址转换过程。图片是取自ARMv8官方文档,建议放大了看。
内存中维护着三个转换表,从虚拟地址转换成物理地址,要经过三次查表的过程。
39位虚拟地址被分成了4部分,作用如下:
bit[38:30] —— 索引第一级表中的表项
bit[29:21] —— 索引第二级表中的表项
bit[20:12] —— 索引第三级表中的表项
bit[11:0] —— 页内偏移
第一步,TTBR寄存器中存放了第一级转换表的起始地址,虚拟地址的bit[38:30]的值表示要查找转换表中的第几项,这个值左移三位(64位地址,每个表项占用8字节),再加上第一级转换表的地址,就是该表项的地址。该表项存放的是第二级转换表的起始地址。
第二步,用第二级转换表的起始地址,再结合虚拟地址的bit[29:21],与第一步计算方法类似,可以计算出第二级表项的地址。第二级表项中存放了第三级转换表的起始地址。
第三步,用第三级转换表的起始地址,再结合虚拟地址的bit[20:12],与第一步计算方法类似,可以计算出第三级表项的地址。第三级表项存放的是最终的页面描述符,有页面的物理地址信息,用这个地址再加上虚拟地址的bit[11:0],就是该虚拟地址对应的物理地址。
5、Linux内核中的关键数据结构
mm_struct结构体是内存描述符,内核用它来维护一个进程的地址空间的所有信息。这个结构体中包含了一个重要成员:pgd指针,pgd的名称是页全局目录,指向的是第一级转换表的的起始地址。
每个进程的task_struct结构体中,都包含了内存描述符。
init_mm全局变量,是内核本身的内存描述符。
背景:我们用tcpdump工具循环抓取网卡上的报文,我们会遇到如下情况:
1. 抓取报文后隔指定的时间保存一次;
2. 抓取报文后达到指定的大小保存一次;
本文就这两种情况给出tcpdump的使用方法
tcpdump -x udp port 6789 -i em2 -nn--------------------------------------->可输出从em2 网卡上的详细的数据包
-nn--------------------------------------> 可输出相应源IP地址到目的IP地址详细信息
tcpdump -X udp port 6789 -nn--------------------------------------------->可输出从端口6789的详细数据包,
1. 抓取报文后隔指定的时间保存一次:
tcpdump -i eth3 -s0 -G 60 -Z root -w %Y_%m%d_%H%M_%S.pcap
这里解释下-G选项 后面接时间 单位为秒 本例中的时间为60秒
2. 抓取报文后达到指定的大小保存一次;
tcpdump -i eth3 -s0 -C 1 -Z root -w jiangsuyinhang.pcap
setsid tcpdump udp port 6789 -s0 -C 1 -Z root -w udp_port_listener.pcap &==========>>后台启动监听端口6789-->udp数据包
-i 指定网卡名称
## 标题队列:先进先出
对数据进行分类(存储的时候分类) 操作:
1. 创建或者获取消息队列 1. 写入或者读取数据 2. 删除消息队列
## 标题创建或者获取消息队列:#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>int msgget(key_t key, int msgflg); 命令方式查看消息队列: ipcs -q 功能: 创建或者获取消息队列 参数: key : 参考共享内存 msgflg: IPC_CREAT|0666 返回值: 成功返回消息队列id号 失败返回-1 并设置error *标题写入或者读取数据:
## *写入:#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); 功能: 往消息队列中写入数据
- 参数:
msqid : msgp : //结构体自已定义 struct msgbuf { long mtype; /* message type, must be > 0 */ char mtext[1]; /* message data */ 可以 为所欲为 };
01. DDL
> 查询所有数据库: show databases;
> 查询当前数据库: select database(); //括号是必须要加的
> 创建数据库: create database [if not exists] 数据库名 [default charset 字符集] [collate 排序规则]
-> 关于字符串: utf8 一个汉字存3字节,但有些特殊符号会存4字节,所以会使用 utf8md4 做为字符集
> 删除: drop database [if exists] 数据库名
> 使用: use 数据库名;
> 查看当前数据库所有的表: show tables;
> 查询表结构: desc 表名;
> 查询指定表的建表语句: show create table 表名;
> 创建数据表
** mysql中的数据类型 (id tinyint unsigned -- 表示:新建表时,创建的是一个无符号珠 tinyint 字段 id )
环境为虚拟机centos7 mysql - u root -p进入mysql时报了这个错误 ,看了网上的帖子说密码输错三次被锁或者不改密码超过期限自动锁定 ,我的应该是因为我把mysql中的user表里一个account_locked字段由‘N’改成了‘Y’ 然后重启了服务,结果进不去了,我还只有这一个账号,具体解决办法如下:1.进入my.cnf修改文件:
vim /etc/my.cnf 或者 vi /etc/my.cnf 增加一句代码,让mysql跳过密码验证直接登陆:
skip-grant-tables 保存后直接输mysql可以登录进去
将表中的account_locked字段值改为N: mysql> update mysql.user set account_locked='N'; 刷新
mysql> flush privileges; 进入etc/my.cnf 注释: #skip-grant-tables
重启mysql服务:
systemctl restart mysqld 重新登陆连接,成功!!!!
版权声明:本文为CSDN博主「和路飞开派对.」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_45256737/article/details/121377308
从3.2开始,monogdb的默认存储引擎就是WiredTiger。mongodb会同时使用wt的内部缓存和文件系统缓存。从3.4开始,mongodb的wt引擎内存缓存的设置规则为:(RAM-1GB)*50% 或者256MB
你需要分析是否对默认的内存做调优。一条比较好的原则就是wt的缓存足够大,能够缓存整个应用的工作集。
查看wt的缓存统计信息:
db.serverStatus().wiredTiger.cache{application threads page read from disk to cache count : 9,application threads page read from disk to cache time (usecs) : 17555,application threads page write from cache to disk count : 1820,application threads page write from cache to disk time (usecs) : 1052322,bytes allocated for updates : 20043,bytes belonging to page images in the cache : 46742,bytes belonging to the history store table in the cache : 173,bytes currently in the cache : 73044,bytes dirty in the cache cumulative : 38638327,bytes not belonging to page images in the cache : 26302,bytes read into cache : 43280,bytes written from cache : 20517382,cache overflow score : 0,checkpoint blocked page eviction : 0,eviction calls to get a page : 5973,eviction calls to get a page found queue empty : 4973,eviction calls to get a page found queue empty after locking : 20,eviction currently operating in aggressive mode : 0,eviction empty score : 0,eviction passes of a file : 0,eviction server candidate queue empty when topping up : 0,eviction server candidate queue not empty when topping up : 0,eviction server evicting pages : 0,eviction server slept, because we did not make progress with eviction : 735,eviction server unable to reach eviction goal : 0,eviction server waiting for a leaf page : 2,eviction state : 64,eviction walk target pages histogram - 0-9 : 0,eviction walk target pages histogram - 10-31 : 0,eviction walk target pages histogram - 128 and higher : 0,eviction walk target pages histogram - 32-63 : 0,eviction walk target pages histogram - 64-128 : 0,eviction walk target strategy both clean and dirty pages : 0,eviction walk target strategy only clean pages : 0,eviction walk target strategy only dirty pages : 0,eviction walks abandoned : 0,eviction walks gave up because they restarted their walk twice : 0,eviction walks gave up because they saw too many pages and found no candidates : 0,eviction walks gave up because they saw too many pages and found too few candidates : 0,eviction walks reached end of tree : 0,eviction walks started from root of tree : 0,eviction walks started from saved location in tree : 0,eviction worker thread active : 4,eviction worker thread created : 0,eviction worker thread evicting pages : 902,eviction worker thread removed : 0,eviction worker thread stable number : 0,files with active eviction walks : 0,files with new eviction walks started : 0,force re-tuning of eviction workers once in a while : 0,forced eviction - history store pages failed to evict while session has history store cursor open : 0,forced eviction - history store pages selected while session has history store cursor open : 0,forced eviction - history store pages successfully evicted while session has history store cursor open : 0,forced eviction - pages evicted that were clean count : 0,forced eviction - pages evicted that were clean time (usecs) : 0,forced eviction - pages evicted that were dirty count : 0,forced eviction - pages evicted that were dirty time (usecs) : 0,forced eviction - pages selected because of too many deleted items count : 0,forced eviction - pages selected count : 0,forced eviction - pages selected unable to be evicted count : 0,forced eviction - pages selected unable to be evicted time : 0,forced eviction - session returned rollback error while force evicting due to being oldest : 0,hazard pointer blocked page eviction : 0,hazard pointer check calls : 902,hazard pointer check entries walked : 25,hazard pointer maximum array length : 1,history store key truncation calls that returned restart : 0,history store key truncation due to mixed timestamps : 0,history store key truncation due to the key being removed from the data page : 0,history store score : 0,history store table insert calls : 0,history store table insert calls that returned restart : 0,history store table max on-disk size : 0,history store table on-disk size : 0,history store table out-of-order resolved updates that lose their durable timestamp : 0,history store table out-of-order updates that were fixed up by moving existing records : 0,history store table out-of-order updates that were fixed up during insertion : 0,history store table reads : 0,history store table reads missed : 0,history store table reads requiring squashed modifies : 0,history store table remove calls due to key truncation : 0,history store table writes requiring squashed modifies : 0,in-memory page passed criteria to be split : 0,in-memory page splits : 0,internal pages evicted : 0,internal pages queued for eviction : 0,internal pages seen by eviction walk : 0,internal pages seen by eviction walk that are already queued : 0,internal pages split during eviction : 0,leaf pages split during eviction : 0,maximum bytes configured : 8053063680,maximum page size at eviction : 376,modified pages evicted : 902,modified pages evicted by application threads : 0,operations timed out waiting for space in cache : 0,overflow pages read into cache : 0,page split during eviction deepened the tree : 0,page written requiring history store records : 0,pages currently held in the cache : 24,pages evicted by application threads : 0,pages queued for eviction : 0,pages queued for eviction post lru sorting : 0,pages queued for urgent eviction : 902,pages queued for urgent eviction during walk : 0,pages read into cache : 20,pages read into cache after truncate : 902,pages read into cache after truncate in prepare state : 0,pages requested from the cache : 33134,pages seen by eviction walk : 0,pages seen by eviction walk that are already queued : 0,pages selected for eviction unable to be evicted : 0,pages selected for eviction unable to be evicted as the parent page has overflow items : 0,pages selected for eviction unable to be evicted because of active children on an internal page : 0,pages selected for eviction unable to be evicted because of failure in reconciliation : 0,pages walked for eviction : 0,pages written from cache : 1822,pages written requiring in-memory restoration : 0,percentage overhead : 8,tracked bytes belonging to internal pages in the cache : 5136,tracked bytes belonging to leaf pages in the cache : 67908,tracked dirty bytes in the cache : 493,tracked dirty pages in the cache : 1,unmodified pages evicted : 0} 这里关于WiredTiger缓存的统计有很多,但是我们应该重点关注以下内容:
按照mysql8.0以前的方法修改报错 mysql> grant all privileges on *.* to 'root'@'%' identified by 'PASSWD'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right mysql8.0以后采用新的语法 create user 'root'@'%' identified by 'PASSWD'; grant all privileges on *.* to 'root'@'%'; mysql> create user 'root'@'%' identified by 'a123456'; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.