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 04057C05027 for ; Thu, 9 Feb 2023 09:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 692476B0074; Thu, 9 Feb 2023 04:22:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 642D16B0075; Thu, 9 Feb 2023 04:22:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50A676B0078; Thu, 9 Feb 2023 04:22:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 416A16B0074 for ; Thu, 9 Feb 2023 04:22:50 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 11898120F33 for ; Thu, 9 Feb 2023 09:22:50 +0000 (UTC) X-FDA: 80447213700.01.664EEC4 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf03.hostedemail.com (Postfix) with ESMTP id E54A720010 for ; Thu, 9 Feb 2023 09:22:46 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BBjL+Xt7; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=AwUzHqGQ; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675934567; a=rsa-sha256; cv=none; b=IAA/Z51Nq+NcDKKe9+kqLkusYD4vjjnDHskHo+CvDy4EsUto7iKpaf1ubO1hFPl6i5PHs0 hMU8tJW/LCLG08ZshmALTWDikdZoHAYS38x1sFs0KR449EKdY5B87kDn0NUJ/Ryz90JaaX //JaqDMtBA2QEoNmeC+a5tpGxsAwHAc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BBjL+Xt7; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=AwUzHqGQ; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675934567; 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=C9kXmUSbj0Uh0U4j6gi3rfA23pb+D6yeELZIIM2RPGM=; b=h6Y3ynqxWFQcOSJ0Uw6fnBERIQA0vSz3eYOHzIKxwaW7Zv1r9FYvbeS9MSmQwNmtV2U10T QoV8ke2nx+I+D4Ilv3DffgUuZdFIsBwFIerzynI6iAvZedzrK3JpZ1E1NHPOIHJH7sakJg ZGR9h7V89fM4ZInX9sNWcVFCZSaKPOY= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 64EF35C5D9; Thu, 9 Feb 2023 09:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1675934565; h=from:from:reply-to: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=C9kXmUSbj0Uh0U4j6gi3rfA23pb+D6yeELZIIM2RPGM=; b=BBjL+Xt7Iy3JA4/7Yty8xBor+MxW59jhPIVyClb7nOhO2gR/E9ACwWLgNWxJtBZXAmz3I7 H9C694sYnrxW9v4fOBWaEHfNTVx1dVjVENS1yKJx9h82Yi5x5oRZlpdPF45/o6MT0UsXjf YJDr/M/HFs8+JTuFS4hTy+BohjWn2ak= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1675934565; h=from:from:reply-to: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=C9kXmUSbj0Uh0U4j6gi3rfA23pb+D6yeELZIIM2RPGM=; b=AwUzHqGQ+lSArs5UYTFwTZISNveZ5mlBjV3T2hQYeyKQpqKBnn2yVCkgmLxm9LatYKDpQ2 XKuvJAwLrck8BfBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3A0C91339E; Thu, 9 Feb 2023 09:22:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id m0V9DWW75GPNKwAAMHmgww (envelope-from ); Thu, 09 Feb 2023 09:22:45 +0000 Message-ID: <575de0c1-18fc-8568-eae9-2bc0b247622e@suse.cz> Date: Thu, 9 Feb 2023 10:22:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH] mm/page_alloc: optimize the loop in find_suitable_fallback() Content-Language: en-US To: Yajun Deng , akpm@linux-foundation.org Cc: ziy@nvidia.com, mgorman@techsingularity.net, david@redhat.com, rppt@linux.ibm.com, osalvador@suse.de, rppt@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <362e1270-8a54-36f5-f7c0-d922b3d12860@suse.cz> <20230209024435.3392916-1-yajun.deng@linux.dev> <7cc548bc6be5f84e1fb9c6cac07b7451@linux.dev> From: Vlastimil Babka In-Reply-To: <7cc548bc6be5f84e1fb9c6cac07b7451@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: E54A720010 X-Rspamd-Server: rspam01 X-Stat-Signature: mkajsmqgaceec5h8kdq3tt3kboomxp7h X-HE-Tag: 1675934566-733655 X-HE-Meta: U2FsdGVkX1+Gb3+Lwb/5nfkqCoqFmmst6N1uUJQz+8gNzYxtfA1q1hYi9zl1JBdbyD6+viMuzd88Kzw6ssLnNuDFGlYNc1p7l/LMjZJGCuDJeVvqtPgfaQiBADJeVi79dcGpTNVm85TNsHpl5aQZ7/ojWcFinMHouguKmmXMlIZyi6htmjr/mjf9yo22bPNUvCd2OPZw6svqeINVg1PB+yuGGmyDsFVp/NnR5dLqD6/Rkf7kDqCY/uyFpATyXRmEGaMPbL66qUPpWAN8oQTKM0pD67vwsS1+UmJV7xZs0iEMz7ZI0TNpmMg6X89rKrwQn+Njc4SIMebUzOpi1mq6VEH3XHk+5e5sEyKhhY/B5aVbOTsMFQJfJDE23XVVC/WISo/9xow7dF+NIbim3odUpWg2W+BNLMg2AXn0af6hMhQoBKrd1GRNbqZyrIAHNFjLCAtqug/iRWHv3Os2n6isIL4Ay7nyKmir6EOgn0DLpB1Q5BZ3vUqe4QZXel48LOr1ZJrv9JM3KMO8cJft1RNN6NiaSSC1RxvQXPM8z79olQ8CVCwax1vnDH+I7rZcEn8n6zEjBHQNmds6RqE0/wzpVMDPX2FqipAHFyn6l8aKVsFYHkFTkUUpLYqg2X50Iii1cmNBM5zRY7Z/qzXemGFbOL9VvQEw9cwTx2JC+DAy96mKV+6ehZcIn3NfevkYmpBrp1h95TSfPNR3DrVe1CqP/nMk6tYjqOZAGF4inQB5T+ozUS+rgUH9Ms5IqhMlDDj4VKzJy8Nx8RY2Q9Nwg+zc6wjGJeZWo6sI1OLCzWxszxy8czioLpqGh8mcREJoGYLIf4L6MBc0mSbf4vk/T27QHNUi5lGtI8ca1fx5C+nCAU0dVNrfYcijBoWIo4lBw/mNhZ4zPpKztQA4LBMnUByrjT3cG6QGUUPgLoU/MzXsSc+43yUctNSuXAhRZMA3sU/Zd4pLkXok+zW8L0Sk1vc M1nk7Xk9 gnZu09HM8gAOrqmB87ERl1WKKXE4lEY4ZmeuSoAEgOc79R8ayIddzDIKa9yCqd1hkkS/v0Y8ld469PP3B4U6wgYX5rC4XTCDm1AJ/opkl9F4KqEC8e1GJGt+lYAOCd96/iw2Ysoq2CIGCCbHWVgKA9P0jZDmrnOgkqArRPFAbE7apJWDYYqmEXBDRfT3Ehuwsc3DAN8sPwY+KksHOvS75o1mF+vfl8c8M0j6Yx30vChYTTzpCtC58UVorA6iyJxBHgZ9yokLqh3TGovk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2/9/23 09:44, Yajun Deng wrote: > February 9, 2023 4:12 PM, "Vlastimil Babka" wrote: > >> On 2/9/23 03:44, Yajun Deng wrote: >> >>> 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 >> >> Acked-by: Vlastimil Babka >> >>> --- >>> 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)) >> >> Just curious, did you the check for extra safety or did you find (by running >> or code inspection) that this can be indeed called with a non-mergeable >> migratetype, and cause out of bounds access of the shrinked fallbacks array? >> > > No, I'm not sure if it is called with a non-mergeable migratetype. > It is just for extra safety. OK, I agree with that. >> BTW, I noticed the commment on migratetype_is_mergeable() contains: >> >> "See fallbacks[MIGRATE_TYPES][3] in page_alloc.c. " >> >> Should probably change it to e.g. "See fallbacks[][] array ..." so we don't >> have to keep it in exact sync... >> > > Yes, this comment should be changed. > So do I need to submit a v2 patch? Please do, with my acked-by. >>> 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;