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 65BFACDB465 for ; Mon, 16 Oct 2023 20:26:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C66ED80029; Mon, 16 Oct 2023 16:26:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C170D80008; Mon, 16 Oct 2023 16:26:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADFB180029; Mon, 16 Oct 2023 16:26:34 -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 9E23880008 for ; Mon, 16 Oct 2023 16:26:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 71976A0B96 for ; Mon, 16 Oct 2023 20:26:34 +0000 (UTC) X-FDA: 81352457508.26.0454B56 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf15.hostedemail.com (Postfix) with ESMTP id 8A3E8A0032 for ; Mon, 16 Oct 2023 20:26:31 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=3ahSFuaz; spf=pass (imf15.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.172 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697487991; a=rsa-sha256; cv=none; b=jMw+YETxJyWBtLf7HAOMQ8aYR8Fq77k7yDZ4JGTt+6oKe2Tzj8t+rFXVqPqy41/PQEqToi buL4mpZBvhfZhWzTDt2LDuClzLYlGNio61mX7reUO6AXvBOIDJYX943iUVqLP3OkCIdf0/ XQBTiPCtb6noortlki6Jug2BMZ/loKo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=3ahSFuaz; spf=pass (imf15.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.172 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697487991; 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=QPTkYTZnZrVHU5549J4NxQtUsfCC6J7hkeHUTqjG73g=; b=GjZaQ8eBWOER/YLD/gNwELf6CbSumrN4Lk9tgk6eMBXr++xtM1BTxCErokCIj7BZcsg863 lJY+ogNeD+jfQJyHSt8z9t49+ckyK8mpgK1uXW9VcADvK/D027Fvg2UaCXD4myDta8jvRp DwnFQuz0y1+ZTjJmJMngErGwOSGNPXM= Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-d9a4c0d89f7so5793028276.1 for ; Mon, 16 Oct 2023 13:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1697487990; x=1698092790; 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=QPTkYTZnZrVHU5549J4NxQtUsfCC6J7hkeHUTqjG73g=; b=3ahSFuaz7dh3NF47q5OnB1330dIu8Ox9AG78/bKQeKKWKkQTvXnYp/GE2Tf7RwlI+6 F2W+YRst+1cdQlft7IugAixVvQVj8JhZwusTbrC71AQ3Tm6jEdvSkFloFz1PXMH3bEJF vRxM7flW0XwTjDY/80Smet3B+zntbuBrCDQbDIi/FgR38ZWCtpacRhhOC65t6bVqDvp2 hIF0qPGbG7Oevv2LzMBzMkPvkvIhfSZZPAdrwun71+yEHYz9gqZtDWxL/HUtLTBvGBi7 k1kZKs45/oK3b3uRHiSsBMUt0vp6rtmRCG6gvbhhh7jFTjsUFT7Hs+Hc8VR71xKBj4X3 mrcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697487990; x=1698092790; 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=QPTkYTZnZrVHU5549J4NxQtUsfCC6J7hkeHUTqjG73g=; b=E4o2VRnjaYWnnJedal08JK97nKnPh9SBBIN+wUudIawB2O5TIoDpmNZrjHrx/edxdC giF75u81oNoiNn+vOai02VgKUxaygs/CjmNYUzYuW9tkArQjnN+plNKL0I3esIynr1XB R37honpIMme4r75VxKRvzUewEi6eB6JxVCE4K08Rv2Cp4PyrBU2R8IyMkVJHH7OOq3Zr K+67B4/BN52abMkCqdWVi1LpCcBvA4Iuuqfo6xYI0Z28PuuEupTJVd5H0llB+yr/rdJf FkIT02ewUgH3pD/f0YlGixZY4aZUSSiNldv3y+cxEx57EtX/P9lJ8a72Nx2Q3OLkxtM2 ETpA== X-Gm-Message-State: AOJu0YzMs9qHuATrbaZVvDqr7z/dfSq8CzdqdzEm5r5N9/Ud9Cukou9v ezCTLjeBJBdxTsu70fe3Gc12tQ== X-Google-Smtp-Source: AGHT+IH0aqxF5tM4qI4FzYmXFdKpzIDnQGEHkOoW4o2/zudOgQHqT6Yuybzsu5DHMDv6uGyO/k+xMQ== X-Received: by 2002:a25:abc6:0:b0:d9a:6316:42c8 with SMTP id v64-20020a25abc6000000b00d9a631642c8mr117592ybi.54.1697487990516; Mon, 16 Oct 2023 13:26:30 -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 pe10-20020a056214494a00b0066d0d3daa58sm3644963qvb.24.2023.10.16.13.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 13:26:30 -0700 (PDT) Date: Mon, 16 Oct 2023 16:26:29 -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: <20231016202629.GA1042487@cmpxchg.org> References: <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> <20231016143717.GH470544@cmpxchg.org> <5B61B70F-E85D-4E6F-8856-17A90B899F98@nvidia.com> <20231016185113.GI470544@cmpxchg.org> <6F2C52B6-2031-4694-A124-0DFDE9F88E88@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6F2C52B6-2031-4694-A124-0DFDE9F88E88@nvidia.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8A3E8A0032 X-Stat-Signature: ysms1izxs7nhhmeauq5ikeg1j6gstprd X-Rspam-User: X-HE-Tag: 1697487991-393849 X-HE-Meta: U2FsdGVkX18TUElr3DYcdarjEceyY30olfvdvgfiJt2DRQWtcRe/lN9mFAmnY7mHJqEHHqtZYLw5N6h6oJWxveuuNwRcYhvktcnbsPSsK7CpeePAgYnKHOeI/MbVm6Y/5u4s3FGmSm3lDq94dYN7ezdi4MSJ0HBpx67t4p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D1/5RlYTRAEkpS0/oWTcM10xyHqMfjix+Qcne+ZjaZDtaZVMDTKjV2aD9PM30xM/808UapXvdBx1myV9ynjlT13JhAeHun7lkT55k8scAj+g83qUccKZFXn0pJDJVA5jymS8DFn/zA4nrnDT4tEzg9cdjizWHBW/0MSNGTWNG5rOGJ7CDW+HcP9z5fPPf3hv2uf3SCFZ04Pcr5sX+UAfiXOUngGtWfS938iBn6766CfJU2RaISnpTT8QtToRwo6tnD0TlIPeaEezAQiNWAzc3FcO0iuA== 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 03:49:49PM -0400, Zi Yan wrote: > On 16 Oct 2023, at 14:51, Johannes Weiner wrote: > > > On Mon, Oct 16, 2023 at 11:00:33AM -0400, Zi Yan wrote: > >> On 16 Oct 2023, at 10:37, Johannes Weiner wrote: > >> > >>> 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. > >> > >> No warnings. But something with the code: > >> > >> 1. in your version, split_free_page() is called without changing any pageblock > >> migratetypes, then split_free_page() is just a no-op, since the page is > >> just deleted from the free list, then freed via different orders. Buddy allocator > >> will merge them back. > > > > Hm not quite. > > > > If it's the tail block of a buddy, I update its type before > > splitting. The splitting loop looks up the type of each block for > > sorting it onto freelists. > > > > If it's the head block, yes I split it first according to its old > > type. But then I let it fall through to scanning the block, which will > > find that buddy, update its type and move it. > > That is the issue, since split_free_page() assumes the pageblocks of > that free page have different types. It basically just free the page > with different small orders summed up to the original free page order. > If all pageblocks of the free page have the same migratetype, __free_one_page() > will merge these small order pages back to the original order free page. duh, of course, you're right. Thanks for patiently explaining this. > >> 2. in my version, I set pageblock migratetype to new_mt before split_free_page(), > >> but it causes free page accounting issues, since in the case of head, free pages > >> are deleted from new_mt when they are in old_mt free list and the accounting > >> decreases new_mt free page number instead of old_mt one. > > > > Right, that makes sense. > > > >> Basically, split_free_page() is awkward as it relies on preset migratetypes, > >> which changes migratetypes without deleting the free pages from the list first. > >> That is why I came up with the new split_free_page() below. > > > > Yeah, the in-between thing is bad. Either it fixes the migratetype > > before deletion, or it doesn't do the deletion. I'm thinking it would > > be simpler to move the deletion out instead. > > Yes and no. After deletion, a free page no longer has PageBuddy set and > has buddy_order information cleared. Either we reset PageBuddy and order > to the deleted free page, or split_free_page() needs to be changed to > accept pages without the information (basically remove the PageBuddy > and order check code). Good point, that requires extra care. It's correct in the code now, but it deserves a comment, especially because of the "buddy" naming in the new split function. > >> Hmm, if CONFIG_ARCH_FORCE_MAX_ORDER can make a buddy have more than one > >> pageblock and in turn makes an in-use page have more than one pageblock, > >> we will have problems. Since in isolate_single_pageblock(), an in-use page > >> can have part of its pageblock set to a different migratetype and be freed, > >> causing the free page with unmatched migratetypes. We might need to > >> free pages at pageblock_order if their orders are bigger than pageblock_order. > > > > Is this a practical issue? You mentioned that right now only gigantic > > pages can be larger than a pageblock, and those are freed in order-0 > > chunks. > > Only if the system allocates a page (non hugetlb pages) with >pageblock_order > and frees it with the same order. I just do not know if such pages exist on > other arch than x86. Maybe I just think too much. Hm, I removed LRU pages from the handling (and added the warning) but I left in PageMovable(). The only users are z3fold, zsmalloc and memory ballooning. AFAICS none of them can be bigger than a pageblock. Let me remove that and add a warning for that case as well. This way, we only attempt to migrate hugetlb, where we know the free path - and get warnings for anything else that's larger than expected. This seems like the safest option. On the off chance that there is a regression, it won't jeopardize anybody's systems, while the warning provides all the information we need to debug what's going on. > > From a0460ad30a24cf73816ac40b262af0ba3723a242 Mon Sep 17 00:00:00 2001 > > From: Johannes Weiner > > Date: Mon, 16 Oct 2023 12:32:21 -0400 > > Subject: [PATCH] mm: page_isolation: prepare for hygienic freelists > > > > Signed-off-by: Johannes Weiner > It looks good to me. Thanks. > > Reviewed-by: Zi Yan Thank you for all your help!