文章目录

  • 一、获取首选内存区域
  • 二、异步回收内存页
  • 三、最低水线也分配
  • 四、直接分配内存

在 【Linux 内核 内存管理】物理分配页 ② ( __alloc_pages_nodemask 函数参数分析 | __alloc_pages_nodemask 函数分配物理页流程 ) 博客中 , 分析了 __alloc_pages_nodemask 函数分配物理页流程如下 :

首先 , 根据 gfp_t gfp_mask 分配标志位 参数 , 得到 " 内存节点 “ 的 首选 ” 区域类型 " 和 " 迁移类型 " ;

然后 , 执行 " 快速路径 " , 第一次分配 尝试使用 低水线分配 ;

如果上述 " 快速路径 " 分配失败 , 则执行 " 慢速路径 " 分配 ;

上述涉及到了 " 快速路径 " 和 " 慢速路径 " 222 种物理页分配方式 ;

继续接着上一篇博客 【Linux 内核 内存管理】物理分配页 ⑦ ( __alloc_pages_slowpath 慢速路径调用函数源码分析 | 判断页阶数 | 读取 mems_allowed | 分配标志位转换 ) 分析 __alloc_pages_slowpath 慢速路径 内存分配 调用函数 的后续部分源码 ;

一、获取首选内存区域


获取 " 首选内存区域 " , 如果获取失败 , 则 goto 跳转到 nopage 标号位置运行后续代码 ;

 /** We need to recalculate the starting point for the zonelist iterator* because we might have used different nodemask in the fast path, or* there was a cpuset modification and we are retrying - otherwise we* could end up iterating over non-eligible zones endlessly.*/ac->preferred_zoneref = first_zones_zonelist(ac->zonelist,ac->high_zoneidx, ac->nodemask);if (!ac->preferred_zoneref->zone)goto nopage;

源码路径 : linux-4.12\mm\page_alloc.c#3731

二、异步回收内存页


调用 wake_all_kswapds 函数 , 异步 回收 物理内存页 ,

这里的异步 是通过 唤醒 " 回收线程 " 进行回收内存页的 ;

 if (gfp_mask & __GFP_KSWAPD_RECLAIM)wake_all_kswapds(order, ac);

源码路径 : linux-4.12\mm\page_alloc.c#3736

三、最低水线也分配


调用 get_page_from_freelist 函数 , 使用 " 最低水线 " 进行物理页分配 ,

如果处理成功 , 则跳转到 got_pg 标号处执行 ;

 /** The adjusted alloc_flags might result in immediate success, so try* that first*/page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);if (page)goto got_pg;

源码路径 : linux-4.12\mm\page_alloc.c#3743

四、直接分配内存


申请 物理页 内存 的阶数 , 满足以下 333 个条件 :

can_direct_reclaim

(costly_order || (order > 0 && ac->migratetype != MIGRATE_MOVABLE))

!gfp_pfmemalloc_allowed(gfp_mask)

执行该分支 " 直接分配内存 " 操作 ;

 /** For costly allocations, try direct compaction first, as it's likely* that we have enough base pages and don't need to reclaim. For non-* movable high-order allocations, do that as well, as compaction will* try prevent permanent fragmentation by migrating from blocks of the* same migratetype.* Don't try this for allocations that are allowed to ignore* watermarks, as the ALLOC_NO_WATERMARKS attempt didn't yet happen.*/if (can_direct_reclaim &&(costly_order ||(order > 0 && ac->migratetype != MIGRATE_MOVABLE))&& !gfp_pfmemalloc_allowed(gfp_mask)) {page = __alloc_pages_direct_compact(gfp_mask, order,alloc_flags, ac,INIT_COMPACT_PRIORITY,&compact_result);if (page)goto got_pg;/** Checks for costly allocations with __GFP_NORETRY, which* includes THP page fault allocations*/if (costly_order && (gfp_mask & __GFP_NORETRY)) {/** If compaction is deferred for high-order allocations,* it is because sync compaction recently failed. If* this is the case and the caller requested a THP* allocation, we do not want to heavily disrupt the* system, so we fail the allocation instead of entering* direct reclaim.*/if (compact_result == COMPACT_DEFERRED)goto nopage;/** Looks like reclaim/compaction is worth trying, but* sync compaction could be very expensive, so keep* using async compaction.*/compact_priority = INIT_COMPACT_PRIORITY;}}

源码路径 : linux-4.12\mm\page_alloc.c#3756

【Linux 内核 内存管理】物理分配页 ⑧ ( __alloc_pages_slowpath 慢速路径调用函数源码分析 | 获取首选内存区域 | 异步回收内存页 | 最低水线也分配 | 直接分配 )相关推荐

  1. 【Linux 内核 内存管理】物理分配页 ⑨ ( __alloc_pages_slowpath 慢速路径调用函数源码分析 | retry 标号代码分析 )

    文章目录 一.retry 标号代码分析 二.retry 标号完整代码 在 [Linux 内核 内存管理]物理分配页 ② ( __alloc_pages_nodemask 函数参数分析 | __allo ...

  2. 【Linux 内核 内存管理】物理分配页 ⑦ ( __alloc_pages_slowpath 慢速路径调用函数源码分析 | 判断页阶数 | 读取 mems_allowed | 分配标志位转换 )

    文章目录 一.__alloc_pages_slowpath 慢速路径调用函数 二.判断页阶数 三.读取进程 mems_allowed 成员 四.分配标志位转换 五.__alloc_pages_slow ...

  3. 【Linux 内核】实时调度类 ⑦ ( 实时调度类核心函数源码分析 | dequeue_task_rt 函数 | 从执行队列中移除进程 )

    文章目录 一.dequeue_task_rt 函数 ( 从执行队列中移除进程 ) 二.update_curr_rt 函数 ( 更新调度信息 ) 本篇博客中 , 开始分析 struct sched_cl ...

  4. 【Linux 内核】实时调度类 ⑥ ( 实时调度类核心函数源码分析 | 插入进程到执行队列 | 从执行队列中选择优先级最高的进程 )

    文章目录 一.enqueue_task_rt 函数 ( 插入进程到执行队列 ) 二.pick_next_task_rt 函数 ( 从执行队列中选择优先级最高的进程 ) 本篇博客中 , 开始分析 str ...

  5. 【Linux 内核 内存管理】mmap 系统调用源码分析 ④ ( do_mmap 函数执行流程 | do_mmap 函数源码 )

    文章目录 一.do_mmap 函数执行流程 二.do_mmap 函数源码 调用 mmap 系统调用 , 先检查 " 偏移 " 是否是 " 内存页大小 " 的 & ...

  6. Linux内核页表管理-那些鲜为人知的秘密

    1.开场白 环境: 处理器架构:arm64 内核源码:linux-5.11 ubuntu版本:20.04.1 代码阅读工具:vim+ctags+cscope 通用操作系统,通常都会开启mmu来支持虚拟 ...

  7. Linux内核-进程管理

    Linux内核-进程管理 引言 本文主要介绍Linux内核进程管理相关知识,包括进程描述符.进程创建.销毁.状态.线程的实现以及Linux进程相关命令等. 进程描述符 内核把进程的列表存放在叫做任务队 ...

  8. Linux 驱动开发 三十五:Linux 内核时钟管理

    参考: linux时间管理,时钟中断,系统节拍_u010936265的博客-CSDN博客_系统节拍时钟中断 Linux内核时钟系统和定时器实现_anonymalias的专栏-CSDN博客_linux内 ...

  9. 挑战360无死角讲解Linux内核 进程管理,调度器的5种实现丨C++后端开发丨C/C++Linux服务器开发丨内核开发丨网络编程

    挑战360无死角讲解 进程管理,调度器的5种实现 1. 8500行 CFS是什么 2. RT调度器使用场景 3. IDLE/Dealine调度器 视频讲解如下,点击观看: 挑战360无死角讲解Linu ...

最新文章

  1. Kdtree(K-dimension tree)学习
  2. 超实用资源,SCI写作到投稿全阶段模板
  3. Matlab与C++混合编程
  4. Cocos2d-x VS. OGEngine,联盟与部落的战争
  5. selenium ruby和java_Selenium 2之Ruby版——安装篇
  6. C语言变量未赋初值时,输出为乱七八糟解释
  7. 爬取猫眼电影相关信息
  8. 嵌入式数据库与数据库服务器
  9. 数据结构与算法--线性表
  10. httpwatch初级使用
  11. aps生产计划排产的计划类型
  12. 期待已久的Apple Tablet PC - iPad 发布了
  13. Android Killer中apktool插件更新
  14. FPGA试题练习--------CMOS门电路分析
  15. Excel如何为介于区间的数值设置背景颜色?
  16. Java实战项目之 [含文档+PPT+源码等]精品基于ssm的足球联赛管理系统的设计与实现
  17. ECC校验有什么作用
  18. 一键实现前程无忧(51job)简历不停刷新(selenium)
  19. Redis数据类型——set
  20. JAVA面试问答 NOTE2

热门文章

  1. Latex入门_第2章:用latex排版文字
  2. red had第二次学习整理
  3. SEO知识(总结土著游民)(1)
  4. mmdetection踩坑记录
  5. 7-139 手机话费 (10分)
  6. JavaSE 接口与内部类
  7. 51nod 1326 遥远的旅途 最短路建模
  8. 华为笔记本没有网线口_matebook 14有网线接口吗
  9. 免费开题报告|基于SpringBoot+Vue的校内跑腿平台
  10. 2020年中国核电阀门行业市场现状分析,新增装机+维修备件持续创造需求「图」