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 D477BC3DA42 for ; Mon, 8 Jul 2024 15:52:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14DA56B0083; Mon, 8 Jul 2024 11:52:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FEA96B0088; Mon, 8 Jul 2024 11:52:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F07576B0089; Mon, 8 Jul 2024 11:52:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D25F46B0083 for ; Mon, 8 Jul 2024 11:52:52 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8905A161381 for ; Mon, 8 Jul 2024 15:52:52 +0000 (UTC) X-FDA: 82317028584.04.5D32B29 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 671741C0020 for ; Mon, 8 Jul 2024 15:52:50 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KDsIjmFx; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720453955; a=rsa-sha256; cv=none; b=Xo34UXmKga/acssNC2hYt9dKppWCmoe3rVOJ8PGX/NLT7UDHnrNzODLR4riAoVFbtT73Hd HhsOoSd1CJqG0zdMndccmHVIWTFqGUKpstFMKY0jw77HFbazHReBMpncIfVAuK7/bwHaUG XJelgm2qIYYw66Shp1YvVZOO9CW0jFo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KDsIjmFx; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720453955; 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=M2Sg9CEez3gjaYBTMUNi2YCXwhQIdNlwaBOWlbCwoa8=; b=VFQdicunQKrUMG7pmyBphirgDFPy681zv0yAcFCSDTSUPVVN2lFqzJRs6mwoJkRvISpbNg eKWPkQG8f3gjlB9h0zZxfV23cCoUwTrxA8OQtaezb7fo/luIY6QNprUDZ2NZtkRu6RDk4V DAFVAq64oEQw+8sQ8XDyoQ69ME9bq6U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720453969; 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=M2Sg9CEez3gjaYBTMUNi2YCXwhQIdNlwaBOWlbCwoa8=; b=KDsIjmFx6eO835TODDNhSdE9Z+fQ6Il15cAG1ZUdgNDrPTFEXDshXWhlhN96ncG8AwT83Q AznL+W8nPnfNtAYyYwIdEeKt2z181M+rvox3o03uFPLZP87s0/pgOSDsKHhZRa528mXRvf ZNDz/Sj82kYgpgj0CM8bf1N/JOc2GJY= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-414-LR6tX5cWOLqqMqCmePRONQ-1; Mon, 08 Jul 2024 11:52:48 -0400 X-MC-Unique: LR6tX5cWOLqqMqCmePRONQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4401522c6bdso12977411cf.3 for ; Mon, 08 Jul 2024 08:52:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720453967; x=1721058767; 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=M2Sg9CEez3gjaYBTMUNi2YCXwhQIdNlwaBOWlbCwoa8=; b=gnd+pmKPrltH0quxiPJ1g/bhwsU/mWNhuwphg25URndDUI5vdJwVfsO9nCw61qmlcQ 9C3p/4I7TYY3GePiagTxmfwaMtOrlAyRQgbva8ftPjdKWCUdAEEUl7uqqFjhhZAq0vnU LrtKNfHd81587bP5/KJ2xS1EtNVn0wjNipvSolofx4xSmyRXmm3IUCJCZy7QyTMj+EO9 YoGPRq+NDS8cGu5tFPXb0TSDCsn/NOyvRdsSM0rxGBuWgQtF7rWPPdsuEqeu+pNX3mbE 8RngU9auwkL8R8+Igd5T+GJJ+oYEBZ7uqvUBblQ2wwCVNHKPXAyIdjd/ZuJkSY+9FOad nzNQ== X-Forwarded-Encrypted: i=1; AJvYcCWs/GtnWT1TtXw9jJpoV3wOALy68ZJYqgykPAzhlSWMtdwg41nKxCa/vTo4+alXDksoxM+cqq0QVfdZoC0g1byP52I= X-Gm-Message-State: AOJu0YwGRuPYXZglmDB2WDP9PBtDlosTt6rKe+ZaVdktHzb/n33Hvs5Z LBdIkPk8BmY5YG5UA5qrxkciBNIjZoEYQkbCfFRs7U/W9hAPFp9Qfz2OhWzJGNsA5Lq0TS1Ll+L bDSadUl/TqgUvcfmrdnKjwk1H85et5SnEMDBMktNC3i2jZYoW X-Received: by 2002:a05:620a:1672:b0:79f:b3c:8fc3 with SMTP id af79cd13be357-79f18e74aa6mr22269485a.6.1720453967566; Mon, 08 Jul 2024 08:52:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyZ9rFiyVy3FxagC7QeMggWqoGK9K/UirLGruKJgLNuoV6vF78PyN78d3WeFBTK0cnPnn78g== X-Received: by 2002:a05:620a:1672:b0:79f:b3c:8fc3 with SMTP id af79cd13be357-79f18e74aa6mr22267885a.6.1720453967244; Mon, 08 Jul 2024 08:52:47 -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 af79cd13be357-79f1902ac12sm3761085a.61.2024.07.08.08.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 08:52:46 -0700 (PDT) Date: Mon, 8 Jul 2024 11:52:44 -0400 From: Peter Xu To: Hugh Dickins Cc: Andrew Morton , Zi Yan , 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: <46c948b4-4dd8-6e03-4c7b-ce4e81cfa536@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Stat-Signature: 8n63i5bife4rqbgoiedrfkzj6z7tdszk X-Rspamd-Queue-Id: 671741C0020 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720453970-3525 X-HE-Meta: U2FsdGVkX19djod41C+u2CfECkGiJKuCxezcoI3b8faCPIy+IM7XB4CfA1eO6ox3k+dOAAu4cGE9WdD+SBYq/YLUfIyNyyWx+DcvZKbMVMefPyT7n11+EdmezbDFrdFLFMniXA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nIEwPkv6tGmhuZAX+9FEaAM/L2CKmD2SXQbHlJAw6/rBnVSa35c7102PTm/L5xlVTs8GlDqXWNatBG9yvmAXjpNEDUHcMQUE5cfJwNeu0C5Qp1FJVHxBbCJiOW3t+arQePFIBQHi3LUJcZm53W2Cp58h31KHRM97PvjKm/oAlpgVXe7yqOlpbKWUzUArg 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 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<=== Thanks, -- Peter Xu