Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp903765lql; Tue, 12 Mar 2024 01:05:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5cHgZWhdaIEyz3z1ZMa0zWInPMOo5q8fclvFoYHpaN+6dyZaMvnJE5CcYn34qFS5JmMh8zmlsMo0o2gpcjb1rkHg/ewIus/6mCur45Q== X-Google-Smtp-Source: AGHT+IEG+lX/AFcG7Ak6nAgaroiboAe/MAjqlm8ZiFBuHvK0WZFFivmX5X0itENkV5oHMOZbyTQe X-Received: by 2002:a17:907:c28b:b0:a46:bb:c4e3 with SMTP id tk11-20020a170907c28b00b00a4600bbc4e3mr7008762ejc.32.1710230752850; Tue, 12 Mar 2024 01:05:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710230752; cv=pass; d=google.com; s=arc-20160816; b=Srh1jg/2jofWJVs9JtPYquvHXfBNyRolFbTjAm4weCsapsM5k6zP9/Yq8IaqOEaHNb n/sT2/oeFLeM1FHQBRcCEU+RCggEz8ShNnHLOF92AeSPUzZLVF84UQa4rQsi7CMhCpvZ kYs1+9krl7h1CiLf8w2SADJJdCHyPmflaPSTaJ99QVNNYDGtnBFNJmljxTBSD5Ge7y6j ej+MlCoEjkqt8N0HOoHTfeHFEjTFPXjeITeYUHegMpYxi05vwTk/Tvuoghxqw6ySZvpY 6MWmT5qo6WwKByvMxC7yI4qAXDbfUE3nqwmXolpZfhMb7FPnyTxnZ+fF0Xr0/16GLs7v k12g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=3la+RgFRQCEZJDbO+LEbYTNiK8j89mtj/7odjb1o3Ts=; fh=TYdGCVl6pmgh3i6mvbY0+ugFOAP7N7LmZqYUyCSH0OQ=; b=dCcQAfa0E7pzRnKRM+D3Cv4cUSj2DLWzo2vpHxKnV1cDXBNtY15+fEhUIYaUS2eyxl MmKyvH5HYZch8Z7d6paEiOsOYsvvoMdUTtpjGteZwsWL8MfGo9CRSXXKH8Q2gJhpdqn+ b27vQRT/grwI6h6nlgHMjJDqq8qZT1PJbfARhh8RuleJ00aMPvlOsQ/HJBCgUBuczjum KgebnRpoykedRaz65tfEcl11XUiAfOLWh0E2H4FTVFvaUzQ4G5fnDv1pIIShs5v1BJ9d tjlNALnQIcsHG3mOQA56fSSgZA9b/qmY78qD6chlYHM/iFH78MMVV5MYZ8XunQMsQsQj 66bA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-99937-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99937-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ht20-20020a170907609400b00a45ff8278cesi3216459ejc.317.2024.03.12.01.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 01:05:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99937-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-99937-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99937-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8F19D1F2260E for ; Tue, 12 Mar 2024 08:05:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B1D769DE6; Tue, 12 Mar 2024 08:05:30 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B00569973 for ; Tue, 12 Mar 2024 08:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710230729; cv=none; b=TvgoxQTWTmIN6cf49HFwxXGnPIe489DlRDhxzFz4ixYlKF1n7EfqBJW/DX6BuPMoHUTDKtHfeV5OlcmnLaMmT8PVPDyoQyzCCXM3lR77ZyKwc3dpU4/oDxDBCT5ZCnstdSt2aD/4/gA0u/sq17gWx6YJy6f7O5YMUNoscy8dBgU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710230729; c=relaxed/simple; bh=bl6AfL2X8NIjP+96i5PQItkn9CCWuVzDqSvid1nmuvo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Nx3VIINUpcCnfSZUm0YDQMxYp+UD7MwqX/rMY2STHUapz2VJTg8XlOqlc7IzH6ZxFTI+akwkeZDfoR5yzOco3rfCCiY4PR6nu6i8/F+a0cTMGr2VPppMgizYLWsSPw0qXE1Wm57LZHwOVr8WCVTGSsoBf4u/pFaMBLnYzzTZpMU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 82A041007; Tue, 12 Mar 2024 01:06:03 -0700 (PDT) Received: from [10.57.68.246] (unknown [10.57.68.246]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC8433F73F; Tue, 12 Mar 2024 01:05:24 -0700 (PDT) Message-ID: Date: Tue, 12 Mar 2024 08:05:23 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/migrate: put dest folio on deferred split list if source was there. Content-Language: en-GB To: Matthew Wilcox , Zi Yan Cc: linux-mm@kvack.org, Andrew Morton , Yang Shi , Huang Ying , "Kirill A . Shutemov" , linux-kernel@vger.kernel.org References: <20240311195848.135067-1-zi.yan@sent.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/03/2024 03:45, Matthew Wilcox wrote: > On Mon, Mar 11, 2024 at 03:58:48PM -0400, Zi Yan wrote: >> @@ -1168,6 +1172,17 @@ static int migrate_folio_unmap(new_folio_t get_new_folio, >> folio_lock(src); >> } >> locked = true; >> + if (folio_test_large_rmappable(src) && I think you also need to check that the order > 1, now that we support order-1 pagecache folios? _deferred_list only exists if order > 1. >> + !list_empty(&src->_deferred_list)) { >> + struct deferred_split *ds_queue = get_deferred_split_queue(src); >> + >> + spin_lock(&ds_queue->split_queue_lock); >> + ds_queue->split_queue_len--; >> + list_del_init(&src->_deferred_list); >> + spin_unlock(&ds_queue->split_queue_lock); >> + old_page_state |= PAGE_WAS_ON_DEFERRED_LIST; >> + } > > I have a few problems with this ... > > Trivial: your whitespace is utterly broken. You can't use a single tab > for both indicating control flow change and for line-too-long. > > Slightly more important: You're checking list_empty outside the lock > (which is fine in order to avoid unnecessarily acquiring the lock), > but you need to re-check it inside the lock in case of a race. And you > didn't mark it as data_race(), so KMSAN will whinge. I've seen data_race() used around list_empty() without the lock held inconsistently (see deferred_split_folio()). What are the rules? Given that we are not doing a memory access here, I don't really understand why it is needed? list_empty() uses READ_ONCE() which I thought would be sufficient? (I've just added a similar lockless check in my swap-out series - will add data_race() if needed, but previously concluded it's not). > > Much more important: You're doing this with a positive refcount, which > breaks the (undocumented) logic in deferred_split_scan() that a folio > with a positive refcount will not be removed from the list. > > Maximally important: Wer shouldn't be doing any of this! This folio is > on the deferred split list. We shouldn't be migrating it as a single > entity; we should be splitting it now that we're in a context where we > can do the right thing and split it. Documentation/mm/transhuge.rst > is clear that we don't split it straight away due to locking context. > Splitting it on migration is clearly the right thing to do. > > If splitting fails, we should just fail the migration; splitting fails > due to excess references, and if the source folio has excess references, > then migration would fail too. This comment makes me wonder what we do in split_huge_page_to_list_to_order() if the target order is greater than 1 and the input folio is on the deferred split list. Looks like we currently just remove it from the deferred list. Is there a case for putting any output folios that are still partially mapped back on the deferred list, or splitting them to a lower order such that all output folios are fully mapped, and all unmapped portions are freed?