linux内核那些事之内存规整(memory compact)
內存規整
內存規整是Mel Gormal開發防止內存碎片anti-fragmen pach補丁的第二個部分Avoiding fragmentation with page clustering v27 [LWN.net],主要用于解決當系統長時間運行之后,造成比較碎化內存時,通過內存規整將處于可以移動MOVE的類型內存,重新進行頁遷移 整合出較大連續物理內存:
內存規整機制原因比較簡單:
- 利用類似快慢指針技巧,當需要對一個zone進行內存規整時,使用migrate_pfn和free_pfn兩個遍歷;
- migrate_pfn 為從zone 頭部開始進行掃描,依次掃描出已經被分配出去但是可以進行頁遷移的頁面
- free_pfn:為從zone 尾部開始掃描,依次掃描出空閑page。
- 當每次掃描結束后,將migrate_pfn掃描出的可遷移頁面 依次遷移到free_pfn 空閑page中。
- 當free_pfn和migrate_pfn 兩個遇見相等時說明內存規整完畢。
- 這樣規整之后,zone前半部分可以需要遷移的頁面被遷移到zone后半部分空閑page中, 這樣前半部分會空閑出大塊連續物理內存,供下次申請內存使用。
內存規整技術是頁遷移技術的一個比較重要的使用場景,幫助系統整理出連續物理內存。
觸發時機
內存規整觸發時機主要有以下三種:
- 通過/proc/sys/vm/compact_memory 由用戶根據手動觸發,如果是NUMA系統則還可以通過/sys/devices/system/node/node<id>/compact 觸發
- kcompatd線程類似與kswapd線程,內存水位不夠時,會觸發kcompactd線程進行異步內存規整。
- 慢速申請內存通道,說明內存壓力過大,__alloc_pages_slowpath會通過__alloc_pages_direct_compact 進行同步內存規整。
相關數據結構
由于內存規整是以zone為單位進行掃描,因此不像kswapd由于pgdata中相關數據,內存規整主要涉及到struct? zone中數據用于記錄內存規整的進度:
struct zone {... ...#if defined CONFIG_COMPACTION || defined CONFIG_CMAunsigned long compact_cached_free_pfn; //用于記錄從尾部開始掃描的空閑page的位置unsigned long compact_cached_migrate_pfn[2];//該數組用于控制異步和同步兩種memory compact場景所從頭部開始掃描的頁遷移位置unsigned long compact_init_migrate_pfn; //內存規整頁遷移起始地址unsigned long compact_init_free_pfn; //內存規整的空閑free起始地址 #endif} ____cacheline_internodealigned_in_smp;struct compact_control
struct compact_control結構類似與kswapd中的struct scan_control, 該結構主要用于內存規整時內部使用的數據結構,同時還可以控制內存規整起始位置,以及策略等。
struct compact_control {struct list_head freepages; /* List of free pages to migrate to */struct list_head migratepages; /* List of pages being migrated */unsigned int nr_freepages; /* Number of isolated free pages */unsigned int nr_migratepages; /* Number of pages to migrate */unsigned long free_pfn; /* isolate_freepages search base */unsigned long migrate_pfn; /* isolate_migratepages search base */unsigned long fast_start_pfn; /* a pfn to start linear scan from */struct zone *zone;unsigned long total_migrate_scanned;unsigned long total_free_scanned;unsigned short fast_search_fail;/* failures to use free list searches */short search_order; /* order to start a fast search at */const gfp_t gfp_mask; /* gfp mask of a direct compactor */int order; /* order a direct compactor needs */int migratetype; /* migratetype of direct compactor */const unsigned int alloc_flags; /* alloc flags of a direct compactor */const int highest_zoneidx; /* zone index of a direct compactor */enum migrate_mode mode; /* Async or sync migration mode */bool ignore_skip_hint; /* Scan blocks even if marked skip */bool no_set_skip_hint; /* Don't mark blocks for skipping */bool ignore_block_suitable; /* Scan blocks considered unsuitable */bool direct_compaction; /* False from kcompactd or /proc/... */bool whole_zone; /* Whole zone should/has been scanned */bool contended; /* Signal lock or sched contention */bool rescan; /* Rescanning the same pageblock */bool alloc_contig; /* alloc_contig_range allocation */ };主要成員說明:
- struct list_head freepages: 空閑頁鏈表,表明頁面要遷移到目的頁即空閑頁鏈表,處于該鏈表中的空閑頁,被isolate孤立出來,防止同時被buddy給其他進程使用。
- struct list_head migratepages:所要遷移的頁面鏈表,用于記錄本次所需要遷移的頁面,處于該鏈表中的空閑頁,被isolate孤立出來,防止頁面被swap out到磁盤或者page cache被釋放等場景。
- unsigned int nr_freepages: 記錄freepages中有多少個空閑頁 被isolate孤立出來。
- unsigned int nr_migratepages: 記錄migratepages中有多少個頁面要進行遷移,并被isolate孤立出來
- unsigned long free_pfn: 從尾部開始掃描的空閑起始頁幀號,即本次掃描zone,從尾部開始掃描尋找空閑頁的起始位置。
- unsigned long migrate_pfn:本次掃描,從頭部往尾部開始掃描的 起始位置,從該位置開始尋找符合要求的頁進行遷移。
- unsigned long fast_start_pfn:用于快速線性掃描的起始位置
- struct zone *zone:所要掃描的zone
- unsigned long total_migrate_scanned:已經掃描并做頁遷移的頁數目
- unsigned long total_free_scanned:已經掃描用用作空閑頁 作為頁前面目的的數目
- const gfp_t gfp_mask: gfp mask
- short search_order: 掃描是開始的order 即一次性做頁遷移的數目
- int order: 掃描時所需要的至少order 頁數目。
- int migratetype:頁遷移類型
- const int highest_zoneidx: 最高zone,掃描的zone范圍‘
- enum migrate_mode mode: 是同步還是異步模式,即是通過kcompact線程進行內存規整,還是通過直接方式進行內存規整
- bool direct_compaction: 如果為false,則是通過kscompact線程 或者??/proc手動觸發觸發
- bool whole_zone:是否一次性掃描整個zone.
compact_zone()
compact_zone()函數是實施內存規整的核心函數,不管是哪種觸發方式最終都會通過compact_zone 規整指定的zone進行內存規整,
調用關系
按照compact_zone觸發關系調用關系圖如下:
上述四種觸發方式,最終都是靠compact_zone實現頁遷移功能
compact_zone源碼
static enum compact_result compact_zone(struct compact_control *cc, struct capture_control *capc) {enum compact_result ret;unsigned long start_pfn = cc->zone->zone_start_pfn;unsigned long end_pfn = zone_end_pfn(cc->zone);unsigned long last_migrated_pfn;const bool sync = cc->mode != MIGRATE_ASYNC;bool update_cached;/** These counters track activities during zone compaction. Initialize* them before compacting a new zone.*/cc->total_migrate_scanned = 0;cc->total_free_scanned = 0;cc->nr_migratepages = 0;cc->nr_freepages = 0;INIT_LIST_HEAD(&cc->freepages);INIT_LIST_HEAD(&cc->migratepages);cc->migratetype = gfp_migratetype(cc->gfp_mask);ret = compaction_suitable(cc->zone, cc->order, cc->alloc_flags,cc->highest_zoneidx);/* Compaction is likely to fail */if (ret == COMPACT_SUCCESS || ret == COMPACT_SKIPPED)return ret;/* huh, compaction_suitable is returning something unexpected */VM_BUG_ON(ret != COMPACT_CONTINUE);/** Clear pageblock skip if there were failures recently and compaction* is about to be retried after being deferred.*/if (compaction_restarting(cc->zone, cc->order))__reset_isolation_suitable(cc->zone);/** Setup to move all movable pages to the end of the zone. Used cached* information on where the scanners should start (unless we explicitly* want to compact the whole zone), but check that it is initialised* by ensuring the values are within zone boundaries.*/cc->fast_start_pfn = 0;if (cc->whole_zone) {cc->migrate_pfn = start_pfn;cc->free_pfn = pageblock_start_pfn(end_pfn - 1);} else {cc->migrate_pfn = cc->zone->compact_cached_migrate_pfn[sync];cc->free_pfn = cc->zone->compact_cached_free_pfn;if (cc->free_pfn < start_pfn || cc->free_pfn >= end_pfn) {cc->free_pfn = pageblock_start_pfn(end_pfn - 1);cc->zone->compact_cached_free_pfn = cc->free_pfn;}if (cc->migrate_pfn < start_pfn || cc->migrate_pfn >= end_pfn) {cc->migrate_pfn = start_pfn;cc->zone->compact_cached_migrate_pfn[0] = cc->migrate_pfn;cc->zone->compact_cached_migrate_pfn[1] = cc->migrate_pfn;}if (cc->migrate_pfn <= cc->zone->compact_init_migrate_pfn)cc->whole_zone = true;}last_migrated_pfn = 0;/** Migrate has separate cached PFNs for ASYNC and SYNC* migration on* the basis that some migrations will fail in ASYNC mode. However,* if the cached PFNs match and pageblocks are skipped due to having* no isolation candidates, then the sync state does not matter.* Until a pageblock with isolation candidates is found, keep the* cached PFNs in sync to avoid revisiting the same blocks.*/update_cached = !sync &&cc->zone->compact_cached_migrate_pfn[0] == cc->zone->compact_cached_migrate_pfn[1];trace_mm_compaction_begin(start_pfn, cc->migrate_pfn,cc->free_pfn, end_pfn, sync);migrate_prep_local();while ((ret = compact_finished(cc)) == COMPACT_CONTINUE) {int err;unsigned long start_pfn = cc->migrate_pfn;/** Avoid multiple rescans which can happen if a page cannot be* isolated (dirty/writeback in async mode) or if the migrated* pages are being allocated before the pageblock is cleared.* The first rescan will capture the entire pageblock for* migration. If it fails, it'll be marked skip and scanning* will proceed as normal.*/cc->rescan = false;if (pageblock_start_pfn(last_migrated_pfn) ==pageblock_start_pfn(start_pfn)) {cc->rescan = true;}switch (isolate_migratepages(cc)) {case ISOLATE_ABORT:ret = COMPACT_CONTENDED;putback_movable_pages(&cc->migratepages);cc->nr_migratepages = 0;goto out;case ISOLATE_NONE:if (update_cached) {cc->zone->compact_cached_migrate_pfn[1] =cc->zone->compact_cached_migrate_pfn[0];}/** We haven't isolated and migrated anything, but* there might still be unflushed migrations from* previous cc->order aligned block.*/goto check_drain;case ISOLATE_SUCCESS:update_cached = false;last_migrated_pfn = start_pfn;;}err = migrate_pages(&cc->migratepages, compaction_alloc,compaction_free, (unsigned long)cc, cc->mode,MR_COMPACTION);trace_mm_compaction_migratepages(cc->nr_migratepages, err,&cc->migratepages);/* All pages were either migrated or will be released */cc->nr_migratepages = 0;if (err) {putback_movable_pages(&cc->migratepages);/** migrate_pages() may return -ENOMEM when scanners meet* and we want compact_finished() to detect it*/if (err == -ENOMEM && !compact_scanners_met(cc)) {ret = COMPACT_CONTENDED;goto out;}/** We failed to migrate at least one page in the current* order-aligned block, so skip the rest of it.*/if (cc->direct_compaction &&(cc->mode == MIGRATE_ASYNC)) {cc->migrate_pfn = block_end_pfn(cc->migrate_pfn - 1, cc->order);/* Draining pcplists is useless in this case */last_migrated_pfn = 0;}}check_drain:/** Has the migration scanner moved away from the previous* cc->order aligned block where we migrated from? If yes,* flush the pages that were freed, so that they can merge and* compact_finished() can detect immediately if allocation* would succeed.*/if (cc->order > 0 && last_migrated_pfn) {unsigned long current_block_start =block_start_pfn(cc->migrate_pfn, cc->order);if (last_migrated_pfn < current_block_start) {lru_add_drain_cpu_zone(cc->zone);/* No more flushing until we migrate again */last_migrated_pfn = 0;}}/* Stop if a page has been captured */if (capc && capc->page) {ret = COMPACT_SUCCESS;break;}}out:/** Release free pages and update where the free scanner should restart,* so we don't leave any returned pages behind in the next attempt.*/if (cc->nr_freepages > 0) {unsigned long free_pfn = release_freepages(&cc->freepages);cc->nr_freepages = 0;VM_BUG_ON(free_pfn == 0);/* The cached pfn is always the first in a pageblock */free_pfn = pageblock_start_pfn(free_pfn);/** Only go back, not forward. The cached pfn might have been* already reset to zone end in compact_finished()*/if (free_pfn > cc->zone->compact_cached_free_pfn)cc->zone->compact_cached_free_pfn = free_pfn;}count_compact_events(COMPACTMIGRATE_SCANNED, cc->total_migrate_scanned);count_compact_events(COMPACTFREE_SCANNED, cc->total_free_scanned);trace_mm_compaction_end(start_pfn, cc->migrate_pfn,cc->free_pfn, end_pfn, sync, ret);return ret; }compact_zone流程
該函數整理處理思路相對比較清晰:
- ?按照指定的zone進行內存規整
- 對compact_control結構中的一些值進行初始化
- compaction_suitable:根據實際內存水位情況判斷是否有必要做內存規整,因為內存規整操作比較耗時,如果空閑內存處于較高情況,則沒有必要觸發內存規整,最終是通過__compaction_suitable實現對內存水位判斷
- compact_finished: 用于處理當前zone是否掃描完畢,zone掃描時使用了處理上的技巧。內存規整時分別從zone頭部掃描migrate_pfn和從zone尾部掃描free_pfn, 當migrate_pfn與free_pfn相遇時,則認為掃描完畢。最終是調用__compact_finished函數
- isolate_migratepages: 將掃描出的要遷移的頁進行孤立isolate,防止在遷移過程中,該頁面被釋放 或者swap out等,也是做頁遷移之前必須準備工作,可以詳見《linux那些事之頁遷移(page migratiom)》
- migrate_pages:將孤立出來的頁面進行頁遷移。
- 當zone掃描內存規整完畢之后,需要free_pfn 等信息保存到zone中 用于記錄本次掃描位置,空閑頁等信息,以便用于下一次內存規整時使用。
- compact_result 為內存規整結果
??????????????關鍵幾個函數
__compaction_suitable
__compaction_suitable用于判斷當前zone是否可以做內存規整:
/** compaction_suitable: Is this suitable to run compaction on this zone now?* Returns* COMPACT_SKIPPED - If there are too few free pages for compaction* COMPACT_SUCCESS - If the allocation would succeed without compaction* COMPACT_CONTINUE - If compaction should run now*/ static enum compact_result __compaction_suitable(struct zone *zone, int order,unsigned int alloc_flags,int highest_zoneidx,unsigned long wmark_target) {unsigned long watermark;if (is_via_compact_memory(order))return COMPACT_CONTINUE;watermark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK);/** If watermarks for high-order allocation are already met, there* should be no need for compaction at all.*/if (zone_watermark_ok(zone, order, watermark, highest_zoneidx,alloc_flags))return COMPACT_SUCCESS;/** Watermarks for order-0 must be met for compaction to be able to* isolate free pages for migration targets. This means that the* watermark and alloc_flags have to match, or be more pessimistic than* the check in __isolate_free_page(). We don't use the direct* compactor's alloc_flags, as they are not relevant for freepage* isolation. We however do use the direct compactor's highest_zoneidx* to skip over zones where lowmem reserves would prevent allocation* even if compaction succeeds.* For costly orders, we require low watermark instead of min for* compaction to proceed to increase its chances.* ALLOC_CMA is used, as pages in CMA pageblocks are considered* suitable migration targets*/watermark = (order > PAGE_ALLOC_COSTLY_ORDER) ?low_wmark_pages(zone) : min_wmark_pages(zone);watermark += compact_gap(order);if (!__zone_watermark_ok(zone, 0, watermark, highest_zoneidx,ALLOC_CMA, wmark_target))return COMPACT_SKIPPED;return COMPACT_CONTINUE; }主要有以下幾種情況:
- is_via_compact_memory: 是否通過/proc/sys/vm/compact_memory 手動強制進行內存規整,如果強制內存規整,則直接返回COMPACT_CONTINUE,繼續后續步驟進行內存規整
- zone_watermark_ok: 當作內存water mark滿足order,則沒有必要做內存規整,能夠申請oder 內存成功,返回COMPACT_SUCCESS
- 當內存不滿足時,則查看是否可以通過內存壓縮滿足內存申請,如果能夠通過內存規整滿足,則返回COMPACT_SUCCESS進行內存規整,如果判斷出當前內存不能夠通過內存壓縮滿足分配要求,則說明內存碎片化不嚴重,沒有必要進行內存壓縮發跳過此次內存規整操作,返回?COMPACT_SKIPPED。
compact_result
compact_result為此次內存規整之后的結果:
/* Return values for compact_zone() and try_to_compact_pages() */ /* When adding new states, please adjust include/trace/events/compaction.h */ enum compact_result {/* For more detailed tracepoint output - internal to compaction */COMPACT_NOT_SUITABLE_ZONE,/** compaction didn't start as it was not possible or direct reclaim* was more suitable*/COMPACT_SKIPPED,/* compaction didn't start as it was deferred due to past failures */COMPACT_DEFERRED,/* compaction not active last round */COMPACT_INACTIVE = COMPACT_DEFERRED,/* For more detailed tracepoint output - internal to compaction */COMPACT_NO_SUITABLE_PAGE,/* compaction should continue to another pageblock */COMPACT_CONTINUE,/** The full zone was compacted scanned but wasn't successfull to compact* suitable pages.*/COMPACT_COMPLETE,/** direct compaction has scanned part of the zone but wasn't successfull* to compact suitable pages.*/COMPACT_PARTIAL_SKIPPED,/* compaction terminated prematurely due to lock contentions */COMPACT_CONTENDED,/** direct compaction terminated after concluding that the allocation* should now succeed*/COMPACT_SUCCESS, };- ?COMPACT_NOT_SUITABLE_ZONE:該zone不適合做內存規整
- COMPACT_SKIPPED:內存規整要求不滿足,跳過該zone
- COMPACT_DEFERRED:由于之前的一些錯誤導致內存規整退出
- COMPACT_INACTIVE:上次內存規整未激活
- COMPACT_NO_SUITABLE_PAGE:沒有合適的物理頁做內存規整
- COMPACT_CONTINUE:下一個頁面塊pageblock繼續做內存規整
- COMPACT_COMPLETE:zone都以及做內存規整掃描完畢,但是沒有合適頁面做內存規整
- COMPACT_PARTIAL_SKIPPED:直接內存規整已經掃描了部分zone頁面,但是仍然沒有合適頁面做內存規整
- COMPACT_CONTENDED:由于某些鎖競爭導致內存規整退出
- COMPACT_SUCCESS:當前zone內存規整滿足頁面分配要求,可以退出
__compact_finished
__compact_finished用于判斷當前內存壓縮掃描是否完成:
static enum compact_result __compact_finished(struct compact_control *cc) {unsigned int order;const int migratetype = cc->migratetype;int ret;/* Compaction run completes if the migrate and free scanner meet */if (compact_scanners_met(cc)) {/* Let the next compaction start anew. */reset_cached_positions(cc->zone);/** Mark that the PG_migrate_skip information should be cleared* by kswapd when it goes to sleep. kcompactd does not set the* flag itself as the decision to be clear should be directly* based on an allocation request.*/if (cc->direct_compaction)cc->zone->compact_blockskip_flush = true;if (cc->whole_zone)return COMPACT_COMPLETE;elsereturn COMPACT_PARTIAL_SKIPPED;}if (is_via_compact_memory(cc->order))return COMPACT_CONTINUE;/** Always finish scanning a pageblock to reduce the possibility of* fallbacks in the future. This is particularly important when* migration source is unmovable/reclaimable but it's not worth* special casing.*/if (!IS_ALIGNED(cc->migrate_pfn, pageblock_nr_pages))return COMPACT_CONTINUE;/* Direct compactor: Is a suitable page free? */ret = COMPACT_NO_SUITABLE_PAGE;for (order = cc->order; order < MAX_ORDER; order++) {struct free_area *area = &cc->zone->free_area[order];bool can_steal;/* Job done if page is free of the right migratetype */if (!free_area_empty(area, migratetype))return COMPACT_SUCCESS;#ifdef CONFIG_CMA/* MIGRATE_MOVABLE can fallback on MIGRATE_CMA */if (migratetype == MIGRATE_MOVABLE &&!free_area_empty(area, MIGRATE_CMA))return COMPACT_SUCCESS; #endif/** Job done if allocation would steal freepages from* other migratetype buddy lists.*/if (find_suitable_fallback(area, order, migratetype,true, &can_steal) != -1) {/* movable pages are OK in any pageblock */if (migratetype == MIGRATE_MOVABLE)return COMPACT_SUCCESS;/** We are stealing for a non-movable allocation. Make* sure we finish compacting the current pageblock* first so it is as free as possible and we won't* have to steal another one soon. This only applies* to sync compaction, as async compaction operates* on pageblocks of the same migratetype.*/if (cc->mode == MIGRATE_ASYNC ||IS_ALIGNED(cc->migrate_pfn,pageblock_nr_pages)) {return COMPACT_SUCCESS;}ret = COMPACT_CONTINUE;break;}}if (cc->contended || fatal_signal_pending(current))ret = COMPACT_CONTENDED;return ret; }- compact_scanners_met: cc->free_pfn和cc->migrate_pfn是否相遇,如果說明已經掃描完畢,返回true
- compact_scanners_met 返回true,如果cc->whole_zone為true說明需要掃描整個zone,并且已經掃描完畢了,返回COMPACT_COMPLETE。如果ccf->whole_zone為false,說明不需要掃描整個zone,但是此時已經掃描完整個zone,說明掃描完整個zone還沒有滿足后續內存分配要求,返回COMPACT_PARTIAL_SKIPPED。
- compact_scanners_met 返回false, is_via_compact_memory()為ture說明是/proc/sys/vm/compact_memory手動觸發,需要繼續掃描zone下一個pageblock,返回COMPACT_CONTINUE。
- 如果cc->migrate_pfn 不是pageblock對齊,則需要繼續掃描
- 接下來一個比較長的循環出來,主要是需要判斷后續掃描是否還有空閑page 用來做遷移目的頁,如果有則可以繼續做遷移,如果沒有則返回COMPACT_NO_SUITABLE_PAGE
isolate_migratepages
isolate_migratepages函數處理比較長,整體處理思路就是繼續掃描,將掃描出合適的物理頁做遷移,并將需要做遷移的頁孤立出來,加入到cc->migratepages中:
static isolate_migrate_t isolate_migratepages(struct compact_control *cc) {unsigned long block_start_pfn;unsigned long block_end_pfn;unsigned long low_pfn;struct page *page;const isolate_mode_t isolate_mode =(sysctl_compact_unevictable_allowed ? ISOLATE_UNEVICTABLE : 0) |(cc->mode != MIGRATE_SYNC ? ISOLATE_ASYNC_MIGRATE : 0);bool fast_find_block;//通過快速通道找到所要遷移掃描的起始pfnlow_pfn = fast_find_migrateblock(cc);//計算出掃描結束page pfn,要求按照pageblock對齊block_start_pfn = pageblock_start_pfn(low_pfn);if (block_start_pfn < cc->zone->zone_start_pfn)block_start_pfn = cc->zone->zone_start_pfn;//快速找到的pfn是否成功fast_find_block = low_pfn != cc->migrate_pfn && !cc->fast_search_fail;/* Only scan within a pageblock boundary */block_end_pfn = pageblock_end_pfn(low_pfn);//對low_pfn起始的pageblock內物理頁面做掃描,將合適的做遷移的頁面孤立出來for (; block_end_pfn <= cc->free_pfn;fast_find_block = false,low_pfn = block_end_pfn,block_start_pfn = block_end_pfn,block_end_pfn += pageblock_nr_pages) {//如果長時間循環,需要進行放權,給其他進程得到調度機會if (!(low_pfn % (SWAP_CLUSTER_MAX * pageblock_nr_pages)))cond_resched();//檢查是否在同一個pageblock內page = pageblock_pfn_to_page(block_start_pfn,block_end_pfn, cc->zone);if (!page)continue;//如果最近孤立頁面失敗,則不進行再次嘗試,僅僅做檢查if (IS_ALIGNED(low_pfn, pageblock_nr_pages) &&!fast_find_block && !isolation_suitable(cc, page))continue;//如果是異步規整,則僅規整move頁面且非huge pageif (!suitable_migration_source(cc, page)) {update_cached_migrate(cc, block_end_pfn);continue;}/* Perform the isolation *///將[low_pfn,block_end_pfn)中的符合內存規整要求的頁面孤立出來,將孤立出來的頁面加入到cc->migratepages中low_pfn = isolate_migratepages_block(cc, low_pfn,block_end_pfn, isolate_mode);if (!low_pfn)return ISOLATE_ABORT;//孤立頁面成功或者失敗都不在繼續break;}//記錄下次重新掃描的做頁遷移的起始pfncc->migrate_pfn = low_pfn;return cc->nr_migratepages ? ISOLATE_SUCCESS : ISOLATE_NONE; }migrate_pages
將上述合適做頁遷移的頁面,且已經孤立到cc->migratepages中頁面做頁遷移:
err = migrate_pages(&cc->migratepages, compaction_alloc,compaction_free, (unsigned long)cc, cc->mode,MR_COMPACTION)關于頁遷移詳細信息可以參考《linux那些事之頁遷移(page migratiom)》
總結
以上是生活随笔為你收集整理的linux内核那些事之内存规整(memory compact)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 初学3D制作,先学C4D还是Blende
- 下一篇: R语言 读写带分隔符的文件