2470 /*2471 * This is the 'heart' of the zoned buddy allocator.2472 */ /* 参数理解: */ /* GFP = Get Free Pages ? */ /* 098 typedef struct { (, ); } ; */ /* #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] */ /* typedef struct { unsigned long bits[ BITS_TO_LONGS( ) ]; } nodemask_t */ /* #define () (, * sizeof(long)) */ /* #define 8 */ /* #define (,) ((() + () - 1) / ()) */ /* d表示一个数据类型有多少bit, n表示要存储多少位, 现在计算要多少个这样的数据类型 */ /* order 表示 2^order 个页 */ / zonelist 表示zone的链表 */2473 struct *2474 ( , unsigned int ,2475 struct *, *)2476 {2477 enum = (); /*
0247 static inline enum ( )0248 {0249 enum ;0250 int = ( int) ( & ); /* 过滤这些标志位吗 ? */0251 0252 = ( >> ( * )) &0253 ((1 << ) - 1);0254 (( >> ) & 1);0255 return ;0256 } */
/* 0219 #define ( \0220 ( << 0 * ) \0221 | ( << * ) \0222 | ( << * ) \0223 | ( << * ) \0224 | ( << * ) \0225 | ( << ( | ) * ) \0226 | ( << ( | ) * ) \0227 | ( << ( | ) * ) \0228 ) */ /* #define (|||) */ /*
0319 #if < 20320 #define 00321 #elif <= 20322 #define 10323 #elif <= 40324 #define 2 */ /* 这么多就是要获取zone的下标 */ 2478 struct *;2479 struct * = ; /* Convert GFP flags to their corresponding migrate type */2480 int = ();2481 unsigned int ;2482
0373 /*0374 * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what0375 * GFP flags are used before interrupts are enabled. Once interrupts are0376 * enabled, it is set to __GFP_BITS_MASK while the system is running. During0377 * hibernation, it is used by PM to avoid I/O during memory allocation while0378 * devices are suspended.0379 */
2483 &= ;2484 2485 ();2486 /* 0169 #define () do { if () (); } while (0) */2487 ( & );2488 2489 if ((, ))2490 return ;2491 2492 /*2493 * Check the zones suitable for the gfp_mask contain at least one2494 * valid zone. It's possible to have an empty zonelist as a result2495 * of GFP_THISNODE and a memoryless node2496 */2497 if ((!->->))2498 return ;2499 2500 retry_cpuset:2501 = ();2502 2503 /* The preferred zone is used for statistics later */2504 (, ,2505 ? : &,2506 &);2507 if (!)2508 goto ;2509 /* 1779 * get_page_from_freelist goes through the zonelist trying to allocate1780 * a page.1781 */ 1782 static struct *1783 ( , *, unsigned int ,1784 struct *, int , int ,1785 struct *, int ){ ... } */ 2510 /* First allocation attempt */2511 = (|, , ,2512 , , |,2513 , );2514 if ((!)) /* 很少失败 */2515 = (, ,2516 , , ,2517 , );2518 2519 trace_mm_page_alloc(, , , );2520 2521 :2522 /*2523 * When updating a task's mems_allowed, it is possible to race with2524 * parallel threads in such a way that an allocation can fail while2525 * the mask is being updated. If a page allocation is about to fail,2526 * check if the cpuset changed during allocation and if so, retry.2527 */2528 if ((!() && !))2529 goto retry_cpuset;2530 2531 return ;2532 }