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 B19E1CD6E7F for ; Wed, 11 Oct 2023 15:45:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F36E8D00C8; Wed, 11 Oct 2023 11:45:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A3618D0050; Wed, 11 Oct 2023 11:45:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16A778D00C8; Wed, 11 Oct 2023 11:45:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 07AFC8D0050 for ; Wed, 11 Oct 2023 11:45:37 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CF89C4014D for ; Wed, 11 Oct 2023 15:45:36 +0000 (UTC) X-FDA: 81333605472.05.5B57753 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by imf29.hostedemail.com (Postfix) with ESMTP id A4A4E12001E for ; Wed, 11 Oct 2023 15:45:34 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=SO6D7POB; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf29.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.169 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697039134; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EgB5ImVhNM/QI8rgc4CZqHFxucrjIchAqAaUbbPMb8k=; b=8azG14AoLJ9eNhUpxdZccj3pll2J6lUUCXavnMJOmAvGtlpGi8UsKCDbeQ3m930glCGEpU P6mw9yHj+Pu6DJCKF3MBG4cM0Ke4IY/0tB8PNug0fba8WScEsp0BjbJqCRCL9d2UTJpbsi kgPxGZGZdW+DMNeh4qdJA/MnF1r8cd8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=SO6D7POB; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf29.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.169 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697039134; a=rsa-sha256; cv=none; b=crcBGXbVMM/2lFj1PXCBOivaMX8XgT4Aqg+TrXCtGDOP0+Nh5teXpR+Lp23hpEU+D1J1FU jMQI+ClvGlldSY+xuHsocyjsjKapmtkV0qWop/w+HDSg4eI82j/hVjqEil3M9jRJ0a72ey I7s7ojdlmnsjFLI+vjW9UkgbwXlN8w0= Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-4180d962b68so46701cf.1 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=kvack.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=SO6D7POB0ida4n8n2z5vRWmz2ZDBToup/e7NMwfuoOOIZlqmuAp0i1eBxGOZZxUcx9 K4E+V49Z9rzg2bKoPxYuqlrSVn1yyZCDSNP8bRxDUJzyuVffFid/ZxzsZ8EyLfjX4CeK f80WZwvAxdJvY0LrQrPOJT3CHyjWtWkE4Ct0+el41XiCfS7V7TkiUUZZO4Tt+ew/ZPkv Dq8udOZdKw4n2Yt4KlSzODG4cunOcRD97nVHosK2bIjmyx2PaU3cGXuizGGOPePg24zX kDzVFNYkc/xUaACYXO6Lq6SSBcT2TP0WM4u2pehgSh1wuapfWKqstUAXLtG5anaHeNXl 6FmA== 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=xNJIkdnem3euhFuGZi/ejCG1JyAH9muTQf4KEMAQYs0/q/zRKcAP/b+OyXSqaEKjlC lWnmydSUcm4vgkzDkXH3z/3OOh/1oYuoBhctfawRNYWZKflDQzKGCgAZvge9MP8k+qn9 CEtf5J7ZpLGowK0/a4FGvZyJDQYM57n9mgV4/F0gh/VGIU2OQlGXWYAi0YhnFzmD1Zfn xLxAWd+AgymahZaseaEoeHElyIzz2OBzucnN8rz0ntymDyAEyB8ilNqHLJvPK2i5M/oj WdsZqXDIE86Oa2VrL4gSUAltF41OFreI0adY3LGCLaritDrWUS2wXpdpcducRzATEnz3 o2oQ== X-Gm-Message-State: AOJu0Yz6ziMyI3Jy5KqDNlBIqT+2s+6EqznVlRrg9W4bqAPUGMD9uG7d cDLnVypjeTeArohemcTel/hkyg== X-Google-Smtp-Source: AGHT+IG2zx5JqexdUuTbyPo/25xvNszaxrIOkjeuPvNp0MwzgZMj4lbYB4LwgI3Q7QdFTaV4mz/h0Q== 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-Rspamd-Queue-Id: A4A4E12001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dpxqur6ethifbt3jo6ycdcjgdyf76m38 X-HE-Tag: 1697039134-2196 X-HE-Meta: U2FsdGVkX19tdb9mkfdHH0WCqN9gqL8VDN6eDyzBBsmLJhmPkw6RX1neo3AUqFL2nBMwvxuXmfduK7VJwSurA3Re8uKTpgG9oq2Xa7XmZtnd8ukpWCH+DbYDP8O6/YRW3vz2jX8z/L9u8kOmEij5HxECB4IuD8strI3vUgrtKaryVojoEdaIK29jcJVCyAaQcCfI6Q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OmBjA7SfLyBqDT6TOqKcyF+MH1qkMsDuWvxRjZ5CKelHaSs+9crChy2cdfxSqT4WPk8ljHqTP/EYu8d0OqrZeuSBY113ih1ATI9UpM2UBZNqahTGzW7uQvMuPEgvjBypJaRt7P5cHUGSt/s2mHhl62DlSLXvq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000455, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.