sbrk/brk如何在Linux中实现? [英] How are sbrk/brk implemented in Linux?

查看:116
本文介绍了sbrk/brk如何在Linux中实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在考虑Linux内核如何实现系统调用,我想知道是否有人可以向我全面介绍sbrk/brk的工作原理?

I was thinking about how the Linux kernel implements system calls and I was wondering if someone could give me a high level view of how sbrk/brk work?

我已经审查了内核代码,但是其中有很多,我不理解.我希望有人提供摘要?

I've reviewed the kernel code, but there is just so much of it and I don't understand it. I was hoping for a summary from someone?

推荐答案

在一个非常高级的视图中,Linux内核将进程可见的内存跟踪为几个内存区域"(struct vm_area_struct).还有一个结构(再次以非常高的层次表示)表示进程的整个地址空间(struct mm_struct).每个进程(某些内核线程除外)都只有一个struct mm_struct,它依次指向它可以访问的内存的所有struct vm_area_struct.

In a very high level view, the Linux kernel tracks the memory visible to a process as several "memory areas" (struct vm_area_struct). There is also a structure which represents (again in a very high level view) a process' whole address space (struct mm_struct). Each process (except some kernel threads) has exactly one struct mm_struct, which in turn points to all the struct vm_area_struct for the memory it can accesss.

sys_brk系统调用(在mm/mmap.c中找到)仅调整了其中一些存储区. (sbrkbrk周围的glibc包装器).通过比较brk地址的旧值(位于struct mm_struct内部)和请求的值来实现.

The sys_brk system call (found in mm/mmap.c) simply adjusts some of these memory areas. (sbrk is a glibc wrapper around brk). It does so by comparing the old value of the brk address (found inside struct mm_struct) and the requested value.

首先查看mmap函数系列会更简单,因为brk是它的特例.

It would be simpler to look at the mmap family of functions first, since brk is a special case of it.

这篇关于sbrk/brk如何在Linux中实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆