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 2F693CD8C9F for ; Wed, 11 Oct 2023 15:25:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A37708D0110; Wed, 11 Oct 2023 11:25:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C0A48D00A3; Wed, 11 Oct 2023 11:25:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 861BC8D0110; Wed, 11 Oct 2023 11:25:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 760498D00A3 for ; Wed, 11 Oct 2023 11:25:30 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 410041CAA01 for ; Wed, 11 Oct 2023 15:25:30 +0000 (UTC) X-FDA: 81333554820.04.8A06D9F Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by imf26.hostedemail.com (Postfix) with ESMTP id 21516140017 for ; Wed, 11 Oct 2023 15:25:27 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=ya8dgFWP; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf26.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.44 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=1697037928; 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=XsMbz3DgW/xqFIUZu44mEh3KqlFcPH8UERBD82Y0mcs=; b=ntV/JauCwmyJYviK4dG1Vivon4PpxB3KP752Sp1cUC4G9jnUzXt6/BfQVkFFZ2GKFCisWm 8BxNRqq0xvew8DVONYNBO8kq3GlvDt9SSHOq+iesOSFX6xZEaOtPukJqu245P0VmVdkUtK zAJwMQAruLPxR1aJKE63h+pRxtwrjAg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=ya8dgFWP; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf26.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.44 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697037928; a=rsa-sha256; cv=none; b=6UqLoAFaZShIJDMXSueqCjts4jAGXScot9+bmTx0MT3Cd0R0iHBfiFtsmm1LgkBbh41bww 1iNzmF/KZ9Hu37FVlU4R6Zy2PT8tui5qmpmtFXkFTDgsNEa5PXqeMaQvj2ImvenUO8MsD0 15854s12HwxqxX8wwva4W2lq+OtBC9Y= Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-66afd39c8edso31136206d6.2 for ; Wed, 11 Oct 2023 08:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1697037927; x=1697642727; 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=XsMbz3DgW/xqFIUZu44mEh3KqlFcPH8UERBD82Y0mcs=; b=ya8dgFWPmiOQHNcYEaCz8B3tXr/w2VY3miv775W/03v5fKv+R3yllEhlbO5RFtVCnG aGqj4qImYcPV5GK0rxwKT8jxIjL/oqbpwloqX8DRbyrVDMwGa//xIeZHQKZvANiLrKOX QAXSzRKXTvP3DrOUtix4sgxdS8IaFh2Jn98xhY68CxZyTixInN/gfNEtR6Fei4BYi3SY VSn+QzQng9hd0uNzkdGS8JOE3ivovhPy4/DB6CDvKOsBu7XbgTOGaBmO7MumnM0VL0af 8ZQO1vzD1SPYr1YdkOrA0OPhw7qKCrXmZHFaeC10UHmL0+A5rnt5Dlo01C29rZ5kgGzB ojHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697037927; x=1697642727; 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=XsMbz3DgW/xqFIUZu44mEh3KqlFcPH8UERBD82Y0mcs=; b=ltSQAV+Car2v3zEJbef8rsD5DDma1ulWKgrrmPv32U3wOEXyJwbpzjOXodio8ZzHtw uxYHbR2JFZiyCiZRn+UyVTHbOqDbiU5sn/TA/5GtRnMHCQQ2AyVM2AYQlpXNwb3fiQfF rpRpllFtySKCaXh3noPUOPLc3ZRfVoKlHorjLKCF7/rXLLXflgF1lY07mbf/D8tjZpfd PJugDdf9vnR0MfnDd3BY3F7KlrzZrOGZNRs6rtn2+16xbzbARuCMYoywz9ivOinZfbgv oj+daOanFeuY7FjKIo9Nod5JW2a4ncww/8iwbj2uSVkP/ABte54rNEwrcPq6laU+ruus w4mg== X-Gm-Message-State: AOJu0YwY+zxgcyqgQeDKSXkOfiHllPC1jlvJjbqCJwj0oIGdg0Hve8u7 GgmbYh9SeiyRnq3kLppBWKbBeQ== X-Google-Smtp-Source: AGHT+IGlLDv3+7x9FfABCsGgOa1is2cQYueStg/wwkdrU9pygWs8+xm3pd5+3iuNFglehPX6pSX/Vg== X-Received: by 2002:a0c:f58c:0:b0:66c:fa81:3f25 with SMTP id k12-20020a0cf58c000000b0066cfa813f25mr4310240qvm.62.1697037927088; Wed, 11 Oct 2023 08:25:27 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:66a6]) by smtp.gmail.com with ESMTPSA id a12-20020a0ce38c000000b0064723b94a23sm5677557qvl.27.2023.10.11.08.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 08:25:26 -0700 (PDT) Date: Wed, 11 Oct 2023 11:25:25 -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: <20231011152525.GA461170@cmpxchg.org> References: <20230920160400.GC124289@cmpxchg.org> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231010211200.GA129823@cmpxchg.org> X-Rspamd-Queue-Id: 21516140017 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ib1h6ewoejcgtf4mkjp5q36f1i6qj358 X-HE-Tag: 1697037927-223180 X-HE-Meta: U2FsdGVkX18P7mzE90e7oNYQZ76NM9zk5ypxTSZjrMCf+1fV4abK0hy3W64+iPLbyw1YuK/GGfDDjvYlZPfM+e5SYF2XRPqLRE9M12WuSYeygWcGewZuOiK5pF7b9CdhOCnpstfLM5Ml0t2FYjd/pqp28/rD6JqOB7SkIs2uYYQDA1oqgWNOhZzWnBpfo4t4qom2Fivv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uttSSpdDChmAJyYcAX7e97hBujeobWDmc7z18S60o0DSmxsQLheeHEMbJ4xWiUGowqVak1aymuKOL40DPfXKEi4hSE+dtS76rjboD7qhTZFAnYbSs9PfcrHY66jyHAch0K1F/Zcjhpm3l93opI183ltQcyiktUBqo7y26jNz8wnm9eF61/+z99AQWkg/jSNdxyk0kw== 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 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 :( So forget about my version of move_free_pages(). Only consider the changes to find_straddling_buddy() and my question about multiple blocks inside the requested range. But I do have another question about your patch then. Say you have an order-1 buddy that straddles into the block: + /* split at start_pfn if it is in the middle of a free page */ + if (new_start_pfn != start_pfn && PageBuddy(pfn_to_page(new_start_pfn))) { + struct page *new_page = pfn_to_page(new_start_pfn); + int new_page_order = buddy_order(new_page); + + if (new_start_pfn + (1 << new_page_order) > start_pfn) { + /* change migratetype so that split_free_page can work */ + set_pageblock_migratetype(pfn_to_page(start_pfn), new_mt); + split_free_page(new_page, buddy_order(new_page), + start_pfn - new_start_pfn); + + mt_changed_pfn = start_pfn; + /* move to next page */ + start_pfn = new_start_pfn + (1 << new_page_order); + } + } this will have changed the type of the block to new_mt. But then the buddy scan will do this: 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(). That move_to_free_list() will complain that the pages no longer match old_mt, no?