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 41AE7CDB465 for ; Mon, 16 Oct 2023 14:37:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AB8D8D00A2; Mon, 16 Oct 2023 10:37:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 933E48D0001; Mon, 16 Oct 2023 10:37:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AE328D00A2; Mon, 16 Oct 2023 10:37:22 -0400 (EDT) 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 6548F8D0001 for ; Mon, 16 Oct 2023 10:37:22 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F04EE808B5 for ; Mon, 16 Oct 2023 14:37:21 +0000 (UTC) X-FDA: 81351577482.05.B63590D Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf05.hostedemail.com (Postfix) with ESMTP id E023C100010 for ; Mon, 16 Oct 2023 14:37:19 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=cxa7auLD; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf05.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.169 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697467040; a=rsa-sha256; cv=none; b=WA9TIziSGXaaigRkxlfzU37xUyaYgtP0ngrPEio7OnVplwPbbbPN+H5n0tiI9NbnWTzKMW GJD3LSbqHafuMBqSzvV+V/vQQ8gTjlEagejzA2v5BAK0oZB3W73S5z3lKpAbdmwwCFxFmJ MgeBHtWZkqs3RKqK91Q6se800xH9tKA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=cxa7auLD; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf05.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.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=1697467040; 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=9086aHxk+q98ln5v/CxlAgOpEVSgUBB3h4FBEcrQxlE=; b=Pd7QaYN3Gai80G/dBN9Ey9ASANwieUSMPNKW5GNH/uF1U+SWbIMzevKgRhxTNI6BXI/naS fi9baF/FCjMGYYPORnKTkohLO0gEaBdG+u9SC6iioz+JyOfG5XDOVPwiicqVroKHG3G3yi cZHWbz2S3drNf6Gmxa9/OfjIdt7XVUc= Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7742da399a2so329107585a.0 for ; Mon, 16 Oct 2023 07:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1697467039; x=1698071839; 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=9086aHxk+q98ln5v/CxlAgOpEVSgUBB3h4FBEcrQxlE=; b=cxa7auLDjGlu3PizgoEpUfRLDBPoB/cpOJR2XFlCzx0Nq5K+7Ai1uZByheEPYdRU+X b1fHC8P+Vf/7l/zTyAuT1uQTKF8xsW6IxO/R40uA9I1wlI0v3wf6Jj65NctH/zOJOU/9 ZNCV9ymfnOhjQlGQf7iTPWyK5vB5HWq3x3zW6uuzADLvB/5Skz2BIzLMEjq/tBQkDy0A 1EgdFn2FUr1G5uzq+lVG7I7Q8jGbmhtUt/ReQPtBTcRgryUtKv15yeDPVsyT6dc8mV/m wtJc3bIKhDW5Am5EkhePsgS9i9xacELCi0rMOIY1kI+7Dv1FYCQsKh/tUsOmI+6W4Xow zKKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697467039; x=1698071839; 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=9086aHxk+q98ln5v/CxlAgOpEVSgUBB3h4FBEcrQxlE=; b=HdZtFPsDthipqgiZEZOgXVI9tuV7H7D9xbVfZLuxCaxRsjIYX28F82tlhykUFHmsyT AngPHK/POt8RA9CX+dvQ0m9rUBY7GSiPa5lUq+hEdTDIvnqbevQ5wV/w8y19DCShfEPr A6Ji0r5yVk4On8wbuBeYM94ZCctnXlS41PyCbVzuNAdeWkB/A2vJYfFpwyfIYsK0lzlE cNrsQMudtt68N3puQ9e3nAumbpuMOp5Xfns3iuNM0tQ/eNdkBujQXspX5gdMGyv/kNFt cR1lkAqvs0xuJya9dxA9iqNq/fLoXLskDFF0BcHqhF8OK8ch7Vns+/9mYiR+wgMjmI7P E6Bw== X-Gm-Message-State: AOJu0YzqgPtc3bAp7KvAUsK+6Xnn7BkLoQUv72x62PHGbVrFX7WT/zXu 2brt3EKiq+pOD8Hav3M9cRXvJA== X-Google-Smtp-Source: AGHT+IHbLWIfMwgeRmDEoOofgQLlwb+6o9ppfCU8KzNHIeshlN8uIRlV34gZBFnnCM3GpWwilCEqYg== X-Received: by 2002:a05:620a:d8a:b0:775:7f6e:1af7 with SMTP id q10-20020a05620a0d8a00b007757f6e1af7mr40917796qkl.24.1697467038804; Mon, 16 Oct 2023 07:37:18 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-3012-16a2-6bc2-2937.res6.spectrum.com. [2603:7000:c01:2716:3012:16a2:6bc2:2937]) by smtp.gmail.com with ESMTPSA id 5-20020a05620a06c500b0076dacd14484sm3017046qky.83.2023.10.16.07.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 07:37:18 -0700 (PDT) Date: Mon, 16 Oct 2023 10:37:17 -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: <20231016143717.GH470544@cmpxchg.org> References: <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> <43350F6E-E56D-41C8-8441-A96D83B7D7C1@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E023C100010 X-Stat-Signature: 4bzerb3r895p5eskuxy5dwhhxf9wgss3 X-HE-Tag: 1697467039-262398 X-HE-Meta: U2FsdGVkX1+dnJ+gH+YcdlncafYzSXYsRTamlHYyrBwEh6gdWyp3eb7CRKhbXKNN9muThXM+8/79g3RFGM6VOQWAMCPHL8SyhW8yb7A5HxFKtTYD+A69Ct1GlfTXXVkDmMl8TWZ6ksK8jFwCYir9cKhJ6t3YtmojNnbnVQtLdNP4TS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P+5CN/6xQ8qIRBT5wQIgXScmGHm4dRYH34p50A9ARUXQdPOwaC7xIv4h7WuENw0NstaGoeE9OGDcm+qKQoMfXhHvsLk4ZGI+jzQlz9j2NDp5My0jrv0VUjkvWFeOi5WYjPn11F8TGFAnP1Wsktgpxghv786PYFROWcqsd+OY9eJzWAGzyttT 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 Mon, Oct 16, 2023 at 09:35:34AM -0400, Zi Yan wrote: > > The attached patch has all the suggested changes, let me know how it > > looks to you. Thanks. > > The one I sent has free page accounting issues. The attached one fixes them. Do you still have the warnings? I wonder what went wrong. > @@ -883,6 +886,10 @@ int split_free_page(struct page *free_page, > mt = get_pfnblock_migratetype(free_page, free_page_pfn); > del_page_from_free_list(free_page, zone, order, mt); > > + set_pageblock_migratetype(free_page, mt1); > + set_pageblock_migratetype(pfn_to_page(free_page_pfn + split_pfn_offset), > + mt2); > + > for (pfn = free_page_pfn; > pfn < free_page_pfn + (1UL << order);) { > int mt = get_pfnblock_migratetype(pfn_to_page(pfn), pfn); I don't think this is quite right. With CONFIG_ARCH_FORCE_MAX_ORDER it's possible that we're dealing with a buddy that is more than two blocks: [pageblock 0][pageblock 1][pageblock 2][pageblock 3] [buddy ] [isolate range .. That for loop splits the buddy into 4 blocks. The code above would set pageblock 0 to old_mt, and pageblock 1 to new_mt. But it should only set pageblock 3 to new_mt. My proposal had the mt update in the caller: > @@ -139,6 +139,62 @@ static struct page *has_unmovable_pages(unsigned long start_pfn, unsigned long e > return NULL; > } > > +/* > + * additional steps for moving free pages during page isolation > + */ > +static int move_freepages_for_isolation(struct zone *zone, unsigned long start_pfn, > + unsigned long end_pfn, int old_mt, int new_mt) > +{ > + struct page *start_page = pfn_to_page(start_pfn); > + unsigned long pfn; > + > + VM_WARN_ON(start_pfn & (pageblock_nr_pages - 1)); > + VM_WARN_ON(start_pfn + pageblock_nr_pages - 1 != end_pfn); > + > + /* > + * A free page may be comprised of 2^n blocks, which means our > + * block of interest could be head or tail in such a page. > + * > + * If we're a tail, update the type of our block, then split > + * the page into pageblocks. The splitting will do the leg > + * work of sorting the blocks into the right freelists. > + * > + * If we're a head, split the page into pageblocks first. This > + * ensures the migratetypes still match up during the freelist > + * removal. Then do the regular scan for buddies in the block > + * of interest, which will handle the rest. > + * > + * In theory, we could try to preserve 2^1 and larger blocks > + * that lie outside our range. In practice, MAX_ORDER is > + * usually one or two pageblocks anyway, so don't bother. > + * > + * Note that this only applies to page isolation, which calls > + * this on random blocks in the pfn range! When we move stuff > + * from inside the page allocator, the pages are coming off > + * the freelist (can't be tail) and multi-block pages are > + * handled directly in the stealing code (can't be a head). > + */ > + > + /* We're a tail */ > + pfn = find_straddling_buddy(start_pfn); > + if (pfn != start_pfn) { > + struct page *free_page = pfn_to_page(pfn); > + > + split_free_page(free_page, buddy_order(free_page), > + pageblock_nr_pages, old_mt, new_mt); > + return pageblock_nr_pages; > + } > + > + /* We're a head */ > + if (PageBuddy(start_page) && buddy_order(start_page) > pageblock_order) { > + split_free_page(start_page, buddy_order(start_page), > + pageblock_nr_pages, new_mt, old_mt); > + return pageblock_nr_pages; > + } i.e. here ^: set the mt of the block that's in isolation range, then split the block. I think I can guess the warning you were getting: in the head case, we need to change the type of the head pageblock that's on the freelist. If we do it before calling split, the del_page_from_freelist() in there warns about the wrong type. How about pulling the freelist removal out of split_free_page()? del_page_from_freelist(huge_buddy); set_pageblock_migratetype(start_page, MIGRATE_ISOLATE); split_free_page(huge_buddy, buddy_order(), pageblock_nr_pages); return pageblock_nr_pages;