Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1185812rwl; Fri, 7 Apr 2023 11:14:17 -0700 (PDT) X-Google-Smtp-Source: AKy350aNsvLf3gQklrZDCK6EmAStm8pyoYsJ9ir7MXYR9Rfqy9fG+PdDSqswS/3lzPVNzWwCf+7u X-Received: by 2002:a05:6a20:be07:b0:da:aaec:9455 with SMTP id ge7-20020a056a20be0700b000daaaec9455mr2355656pzb.43.1680891257371; Fri, 07 Apr 2023 11:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680891257; cv=none; d=google.com; s=arc-20160816; b=kSEP+uHjujGq2LB5njm0d5BADn+yOXVNHzNigDfJipK2nR+zumjHuw4FIFaV5F/4Po S9Dox9U1hKi1vkD3rCXYBkMtY6DDBdASpIagOPJsjatzQdTvLOMEFcFhKo/GvW3rN42v 6thZu3PX1Npx+Yqf57xqDYe49/Tla2thrYFVYTaksTWVJJ7q3U8pgEK/y66kwnCJum2f vKhZeDO1pTNyyRvdPTznHnOpOGXkF0oB1xX5lp+cu1aRIA6x5z8d9iRipTsXuSjsV5z7 ZMInKfWyV8+u7UG/p9FPthH8d9lw3CG721o2XqQeTfTaKGzZx4IO3kpPrO+N8bXWr2aF y1Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xM4Wkps3g4rIAc+eTYo1Alveqdz54rBUU9jp3o8/ZGI=; b=veKhdalbrk2DoQ/30yJUUG41EvxdSzekQ/RcKJPk+2RiPugQ4DnuVEO32PlN/4PQzH jQlmP93Pub+8HYyxlpLtWTJlN8ugxAmetvgg1C9Dno0ghEFjoWWoq/yWgaIPcCf1p2VR nL7rjOai7e5YacsiQUmi8yhgFvDsgtfplTu/wnDRjtK57IFYZ3MAf9EmblLgGTgyA8tc lOpj2sV4c2jn2/cO0LakY7G5QO2W8rK2BiJhyzt2YdHa0jToP4kuHFhHsHfBw7Mj9aFT RSZLh2qzIPuSiPOepUjLKW2Qr9d+plSc+eo+wDp674KNb11jiFGNy94MPmtsTD/hWvUU /1fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOGgaZo+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a636b07000000b00502d6f14309si3813065pgc.809.2023.04.07.11.14.04; Fri, 07 Apr 2023 11:14:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOGgaZo+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231426AbjDGSEJ (ORCPT + 99 others); Fri, 7 Apr 2023 14:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbjDGSEI (ORCPT ); Fri, 7 Apr 2023 14:04:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D159EC140 for ; Fri, 7 Apr 2023 11:03:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 276C660DCE for ; Fri, 7 Apr 2023 18:03:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A212BC433EF; Fri, 7 Apr 2023 18:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680890616; bh=zeLvM+wG9Reg7GPWHX1rrEptBgIOs976gIhZ41Bbdos=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bOGgaZo+OHVpjw84ut+dKEBX8kFMCYoAYvoqWCKJ+4sKeUDzoTpJFXWmNWDitx7Fz az/TmAIhaqK17Oq6C8Bg/3lHyHo9y8gco3TEVPnUjZH1tyucUpvdp2ILqKtfPrIwxm QnRv47iEtUSkXPWdL/GAlDpOPu07hs6MQcowF7tYX2ohpph3bbxrVIqbnr3Hsy56NO uK1YxKGwuZY6n36JWZOQquc5nKAJwrYfX5mtk7QXlms/euEEbz+c1a8MFZFQgJ6dZo dVf764QB+0TmW9RpbsMPNaA7inIOik2tT7UU3PO4JQmlKMm+rBHt8NxlmNQhWIY9L/ aI7IapTui+ybg== Date: Fri, 7 Apr 2023 21:03:24 +0300 From: Mike Rapoport To: "Kirill A. Shutemov" Cc: Andrew Morton , Guenter Roeck , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm-treewide-redefine-max_order-sanely-fix.txt Message-ID: References: <9460377a-38aa-4f39-ad57-fb73725f92db@roeck-us.net> <20230406072529.vupqyrzqnhyozeyh@box.shutemov.name> <83e6bc46-dfc0-0e95-e69c-5b996af1e50b@roeck-us.net> <20230406151015.yndcm24fyxitvqyc@box.shutemov.name> <20230406154423.20a991bbdd47630fc38d94e8@linux-foundation.org> <20230407124054.27iiers6o36pdfei@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230407124054.27iiers6o36pdfei@box.shutemov.name> X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 07, 2023 at 03:40:54PM +0300, Kirill A. Shutemov wrote: > On Thu, Apr 06, 2023 at 03:44:23PM -0700, Andrew Morton wrote: > > On Fri, 7 Apr 2023 00:14:31 +0300 Mike Rapoport wrote: > > > > > > > Shouldn't that be > > > > > else > > > > > order = 0; > > > > > ? > > > > > > > > +Mike. > > > > > > > > No. start == 0 is MAX_ORDER-aligned. We want to free the pages in the > > > > largest chunks alignment allows. > > > > > > Right. Before the changes to MAX_ORDER it was > > > > > > order = min(MAX_ORDER - 1UL, __ffs(start)); > > > > > > which would evaluate to 10. > > > > > > I'd just prefer the comment to include the explanation about why we choose > > > MAX_ORDER for start == 0. Say > > > > > > /* > > > * __ffs() behaviour is undefined for 0 and we want to free the > > > * pages in the largest chunks alignment allows, so set order to > > > * MAX_ORDER when start == 0 > > > */ > > > > Meanwhile I'd like to fix "various boot failures (hang) on arm targets" > > in -next, so I queued up Kirill's informal fix for now. > > Here's my variant of the fix up with more vervose comments. > > diff --git a/mm/memblock.c b/mm/memblock.c > index 7911224b1ed3..381e36ac9e4d 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -2043,7 +2043,16 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end) > int order; > > while (start < end) { > - order = min_t(int, MAX_ORDER, __ffs(start)); > + /* > + * Free the pages in the largest chunks alignment allows. > + * > + * __ffs() behaviour is undefined for 0. start == 0 is > + * MAX_ORDER-aligned, Set order to MAX_ORDER for the case. ^ small s otherwise feel free to add Reviewed-by: Mike Rapoport (IBM) > + */ > + if (start) > + order = min_t(int, MAX_ORDER, __ffs(start)); > + else > + order = MAX_ORDER; > > while (start + (1UL << order) > end) > order--; > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index c8f0a8c2d049..8e0fa209d533 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -605,7 +605,18 @@ static void online_pages_range(unsigned long start_pfn, unsigned long nr_pages) > * this and the first chunk to online will be pageblock_nr_pages. > */ > for (pfn = start_pfn; pfn < end_pfn;) { > - int order = min_t(int, MAX_ORDER, __ffs(pfn)); > + int order; > + > + /* > + * Free to online pages in the largest chunks alignment allows. > + * > + * __ffs() behaviour is undefined for 0. start == 0 is > + * MAX_ORDER-aligned, Set order to MAX_ORDER for the case. > + */ > + if (pfn) > + order = min_t(int, MAX_ORDER, __ffs(pfn)); > + else > + order = MAX_ORDER; > > (*online_page_callback)(pfn_to_page(pfn), order); > pfn += (1UL << order); > -- > Kiryl Shutsemau / Kirill A. Shutemov -- Sincerely yours, Mike.