From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail144.messagelabs.com (mail144.messagelabs.com [216.82.254.51]) by kanga.kvack.org (Postfix) with ESMTP id AD2056B008A for ; Thu, 24 Nov 2011 20:21:38 -0500 (EST) Received: by wwg38 with SMTP id 38so4342503wwg.26 for ; Thu, 24 Nov 2011 17:21:35 -0800 (PST) MIME-Version: 1.0 Date: Fri, 25 Nov 2011 09:21:35 +0800 Message-ID: Subject: Question about __zone_watermark_ok: why there is a "+ 1" in computing free_pages? From: Wang Sheng-Hui Content-Type: multipart/alternative; boundary=e89a8f3b9da554164404b284f9c2 Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org --e89a8f3b9da554164404b284f9c2 Content-Type: text/plain; charset=ISO-8859-1 In line 1459, we have "free_pages -= (1 << order) + 1;". Suppose allocating one 0-order page, here we'll get free_pages -= 1 + 1 I wonder why there is a "+ 1"? 1448/* 1449 * Return true if free pages are above 'mark'. This takes into account the order 1450 * of the allocation. 1451 */ 1452static bool __zone_watermark_ok(struct zone *z, int order, unsigned long mark, 1453 int classzone_idx, int alloc_flags, long free_pages) 1454{ 1455 /* free_pages my go negative - that's OK */ 1456 long min = mark; 1457 int o; 1458 1459 free_pages -= (1 << order) + 1; 1460 if (alloc_flags & ALLOC_HIGH) 1461 min -= min / 2; 1462 if (alloc_flags & ALLOC_HARDER) 1463 min -= min / 4; 1464 1465 if (free_pages <= min + z->lowmem_reserve[classzone_idx]) 1466 return false; 1467 for (o = 0; o < order; o++) { 1468 /* At the next order, this order's pages become unavailable */ 1469 free_pages -= z->free_area[o].nr_free << o; 1470 1471 /* Require fewer higher order pages to be free */ 1472 min >>= 1; 1473 1474 if (free_pages <= min) 1475 return false; 1476 } 1477 return true; 1478} --e89a8f3b9da554164404b284f9c2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable In line 1459, we have "free_pages -=3D (1 << order) + 1;".<= br>Suppose allocating one 0-order page, here we'll get
=A0=A0=A0 fr= ee_pages -=3D 1 + 1
I wonder why there is a "+ 1"?

1448= /*
1449 * Return true if free pages are above 'mark'. This takes= into account the order
1450 * of the allocation.
1451 */
1452static bool __zone_watermark_ok= (struct zone *z, int order, unsigned long mark,
1453=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 int classzone_idx, int alloc_= flags, long free_pages)
1454{
1455=A0=A0=A0=A0=A0=A0=A0 /* free_pages= my go negative - that's OK */
1456=A0=A0=A0=A0=A0=A0=A0 long min =3D mark;
1457=A0=A0=A0=A0=A0=A0=A0 i= nt o;
1458
1459=A0=A0=A0=A0=A0=A0=A0 free_pages -=3D (1 << orde= r) + 1;
1460=A0=A0=A0=A0=A0=A0=A0 if (alloc_flags & ALLOC_HIGH)
1= 461=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 min -=3D min / 2;
1462= =A0=A0=A0=A0=A0=A0=A0 if (alloc_flags & ALLOC_HARDER)
1463=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 min -=3D min / 4;
1464=
1465=A0=A0=A0=A0=A0=A0=A0 if (free_pages <=3D min + z->lowmem_res= erve[classzone_idx])
1466=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 r= eturn false;
1467=A0=A0=A0=A0=A0=A0=A0 for (o =3D 0; o < order; o++) = {
1468=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 /* At the next order= , this order's pages become unavailable */
1469=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 free_pages -=3D z->fre= e_area[o].nr_free << o;
1470
1471=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 /* Require fewer higher order pages to be free */
1472= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 min >>=3D 1;
14731474=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (free_pages <=3D m= in)
1475=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 r= eturn false;
1476=A0=A0=A0=A0=A0=A0=A0 }
1477=A0=A0=A0=A0=A0=A0=A0 re= turn true;
1478}


--e89a8f3b9da554164404b284f9c2-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org