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 2803AC3271E for ; Mon, 8 Jul 2024 21:51:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78B446B0095; Mon, 8 Jul 2024 17:50:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73AF86B0096; Mon, 8 Jul 2024 17:50:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DBAA6B0098; Mon, 8 Jul 2024 17:50:59 -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 3DB536B0095 for ; Mon, 8 Jul 2024 17:50:59 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D930C8154A for ; Mon, 8 Jul 2024 21:50:58 +0000 (UTC) X-FDA: 82317930996.22.18547CA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id BFB3740002 for ; Mon, 8 Jul 2024 21:50:56 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pko8UKW3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720475432; a=rsa-sha256; cv=none; b=BdY76Q67axDPSeC/o8D17FKWTOzVVGVH0u/ug1qz80NYYKblharnHKUi4s9ZZ9oqDmAqCw vqpKojQ30os0iYMwMD5KJm2yt1A+Ccs4g014erxizGi8NGx+Tic2q+MKroZq3snXjJumKi +s54JoFTzPiC1HBSN0w3y1eYQ2pg0Vk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pko8UKW3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720475432; 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=XseuSPGkDJ27OOmizeaAYkdaDU09mgUt9vN5WdBaaf0=; b=XSaKMeJyL1FhuJ01OwhAqxkuHhGA5K2HfNNVf4Fia1Y9Bi9jP7a07qgDr+gTBZwTlw1JIt HAYkmDKXno32+HHMFSuDPac8fMap6kMykLxKdF3bKUZNLWzPbvXnpET6SopWZp0kL2Z2Qp WsNrqBensYreTFUge+qO+kF1htIXYMU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720475456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XseuSPGkDJ27OOmizeaAYkdaDU09mgUt9vN5WdBaaf0=; b=Pko8UKW3oq9IBW32DWPjFE8shU+7xUzm8ndVIBQhdRKTbfP0R9eCc7Bs/HzvbxvSNc2FI8 VG2p9DKIk2EP/jEOautpuwLwFLx8rRV/EmM8+5nYFKLMHZTPwOwPev6h6l3g74s3dFdcQh Tc7qSbh5zdCrcY+y90bZL4u7/vYlbG8= Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-CukO_s0wMvG6YHfZUeBBQQ-1; Mon, 08 Jul 2024 17:50:54 -0400 X-MC-Unique: CukO_s0wMvG6YHfZUeBBQQ-1 Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-48fe91be9c8so299347137.3 for ; Mon, 08 Jul 2024 14:50:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720475454; x=1721080254; 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=XseuSPGkDJ27OOmizeaAYkdaDU09mgUt9vN5WdBaaf0=; b=QRQr8ZeJPPAhuYudZckEvpGVRvRd1zq0gU+ITL9HE/u0RLhN2Afd+Tk0wwPuP3DCN7 xXAPUS9U7AJuSO92hlEbufZzyDHBMbyeHf4ZSYewFLhnLw3p83W4pHQOfR9NzL9ZegCa U712/3o4TlsnVdi5/MrSfuSVSCveA0TG9nAzxR+x6Gl2Hk8jnBHY376kWB2PGl0qihJA IylJvjTwb4N6iFdDNj0lfhFgPcrkz7R99010t0K1jS35CV86ilEX16KB2E7zmJfI3AdH GUULvGKHQd88mznt4ZL44OywXcOqmkpGP4ZDu2LTzNqCc+/V2meoAsaEv63UbW/96yu8 AyPQ== X-Forwarded-Encrypted: i=1; AJvYcCVVz4e62A9N0efY9EoP+oWb0fjVbyeU75FBjWZEybsTqA3NQfk4q5epiGU7UPhkqP3Cob/ORp2qesP8QuyVVRoae8A= X-Gm-Message-State: AOJu0YzzP1qqUoQ8Ar3zBmrV50IgkNMjnDXz5+gTjnZEYBskgOvG4ajI aRIFJe81misuRQQPweL0wNQLQRYhwpl7ahQZOChuJBrQdUkutk5ifjr0RpCdSMRKcJGW3TkdnDh 69lyCBSBzLzoGNBCZPhsYzMwGdJKv5rd1Z+SPAox5Il9HtA33 X-Received: by 2002:a05:6102:549e:b0:48f:e729:f476 with SMTP id ada2fe7eead31-4903220c4c2mr771716137.2.1720475452865; Mon, 08 Jul 2024 14:50:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXeSjvMFB80yk4vNSDELW45skeRc2NPeBOJ3FpTQYCg15myh1f/p8d//jJWxYNCrhNEEK1vw== X-Received: by 2002:a05:6102:549e:b0:48f:e729:f476 with SMTP id ada2fe7eead31-4903220c4c2mr771706137.2.1720475452543; Mon, 08 Jul 2024 14:50:52 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-447f9b522fesm3533721cf.51.2024.07.08.14.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 14:50:51 -0700 (PDT) Date: Mon, 8 Jul 2024 17:50:49 -0400 From: Peter Xu To: Zi Yan Cc: Hugh Dickins , Andrew Morton , Baolin Wang , Huang Ying , David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH hotfix] mm/migrate: fix kernel BUG at mm/compaction.c:2761! Message-ID: References: <46c948b4-4dd8-6e03-4c7b-ce4e81cfa536@google.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BFB3740002 X-Stat-Signature: t7cqweuskcy1jr7kxchsxde1z4f4fhic X-Rspam-User: X-HE-Tag: 1720475456-279247 X-HE-Meta: U2FsdGVkX19SO9C9xugd7D+aE78MU/S3hT6hxhV6K1tY+/HENagdiEs4xkdcPt04x3LFgZq2rRbY9poE/X4hOm6JaPpZY14F6hHi7UlHKYg0sR2wXnhtBZXXqILsdZpRDXg831woO1kkX0af6HrRT/h8BrfPLJ2GUR0Dz6fzyyLsnbDqLUUYfMBdA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s79SNmDO7ectqZXX02+ekEov2b4Yz+yHXBWDK5romHsE/IOv0I/QDeWcGz0TMk9rLexOr1UXYC0WlSIATexial6HGyPTOP/FzSywH/sXiARbgFaY4ZxjDj1jJ6Y0VrUxmVs 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 Mon, Jul 08, 2024 at 12:39:10PM -0400, Zi Yan wrote: > On 8 Jul 2024, at 11:52, Peter Xu wrote: > > > On Tue, Jun 11, 2024 at 10:06:20PM -0700, Hugh Dickins wrote: > >> I hit the VM_BUG_ON(!list_empty(&cc->migratepages)) in compact_zone(); > >> and if DEBUG_VM were off, then pages would be lost on a local list. > >> > >> Our convention is that if migrate_pages() reports complete success (0), > >> then the migratepages list will be empty; but if it reports an error or > >> some pages remaining, then its caller must putback_movable_pages(). > >> > >> There's a new case in which migrate_pages() has been reporting complete > >> success, but returning with pages left on the migratepages list: when > >> migrate_pages_batch() successfully split a folio on the deferred list, > >> but then the "Failure isn't counted" call does not dispose of them all. > >> > >> Since that block is expecting the large folio to have been counted as 1 > >> failure already, and since the return code is later adjusted to success > >> whenever the returned list is found empty, the simple way to fix this > >> safely is to count splitting the deferred folio as "a failure". > >> > >> Fixes: 7262f208ca68 ("mm/migrate: split source folio if it is on deferred split list") > >> Signed-off-by: Hugh Dickins > >> --- > >> A hotfix to 6.10-rc, not needed for stable. > >> > >> mm/migrate.c | 8 +++++++- > >> 1 file changed, 7 insertions(+), 1 deletion(-) > >> > >> --- a/mm/migrate.c > >> +++ b/mm/migrate.c > >> @@ -1654,7 +1654,12 @@ static int migrate_pages_batch(struct list_head *from, > >> > >> /* > >> * The rare folio on the deferred split list should > >> - * be split now. It should not count as a failure. > >> + * be split now. It should not count as a failure: > >> + * but increment nr_failed because, without doing so, > >> + * migrate_pages() may report success with (split but > >> + * unmigrated) pages still on its fromlist; whereas it > >> + * always reports success when its fromlist is empty. > >> + * > >> * Only check it without removing it from the list. > >> * Since the folio can be on deferred_split_scan() > >> * local list and removing it can cause the local list > >> @@ -1669,6 +1674,7 @@ static int migrate_pages_batch(struct list_head *from, > >> if (nr_pages > 2 && > >> !list_empty(&folio->_deferred_list)) { > >> if (try_split_folio(folio, split_folios) == 0) { > >> + nr_failed++; > >> stats->nr_thp_split += is_thp; > >> stats->nr_split++; > >> continue; > >> -- > >> 2.35.3 > >> > >> > > > > We probably hit the same issue in our testbeds, but in the other > > migrate_misplaced_folio() path, which contains the BUG_ON() rather than > > VM_BUG_ON(). Looks like this patch can also fix that. > > > > When looking at that, I wonder whether we overlooked one more spot where we > > mostly always use putback_movable_pages() for migrate failures, but didn't > > in migrate_misplaced_folio(). I feel like it was overlooked but want to > > check with all of you here, as I do think the folio can already be split > > when reaching here too. So I wonder whether below would make sense as a fix > > from that POV. > > > > ===8<=== > > diff --git a/mm/migrate.c b/mm/migrate.c > > index e10d2445fbd8..20da2595527a 100644 > > --- a/mm/migrate.c > > +++ b/mm/migrate.c > > @@ -2615,14 +2615,8 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, > > nr_remaining = migrate_pages(&migratepages, alloc_misplaced_dst_folio, > > NULL, node, MIGRATE_ASYNC, > > MR_NUMA_MISPLACED, &nr_succeeded); > > - if (nr_remaining) { > > - if (!list_empty(&migratepages)) { > > - list_del(&folio->lru); > > - node_stat_mod_folio(folio, NR_ISOLATED_ANON + > > - folio_is_file_lru(folio), -nr_pages); > > - folio_putback_lru(folio); > > - } > > - } > > + if (nr_remaining && !list_empty(&migratepages)) > > + putback_movable_pages(&migratepages); > > if (nr_succeeded) { > > count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded); > > if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node)) > > ===8<=== > > If the original folio is large and split without migrating all subpages, > not migrated sub pages will be left on migratepages list. list_del(&folio->lru) > can remove the first subpage from a wrong list, if it is migrated, and loses > the rest. It is not a problem before, since MR_NUMA_MISPLACED prevents the > folio from being split. > > The fix looks good to me. Thanks, Zi. Let me send a formal patch then. -- Peter Xu