Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSN 源码解析:内存复用机制 #27

Closed
rootsongjc opened this issue Feb 12, 2020 · 8 comments
Closed

MOSN 源码解析:内存复用机制 #27

rootsongjc opened this issue Feb 12, 2020 · 8 comments
Assignees
Labels

Comments

@rootsongjc
Copy link
Member

Reviewer: @taoyuanyuan

@trainyao
Copy link
Contributor

/assign

@trainyao
Copy link
Contributor

@taoyuanyuan
请教一下..buffer 分bufferPoolArraybufferValue两个地方管理, bufferValue似乎有些重复的感觉..是有什么优化考虑么?
看上去是为了管理多种已注册的 buffer 类型 所以定的 bufferValue 这个结构?

@taoyuanyuan
Copy link
Contributor

@trainyao bufferPoolArray里面存的是bufferPool,表示注册的每种内存的分配和释放方法。
bufferValue可以认为是真实分配的内存,每个请求会有一个这个结构体,在请求初始化分配,结束时释放。
可以认为bufferPoolArray是方法,bufferValue是结果,真实的内存实体。

@trainyao
Copy link
Contributor

@taoyuanyuan 了解,还想问一下,vendor 里面的 bytebufferpool byte 块都对齐到了64个字节是避免伪共享么?

有一个想法,和源码解析无关,需不需要考虑在堆里面的分布情况? byte是make出来的,会不会本身堆里面就没有对齐64字节, 那上面的算法算出来的byte块对齐可能会失效

@taoyuanyuan
Copy link
Contributor

taoyuanyuan commented Feb 16, 2020

@trainyao 你的想法挺有意思的,我看伪共享主要作用于struct上。对于make runtime底层也有一层cache,对于是否有fasle sharing需要看看源码,你可以调研下。
这儿的作用其实主要是为了设置一个最小值,表示小于64字节的数据都分配一样的slab,提高小内存的复用度。

// CacheLinePad is used to pad structs to avoid false sharing.
type CacheLinePad struct{ _ [CacheLinePadSize]byte }

// CacheLineSize is the CPU's assumed cache line size.
// There is currently no runtime detection of the real cache line size
// so we use the constant per GOARCH CacheLinePadSize as an approximation.
var CacheLineSize uintptr = CacheLinePadSize

@trainyao
Copy link
Contributor

@taoyuanyuan 了解,谢谢指点~

@trainyao
Copy link
Contributor

@taoyuanyuan 有劳大神 review~

@rootsongjc
Copy link
Member Author

This blog has been published at https://mosn.io/zh/blog/code/mosn-buffer/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants