mmap

Linux内存简单汇总

我的未来我决定 提交于 2019-11-27 18:48:21
Linux内存主要用来存储系统和应用程序的指令,数据,缓存等 一,内存映射 1,内核给每个进程提供一个独立的虚拟机地址空间,并且这个地址空间是连续的 2,虚拟地址空间内部又被分为内核空间和用户空间 3,32位和64位系统的虚拟地址空间 32 位系统的内核空间占用 1G,位于最高处,剩下的 3G 是用户空间。而 64 位系统的内核空间和用户空间都是 128T,分别占据整个内存空间的最高和最低处,剩下的中间部分是未定义的 4,进程在用户态时,只能访问用户空间内存;只有进入内核态后,才可以访问内核空间内存 5,只有实际使用的虚拟内存才会被分配物理内存,通过内存映射来管理 6, 内存映射 ,就是将虚拟内存地址映射到物理内存地址。为了完成内存映射,内核为每个进程都维护了一张 表,记录虚拟地址与物理地址的映射关系 7, 页表 存储在内存管理单元 [MMU]( https://blog.csdn.net/u010442934/article/details/79900449 ) 中 8,进程访问虚拟地址在页表中查不到时,系统会产生一个 缺页异常 9,TLB(Translation Lookaside Buffer,转译后备缓冲器)会影响 CPU 的内存访问性能 ,TLB是MMU中页表的高速缓存,。于进程的虚拟地址空间是独立的,而 TLB 的访问速度又比 MMU 快得多,所以

Android NDK mmap call broken on 32-bit devices after upgrading to Lollipop

人盡茶涼 提交于 2019-11-27 17:59:09
问题 I'm trying to grab 784 MiB of memory. Yes, I know that is a lot for a 32-bit phone, but the following call worked before Android 5.0: mmap(0, 0x31000000, PROT_NONE, MAP_ANON | MAP_SHARED, -1, 0); However, on three different devices from different manufacturers, upgrading to Android 5.0 has broken this. I assume this is some change in memory allocation functionality in 5.0; maybe different flags need to be passed in? Here's the error message returned in logcat: E/libc﹕ mmap fail (pid 9994, tid

how can I detect whether a specific page is mapped in memory?

萝らか妹 提交于 2019-11-27 17:51:23
问题 I would like to detect whether or not a specific page has already been mapped in memory. The goal here is to be able to perform this check before calling mmap with a fixed memory address. The following code illustrates what happens in this case by default: mmap silently remaps the original memory pages. #include <sys/mman.h> #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { int page_size; void *ptr; page_size = getpagesize(); ptr = mmap(0, 10 * page_size, PROT_READ |

Driving Beaglebone GPIO through /dev/mem

坚强是说给别人听的谎言 提交于 2019-11-27 17:10:47
I'm trying to write a C program for blinking a LED on the Beaglebone. I know I can use the sysfs way...but I'd like to see if it is possible to get the same result mapping the physical address space with /dev/mem. I have a header file, beaglebone_gpio.h wit the following contents: #ifndef _BEAGLEBONE_GPIO_H_ #define _BEAGLEBONE_GPIO_H_ #define GPIO1_START_ADDR 0x4804C000 #define GPIO1_END_ADDR 0x4804DFFF #define GPIO1_SIZE (GPIO1_END_ADDR - GPIO1_START_ADDR) #define GPIO_OE 0x134 #define GPIO_SETDATAOUT 0x194 #define GPIO_CLEARDATAOUT 0x190 #define USR0_LED (1<<21) #define USR1_LED (1<<22)

android mmap fails with out of memory

房东的猫 提交于 2019-11-27 16:51:18
问题 I've searched everywhere for an answer but I think I'm hitting the limits of what I can find. My question seems somewhat related to this one : Android NDK mmap call broken on 32-bit devices after upgrading to Lollipop but no answer has been provided. My problem is that I try to memory map 457232384 bytes from a file through a mmap call. On two different devices (Samsung Galaxy Note 3 & OnePlus One, 3GB RAM each) with Android 5.1.1, that call fails with errno 12 "Out of memory". Actually, the

2015 Syrian Private Universities Collegiate Programming Contest

五迷三道 提交于 2019-11-27 16:43:53
题目 A题(好吧他加载不出来) B题 把给的一个n*m的矩形切成一个个小方格,需要切n*m-1次,切奇数次是先手赢,偶数次先手输。 #include <stdio.h> #define ll long long int main() { int T,a,b; ll z; scanf("%d",&T); while(T--) { scanf("%d%d",&a,&b); z=a*b; if((z-1)%2==0) printf("Hussain\n"); else printf("Hasan\n"); } return 0; } C题 给出n个矩形的坐标,(i,0)左下,(j,k)右上,求矩形面积。 数据量小,暴力搜索给出坐标内的矩形有没有遍历过。 #include<bits/stdc++.h> #include <iostream> using namespace std; int main() { int i,j,n,sum,t; int x,y,z; int vis[105][105]; ios::sync_with_stdio(false); cin>>t; while(t--) { cin>>n; memset(vis,0,sizeof(vis)); sum=0; while(n--) { cin>>x>>y>>z; for(i=0;i<z;i++) { for(j=x;j

How does mmap improve file reading speed?

白昼怎懂夜的黑 提交于 2019-11-27 14:52:58
Assuming the address space can cover the file, it appears to me that mmap simply allocates a chunk of memory as large as the file about to be read, and creates a 1-to-1 relation between their corresponding blocks. However, why doing so speeds up file reading? It seems that in order to actually get the contents of the file, you still have to go to the disk, and read all the bytes on it. What difference does it make, compared to malloc'ing the same size of memory and manually read the entire file into the malloc'ed area? Craig Estey mmap works differently. It is anticipatory and adapts to the

Can the dirtiness of pages of a mmap be found from userspace?

我的未来我决定 提交于 2019-11-27 14:44:52
问题 Can dirtiness of pages of a (non-shared) mmap be accessed from userspace under linux 2.6.30+? Platform-specific hacks and kludges welcome. Ideally, I'm looking for an array of bits, one per page (4kB?) of the mmap'ed region, which are set if that page has been written to since the region was mmap'ed. (I am aware, that the process doing the writing could keep track of this information - but it seems silly to do so if the kernel is doing it anyway.) Thanks, Chris. 回答1: See /proc/*/pagemap and

Python - Download File Using Requests, Directly to Memory

爱⌒轻易说出口 提交于 2019-11-27 13:55:28
问题 The goal is to download a file from the internet, and create from it a file object, or a file like object without ever having it touch the hard drive. This is just for my knowledge, wanting to know if its possible or practical, particularly because I would like to see if I can circumvent having to code a file deletion line. This is how I would normally download something from the web, and map it to memory: import requests import mmap u = requests.get("http://www.pythonchallenge.com/pc/def

项目一. 移动物体监控系统

馋奶兔 提交于 2019-11-27 13:36:31
项目一. 移动物体监控系统 Sprint0-产品设计与规划 第1课-产品功能展示 我们在学校的时候,做项目开发,可能就是想到了哪里就做哪里。但是在实际公司的开发过程中,我们是要严格的按照公司的流程来进行的。 项目开发分成了准备阶段和开发阶段: 我们的最后效果就是,利用摄像头和音响完成连接,如图: 当有移动物体在摄像头面前移动时,摄像头能采集图像和视频,并且发出报警的声音。通过访问对应的局域网,我们可以通过网页访问,如下: 第2课-产品功能模型设计 第3课-Product Backlog规划 我们登录网址https://www.leangoo.com/kanban/board_list,进行相应的注册。 创建新的product-backlog,添加我们需要的功能,完成后如下: Sprint1-声音报警子系统开发 第1节- Sprint Backlog规划 product-backlog是关于我们产品的一个功能的需求列表,这是一个大的需求,并不够细化,于是我们还要进行sprint-backlog的规划。 我们在网站https://www.leangoo.com/中,创建新的sprint-backlog。接下来我们分析我们应该做的事情,首先我们需要声卡的使能,接下来是播放器的移植。 我们创建如下所示的sprint-backlog,对项目进行相应的时间规划,工作量规划。随着我们工作量的完成