anonymous memory

 As part of some work I've been doing I've had to talk a lot about anonymous memory. So I thought I'd write it down while I remember what its all about. anonymous memory is memory that is managed by segvn but is not really directly associated with a file. It's used for things like process stacks, heap, or COW (copy on write) pages. A good example of this is if you fork a process. All the addresses in the second process actually map back to the same bits of physical memory (the same pages). However if youre child process was then to do something different with the memory (eg. the child went off and manipulated an array in memory) the VM subsytem would copy those pages and change the mappings in the child process to point to the new pages. This new memory would be anonymous memory, and the child process would merrily make the changes to the array, unaware it now had new "physical" memory it was talking to. In a bit more detail, you've probably heard people talking about " anon_maps" and " vnode, offsets". Or at least if you're interested in VM and have been trawling the code you probably have. So I'll try and put a simplistic view of what they mean. Typically when you mmap a file, you are give it a vnode, offset and length. Segvn manages mmaped files and stores this in its private data structure. So when you walk through the address space of the process looking for a virtual address, you'll see that the segment contains that address and be able to map it to the vnode and where in that file using the offset. As mentioned above anonymous memory is not associated with files, but with perhaps swap (you'd get to uses anon memory if you mmaped /dev/zero BTW). So the purpose of anonymous memory or the anon layer is to fake up a vnode and offset for segvn to find the data on a swap device (actually by going through swapfs which I haven't yet looked at). The core of the anon layer is the anon_map structure. This is stored in the segvn_data structure and points you to the anon_hdr for this segment. Each anon_hdr is linked to an array on anon structures which are the swapfs implementation of how to find a vnode and offset on a swap file system (or it might be on a real swap device if you bypass swapfs, I think I'll need another blog entry for swapfs after this). So after some swapfs magic we can find the backing store for this anonmap. You might have noticed a bit if handwaiving in the middle there. What was that about an array of anon structures? Why do we need one of them? Well each anon strucure represents a page of memory. Our segment may be more than one page in size (try pmap $$ and you may well see some anon segments of more than 8K on sparc) so would need more than one of these anon structure to describe it. So we have this array.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值