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 0763BCD5BA7 for ; Thu, 5 Sep 2024 10:21:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B4F86B00F9; Thu, 5 Sep 2024 06:21:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 864226B0105; Thu, 5 Sep 2024 06:21:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 707486B013A; Thu, 5 Sep 2024 06:21:31 -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 4EFB66B00F9 for ; Thu, 5 Sep 2024 06:21:31 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E9501419A9 for ; Thu, 5 Sep 2024 10:21:30 +0000 (UTC) X-FDA: 82530292740.05.3DA2ED2 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by imf09.hostedemail.com (Postfix) with ESMTP id E2C8414001F for ; Thu, 5 Sep 2024 10:21:27 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hGsnJRue; spf=pass (imf09.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.208.177 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725531611; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eWUmOKRHUFdWNzdh5pw1Ez/2T72/kqrXnIrfhfqLjOw=; b=MyFe0rFmue7Fr5V8bdFcUQ5uiJ/fWwOXk5VJn8Vx7KqkjOrxSksdTPZlu0exoz2TUQa3/i 0yUExtmFaPjJBWxFk/GyGZYBrDTI18cWJUYWhCTP8TENIX9ptdkdDucLNTYzjun/W21vvV OknPzGVOjOOCuFUCf3Yz4+hn90arT/E= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hGsnJRue; spf=pass (imf09.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.208.177 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725531611; a=rsa-sha256; cv=none; b=fYEIq20EvX+6OYBWA/yhjGaafvQ61+myAf1obXxSYtGeamDnexIqxsEnBLOOI1Dr6IcIbp KltH4x3mnwEUR5PYorQ2z/5tMj1UgIgvrs2AQr++G2Y+iWBE6XpZlrn/TNAVjpZAUsdqAA 2VhfKYdKzimM3q09wXZCiEX9SztwpFg= Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2f43de7ad5eso7766321fa.1 for ; Thu, 05 Sep 2024 03:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725531686; x=1726136486; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=eWUmOKRHUFdWNzdh5pw1Ez/2T72/kqrXnIrfhfqLjOw=; b=hGsnJRueqhP3IaIeKJvv7J2i7/zhnL0ZqBIvlVluhwnZhAIDfXbOQlbev9P/954eNy 3qwDK7UvHlF0P39KHwy0ZhbEVOc0gwCGmMIkwy+6zD5qWgXugNb2X8FVQ3cilORZwWYv nvBnHbEdjNnrQCffc0r/ON0VAsfA2xIrb8BI94Ad8huNjpqmMlSoOFgwnULWOo/XDLnJ SZB32tPSRtJZNtW4vdsWqzpV1uBZtM1ekqO9dPvpqf/bWkunLKDzrFxp4EXsShr0CPg7 h12cgBwTe2wm15cRyYRW8eZAzHQJ8RvCCTaXX3Mb+NiR/ddMMdwO75G4rdev9V3W7K+O XfUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725531686; x=1726136486; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eWUmOKRHUFdWNzdh5pw1Ez/2T72/kqrXnIrfhfqLjOw=; b=iZTb6kOVQ2D12YhbBdB2qE1GhsAI6kxZb6LlVE6ctmA5f8STAKmIJhisuH9VM5XT5N Y1ks5devW3G4C3ReIQfZudcO7Ut7om1yllxAuQQceWf42h7S5MvctIHrq/KnGAyWPZbC uq7L1kpCH9/zDfDNB7V3rbgume/Pa1OollbV2iOGsS1OGJ8kwSmUTg1zA8fTPQLY/gtp l9Bcn4oUtiDSEigv/jARiNIT8vePv+fSWlf3eP9W5GA8+JDhnzF6tG2YZt+ezn79J3ZF xqpYnbwWugv1/6ulxWbtFqGjreD5M05rZqdDn0glfi5KogcdBznSMQUhtwHST0kfx9ZF Tuvg== X-Gm-Message-State: AOJu0YzQZG8nmTpYVvD7sWU+eSzfbpuB9Xt2Q4wGUlxdwgw+MJJBG/qJ NFZczupsDysJdcj8GmHId/zBzPNdzSoXO4o9OrC8HP/JXdAAv0+1 X-Google-Smtp-Source: AGHT+IE4tuR7i13hi7xoa6Z32tZC3aqE0CEUTpKvkNhLfuBTyGVZxY/7WThhqRCv/GWXoJeYnISRhA== X-Received: by 2002:a2e:a544:0:b0:2ef:2b06:e554 with SMTP id 38308e7fff4ca-2f626565176mr137523161fa.15.1725531685237; Thu, 05 Sep 2024 03:21:25 -0700 (PDT) Received: from ?IPV6:2a03:83e0:1126:4:eb:d0d0:c7fd:c82c? ([2620:10d:c092:500::5:decd]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3cc568559sm1031499a12.42.2024.09.05.03.21.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Sep 2024 03:21:24 -0700 (PDT) Message-ID: <1ffdf94d-ce3f-4dac-8ed3-0681f98beebf@gmail.com> Date: Thu, 5 Sep 2024 11:21:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 1/6] mm: free zapped tail pages when splitting isolated thp To: Hugh Dickins , Andrew Morton , Yu Zhao Cc: linux-mm@kvack.org, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, roman.gushchin@linux.dev, david@redhat.com, npache@redhat.com, baohua@kernel.org, ryan.roberts@arm.com, rppt@kernel.org, willy@infradead.org, cerasuolodomenico@gmail.com, ryncsn@gmail.com, corbet@lwn.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kernel-team@meta.com, Shuang Zhai References: <20240830100438.3623486-1-usamaarif642@gmail.com> <20240830100438.3623486-2-usamaarif642@gmail.com> <1d490ab5-5cf8-4c16-65d0-37a62999fcd5@google.com> Content-Language: en-US From: Usama Arif In-Reply-To: <1d490ab5-5cf8-4c16-65d0-37a62999fcd5@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: dq97hm5egzusgd9mbitkccng7sjsd4n1 X-Rspam-User: X-Rspamd-Queue-Id: E2C8414001F X-Rspamd-Server: rspam02 X-HE-Tag: 1725531687-580257 X-HE-Meta: U2FsdGVkX18e1yBYSuwgJDaJynp+jRymygdW3ofxi11Yb245KsENJ1djZbZ3sKYRw51LEaeMoJg8FmdlfzLbLpQ6iLUTFSPlCWMiUtXEexH+t2b0VVgoZ1yjq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pwZBmx9UUTZOj+js8g4bD/uu6cBHsHKnPnNBEkW5+7W3tK/9kMHteVu0R0LC57S0cFtSDLw/7uIeDCH6No/MArb6/CmdLNbGot9k2CQmne6KyInZ+Uq2knj2PE/EwWjrNJLO64d/64BnDA2S6lsr6Ne+AVqD4SPLe9WlC2GXt+ZxIBTa/fHeLz1eO2eh3WQwrsWxXKxvP82PImRGXECQ/aXjP43HgTppTURLLC8DoNYfo3jZwbu48LrVu9yRn9UfFA75b5lkUPQLhlcG1ZMwdaBTwqFGMJKMXRr630Ket2LBYywj9e3t88uaRg/fSIx0jvIvgttPFUMINZ7apTBLTaUMqYdbIAouAE 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: List-Subscribe: List-Unsubscribe: On 05/09/2024 09:46, Hugh Dickins wrote: > On Fri, 30 Aug 2024, Usama Arif wrote: > >> From: Yu Zhao >> >> If a tail page has only two references left, one inherited from the >> isolation of its head and the other from lru_add_page_tail() which we >> are about to drop, it means this tail page was concurrently zapped. >> Then we can safely free it and save page reclaim or migration the >> trouble of trying it. >> >> Signed-off-by: Yu Zhao >> Tested-by: Shuang Zhai >> Acked-by: Johannes Weiner >> Signed-off-by: Usama Arif > > I'm sorry, but I think this patch (just this 1/6) needs to be dropped: > it is only an optimization, and unless a persuasive performance case > can be made to extend it, it ought to go (perhaps revisited later). > I am ok for patch 1 only to be dropped. Patches 2-6 are not dependent on it. Its an optimization and underused shrinker doesn't depend on it. Its possible that folio->new_folio below might fix it? But if it doesn't, I can retry later on to make this work and resend it only if it alone shows a significant performance improvement. Thanks a lot for debugging this! and sorry it caused an issue. > The problem I kept hitting was that all my work, requiring compaction and > reclaim, got (killably) stuck in or repeatedly calling reclaim_throttle(): > because nr_isolated_anon had grown high - and remained high even when the > load had all been killed. > > Bisection led to the 2/6 (remap to shared zeropage), but I'd say this 1/6 > is the one to blame. I was intending to send this patch to "fix" it: > > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3295,6 +3295,8 @@ static void __split_huge_page(struct pag > folio_clear_active(new_folio); > folio_clear_unevictable(new_folio); > list_del(&new_folio->lru); > + node_stat_sub_folio(folio, NR_ISOLATED_ANON + > + folio_is_file_lru(folio)); Maybe this should have been below? (Notice the folio->new_folio) + node_stat_sub_folio(new_folio, NR_ISOLATED_ANON + + folio_is_file_lru(new_folio)); > if (!folio_batch_add(&free_folios, new_folio)) { > mem_cgroup_uncharge_folios(&free_folios); > free_unref_folios(&free_folios); > > And that ran nicely, until I terminated the run and did > grep nr_isolated /proc/sys/vm/stat_refresh /proc/vmstat > at the end: stat_refresh kindly left a pr_warn in dmesg to say > nr_isolated_anon -334013737 > > My patch is not good enough. IIUC, some split_huge_pagers (reclaim?) > know how many pages they isolated and decremented the stats by, and > increment by that same number at the end; whereas other split_huge_pagers > (migration?) decrement one by one as they go through the list afterwards. > > I've run out of time (I'm about to take a break): I gave up researching > who needs what, and was already feeling this optimization does too much > second guessing of what's needed (and its array of VM_WARN_ON_ONCE_FOLIOs > rather admits to that). > > And I don't think it's as simple as moving the node_stat_sub_folio() > into 2/6 where the zero pte is substituted: that would probably handle > the vast majority of cases, but aren't there others which pass the > folio_ref_freeze(new_folio, 2) test - the title's zapped tail pages, > or racily truncated now that the folio has been unlocked, for example? > > Hugh