Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1026648lql; Tue, 12 Mar 2024 05:34:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqe181J2DGHcw7hxRAzEs92mHZJ+ouema0mIrrsKqrF+Hn9N7JDvkdDOzbhDjQ1lXi31pdgO1hwLqOqkJQ3gdVbo1gjLAOwe7hgqM4PA== X-Google-Smtp-Source: AGHT+IEtXgd4DOWocriyWr2u6DKFujgY0DRM9Yl79gcYYD539NBTpN/xe2dUnzYumKjZh1O/Ocbf X-Received: by 2002:a2e:928c:0:b0:2d2:2ddb:28c7 with SMTP id d12-20020a2e928c000000b002d22ddb28c7mr5911133ljh.26.1710246886092; Tue, 12 Mar 2024 05:34:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710246886; cv=pass; d=google.com; s=arc-20160816; b=l7bFwpG7gTGYVs52Fp3TtcrErWbsg0HqDM3WVZvvcHy8geIXUzCKDWhdDdzgBqQJmr YIVn8MW/i2Gp9kL2eZayvHnw4Rj7vNlCPw5OxGzxpjbHGcFJlHaild8xZgIxBDSkyL35 aRGa2eoXg/rm42/eF6zGFNTZDhdu1UUp/o7iuVfLSTAjroVx4DS8fApntuUlL9wuD/aO LfpMRDTSW3JV+865obxIZ3X6eWJpTLABQaS3uUMVbmHsEQ+mGxpnseXl9+NFWf7uWu5Y hX0xuXTgXPsQc6YGsKGWOOLSGO5P7aTpwTzqqICiG0kdg5OLjkYTq3hnbPWy1kxHWSwH F6uQ== 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=OfWFuv8p5fTBu2yY135tF1HCs/abpLQ+AkJc7p2Kckc=; fh=OI1RqaAYI3PSwUa1oCQoPGsdNAZUiS2No1UCAmGzcxw=; b=r8VzqczzlXCI0GIwR3jLCO+COxOywQjjFaxCdzvLKz2ArYN6amdhH2mYS4odCxaUNl aZl16rJjxw5GIH0YsaMJG11FBSuYddsF/Os8uFadDmJB2P1t66dhVd4tjr2AjjpNd+QG nGHChziMJHf0nhLjMYvWmjFOotwEi52N9LITmWeUhNwpBn/I3P9gHuXYrEoDuFkzt2Yc TrUFlrabY8t9dj1pV3uiAWvUbjUSMrnYiJ6jL3iEWTehPbSuZVxnEMtanuFN2h4EVdIm reeZ0CMfUPRWjQjX/uAfIwIaReI9ArzlHHKVuUwaYZ//MgN7vdqps0itrUj+q/vQxM5F eJeg==; 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-100262-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100262-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y7-20020a056402270700b005683378c0d0si3469503edd.22.2024.03.12.05.34.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 05:34:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100262-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-100262-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100262-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 B9B261F23C98 for ; Tue, 12 Mar 2024 12:34:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00E354D9EF; Tue, 12 Mar 2024 12:34:39 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E66C9811 for ; Tue, 12 Mar 2024 12:34:35 +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=1710246878; cv=none; b=FASWBru8JyGP7XN5WqLLUAue4oT42lGebqs13HvJn89qCe4AEtkPWJgmcQqAIxfRUZviy9jAOOcP3ELLJ9RPF2xPN5wphy/25GzANaQ9ggn45e7/xGTAMl6Bpo7PJmhl91HSfhv7W7dM7BI7+ETix/S6SWdq0cwmvJxpVWVVs0U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710246878; c=relaxed/simple; bh=00ALwGCpmxxMsJj+o8wyLH2RHkjByrRU74ql53w1Eug=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LGNQ15SzjGQHGPKlO4GJDhmVoUoIkwunTUMlFk5dXW2ZfjdFU5iirOEq0XOjxSqRyei+Gc4aIVo7cVImmtdmqZpFCvKlONRItahnT/hJ0XUMLVhihx74KdCwthZo9cyIR+YBY8/Ba6B9pwkvI0mAN9dJLkB2Y8F5ANZJcf9I1qk= 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 2FB4D1007; Tue, 12 Mar 2024 05:35:12 -0700 (PDT) Received: from [10.1.27.122] (XHFQ2J9959.cambridge.arm.com [10.1.27.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 696043F73F; Tue, 12 Mar 2024 05:34:29 -0700 (PDT) Message-ID: Date: Tue, 12 Mar 2024 12:34:27 +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: [RFC PATCH v3 3/5] mm: swap: make should_try_to_free_swap() support large-folio Content-Language: en-GB To: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: chengming.zhou@linux.dev, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, kasong@tencent.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mhocko@suse.com, nphamcs@gmail.com, shy828301@gmail.com, steven.price@arm.com, surenb@google.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, Chuanhua Han , Barry Song References: <20240304081348.197341-1-21cnbao@gmail.com> <20240304081348.197341-4-21cnbao@gmail.com> From: Ryan Roberts In-Reply-To: <20240304081348.197341-4-21cnbao@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 04/03/2024 08:13, Barry Song wrote: > From: Chuanhua Han > > should_try_to_free_swap() works with an assumption that swap-in is always done > at normal page granularity, aka, folio_nr_pages = 1. To support large folio > swap-in, this patch removes the assumption. > > Signed-off-by: Chuanhua Han > Co-developed-by: Barry Song > Signed-off-by: Barry Song > Acked-by: Chris Li > --- > mm/memory.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/memory.c b/mm/memory.c > index abd4f33d62c9..e0d34d705e07 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3837,7 +3837,7 @@ static inline bool should_try_to_free_swap(struct folio *folio, > * reference only in case it's likely that we'll be the exlusive user. > */ > return (fault_flags & FAULT_FLAG_WRITE) && !folio_test_ksm(folio) && > - folio_ref_count(folio) == 2; > + folio_ref_count(folio) == (1 + folio_nr_pages(folio)); I don't think this is correct; one reference has just been added to the folio in do_swap_page(), either by getting from swapcache (swap_cache_get_folio()) or by allocating. If it came from the swapcache, it could be a large folio, because we swapped out a large folio and never removed it from swapcache. But in that case, others may have partially mapped it, so the refcount could legitimately equal the number of pages while still not being exclusively mapped. I'm guessing this logic is trying to estimate when we are likely exclusive so that we remove from swapcache (release ref) and can then reuse rather than CoW the folio? The main CoW path currently CoWs page-by-page even for large folios, and with Barry's recent patch, even the last page gets copied. So not sure what this change is really trying to achieve? > } > > static vm_fault_t pte_marker_clear(struct vm_fault *vmf)