Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp479490rdb; Sat, 27 Jan 2024 15:42:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyrf/ay+J4xXE/YfvCmPK5nrgislzGjUS/xv2lQ5DCWQZjnxCecrZpHMP1fOZ4MZbi4sm6 X-Received: by 2002:a05:6808:1393:b0:3bd:9d97:42ca with SMTP id c19-20020a056808139300b003bd9d9742camr3168042oiw.51.1706398930241; Sat, 27 Jan 2024 15:42:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706398930; cv=pass; d=google.com; s=arc-20160816; b=FKd6COCTZMUDMu1s5Wq3GScksedtu7GgYcnh9YtwhnVv8YOl6BUIe52KPtHHMnqH+K 2fdabZkH9wMyuvkHSbkuH6PPJoLEQxLFAM96T9tq0xJugyH1w6Uty6Uc2CX0V8ScMNrp x+L75d541awCiAfbktxDkt49y1lAyH3OWUlZdoz5GJJveWqX61iX0zVHVqEohCDQhAbW oxKgHbXSnTRqaasLKbJI5+AjgSD81b9siUOlXcJ1xHWX5xXN6KJJenU75Io1XHWX28o8 g9h2phjMNO74ta7Uw6rGQh4FszsrJEDakfnFgg+Nm+l5Fa7wyjvQpio3lRjo2w13Swzz q/9w== 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=NIPQNShO98+hVb/X4Z8D6Rhr7gPLRVT3mMbI3BiEksA=; fh=Tv037mbbtQXa+MfA4YgRdJGUIXs5z9DEoSQXTn3DpTs=; b=chkmYqjPIY3zleEaiRp/t12n4rTvWvzlu7mmZAO2DwzW2xGzFFQzDFn/VsDi2TBC3f ANQHxKz/G/hIyG5DennlmLHQhYwb8sdqTXg/RvycdU2Hb+aB/RfRJhJu5ooqQ4wPBrPb ONCEOovwGzpSexXsDr0fnobL03421O/Q9nUmImRU6bPaRoFGsEOsAdppfzTRiRN1DIXc XP331Zoi+oRQY+kI5ylFNzZ7lgDxDF+dyVfXcbREETvyuyxq0Bh4Y9L+wlDfuoEqiUFh UsAb1VHhlKdhYUBBd6b0gZsKze/CnaCKIW33Ni1no3YDvt9eHUaVzlK3Z8rKLvODE1+3 w8bQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RMCoWS7R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41465-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41465-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id jb10-20020a170903258a00b001d716a2b77bsi3345266plb.71.2024.01.27.15.42.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 15:42:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41465-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RMCoWS7R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41465-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41465-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 62B54B2162F for ; Sat, 27 Jan 2024 23:42:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A825F2374A; Sat, 27 Jan 2024 23:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RMCoWS7R" 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 C8DC822F0F for ; Sat, 27 Jan 2024 23:42:03 +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=1706398923; cv=none; b=L2w2IH0lSasoZKufl4LyFzcGfXMpJlUGO1vABMONVVdnN1t2odMxmigw825vvVF0C3WUNuRNRsQCDFmq4q1tn363NWm4UKGCx+mKCa7+sv8bdsdtcPjnCzF52GORMx5XBs3pcTbrugbvNSTMvv2vy202yxklwo4KcS7+Pddr2Qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706398923; c=relaxed/simple; bh=aLwsjk+yqZJ8iDmZN++A6YSY8VPjmsd8uJByyE+0yic=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=TTmeN3mQcCBxOh5uUjW67BoUiR8YmZ+12g58g9z9SdMrC5/niGIsSgfY0uaBntwnP1pQO3LYNwreKVETZLJd6VIt3T//asHixTmCVurCTo6LGLBoQ9tCQ8tv3e+0JwUQ8vQhp4bdxfynIe+fUTsfcV/eIyhg5+OhDwF1A4kjJuw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RMCoWS7R; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89135C4166B for ; Sat, 27 Jan 2024 23:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706398923; bh=aLwsjk+yqZJ8iDmZN++A6YSY8VPjmsd8uJByyE+0yic=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RMCoWS7RHEo8nhQFvZPcaWsccsH97v0vREo4GbTlKeqs1Ma/nR7q8KiYpgf2S5krL 5ed0URKDyDU6ppoyYCyQZYunRGrT98uaxFaFOaKECCtPSxKMq2SbVjLSmKbAqyMZpe w9/hrV9Re7Sbreays5AxS6Vi28D9karYZmqtA9zzr1UjsBwkwuYTM0tFm1HjUb2p/1 wycOdo1v1stuZwd7RilsmoGrhoBiU+Ghu6WrpJhAXJ0tOQqCgkGDdgkQqrxnX4Fsq4 X4ZiImJEvqnbo/is7lOhleMeG6USBd9mFLudy9ZmKUcpoL5WAAlez4Weh9lw47ttJ0 qenfayiqkpFoA== Received: by mail-il1-f177.google.com with SMTP id e9e14a558f8ab-3606ebda57cso4820595ab.2 for ; Sat, 27 Jan 2024 15:42:03 -0800 (PST) X-Gm-Message-State: AOJu0YzU4zUvffb8yVXfZ/ThK18xSmvodXOV6e9ut3eTEbTqr/7JyAHa rAgj7YSTf3I8HudgzXSHvDN1I/Es9X9VWDvwfezWhlpT2egchfF7J1dkJQH/uhiN5RSDQ7zK/lJ ELr3emHisye+UhO3HrAsiW5LFB26kyzXKDh+x X-Received: by 2002:a92:2a03:0:b0:363:73ae:5f86 with SMTP id r3-20020a922a03000000b0036373ae5f86mr2119802ile.2.1706398922757; Sat, 27 Jan 2024 15:42:02 -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> In-Reply-To: <20240118111036.72641-6-21cnbao@gmail.com> From: Chris Li Date: Sat, 27 Jan 2024 15:41:50 -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: ryan.roberts@arm.com, akpm@linux-foundation.org, david@redhat.com, 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 On Thu, Jan 18, 2024 at 3:12=E2=80=AFAM Barry Song <21cnbao@gmail.com> wrot= e: > > From: Barry Song > > In do_swap_page(), while supporting large folio swap-in, we are using the= helper > folio_add_anon_rmap_ptes. This is triggerring a WARN_ON in __folio_add_an= on_rmap. > We can make the warning quiet by two ways > 1. in do_swap_page, we call folio_add_new_anon_rmap() if we are sure the = large > folio is new allocated one; we call folio_add_anon_rmap_ptes() if we find= the > large folio in swapcache. > 2. we always call folio_add_anon_rmap_ptes() in do_swap_page but weaken t= he > WARN_ON in __folio_add_anon_rmap() by letting the WARN_ON less sensitive. > > Option 2 seems to be better for do_swap_page() as it can use unified code= for > all cases. > > Signed-off-by: Barry Song > Tested-by: Chuanhua Han > --- > mm/rmap.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/rmap.c b/mm/rmap.c > index f5d43edad529..469fcfd32317 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1304,7 +1304,10 @@ static __always_inline void __folio_add_anon_rmap(= struct folio *folio, > * page. > */ > VM_WARN_ON_FOLIO(folio_test_large(folio) && > - level !=3D RMAP_LEVEL_PMD, folio); > + level !=3D RMAP_LEVEL_PMD && > + (!IS_ALIGNED(address, nr_pages * PAGE_SI= ZE) || Some minor nitpick here. There are two leading "(" in this and next line. This is the first "(" > + (folio_test_swapcache(folio) && !IS_ALIG= NED(folio->index, nr_pages)) || Second "(" here. These two "(" are NOT at the same nested level. They should not have the same indentation. On my first glance, I misread the scope of the "||" due to the same level indentation. We can do one of the two 1) add more indentation on the second "(" to reflect the nesting level. > + page !=3D &folio->page), folio); Also moving the folio to the next line, because the multiline expression is huge and complex. Make it obvious the ending "folio" is not part of the testing condition. 2) Move the multiline test condition to a checking function. Inside the function it can return early when the shortcut condition is met. That will also help the readability of this warning condition. Chris > __folio_set_anon(folio, vma, address, > !!(flags & RMAP_EXCLUSIVE)); > } else if (likely(!folio_test_ksm(folio))) { > -- > 2.34.1 > >