From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35CFCC05027 for ; Fri, 10 Feb 2023 01:57:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD7E46B00CF; Thu, 9 Feb 2023 20:57:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A87E56B00D1; Thu, 9 Feb 2023 20:57:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 976DE6B00D2; Thu, 9 Feb 2023 20:57:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 875436B00CF for ; Thu, 9 Feb 2023 20:57:16 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 48727411E1 for ; Fri, 10 Feb 2023 01:57:16 +0000 (UTC) X-FDA: 80449719672.11.9346ADD Received: from out-32.mta1.migadu.com (out-32.mta1.migadu.com [95.215.58.32]) by imf05.hostedemail.com (Postfix) with ESMTP id 621C5100019 for ; Fri, 10 Feb 2023 01:57:13 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bb0svPJr; spf=pass (imf05.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.32 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675994233; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RinPeFsXh+XMzYYEWfsQdeulY7XTEoCzMTiHJ7AIgls=; b=okqgOMADNdZESOy97Umzz31omWD5qDsQflMgYTyGM3avwzaFAhk427qbeScdLJiFa3KhP7 PLdMWvisU6EpZqLjtJ86gQb85GBwMmSHqfNeogmgrJLErh/kDECcz8slyBVOAMWiY6CQQQ hCxZZ5jJbNd3Lw2pYAZH7pUDNSHLTuA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bb0svPJr; spf=pass (imf05.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.32 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675994233; a=rsa-sha256; cv=none; b=pw018Vu4DYlWeBFV9ecs8Up9VvEa0JP2bRoDrrfKrJ5IvfRl5iGkxavF0sKsqixjDyei3m Ea09iUwEX+oUzNtoLVarAM6QPwdtxqPQ35CDbp9bZ4k0lH3w47APllOSV3uUREBpK22Iik /z+wcccFQUBXfxey3X76bbZloMN4A9E= MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1675994230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RinPeFsXh+XMzYYEWfsQdeulY7XTEoCzMTiHJ7AIgls=; b=bb0svPJrVm7XmGXTwmnYKCVRA1/yjOzA/0xlCBDKtFe67DN5ktFzIBgxgs7yjdXhp4MLe1 2+dcavVmgDVFfkczF0lzMwl58J9S7accl0D+K/U1edhpqq8IrvbgojKFifPIC76rFQcegG W+hkK9oUxzhu8Td3mx6EEvLgOHTxVuo= Date: Fri, 10 Feb 2023 01:57:06 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Yajun Deng" Message-ID: Subject: Re: [PATCH v2] mm/page_alloc: optimize find_suitable_fallback() and fallbacks array To: "Zi Yan" Cc: akpm@linux-foundation.org, 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 In-Reply-To: <4C196D76-49A9-4B06-A51F-D8A13109DF3B@nvidia.com> References: <4C196D76-49A9-4B06-A51F-D8A13109DF3B@nvidia.com> <20230209101144.496144-1-yajun.deng@linux.dev> X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 621C5100019 X-Stat-Signature: 4m6du698qzetrpumjgz6kpc4zx7feht1 X-Rspam-User: X-HE-Tag: 1675994233-169361 X-HE-Meta: U2FsdGVkX1+ENvHMmcFPJengbyYjhO4fitzBX6tRVKmDE7YscFHyGBZdGUzvVWxjA0ambG22BRWzVaikxnmz9cojbJCgeulEKWVoYX1skVfZ3mdGaaVTivEJ9Sjcnje7gCCvSv4YXo8HJL1OoDHBmu+aMQW6FGexVkcZgQ4PTp35mmeVcyiIHExSRzNdczzpqVc/0lG6fIsyF4LyRFOnjuZXf7q8kRHQD2n8QbbDW6KgxLuhU5jFQXI9JmkJfu4eszgV3OwQDdcPYY36cvCOXkBXmguVr9zg7hzEgsDaeTAPHOHXG6J/i+FfpoztQec4N3lDjZt0bZz0rH0uJeXVeBcR/U5hERuvHhhQh+OV2bgTYr0zxnWNkmQp43pj+3FEceghcjA2k9E4l9ai24LrXhsHkjTJAmOUf0XW37xcERDjXStdl/sU7z3XD6zXN3h7B94DNhkqFptL59C3KN/+UakumVZoEjTaWhPWuBFhA5R2hVM1rRLkTBN1wtDcg8TrRBF44CY0S9Ac9rPmwuA2P57wGL3tulPAH+VyPbLvLMifmeg29rliQ7Vu4p+Ykt6DoKHCbDy5fyDmt31zWLWuMEkHXtDg/DKgZQ7WqRLFRGTLTXYrKqT9xiNpiH9+ji0CLjqzG66R381hRh/3MZRZjCS504hHKgjnuOoaBl9prGlx4/4tIkGdi4qRNqgnU4GO8kwM0T5ZY07TD9oWg1snKxl86UIKzMWNKNYGUvje20Qcb3/Y24msUpRdZQyDo6Tg5BXNG6yW0X47OoMVUkHvpkEMcsIjS/Ub88xFbCmyEoZ/8I/DW+3OsuOmxIry/5uA4lh2IUbIuXkeKT6xDGcYJRJS42CdrNJzC0Gz4G7MSgZrgf/p/1Xoc3n3TVVMVeo56AT6V7g5beK4y/Lecoc1UVHYuaqL/PG1oZRhRdjiZIHlR00ijPP7DomPImKkEelzydy5H7Uwe6PTG+R5/0C S0yiudZq VvnyvD2y4BX6gCzfF1oJbD7Bmm9kAP0pcS+SLhhUxhAgDVXrESzbLG/MZHqABgENJP/53WMkXX4motvmdMptIbVhvndINgJMJiY2j4dUosfSba1Z0HzFzE4LsaOQ0/DVH+nizaet5aWThE/dHedsMA5tLMxzRiOcQ6ICdHbJWqp8ALToQMad3Z2bvTf5x/4zdhkZxb/K2dciUgFf1RGZat4G/eWpVGuDUeW7a X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: February 9, 2023 11:50 PM, "Zi Yan" wrote:=0A=0A> On 9 F= eb 2023, at 5:11, Yajun Deng wrote:=0A> =0A>> There is no need to execute= the next loop if it not return in the first=0A>> loop. So add a break at= the end of the loop.=0A> =0A> Can you explain why? If it is the case, MI= GRATE_UNMOVABLE cannot fall back=0A> to MIGRATE_MOVABLE? And MIGRATE_MOVA= BLE cannot fall back to MIGRATE_UNMOVABLE?=0A> And MIGRATE_RECLAIMABLE ca= nnot fall back to MIGRATE_MOVABLE?=0A> =0A=0AThe return in the loop is on= ly related to 'order', 'migratetype' and 'only_stealable'=0Avariables. Ev= en if it execute the next loop, it can't change the result. So the loop= =0Acan be broken if the first loop can't return.=0A=0A>> At the same time= , add !migratetype_is_mergeable() before the loop and=0A>> reduce the fir= st index size from MIGRATE_TYPES to MIGRATE_PCPTYPES in=0A>> fallbacks ar= ray.=0A> =0A> You sent a patch: https://lore.kernel.org/all/2023020310013= 2.1627787-1-yajun.deng@linux.dev/T/#u,=0A> why not squash this one into t= hat? Why do=0A> we need two separate small patches working on the same co= de?=0A> =0A=0AYes, this is better, but I overlooked this one when I sent = the first patch. It is already merged.=0A=0AAs Vlastimil Babka said, redu= ce the first index from MIGRATE_TYPES to MIGRATE_PCPTYPES may be =0Acause= out of bounds access of the shrinked fallbacks array If we don't judge t= he range of =0Amigratetype. But this doesn't happen with the second index= .=0A=0A> Thanks.=0A> =0A>> Signed-off-by: Yajun Deng =0A>> Acked-by: Vlastimil Babka =0A>> ---=0A>> include/= linux/mmzone.h | 2 +-=0A>> mm/page_alloc.c | 11 +++++------=0A>> 2 files = changed, 6 insertions(+), 7 deletions(-)=0A>> =0A>> diff --git a/include/= linux/mmzone.h b/include/linux/mmzone.h=0A>> index ab94985ee7d9..0a817b8c= 7fb2 100644=0A>> --- a/include/linux/mmzone.h=0A>> +++ b/include/linux/mm= zone.h=0A>> @@ -85,7 +85,7 @@ static inline bool is_migrate_movable(int m= t)=0A>> * Check whether a migratetype can be merged with another migratet= ype.=0A>> *=0A>> * It is only mergeable when it can fall back to other mi= gratetypes for=0A>> - * allocation. See fallbacks[MIGRATE_TYPES][3] in pa= ge_alloc.c.=0A>> + * allocation. See fallbacks[][] array in page_alloc.c.= =0A>> */=0A>> static inline bool migratetype_is_mergeable(int mt)=0A>> {= =0A>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c=0A>> index 1113483fa= 6c5..536e8d838fb5 100644=0A>> --- a/mm/page_alloc.c=0A>> +++ b/mm/page_al= loc.c=0A>> @@ -2603,7 +2603,7 @@ struct page *__rmqueue_smallest(struct z= one *zone, unsigned int order,=0A>> *=0A>> * The other migratetypes do no= t have fallbacks.=0A>> */=0A>> -static int fallbacks[MIGRATE_TYPES][MIGRA= TE_PCPTYPES - 1] =3D {=0A>> +static int fallbacks[MIGRATE_PCPTYPES][MIGRA= TE_PCPTYPES - 1] =3D {=0A>> [MIGRATE_UNMOVABLE] =3D { MIGRATE_RECLAIMABLE= , MIGRATE_MOVABLE },=0A>> [MIGRATE_MOVABLE] =3D { MIGRATE_RECLAIMABLE, MI= GRATE_UNMOVABLE },=0A>> [MIGRATE_RECLAIMABLE] =3D { MIGRATE_UNMOVABLE, MI= GRATE_MOVABLE },=0A>> @@ -2861,7 +2861,7 @@ int find_suitable_fallback(st= ruct free_area *area, unsigned int order,=0A>> int i;=0A>> int fallback_m= t;=0A>> =0A>> - if (area->nr_free =3D=3D 0)=0A>> + if (area->nr_free =3D= =3D 0 || !migratetype_is_mergeable(migratetype))=0A>> return -1;=0A>> =0A= >> *can_steal =3D false;=0A>> @@ -2873,11 +2873,10 @@ int find_suitable_f= allback(struct free_area *area, unsigned int order,=0A>> if (can_steal_fa= llback(order, migratetype))=0A>> *can_steal =3D true;=0A>> =0A>> - if (!o= nly_stealable)=0A>> - return fallback_mt;=0A>> -=0A>> - if (*can_steal)= =0A>> + if (!only_stealable || *can_steal)=0A>> return fallback_mt;=0A>> = + else=0A>> + break;=0A>> }=0A>> =0A>> return -1;=0A>> --=0A>> 2.25.1=0A>= =0A> --=0A> Best Regards,=0A> Yan, Zi