From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77520C10F1A for ; Tue, 7 May 2024 09:24:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F14886B0095; Tue, 7 May 2024 05:24:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC5BE6B0098; Tue, 7 May 2024 05:24:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8C4B6B0099; Tue, 7 May 2024 05:24:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BB3766B0095 for ; Tue, 7 May 2024 05:24:46 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 657B8A1BD3 for ; Tue, 7 May 2024 09:24:46 +0000 (UTC) X-FDA: 82091064972.02.78051B0 Received: from mail-vk1-f179.google.com (mail-vk1-f179.google.com [209.85.221.179]) by imf03.hostedemail.com (Postfix) with ESMTP id 9482020020 for ; Tue, 7 May 2024 09:24:44 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ls0U8K35; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715073884; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FUX/saWbO2sPYn3s2vChssRcjV2MRiGWaS+fdYSnFZ4=; b=X3aqcqlM6j7PiHhTXO9IuIWQDIU6zeIjmd5AFJJDh6n6ATCIMiltBidFuQ4Ja07NueEsXf +Z3r7m7/TBpAM3k1eP5j/K513+NQORS8yDnXpTt8XSdNR7tb7AIYubFT2hCiBJig5SLoNQ hLnKofA/HLBY1ROI+jj6hP1s1ZMCsc8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ls0U8K35; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715073884; a=rsa-sha256; cv=none; b=DgfkbzjsnwhJpdVnaZTLyldqrU3ig9uaQr24je8jHJQYdyb5YkUfGsAOYflhLGCkA/hfuu rpDKEIyS5vICwS1bYdNKqKME193bUZ0q0IHKWtB1KPKvwFyyV3fIPUSoIBV2xPe8k/Tv8r z6Ru7409teP7c1Cuw3dSpvE/Rdr9TtA= Received: by mail-vk1-f179.google.com with SMTP id 71dfb90a1353d-4df214fdc37so1556604e0c.0 for ; Tue, 07 May 2024 02:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715073884; x=1715678684; darn=kvack.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=FUX/saWbO2sPYn3s2vChssRcjV2MRiGWaS+fdYSnFZ4=; b=Ls0U8K35Ma2l6erjty3+3UZc24067RvCxQb83k0Z0coVUpq1rxB4sZ871cK7+MBUEK 30lDdYEzJ/lBlAZaV72vVf+kGRu1eUCYXlUdDeZmNRMKi0K5bIeG6G6ueFWuET3wqKZw FpG2xTG7aW9f+1iAVzHYqDo9xfeUdgJA/BqwPzrwvzUlSAI3lk13NZeQcQS7+bx2iR6G JS1la6ePBqNzP7QCf9IDDdWYUec+8SkajIm+Kvv132hk7flDbWclolkDiRjyDSHW6tV1 NYOfAWR3lt3joHiO2LdqwsnEqWtDClyyYcRVzySBPB4BTrh10ZwJEzA8wR9PoAvBTG0j cW8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715073884; x=1715678684; 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=FUX/saWbO2sPYn3s2vChssRcjV2MRiGWaS+fdYSnFZ4=; b=nWmX/NNXkGLJR4nqsJNkfO64ln9B+L67QuGJ9geQbXwY5LI4h5ER8+A7LZhIHZmf4b HykO01KgvBosCeE82tq0Mf+sQXIYYWhM+DFOanhXkVulqYtBdj8ZR3P2S4gVf1NZFhXY wk4EiNda1GBICFWqM0xatkS83tyy2Irye0icLtyEYNJOtzJRjAx2d02bEoehTTkCxJrU Q1KTsQVxreRCTG/PVQzG++jaRE9SYcs8qECSZiIFau53H/HyLXSqySo0jHNk7+up2zyn agCiao+WyvTpmjutxXVMFyuavJT8xix7fG9Zxf5xUkuzFvL78UzsRD7vabqB34K2EHTO w1zw== X-Forwarded-Encrypted: i=1; AJvYcCUmODRk5ArvkoTqUPyTnAEWe2WOImwwJAB26B3k84iX1GQbm5VcsMi7o8qzh4cfhmbxIL6d4MRODyXICcPmtjKNBvs= X-Gm-Message-State: AOJu0Yxxc4cNSW7QWzWkdSe0tuYUEmfRe8uQib3g33uNUBmILOWOaBZl MSoGjijID3HB7/CZEWQc/AXd9ZHM+WCLEmVTGVc4jxhW0sbuH4bkne/MEb/RK/fxVO+QyqwYqs3 CJ4Xox8akqmnGDwr1eHf20rmKpHk= X-Google-Smtp-Source: AGHT+IGl8rQOKWt46bnh6yFyPkhvxMFPAQhx4ZovtHKw8fXy4iuGV4Sm/O/FZpP5PW2RIIvyILPoCgj3gsGaYRTjBEU= X-Received: by 2002:a05:6122:3c4f:b0:4da:e199:4411 with SMTP id 71dfb90a1353d-4df58828726mr1759406e0c.7.1715073883632; Tue, 07 May 2024 02:24:43 -0700 (PDT) MIME-Version: 1.0 References: <20240503005023.174597-1-21cnbao@gmail.com> <20240503005023.174597-7-21cnbao@gmail.com> <0b4d4d4b-91d8-4fd5-af4e-aebe9ee08b89@arm.com> <5b770715-7516-42a8-9ea0-3f61572d92af@redhat.com> <7dc2084e-d8b1-42f7-b854-38981839f82e@redhat.com> <099a2c9e-f85e-4fe7-99dd-81b61115935c@redhat.com> In-Reply-To: <099a2c9e-f85e-4fe7-99dd-81b61115935c@redhat.com> From: Barry Song <21cnbao@gmail.com> Date: Tue, 7 May 2024 21:24:32 +1200 Message-ID: Subject: Re: [PATCH v3 6/6] mm: swap: entirely map large folios found in swapcache To: David Hildenbrand Cc: Ryan Roberts , akpm@linux-foundation.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, chrisl@kernel.org, hanchuanhua@oppo.com, hannes@cmpxchg.org, hughd@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, ziy@nvidia.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9482020020 X-Stat-Signature: 1yfgnahphssourgfg1ors6ygz4m6kipd X-Rspam-User: X-HE-Tag: 1715073884-719688 X-HE-Meta: U2FsdGVkX19BJg8NhwclzG9MAsGIfbhpGPQ5vUy4lh10MndViUe38/7+7jDf3odMoR+Fp2xdNn8/d40ACd1y8vdxc8lhGgwMyY/Ue71xkxYzjvwUQhBRfZbHvGj/NK6q9ORTsR8s9xdWfUQ5nz2TsTqGEFgLVUE+eP2XVnYL/V9nCY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RO1jgg8uz6cWzVULAlbbDDDeJNpvN5HcDfZgOfMO524dEfeRDC5x7VYHw+YIVa520ouU2e0oX5pHTRczdcO+6QsScmtFqDlQ37AVkEqyGJG6Fz9Sp5W38y/QACRS9PFlk8OnVs08YvCIOelWekEO X-Bogosity: Ham, tests=bogofilter, spamicity=0.000018, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, May 7, 2024 at 8:59=E2=80=AFPM David Hildenbrand = wrote: > > >> Let's assume a single subpage of a large folio is no longer mapped. > >> Then, we'd have: > >> > >> nr_pages =3D=3D folio_nr_pages(folio) - 1. > >> > >> You could simply map+reuse most of the folio without COWing. > > > > yes. This is good but the pte which is no longer mapped could be > > anyone within the nr_pages PTEs. so it could be quite tricky for > > set_ptes. > > The swap batching logic should take care of that, otherwise it would be > buggy. When you mention "it would be buggy," are you also referring to the current fallback approach? or only refer to the future patch which might be able to map/reuse "nr_pages - 1" pages? The current patch falls back to setting nr_pages =3D 1 without mapping or reusing nr_pages - 1. I feel your concern doesn't refer to this fallback? > > > > >> > >> Once we support COW reuse of PTE-mapped THP we'd do the same. Here, it= 's > >> just easy to detect that the folio is exclusive (folio_ref_count(folio= ) > >> =3D=3D 1 before mapping anything). > >> > >> If you really want to mimic what do_wp_page() currently does, you shou= ld > >> have: > >> > >> exclusive || (folio_ref_count(folio) =3D=3D 1 && !folio_test_large(fol= io)) > > > > I actually dislike the part that do_wp_page() handles the reuse of a la= rge > > folio which is entirely mapped. For example, A forks B, B exit, we writ= e > > A's large folio, we get nr_pages CoW of small folios. Ideally, we can > > reuse the whole folios for writing. > > Yes, see the link I shared to what I am working on. There isn't really a > question if what we do right now needs to be improved and all these > scenarios are pretty obvious clear. Great! I plan to dedicate more time to reviewing your work. > > > > >> > >> Personally, I think we should keep it simple here and use: > >> > >> exclusive || folio_ref_count(folio) =3D=3D 1 > > > > I feel this is still better than > > exclusive || (folio_ref_count(folio) =3D=3D 1 && !folio_test_large(foli= o)) > > as we reuse the whole large folio. the do_wp_page() behaviour > > doesn't have this. > > Yes, but there is the comment "Same logic as in do_wp_page();". We > already ran into issues having different COW reuse logic all over the > place. For this case here, I don't care if we leave it as > > "exclusive || folio_ref_count(folio) =3D=3D 1" I'm perfectly fine with using the code for this patchset and maybe looking for other opportunities for potential optimization as an incremental patchset, for example, reusing the remaining PTEs as suggested by you - "simply map+reuse most of the folio without COWing." > > But let's not try inventing new stuff here. It seems you ignored and snipped my "16 + 14" pages and "15" pages example though. but once we support "simply map+reuse most of the folio without COWing", the "16+14" problem can be resolved, instead, we consume 16 pages. > > -- > Cheers, > > David / dhildenb Thanks Barry