Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp909448rdg; Wed, 11 Oct 2023 08:46:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHI6eH1hBjz8/PxF+Xz0n3bNI+j9UdJ3Yb+QHM7TwxgOdXh83iCKhN5vh/mUrbyg1ojRVjT X-Received: by 2002:a05:6a20:8f0e:b0:16b:f8ef:f31e with SMTP id b14-20020a056a208f0e00b0016bf8eff31emr14583452pzk.5.1697039170793; Wed, 11 Oct 2023 08:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697039170; cv=none; d=google.com; s=arc-20160816; b=k94riPtgH5EMdkQ61HhfT+eQZL940ZAFFZKjtQ7ZlWl3MOJcAZJWoQ75+E7hPXy4HZ VZMg8HCbqW6WN36StVsNYUXLF1w2O6bI36jSJgYUiD1f3pWTSExW9m3l142WebxVVmjy 6pMjWQzLm8skG0+Uinsvjt+tB/Ki4LEvULvTfWPHNpooU/L2x1Hvqyn01vScUW8jtcIT G96ZQjtIUVcxeVPyFOH3byY0BlH+9yuoOc+tsGqRmMvwF/w8fEXqXA1AMRacaWvf6nhE qSAxODlKywVcDgc47SBTKpAsCGljGpcaUv8HxdTiiTfjfFIyZa3+ZVY9tI6wj3U8Kgx5 1RKg== 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=EgB5ImVhNM/QI8rgc4CZqHFxucrjIchAqAaUbbPMb8k=; fh=B6w9aO6g22upnX7qPGmZ+Y25kRzRJyXUEXqSxtGDWnU=; b=pG0aXAbTzypyLhdC+fm3cHfxPoAE00mKfzOWg1KY/RQiwoAon1R9rhK+ZBTemqh4K1 /XYep0fYSfXZ99XoJg0BGyG7rPmYCeIN5l/sEAeHK0Pqmf7oe4tGc8wtFZ+NFEszRJQB i20djKzy2Ifaeu2pC5XrQSMEoRK7n+kfjQxCDSiITowak+L3JDM/e43vx7Ic1qS/1QT9 2hLBfAvQAqHQJdQRk62QZVCZQ/3eQ7bqmkvZkV9GbbVuVEdcmG8LVJfD7XoYkEz1RQQL nGYMPjc3Q/e/727YuJwqvcsnopS1OJQc+PyhTaIL5aJXu3TyEw+DjAlCKiNbiQ++OfSj Z24Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=vFHmAtNA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id be3-20020a656e43000000b00589ab0ae2edsi26326pgb.649.2023.10.11.08.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 08:46:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=vFHmAtNA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 0FD75825027B; Wed, 11 Oct 2023 08:45:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346770AbjJKPpi (ORCPT + 99 others); Wed, 11 Oct 2023 11:45:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235100AbjJKPpg (ORCPT ); Wed, 11 Oct 2023 11:45:36 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F57493 for ; Wed, 11 Oct 2023 08:45:34 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-41b1a3329f2so118151cf.0 for ; Wed, 11 Oct 2023 08:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1697039133; x=1697643933; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=EgB5ImVhNM/QI8rgc4CZqHFxucrjIchAqAaUbbPMb8k=; b=vFHmAtNAjW96fI66fwu6kotzo36+wSoFn1hIGb3vpsQTOsmBY8EdBUPyN/RJ5cZqJ4 avd1NQRdozXYQSzLGt1Xy2igB7hMuF3TsGZPMg2QTkAdKc+9v2f+HQHq2gCEzgG2Ry4B xJipVPkLj4CCQLoH5UslEkdhPQAutLaSTRw7eQS4BzBJGFEB+Lme/duM3XwQ7UbAXs6H QO535mcDRTAewhE+N5O7BXuI3GDs9GDV0FDD7WLpAgmrFq5eGpnX7BGxxJs1QIDjTwks w3kCLSiw5vMGE+twqIIzeyoDEB445BD8oAUyjPhbielwe1lORPTCgzK/HwlKLPYgTMGD eeOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697039133; x=1697643933; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EgB5ImVhNM/QI8rgc4CZqHFxucrjIchAqAaUbbPMb8k=; b=Cf6N6naqNbzxG4anasw7hSI9zkKEfNZvJUgp7JhZri0mQZWpLicUM/5dzO4VPbdPH6 p/K2U+CyeAhhx5FWF2CKhtbLKicuo3QicOm9wLIZPbC1OImuzrxqeJkuD7bePvFAqtoh Oe2SqNXz3xl9dz04jdR6lQFMX1YqQttb2kcNicSn5XGQK8HsZR0rY/iVk+i6kxvWk+Ss BJ8hj4ZXzOd+gSSorKb9IhKDB50K0Vng17ciW1L6Mgp7W9IrUC9Zovoqlnc3c7egl3Dv 8dmqmAQ14DgP0RtfSS5ZPbpFJgeQeabpHe4kwhwko92ypGJk+RsWx6t+ZLyPvk7cy8Py hejg== X-Gm-Message-State: AOJu0Yyb7hUSnmkgKNhM/hUBXK6cfX8gY2yb5h3gNvF0DkIVtD80aJeE Qsf4TJDzMV3MQoDj89ejts2bN1/FoGBSZwo5jyo= X-Received: by 2002:ac8:7d10:0:b0:417:9a94:870b with SMTP id g16-20020ac87d10000000b004179a94870bmr24831509qtb.35.1697039133612; Wed, 11 Oct 2023 08:45:33 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:66a6]) by smtp.gmail.com with ESMTPSA id b21-20020ac84f15000000b004180fdcb482sm5463227qte.81.2023.10.11.08.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 08:45:33 -0700 (PDT) Date: Wed, 11 Oct 2023 11:45:32 -0400 From: Johannes Weiner To: Zi Yan Cc: David Hildenbrand , Vlastimil Babka , Mike Kravetz , Andrew Morton , Mel Gorman , Miaohe Lin , Kefeng Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2 0/6] mm: page_alloc: freelist migratetype hygiene Message-ID: <20231011154532.GB461170@cmpxchg.org> References: <762CA634-053A-41DD-8ED7-895374640858@nvidia.com> <505e7f55-f63a-b33d-aa10-44de16d2d3cc@redhat.com> <4466F447-43D3-43CD-8930-FBE9A49028BA@nvidia.com> <92AE29D4-E715-447C-AF99-ECF42383C74D@nvidia.com> <20230926173939.GA348484@cmpxchg.org> <0D2BD71D-5E65-4175-8872-5E70278C57DA@nvidia.com> <329AB331-DDC1-4074-A85E-AB5CF866CE84@nvidia.com> <20231010211200.GA129823@cmpxchg.org> <20231011152525.GA461170@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231011152525.GA461170@cmpxchg.org> X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 11 Oct 2023 08:45:54 -0700 (PDT) X-Spam-Level: ** On Wed, Oct 11, 2023 at 11:25:27AM -0400, Johannes Weiner wrote: > On Tue, Oct 10, 2023 at 05:12:01PM -0400, Johannes Weiner wrote: > > On Mon, Oct 02, 2023 at 10:26:44PM -0400, Zi Yan wrote: > > > @@ -1614,10 +1652,43 @@ static int move_freepages(struct zone *zone, unsigned long start_pfn, > > > > > > order = buddy_order(page); > > > move_to_free_list(page, zone, order, old_mt, new_mt); > > > + /* > > > + * set page migratetype 1) only after we move all free pages in > > > + * one pageblock and 2) for all pageblocks within the page. > > > + * > > > + * for 1), since move_to_free_list() checks page migratetype with > > > + * old_mt and changing one page migratetype affects all pages > > > + * within the same pageblock, if we are moving more than > > > + * one free pages in the same pageblock, setting migratetype > > > + * right after first move_to_free_list() triggers the warning > > > + * in the following move_to_free_list(). > > > + * > > > + * for 2), when a free page order is greater than pageblock_order, > > > + * all pageblocks within the free page need to be changed after > > > + * move_to_free_list(). > > > > I think this can be somewhat simplified. > > > > There are two assumptions we can make. Buddies always consist of 2^n > > pages. And buddies and pageblocks are naturally aligned. This means > > that if this pageblock has the start of a buddy that straddles into > > the next pageblock(s), it must be the first page in the block. That in > > turn means we can move the handling before the loop. > > Eh, scratch that. Obviously, a sub-block buddy can straddle blocks :( I apologize for the back and forth, but I think I had it right the first time. Say we have order-0 frees at pfn 511 and 512. Those can't merge because their order-0 buddies are 510 and 513 respectively. The same keeps higher-order merges below block size within the pageblock. So again, due to the pow2 alignment, the only way for a buddy to straddle a pageblock boundary is if it's >pageblock_order. Please double check me on this, because I've stared at your patches and the allocator code long enough now to thoroughly confuse myself. My proposal for the follow-up changes still stands for now.