Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp160469rdb; Sun, 28 Jan 2024 19:25:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IExQ1qHqTG1bHcBnoOLOHho5iKT+octu6DpkoJWGRkoB2+FSLVdmjRc7YNTxtYpNBYSUigR X-Received: by 2002:a17:902:ce91:b0:1d5:f0da:625a with SMTP id f17-20020a170902ce9100b001d5f0da625amr5639006plg.7.1706498745618; Sun, 28 Jan 2024 19:25:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706498745; cv=pass; d=google.com; s=arc-20160816; b=ExkKH4mK5tlh4ocuILSy7A37HzqYX+jeLpnHWF3QxfaFDhtasBAU+EGpaRNEs1xJDN u0PLeLgfBDn38JciqIwQMMpzaWU+aFy2jXJFuPTd5PePyGoxdYZef57Z1yafPqKz8bjG ilITbNSorr6QWRwCrA93+hj+XaIfYZfGj/WSqv90h7cSKJrffNQDZHEv/PlDEDK0aTx+ 87CvzR4gF3Yw7Tckp9FZl3rn5rkq0KeA3KluWfbNjs/NqYwwwOoB63o4WmOBPo1DZgT7 9kKR5TJuiM1IqkvfZMTnW9kXnEnHr8mPXebPocDOtwrjYVB0ns7EC/nYXdeAs8qtHwJw sydQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=tMf/u4nUvTcp7DalQlyr/FBsJctfVs+/SEKhoDWCN+M=; fh=GOJue2xJW1zRmFXI1bdabYwFY54pftDVl+QyXujC4Zw=; b=OcJiDXEtpdYBr/pd6q2cGSFwx9SxKUfasPKBW0jC1kSANV56Bst03H3iaEmsdmI+2n 4AQ+7PzbKt3lfS8Kd49+DNNRPO9g2ba5EDLI36b4GMtoiVzYi3QnNETAacd+TS7poDFo I1B+h1A4+SELsUJUsxxkLJEm3ejZLbCxh9KyD22CSleqHBpycfgS6k1YSXUpdhOolkdR caBpkaGHp9WW7RVPQBNl9tGZI9JeWMkgcCnYKaw25/vAjOL+Z7JyUF2PecCRuOmdsPS7 r9jIOgbAZ0WWpQWLpCG1Ax7497M2LhlT+1ClrtD/jEM43cpJEW0Ng7/2KkOLWIyvPltK azkA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YUElTykJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-42121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d8-20020a170902728800b001d75b637d4esi4812930pll.184.2024.01.28.19.25.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 19:25:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YUElTykJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-42121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 43C1A28381A for ; Mon, 29 Jan 2024 03:25:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34F5211C94; Mon, 29 Jan 2024 03:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YUElTykJ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40A3BFC02 for ; Mon, 29 Jan 2024 03:25:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706498724; cv=none; b=FTs1644YTWTroWJos16SavqVsCcSQgVVAEGRDRO92Q+O/rfzq+XpWXo3WnweEK/QtbXGJs1c/ytYeNb0aBqlh6KlC0SE0IedPosVJA169MZ2gwGcZZgCtjax0/6Agf+wGvjxFID7TMa/3AZi7mJkUc4Zku8NJtU0SaoRiLowGeY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706498724; c=relaxed/simple; bh=IScpMroxh2pczHI5A0NNatcLDAXs5qdNngeznddEdd0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=WaU8HjVSoOKAvRvvyx2lUU0PPFms7Tam9hkZ9U4ItyBno7IU2TvGU0gJGCe5rx3T/FPJumluUZ3EyJA/B78jTv1WC8IpvtS0pZWT8qCvBSkNcuJwBg8HNaP5x/+XxWZVj8sRnniRKD/mSfHOtZMjVFVkGvW7FjgLsDLUSJ0oqqI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YUElTykJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0C31C433F1 for ; Mon, 29 Jan 2024 03:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706498723; bh=IScpMroxh2pczHI5A0NNatcLDAXs5qdNngeznddEdd0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YUElTykJFQHY+VK4+A+vYB3ivUaqsXLWW++gXr/K6I5Xb2J1qGqeBgrtg7jFyENcg SHT0+WeH45jENJYumrg5D+VempeYzdlIGLVkU6H1pH3qTQ2V7zeLNuGNWvXnXPk9lK K7ironnh2qYeu/iDqMKqKvBXrWVG/66XAUZ7VTXaN5KashA+RMcf1pytJADaNKDoXp vIJXFe/QloyriACuYwbf3QhYpAIEuywRDLKWx9drF182SKZ9wnJEBETN82CFTR9AMg ISr3Q5S9EgEpEeLgiUHDwSuZagFZUT9E4aK8sjHIX9OocTtDniNoKTjHYIMV5kr/Gn c6V/xFpKkL7jQ== Received: by mail-io1-f46.google.com with SMTP id ca18e2360f4ac-7baa8097064so131431139f.3 for ; Sun, 28 Jan 2024 19:25:23 -0800 (PST) X-Gm-Message-State: AOJu0YzMLoeHRnEx0sGWB6Ry7YolvsGGMHu0xqww6Dw285KHCU36/no1 RIdJfISQDaoNh6Ss5ZxBec8p9cnbEu9jtFFBlBcSVbLF7mzRUoyfMy/3IyaGQyMxDc65Nto+tzO fC3gYw9BlaD3oxdMSK+QhRqfynpX6dyULUrCv X-Received: by 2002:a92:a305:0:b0:361:923e:ec48 with SMTP id a5-20020a92a305000000b00361923eec48mr5038339ili.8.1706498723104; Sun, 28 Jan 2024 19:25:23 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231025144546.577640-1-ryan.roberts@arm.com> <20240118111036.72641-1-21cnbao@gmail.com> <20240118111036.72641-6-21cnbao@gmail.com> <58efd8d4-28aa-45d6-b384-7463568b24bb@redhat.com> In-Reply-To: From: Chris Li Date: Sun, 28 Jan 2024 19:25:11 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC 5/6] mm: rmap: weaken the WARN_ON in __folio_add_anon_rmap() To: Barry Song <21cnbao@gmail.com> Cc: David Hildenbrand , ryan.roberts@arm.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, mhocko@suse.com, shy828301@gmail.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com, surenb@google.com, steven.price@arm.com, Barry Song , Chuanhua Han Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi David and Barry, On Mon, Jan 22, 2024 at 10:49=E2=80=AFPM Barry Song <21cnbao@gmail.com> wro= te: > > > > > > > I have on my todo list to move all that !anon handling out of > > folio_add_anon_rmap_ptes(), and instead make swapin code call add > > folio_add_new_anon_rmap(), where we'll have to pass an exclusive flag > > then (-> whole new folio exclusive). > > > > That's the cleaner approach. > > > > one tricky thing is that sometimes it is hard to know who is the first > one to add rmap and thus should > call folio_add_new_anon_rmap. > especially when we want to support swapin_readahead(), the one who > allocated large filio might not > be that one who firstly does rmap. I think Barry has a point. Two tasks might race to swap in the folio then race to perform the rmap. folio_add_new_anon_rmap() should only call a folio that is absolutely "new", not shared. The sharing in swap cache disqualifies that condition. > is it an acceptable way to do the below in do_swap_page? > if (!folio_test_anon(folio)) > folio_add_new_anon_rmap() > else > folio_add_anon_rmap_ptes() I am curious to know the answer as well. BTW, that test might have a race as well. By the time the task got !anon result, this result might get changed by another task. We need to make sure in the caller context this race can't happen. Otherwise we can't do the above safely. Chris.