08 分配内存

NOTICE


struct kmem_cache_t *
kmem_cache_create (const char *name, size_t size, size_t align,unsigned long flags,
void (*ctor)(void*, kmem_cache_t *, unsigned long),
void (*dtor)(void*, kmem_cache_t *, unsigned long))
//变为
struct kmem_cache *
kmem_cache_create(const char *name, size_t size,size_t align, unsigned long flags,

void (*ctor)(void *))





QA:


Q1:

要调优特定的 slab 缓存,可以简单地向 /proc/slabinfo 文件中以字符串的形式回转 slab 缓存名称和 3 个可调整的参数。

下面的例子展示了如何增加 limit 和 batchcount 的值,而保留 shared factor 不变(格式为 “cache name limit batchcount shared factor”):

# echo "my_cache 128 64 8" > /proc/slabinfo	

limit 字段表示每个 CPU 可以缓存的对象的最大数量。 batchcount 字段是当缓存为空时转换到每个 CPU 缓存中全局缓存对象的最大数量。 shared 参数说明了对称多处理器(Symmetric MultiProcessing,SMP)系统的共享行为。

空闲slab对象的本地高速缓存 (8.2.11. Local Caches of Free Slab Objects)翻译成 slab中的空闲obj比较不容易误会..


/*
 * struct array_cache
 *
 * Purpose:
 * - LIFO ordering, to hand out cache-warm objects from _alloc
 * - reduce the number of linked list operations
 * - reduce spinlock operations
 *
 * The limit is stored in the per-cpu structure to reduce the data cache
 * footprint.
 *
 */
struct array_cache {
	unsigned int avail;
	unsigned int limit;
	unsigned int batchcount;
	unsigned int touched;
	spinlock_t lock;
	void *entry[];	/*
			 * Must have this definition in here for the proper
			 * alignment of array_cache. Also simplifies accessing
			 * the entries.
			 */
};

The fields of the array_cache structure
TypeNameDescription
unsigned intavailNumber of pointers to available objects in the local cache. The field also acts as the index of the first free slot in the cache.
unsigned intlimitSize of the local cachethat is, the maximum number of pointers in the local cache.
unsigned intbatchcountChunk size for local cache refill or emptying.
unsigned inttouchedFlag set to 1 if the local cache has been recently used.


A1:




Q: location of pages for slab?

A:

RESOURCE


Linux slab 分配器剖析

多核cache的一致性




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值