| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 9448 人关注过本帖
标题:计算机
只看楼主 加入收藏
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
Page cache一小例
when you first open a source file in a text editor,

data from the file is read into memory from disk.

As you edit the file, more and more pages are read in.

When you later compile the file,

the kernel can use the pages directly from the page cache;

it need not reread the file from disk.

Because users tend to read and manipulate the same files repeatedly,

the page cache reduces the need for a large number of disk operations.

The quieter you become, the more you can hear
2012-09-12 23:41
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
The Linux page cache aims to cache any page-based object, which includes many forms of files and memory mappings.

To remain generic, the Linux page cache uses the address_space structure to identify pages in the page cache. This structure is defined in <linux/fs.h>

The quieter you become, the more you can hear
2012-09-13 00:03
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
由于页高速缓存的缓存作用,写操作实际上会被延迟。当页高速缓存中的数据比后台存储的数据更新时,该数据就被称做脏数据。在内存中累积起来的脏页最终必须被写回磁盘。在以下两种情况发生时,脏页被写回磁盘:

·当空闲内存低于一个特定的阈值时,内核必须将脏页写回磁盘,以便释放内存。

·当脏页在内存中驻留时间超过一个特定的阈值时,内核必须将超时的脏页写回磁盘,以确保脏页不会无限期地驻留在内存中。

    上面两种工作的目的完全不同。实际上,在老内核中,这是由两个独立的内核线程分别完成的。但是在2.6内核中,由一群内核线程(pdflush后台回写例程)统一执行两种工作

The quieter you become, the more you can hear
2012-09-13 00:22
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
RCU(Read-Copy Update),顾名思义就是读-拷贝修改,它是基于其原理命名的。
对于被RCU保护的共享数据结构,读者不需要获得任何锁就可以访问它,
但写者在访问它时首先拷贝一个副本,然后对副本进行修改,
最后使用一个回调(callback)机制在适当的时机把指向原来数据的指针重新指向新的被修改的数据。
这个时机就是所有引用该数据的CPU都退出对共享数据的操作。

The quieter you become, the more you can hear
2012-09-20 21:38
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
> In function do_fork (), i see that we allocate some pidmap.
> Could someone please tell me -
> what is pidmap ?
> what is its use?
>

While creating a new process, we need to allocate and initialize a "struct pid" for it. In alloc_pid(),

the kernel tries to allocate & initialize the fields of struct pid.

One of the fields ("nr") is the actual NUMERIC pid (visible to user and for all other purposes) and it is initialized using alloc_pidmap().

The pidmap is just an efficient way to keep track of which all process IDs (numbers) are in use and which ones are not.

Basically we keep a bitmap of all the possible PIDs (1 bit for each PID).

The bit is set/unset depending upon whether the PID is allocated to some process or not.

alloc_pid() determines the number by simply checking the first bit that is set in the map.

The quieter you become, the more you can hear
2012-09-20 21:57
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
虚拟内存
只是作为一个例子,让我们假定您的程序正在访问地址为 629 的内存。
不过,虚拟内存系统不需要将其存储在位置为 629 的 RAM 中。
实际上,它甚至可以不在 RAM 中 —— 如果物理 RAM 已经满了,它甚至 可能已经被转移到硬盘上!
由于这类地址不必反映内存所在的物理位置,所以它们被称为虚拟内存。
操作系统维持着一个虚拟地址到物理地址的转换的表,以便计算机硬件可以正确地响应地址请求。
并且,如果地址在硬盘上而不是在 RAM 中,那么操作系统将暂时停止您的进程,将其他内存转存到硬盘中,从硬盘上加载被请求的内存, 然后再重新启动您的进程。
这样,每个进程都获得了自己可以使用的地址空间,可以访问比您物理上安装的内存更多的内存

The quieter you become, the more you can hear
2012-09-20 22:06
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
PID 的管理围绕两个数据结构展开, struct pid 是内核对PID的内部表示, 而struct upid 则表示特定的命名空间中可见的信息

struct upid {
        int nr;                    /*nr 表示ID的数值*/
        struct pid_namespace *ns;        /*ns是指向该ID所属的命名空间的指针*/
        struct hlist_node pid_chain;    /* pid_chain 用内核的标准方法实现了散列溢出链表*/
}

The quieter you become, the more you can hear
2012-09-21 08:27
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
Linux的fork 只复制页表,这样就建立了虚拟地址空间和物理内存页这间的联系

In linux, a thread is merry a process that shares certain resources with other processes.

Each thread has a unique task_struct and appears to the kernel as a normal process-- threads just happen to share resources, such as an address space,

with other processes.


[ 本帖最后由 madfrogme 于 2012-9-22 09:21 编辑 ]

The quieter you become, the more you can hear
2012-09-21 10:31
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
In the mm_release() function,

which is used when a task exits a memory address space,

vfork_done is checked to see whether it is NULL,

If it is not, the parent is signaled.

/* notify parent sleeping on vfork(), fork.c 的 mm_release()中 */

    if (vfork_done) {

        tsk->vfork_done = NULL;

        complete(vfork_done);
    }

The quieter you become, the more you can hear
2012-09-22 08:14
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
To work with threads you would need the header file linux/kthread.h
A thread is created by the call to the function
struct task_struct *kthread_create(int (*function)(void *data),
                                   void *data,
                                   const char name[],
                                   ...)
The function takes the following arguments 
function: The function that the thread has to execute
data : The "data" to be passed to the function 
name: The name by which the process will be recognised in the kernel. 

A thread created using the above call does not run but only gets created. To run the thread we need to call the function "wake_up_process" passing the thread id that is returned by "kthread_create". 

When the wake_up_process is called the function passed to kthread_create gets executed. 

To stop a thread that is running we need to call the kthread_stop(struct task_struct *threadid) where threadid is the same that is returned by the kthread_create call.

The quieter you become, the more you can hear
2012-09-22 09:11
快速回复:计算机
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028856 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved