Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp296794rdb; Mon, 22 Jan 2024 22:49:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCxIz6dF0qKpLEcDrZZMJlKGsdsc2QQb7HqDnBL4TKU0oCRsEa+rvL4blavBpyXeHO98RH X-Received: by 2002:a05:6214:262c:b0:686:a185:dc11 with SMTP id gv12-20020a056214262c00b00686a185dc11mr343779qvb.55.1705992570816; Mon, 22 Jan 2024 22:49:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705992570; cv=pass; d=google.com; s=arc-20160816; b=vpu/ftVum3uLv4nWKqy7hpJy5724SL6LmQxpLlAbbh0rS8DI82wWBCq2xvVqYfpxvh OdDMnMEemSi5INs0egzL8oRFuoVYgifTVFcnEPS5+rXOawt9g2oybWd7eXS64BxsVgdT ed2nm+KD93Yc06wlPCYGiLHNRCh1L8IZSd9fbqVBAUHIR/JqbSvpWXwn19p/qUpFCdpP 2YAnzQc+Qd+6wcEphd0foqXNOLYRQu1s7Qd9tbrgB7vfL2/8XqpHL/DaBy/TdpuhF8fv j1WQE86NHcIUvJbFBDP9fUWwEwckHBskzfp1GzNMhXpuEEjTuigJFewYS82irWfJQOP2 rRkw== 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=umePHjAi6OPcq1K6nxeQmgi5O1MnXjNUe9aGL0eZ2Jk=; fh=M5hcn3sZD6M+8CR9UFBKasHhHYmVrsX2RhhKFeLqO78=; b=NJ/YnAuhJki3G+OePA82J/VKrVCOIrCptB//1JFcC+5QZ1aDhxNv0CYh+WlCFUpQ8l skUcAPI/ggHUuXn1DU3p0G5eNZVXBYairXL1X3MQF/qzwfA1wCinzkrLWTZFpPAW0W2I Ybft+IiCKhmImldsfytAz0QQQf3zJorJJ0MLFo1wUix+bsP4RdgFKLeODpB+5oqqVrD9 TjKgUtnh4oDLe2e2bdHZWHDh5UUo+oEArcO9aSFSU62ROCiJV7ZU8C/8NbgsymGuH5r1 mDTrY5Hhsf70RT4mp72v3yaswK6FcvdvMgUqDzHXPqgaf8fRigGJ6EcodG+iAi0+0iWU dUPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RvqSuqLE; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34805-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34805-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b17-20020a0ccd11000000b00682bfd3296dsi7395995qvm.266.2024.01.22.22.49.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:49:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34805-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RvqSuqLE; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34805-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34805-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8290F1C22BFF for ; Tue, 23 Jan 2024 06:49:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61C8A50A6F; Tue, 23 Jan 2024 06:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RvqSuqLE" Received: from mail-ua1-f47.google.com (mail-ua1-f47.google.com [209.85.222.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28C4E8C04 for ; Tue, 23 Jan 2024 06:49:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705992562; cv=none; b=cG061N2A/pPxaNd32ZPlehlZP6Pkh8UuO6Bh9kgeulQP0gVDkAsfLlpC7sSl4TSAwHJBFxR3GEdKEhj1WhAhAbK9yJ7OGgMHO5bffUc4EEMbYFlSQ6500jd0/gOPgxgRUoGTRBKgpqQbXIVGdW2p3KHWVk6tqAUQIrj9Ls0aQgg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705992562; c=relaxed/simple; bh=lrKf7co4dZd/i5bdvHclIGgfH9Ox1JQUyqlDDpHyH8Q=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=HqsjnxjkOmaay0ZtDAiilnm9hjwojbELwr9p6k3Z5qNyjmtqcZVC75jbd9Ou1MKka8eS/h9ud22WGW/ZUS6fkSrRdZhGjc2NIl1901poqv8pnCtn0uKh+GU9Q8eBM7bwvhf2BBcl8bCK3bpN5+pUKLOAh4SCvdfuUSGlNP/Cvks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RvqSuqLE; arc=none smtp.client-ip=209.85.222.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ua1-f47.google.com with SMTP id a1e0cc1a2514c-7d2dfe840f2so1111874241.3 for ; Mon, 22 Jan 2024 22:49:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705992560; x=1706597360; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=umePHjAi6OPcq1K6nxeQmgi5O1MnXjNUe9aGL0eZ2Jk=; b=RvqSuqLEr6xIBI0DtoxuR+JeO7VpjAWQi7fOsAxDPOZxF3SPw5MAmYk6HQPa3iNGAK aUFbawn45yiEdYS52mbGmvdi0C/aUHw1LPpx2ysYcNYQT7eAcvBrQIQeB5AzInRNYTVw 0SrmYRnnkhKmjpEMFjHO2qqpmR7W3LJCd3mOzr7XW871YvBsrvVTUZeHhbilS3+VfLUn 0s212o5SqbwR0Uc6uZH81kXWltXGxpTgrp3wKR4OWX9YuL8XY9E89/AOx7KfGpt0qBQt f+yNu2W6jV5c82t8qo76ziLajtCRTDSFnFPt8g3IQPLJ28Gd8S+hJxt4HDTSLawcNBRc uFGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705992560; x=1706597360; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=umePHjAi6OPcq1K6nxeQmgi5O1MnXjNUe9aGL0eZ2Jk=; b=w98xzdQQdrvJKgyuUGtKL0sz51w+/IhBe9zW9iTbtQGOayuuoAEChE6kO2ffQlU5Dh S27ixV/O+s+eVLPLvkjLG12oT+mqPs1UyMR9Y/nIdA6CRWO+o9tWYGQeflpS2v8F/UTH PYg6LVZo43+d5PtIcq0bEkItT6VrKdkGOYHgL3B+TaGeucwHUkZQevvpihQlvAvXW+AW V62JitfaXkk8uAeQDFWAVhAw8mX1QyOxM3m63+w6yyMvG9ogyfoviDA71f2SiN/aQ6s6 39bTzWvUXGwyI1GcL9tku8nkRwg/tym4O3g8/yCoy5xoF6xu8cSKGpGJacvpVSMg+q9y ihjw== X-Gm-Message-State: AOJu0YzvrJ45P1xYeBcbiJXC5VA+co9P9eXQ4esdJZHG3Zskqs7ciSAn dX3wfHOUuEmSxqvd0JwPJT0e4xbK8ESyv3dob9zq2Fm7MsK9tbzTkfpoAKhGyLFm2uSpmp8qblr MzCDxZjaPjX8FWHYvwyvRlw9vo4E= X-Received: by 2002:a1f:4a07:0:b0:4b8:ce85:1e97 with SMTP id x7-20020a1f4a07000000b004b8ce851e97mr1885512vka.20.1705992559918; Mon, 22 Jan 2024 22:49:19 -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: <58efd8d4-28aa-45d6-b384-7463568b24bb@redhat.com> From: Barry Song <21cnbao@gmail.com> Date: Tue, 23 Jan 2024 14:49:08 +0800 Message-ID: Subject: Re: [PATCH RFC 5/6] mm: rmap: weaken the WARN_ON in __folio_add_anon_rmap() To: David Hildenbrand Cc: 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 On Thu, Jan 18, 2024 at 7:54=E2=80=AFPM David Hildenbrand wrote: > > On 18.01.24 12:10, Barry Song wrote: > > From: Barry Song > > > > In do_swap_page(), while supporting large folio swap-in, we are using t= he helper > > folio_add_anon_rmap_ptes. This is triggerring a WARN_ON in __folio_add_= anon_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 th= e large > > folio is new allocated one; we call folio_add_anon_rmap_ptes() if we fi= nd the > > large folio in swapcache. > > 2. we always call folio_add_anon_rmap_ptes() in do_swap_page but weaken= the > > WARN_ON in __folio_add_anon_rmap() by letting the WARN_ON less sensitiv= e. > > > > Option 2 seems to be better for do_swap_page() as it can use unified co= de 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_rma= p(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) || > > + (folio_test_swapcache(folio) && !IS_ALIG= NED(folio->index, nr_pages)) || > > + page !=3D &folio->page), folio); > > __folio_set_anon(folio, vma, address, > > !!(flags & RMAP_EXCLUSIVE)); > > } else if (likely(!folio_test_ksm(folio))) { > > > 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. 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() > -- > Cheers, > > David / dhildenb > Thanks Barry