《Linux性能优化实战》学习笔记 Day02

一个导致JVM物理内存消耗大的Bug 本文来自: PerfMa技术社区 PerfMa(笨马网络)官网 概述 最近我们公司在帮一个客户查一个JVM的问题(JDK1.8.0_191-b12),发现一个系统老是被OS Kill掉,是内存泄露导致的。在查的过程中,阴差阳错地发现了JVM另外的一个Bug。这个Bug可能会导致大量物理内存被使用,我们已经反馈给了社区,并得到快速反馈,预计在OpenJDK8最新版中发布(JDK11中也存在这个问题)。 PS:用户的那个问题最终也解决了,定位下来算是C2的一个设计缺陷导致大量内存被使用,安全性上没有得到保. 阅读详情

02 | 内存池:如何提升内存分配的效率?

原文摘抄

在 Linux 系统中,用 Xmx 设置 JVM 的最大堆内存为 8GB,但在近百个并发线程下,观察到 Java 进程占用了 14GB 的内存。为什么会这样呢?

绝大部分高级语言都是用 C 语言编写的,包括 Java,申请内存必须经过 C 库,而 C 库通过预分配更大的空间作为内存池,来加快后续申请内存的速度。这样,预分配的 6GB 的 C 库内存池就与 JVM 中预分配的 8G 内存池叠加在一起(只有程序申请堆外内存时,才会分配C库内存池;否则不会申请),造成了 Java 进程的内存占用超出了预期。

应用层-C库内存池-操作系统内核
在这里插入图片描述

每个子线程预分配的内存是 64MB(Ptmalloc2 中被称为 Thread Arena,32 位系统下为 1MB,64 位系统下为 64MB)。如果有 100 个线程,就将有 6GB 的内存都会被内存池占用。这也就是为什么平凡的创建销毁线程浪费资源的原因。

通过设置 MALLOC_ARENA_MAX 环境变量,可以限制线程内存池的最大数量。可以更换掉 Ptmalloc2 内存池,选择一个预分配内存更少的内存池,比如 Google 的 TCMalloc。

TCMalloc 适用的场景,它对多线程下小内存的分配特别友好。

Ptmalloc2 假定,如果线程 A 申请并释放了的内存,线程 B 可能也会申请类似的内存,所以它允许内存池在线程间复用以提升性能。

因此,每次分配内存,Ptmalloc2 一定要加锁,才能解决共享资源的互斥问题。然而,加锁的消耗并不小。TCMalloc 针对小内存做了很多优化,每个线程独立分配内存

程序莫名内存”泄露“,可能是glibc malloc Arena引发的 glibc malloc大量内存碎片导致程序莫名的内存”泄露“。 阅读详情

相关推荐

glibc malloc内存不释放?3种方法彻底解决Arena内存‘泄露‘问题

本文深入剖析了glibc malloc内存分配器中的Arena机制导致进程RSS内存居高不下的‘伪内存泄露’问题。通过分析其根源,提供了三种实战解决方案:调整MALLOC_ARENA_MAX环境变量、主动调用malloc_trim函数进行内存回收,以及彻底替换为jemalloc或tcmalloc等优化分配器,帮助开发者从根本上优化长期运行服务的内存占用。

neovim7hacker的博客 512

Linux Ansible项目实战 79-63

DAY-63j笔记 1、Ansible Playbook剧本概念&实战演练 1)Ansible可以使用单个模块,通过AD-HOC点对点模式去远程机器配置和管理,也可以将多个模块进行组合,形成剧本(playbook)任务; 2)通过Playbook任务,能够集中管理多个任务,将多个任务关联起来,从而实现更加复杂工作,满足生产环境的各个需求,提高运维人员管理服务器效率; 3)Playbook剧本的产物YAML文件,类似XML接口(Tomcat)文件,内部有固定语法、参数等,要掌握常用的YAML语法编写,

weixin_43522034的博客 250

华为昇腾CANN PyPTO框架解析:Python算子开发与蚂蚁百灵大模型0 Day支持实战

在AI硬件加速领域,高性能算子开发是释放芯片算力的关键。传统上,为特定AI加速卡(如NPU、GPU)编写算子需要深厚的C++和硬件架构知识,门槛极高。其原理是通过编译器将计算逻辑映射为底层硬件指令,实现计算加速。这项技术的核心价值在于打通算法创新与硬件性能之间的鸿沟,直接影响模型推理效率与部署成本。随着大语言模型等复杂AI应用兴起,对灵活、高效的自定义算子需求日益迫切。华为昇腾最新推出的CANN PyPTO框架,正是针对这一痛点,允许开发者使用熟悉的Python语法开发昇腾NPU高性能算子,大幅降低开发门槛

weixin_34411563的博客 429

手把手教你配置Obsidian Day Planner:从基础时间线到高级甘特图(避坑提醒通知不生效)

本文详细介绍了如何配置Obsidian Day Planner插件,从基础时间线到高级甘特图功能,特别针对常见的提醒通知失效问题提供了深度排查方法。通过系统级权限检查、插件内部定时器校准和时区设置等技巧,帮助用户高效管理时间规划,提升工作效率。

weixin_33691700的博客 331

Linux 之 性能优化

Linux 性能

zhixingheyi_tian的博客 1433

【清风数学建模笔记】第十一讲:时间序列分析

【清风数学建模笔记】第十一讲:时间序列分析

manerzi的博客 825

【rk3566/3568】Android 11移植gms

【rk3566/3568】Android 11移植gms 1、前言 测试功能时,想去Google play store去下个应用测试,发现通过网页搜索总是下载不到正确的谷歌服务框架;于是就不得不去搞一个内置的gms。 2、移植 1、需要下载Android 11对应的gms的包 opengapps 2、看下文件目录 直接移植core里面的文件,GAPPs Optional按需添加 3、在vendor下创建google目录 ...

lin_ff的博客 7631

奔图M6700-M6800-M7100-M7200 系列打印机拆解教程?

奔图M6700-M6800-M7100-M7200 系列打印机拆解教程?

m0_58098052的博客 1560

数字电子时钟——数字电路课设

本文设计了一种基于中小规模集成电路的数字电子时钟系统,采用模块化设计方法,包含晶振电路(CD4060+D触发器)、计时电路(74HC161计数器)、数码管驱动(CD4511)和整点报时功能。系统实现了60进制秒/分、24进制小时、7进制星期的计时显示,支持手动校时功能,并具备整点报时特性(59分54-58秒5次500Hz低音,59秒1次1000Hz高音)。通过分模块调试与整合,最终实物电路满足设计要求,获得优秀评价。

来自FZU——电子科学与技术专业 1482

RockChip Android14 修改LCD背光最大值

在调试LCD屏时时长会出现硬件不匹配,导致电流过大,屏幕发热严重。在不调整硬件的情况下,我们可以通过修改软件,降低LCD背光最大值来实现适配。我们都知道LCD屏背光是靠pwm来控制,一般来说最大值可以设置为255,针对上述问题,我们可以通过软件来降低该值,比如200,100等等。

qq_34968572的博客 627

在MATLAB中将C语言代码转化为可执行的mexw64文件

这样,您可以将高效的C语言算法集成到MATLAB环境中,以便更好地利用MATLAB的功能和特性。请记住,在使用mex转换C语言代码之前,您需要正确编写和测试C语言代码,并确保它与MATLAB的mex接口兼容。MATLAB是一种功能强大的数值计算软件,它提供了一个机制,可以将C语言代码转化为MATLAB可执行的mexw64文件。在上述命令中,"-output"选项指定生成的mex文件的名称,"myfunction"是您选择的名称,"myfunction.c"是要编译的C语言源文件。步骤1:编写C语言代码。

CodeRoarX的博客 1423

【WRF数据准备】海温(SST)数据替换

【WRF数据准备】海温(SST)数据替换

WW、forever的博客 1115

仿真学习系列(二):ADS仿真直观理解方波与频谱分量的关系

在高速电路设计中,我们常常听到一句话:“信号其实不是电压在传输,而是频率在传播。” 这句话看似抽象,却揭示了信号世界的核心本质——任何时域波形,都可以被拆解为一系列不同频率的正弦波。 那么,一个看似简单的方波,究竟由哪些频率成分组成?为什么在示波器上,有的方波上升沿又快又“方”,而有的却“圆润”得多?这些差异背后,隐藏的正是高频分量的力量。 本文将通过使用 Keysight ADS,从零搭建仿真电路,直观地观察方波与其谐波成分之间的关系。

案例文章,高速信号 810

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

上一篇: 《Linux性能优化实战》学习笔记 Day01
下一篇: 《后端技术面试 38 讲》学习笔记 Day 14
辉度
博客等级 码龄11年 67粉丝 100原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值