91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

仿照linux的buddy+slub內存管理算法,可以在裸機中應用標準內存管理庫函數,如malloc free等

資源截圖

代碼片段和文件信息

/*
?*?slab?allocator?implementation
?*
?*?A?slab?allocator?reserves?a?ZONE?for?each?chunk?size?then?lays?the
?*?chunks?out?in?an?array?within?the?zone.??Allocation?and?deallocation
?*?is?nearly?instantanious?and?fragmentation/overhead?losses?are?limited
?*?to?a?fixed?worst-case?amount.
?*
?*?The?downside?of?this?slab?implementation?is?in?the?chunk?size
?*?multiplied?by?the?number?of?zones.??~80?zones?*?128K?=?10MB?of?VM?per?cpu.
?*?In?a?kernel?implementation?all?this?memory?will?be?physical?so
?*?the?zone?size?is?adjusted?downward?on?machines?with?less?physical
?*?memory.??The?upside?is?that?overhead?is?bounded...?this?is?the?*worst*
?*?case?overhead.
?*
?*?Slab?management?is?done?on?a?per-cpu?basis?and?no?locking?or?mutexes
?*?are?required?only?a?critical?section.??When?one?cpu?frees?memory
?*?belonging?to?another?cpu‘s?slab?manager?an?asynchronous?IPI?message
?*?will?be?queued?to?execute?the?operation.???In?addition?both?the
?*?high?level?slab?allocator?and?the?low?level?zone?allocator?optimize
?*?M_ZERO?requests?and?the?slab?allocator?does?not?have?to?pre?initialize
?*?the?linked?list?of?chunks.
?*
?*?XXX?Balancing?is?needed?between?cpus.??Balance?will?be?handled?through
?*?asynchronous?IPIs?primarily?by?reassigning?the?z_Cpu?ownership?of?chunks.
?*
?*?XXX?If?we?have?to?allocate?a?new?zone?and?M_USE_RESERVE?is?set?use?of
?*?the?new?zone?should?be?restricted?to?M_USE_RESERVE?requests?only.
?*
?* Alloc?Size Chunking????????Number?of?zones
?* 0-127 8 16
?* 128-255 16 8
?* 256-511 32 8
?* 512-1023 64 8
?* 1024-2047 128 8
?* 2048-4095 256 8
?* 4096-8191 512 8
?* 8192-16383 1024 8
?* 16384-32767 2048 8
?* (if?PAGE_SIZE?is?4K?the?maximum?zone?allocation?is?16383)
?*
?* Allocations?>=?zone_limit?go?directly?to?kmem.
?*
?* API?REQUIREMENTS?AND?SIDE?EFFECTS
?*
?*????To?operate?as?a?drop-in?replacement?to?the?FreeBSD-4.x?malloc()?we
?*????have?remained?compatible?with?the?following?API?requirements:
?*
?*????+?small?power-of-2?sized?allocations?are?power-of-2?aligned?(kern_tty)
?*????+?all?power-of-2?sized?allocations?are?power-of-2?aligned?(twe)
?*????+?malloc(0)?is?allowed?and?returns?non-0?(ahc?driver)
?*????+?ability?to?allocate?arbitrarily?large?chunks?of?memory
?*/

/*
?*?Chunk?structure?for?free?elements
?*/


#define?ASSERT(a)
#define?ALIGN(size?align) (((size)?+?(align)?-?1)?&?~((align)-1))
/**
?*?@ingroup?BasicDef
?*
?*?@def?ALIGN_DOWN(size?align)
?*?Return?the?down?number?of?aligned?at?specified?width.?ALIGN_DOWN(13?4)
?*?would?return?12.?
?*/
#define?ALIGN_DOWN(size?align) ((size)?&?~((align)?-1))?

#define?PAGE_SIZE 4096
#define?PAGE_MASK? (PAGE_SIZE?-?1)
#define?PAGE_BITS 12
#define?SLAB_DEBUG
#define?MEM_STATS

/*?some?statistical?variable?*/
#ifdef?MEM_STATS
static?unsigned?int?used_mem?max_mem;
#endif
static?void?(*malloc_hook)(void?*ptr?unsigned?int?size)=NULL;
static?void?(*free_hook)(void?*ptr)=NULL;

void?malloc_sethook(void?(*hook)(void?*ptr?unsigned?int?size))
{
malloc_hook?

評論

共有 條評論