A memory allocation program, it is used for doing an experiment to find out the detail of Microsoft Windows taskmgr performance information

Overview

memory-allocation-test

A memory allocation program, it is used for doing an experiment to find out the detail of Microsoft Windows taskmgr performance information

Microsoft Windows 任务管理器 【内存】选项卡中各项指标的含义

Microsoft_Windows_taskmgr_screenshot 如图所示,Microsoft Windows 任务管理器 【内存】选项卡中包含如下指标

  • 使用中(已压缩)
  • 可用
  • 已提交
  • 已缓存
  • 分页缓冲池
  • 非分页缓冲池

接下来以上图为例,对这些指标做解释

已提交

对应图上的 40.9/72.8 GB

该参数有两个部分,从左至右分别对应:已申请/总虚拟内存

已申请

对应上图的40.9部分

其指示当前操作系统上所有进程使用 malloc() 等内存分配函数已经申请的内存总容量

例如当你启动一个新的进程,并且执行了 malloc(1024 * 1024) ,那么此时【已申请】部分则会增加 1 MB

总虚拟内存

对应上图的 72.8 GB 操作系统的【总虚拟内存】包括【物理内存】和【交换区】

物理内存

【物理内存】为实际安装在电脑主板上的内存条所包含的总容量

如上图所示,我在电脑上安装了两条 32 GB 的内存条,则我的总【物理内存】为 2 * 32 = 64 GB

交换区

当【物理内存】不够用时,操作系统会向硬盘申请一块存储空间,临时将部分不被经常使用的内存数据存储在硬盘上。 等该部分不被经常使用的内存数据被需要读写时,再重新将其从硬盘拷贝至物理内存中交换区

由于位于交换区的数据需要在【物理内存】和【硬盘】上交换数据,因此称为【交换区】

但是实际上在 Windows Microsoft 操作系统的 UI 文案中通常将其写为【虚拟内存】, 其概念并非通常在 Computer Science 学科中所指的【虚拟内存空间】 ,因此请注意不要混淆

使用中

对应上图的30.6 GB部分

其指示当前操作系统上所有进程使用 malloc() 等内存分配函数已经申请, 并且使用任何能够写入该内存区域的手段对该内存区域进行写入之后的内存总容量

例如当你启动一个新的进程,并且执行了 void *point = malloc(1024 * 1024) ,那么此时【已申请】部分则会增加 1 MB, 在这之后执行了 memset(point, 0, 1024 * 1024) ,则【使用中】部分将会增加 1 MB

实验

在本 GitHub repo 的 Release 页面中下载对应的测试程序 https://github.com/cw1997/memory-allocation-test/releases

初始内存占用情况如图所示

  • 使用中:27.7 GB
  • 已提交:63.4 GB

Microsoft_Windows_taskmgr_screenshot_initial_status

打开后输入需要申请的内存空间 第一次输入 20 后按回车键,测试程序将会调用 malloc() 函数向操作系统申请 20 GB 的内存空间

此时观察 taskmgr 将会发现 【已提交】的左半部分(即【已申请】部分)从 43.4 增长至 63.4 ,增长了 20 GB , 【使用中】几乎无变化, 说明 【已提交】的左半部分(即【已申请】部分)对应已经向操作系统申请内存的空间大小

Microsoft_Windows_taskmgr_screenshot_allocated_status

再次按下回车键,测试程序将会调用 memset() 函数向刚刚申请的 20 GB 的内存空间中写入 20 GB 的数据 (数据值为 memset()第二个参数,在本程序中为全 0)

此时观察 taskmgr 将会发现 【使用中】从 27.7 增长至 47.5 ,增长了 20 GB , 【可用】从 36.1 增长至 16.3 ,大约降低了 20 GB , 说明 【使用中】对应已经向操作系统申请并且使用的内存的空间大小, 【可用】对应内存中实际可以继续被其他进程所使用的空间

Microsoft_Windows_taskmgr_screenshot_memsted_status

再次按下回车键,程序退出,操作系统回收该程序进程所占用的所有内存空间,该内存空间可被其它进程所使用

此时观察 taskmgr 将会发现 【使用中】从 47.5 增长至 27.5 ,降低了 20 GB , 【已提交】的左半部分(即【已申请】部分)从 63.4 增长至 463.4 ,降低了 20 GB , 【可用】从 16.3 增长至 36.2 ,大约增长了 20 GB

Microsoft_Windows_taskmgr_screenshot_exited_status

已压缩

现代 CPU 性能已经足够高,因此可以充分利用空闲的 CPU 时间对内存中较为不常用的数据进行压缩后存储在内存中, 当这部分数据重新被读写时再将其解压缩

操作系统根据一定策略自动进行该内存压缩操作

已缓存

Microsoft Windows 会在读取硬盘数据的同时将该数据存入内存中的可用区域,以便加速下一次访问, 这些被磁盘数据所占用的区域称为【已缓存】

当某个进程需要对【已缓存】区域中的数据对应在硬盘上的文件进行读写时, Microsoft Windows 会自动同时修改内存缓存区和硬盘上的文件数据, 内存缓存区域内已修改的数据同步在硬盘上修改的过程称为“刷盘”或者“同步”, 这些过程都会被操作系统自动执行以保证数据安全落盘,因此大部分情况下无需担心突然掉电或者宕机等意外事故导致数据丢失的问题

非分页缓冲池

操作系统中有一部分对实时性要求极高的关键性数据,例如 CPU 中断处理函数,驱动程序代码等, 这些数据不允许被交换到硬盘(否则会极大影响系统运行速度), 或者当被用作【交换区】的硬盘出现故障时,关键性代码将无法从硬盘交换到物理内存被执行,导致系统宕机 (考虑一种情况:作为【交换区】的磁盘分区并非安装有操作系统的磁盘分区, 因此当未把关键性数据交换到硬盘的时候,当作为【交换区】的磁盘分区发生故障并不会导致整个操作系统宕机)

分页缓冲池

还记得前面提到的【交换区】吗?这里便是已经被交换到硬盘上的数据

因为物理内存数据交换到交换区的过程中,数据是以“页面”的方式交换出来,页面是操作系统将一块内存数据按照“页尺寸”划分为多个“页面”, 然后将这些“页面”数据交换至硬盘中,这是“分页”一词的含义

Releases(latest-release)
Owner
Chang Wei
Focus on Computer Science(CS) and Electronic Engineering(EE). As a full stack engineer, I research everything from the Digital Circuits to the User Interface
Chang Wei
PoC for CVE-2021-32537: an out-of-bounds memory access that leads to pool corruption in the Windows kernel.

CVE-2021-32537: Out-of-bounds access in RTKVHD64 leading to pool corruption. This is a bug that I reported to Realtek beginning of April 2021. The aff

Axel Souchet 55 Feb 14, 2022
A tool for tracking memory allocation based ld-preload

libmallocTrace A tool for tracking memory allocation based ld-preload how to build make cd example && make how to use a simple way is to execute some

赵政 1 Mar 12, 2022
The Hoard Memory Allocator: A Fast, Scalable, and Memory-efficient Malloc for Linux, Windows, and Mac.

The Hoard Memory Allocator Copyright (C) 1998-2020 by Emery Berger The Hoard memory allocator is a fast, scalable, and memory-efficient memory allocat

Emery Berger 882 May 13, 2022
MMCTX (Memory Management ConTeXualizer), is a tiny (< 300 lines), single header C99 library that allows for easier memory management by implementing contexts that remember allocations for you and provide freeall()-like functionality.

MMCTX (Memory Management ConTeXualizer), is a tiny (< 300 lines), single header C99 library that allows for easier memory management by implementing contexts that remember allocations for you and provide freeall()-like functionality.

A.P. Jo. 4 Oct 2, 2021
Memory-dumper - A tool for dumping files from processes memory

What is memory-dumper memory-dumper is a tool for dumping files from process's memory. The main purpose is to find patterns inside the process's memor

Alexander Nestorov 29 Feb 5, 2022
Mesh - A memory allocator that automatically reduces the memory footprint of C/C++ applications.

Mesh: Compacting Memory Management for C/C++ Mesh is a drop in replacement for malloc(3) that can transparently recover from memory fragmentation with

PLASMA @ UMass 1.4k May 7, 2022
Initialize the 8-bit computer memory with a program to be executed automatically on powering.

Initialize the 8-bit computer memory with a program to be executed automatically on powering. This project is small extension of Ben Eater's computer

Dmytro Striletskyi 62 Dec 13, 2021
A single file drop-in memory leak tracking solution for C++ on Windows

MemLeakTracker A single file drop-in memory leak tracking solution for C++ on Windows This small piece of code allows for global memory leak tracking

null 22 Apr 23, 2022
A simple windows driver that can read and write to process memory from kernel mode

ReadWriteProcessMemoryDriver A simple windows driver that can read and write to process memory from kernel mode This was just a small project for me t

Hypervisor 6 Mar 30, 2022
Modern C++ 32bit Windows Process Memory Library.

basil Simple 32-bit Windows Process Memory Library. Written in Modern C++. JavaScript bindings basil (wilL) be available as bindings for JavaScript. C

cristei 3 Sep 23, 2021
Using shared memory to communicate between two executables or processes, for Windows, Linux and MacOS (posix). Can also be useful for remote visualization/debugging.

shared-memory-example Using shared memory to communicate between two executables or processes, for Windows, Linux and MacOS (posix). Can also be usefu

null 8 Mar 18, 2022
STL compatible C++ memory allocator library using a new RawAllocator concept that is similar to an Allocator but easier to use and write.

memory The C++ STL allocator model has various flaws. For example, they are fixed to a certain type, because they are almost necessarily required to b

Jonathan Müller 1.1k May 9, 2022
mimalloc is a compact general purpose allocator with excellent performance.

mimalloc mimalloc (pronounced "me-malloc") is a general purpose allocator with excellent performance characteristics. Initially developed by Daan Leij

Microsoft 6.7k May 13, 2022
Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

rpmalloc - General Purpose Memory Allocator This library provides a public domain cross platform lock free thread caching 16-byte aligned memory alloc

Mattias Jansson 1.5k May 10, 2022
OpenXenium JTAG and Flash Memory programmer

OpenXenium JTAG and Flash Memory programmer * Read: "Home Brew" on ORIGINAL XBOX - a detailed article on why and how * The tools in this repo will all

Koos du Preez 25 Feb 14, 2022
manually map driver for a signed driver memory space

smap manually map driver for a signed driver memory space credits https://github.com/btbd/umap tested system Windows 10 Education 20H2 UEFI installati

ekknod 71 Apr 9, 2022
Memory instrumentation tool for android app&game developers.

Overview LoliProfiler is a C/C++ memory profiling tool for Android games and applications. LoliProfiler supports profiling debuggable applications out

Tencent 416 May 13, 2022
Dump the memory of a PPL with a userland exploit

PPLdump This tool implements a userland exploit that was initially discussed by James Forshaw (a.k.a. @tiraniddo) - in this blog post - for dumping th

Clément Labro 546 May 14, 2022
Implementation of System V shared memory (a type of inter process communication) in xv6 operating system.

NOTE: we have stopped maintaining the x86 version of xv6, and switched our efforts to the RISC-V version (https://github.com/mit-pdos/xv6-riscv.git)

Viraj Jadhav 5 Feb 21, 2022