Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E53BC636CC for ; Thu, 9 Feb 2023 02:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232342AbjBICzj (ORCPT ); Wed, 8 Feb 2023 21:55:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232259AbjBICyg (ORCPT ); Wed, 8 Feb 2023 21:54:36 -0500 X-Greylist: delayed 416 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 08 Feb 2023 18:51:52 PST Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [IPv6:2001:41d0:1004:224b::b8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D27286BF for ; Wed, 8 Feb 2023 18:51:51 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1675910693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6j791U1wIUFSOI7G5OFn8eDWYHiEod5wKDWuChvQKYw=; b=YxT2MBU6ERJfONrIkOap8zG+cxkJFGKQtMQMMqerZX2JyQAMZFxUDz8IrRZnONqOUFWPrS MGCYEkvg0+xid3z3ybjMcByY3Z4pmwpk5E3q5l0ZGTMS5VdXUPrZvwGrBSiF6r7xtE0D0B WGMhQb3Qe+2Aus6swE/JXS+/qAghOns= From: Yajun Deng To: akpm@linux-foundation.org Cc: ziy@nvidia.com, mgorman@techsingularity.net, david@redhat.com, vbabka@suse.cz, rppt@linux.ibm.com, osalvador@suse.de, rppt@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH] mm/page_alloc: optimize the loop in find_suitable_fallback() Date: Thu, 9 Feb 2023 10:44:35 +0800 Message-Id: <20230209024435.3392916-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no need to execute the next loop if it not return in the first loop. So add a break at the end of the loop. There are only three rows in fallbacks, so reduce the first index size from MIGRATE_TYPES to MIGRATE_PCPTYPES. Signed-off-by: Yajun Deng --- mm/page_alloc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1113483fa6c5..536e8d838fb5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2603,7 +2603,7 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, * * The other migratetypes do not have fallbacks. */ -static int fallbacks[MIGRATE_TYPES][MIGRATE_PCPTYPES - 1] = { +static int fallbacks[MIGRATE_PCPTYPES][MIGRATE_PCPTYPES - 1] = { [MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE }, [MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE }, [MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE }, @@ -2861,7 +2861,7 @@ int find_suitable_fallback(struct free_area *area, unsigned int order, int i; int fallback_mt; - if (area->nr_free == 0) + if (area->nr_free == 0 || !migratetype_is_mergeable(migratetype)) return -1; *can_steal = false; @@ -2873,11 +2873,10 @@ int find_suitable_fallback(struct free_area *area, unsigned int order, if (can_steal_fallback(order, migratetype)) *can_steal = true; - if (!only_stealable) - return fallback_mt; - - if (*can_steal) + if (!only_stealable || *can_steal) return fallback_mt; + else + break; } return -1; -- 2.25.1