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 0021ACA0ED3 for ; Wed, 4 Sep 2024 07:22:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8191F8D0231; Wed, 4 Sep 2024 03:22:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C9858D0228; Wed, 4 Sep 2024 03:22:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 643158D0231; Wed, 4 Sep 2024 03:22:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 44AB88D0228 for ; Wed, 4 Sep 2024 03:22:51 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C6202A0D83 for ; Wed, 4 Sep 2024 07:22:50 +0000 (UTC) X-FDA: 82526213700.22.CF7A586 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf02.hostedemail.com (Postfix) with ESMTP id F1AE18000F for ; Wed, 4 Sep 2024 07:22:48 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R5NHqy8Y; spf=pass (imf02.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725434493; 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=3zOhdoj9/Ybg8aoB4iZX9Xi/vhy5Ul9rRLj5zkxP+T8=; b=u3qySSACHTM5IzJstj/RjNcyyGKwwka3rfnFU12rqDqk1ydhi0HiBbpbkIIp/Usn7CvWW1 L7KaVkmp9mRqFQOfobw+d3X8X+0dAl2/IhsKzzXPQH3aEc6YUid/lHj8aD5eID/lyKBEhd HPLYq9Er+1VbcRZsAc7ZtqypiIAGQG4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R5NHqy8Y; spf=pass (imf02.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725434493; a=rsa-sha256; cv=none; b=g9CZN/fF9UyJTf4yxRvuacieQTTRk9AXnf96S/Butpdulm7iMm8ahMi/8m+r9Tsn1s5WWx ct5oaqmMfgjFW3wZWyl6bbbnTNflcTVdxk1e0HnbdC053FQRkCdFy6bTAhGhGFpNpb8Jig C8mdoJfKa97fiRkhDPziQIVORn6Wuj0= Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a86abbd68ffso77618066b.0 for ; Wed, 04 Sep 2024 00:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725434567; x=1726039367; 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=3zOhdoj9/Ybg8aoB4iZX9Xi/vhy5Ul9rRLj5zkxP+T8=; b=R5NHqy8Y/PUfKxaIaVmcwAsR3uM6uNs2uwC3qFCOn2X7V7wbzSNsGz5AXbPTiLbdO1 K9ALnJQtCE4/8l1dI04nAVM2IasvaVnzSMM8dr3W0xhniKmToQqLiNUfliVm629F5upW A8OSKDAKNrFyA36cx1bgSL0BdSAwQu1dsfJ9y0az3XJJCoqwxbEMmvkg/LVNFJLlGccL AvD40QETGKGVlmu+pcdYYA6SnnqjDP6AHcJkbLichJkT9I5Qs7b2LiqZ4tHGkahmTfMm BhwvXcpkZjSUt035k+Orp8L0ZMtGuDbQFI90dZoR+3W6MwQqEm7VT+tsVvHb1yvle7Uz wYng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434567; x=1726039367; 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=3zOhdoj9/Ybg8aoB4iZX9Xi/vhy5Ul9rRLj5zkxP+T8=; b=jh+8TtSKvHUWbRFFHc5aocSbVaRx9jRA8QPVOOWLjJanQbKcyUABsJQxDQKZl5lWX4 0OSIxKN9n/XQ02nHgCMcc4gB8kGiXwSkgGo/hLTHv4IEmbi65AWbv2LHu9HtCFZrG+rv eWqSmLnSJw70U+LtzgDt3c2KWtfUeOQB0fhQ7offh+WaaMobjUWl/Qlj2M/8Z1IrVUJw FaCnBcK4T0YwX3Xh+ePyoQrGvw3UmEwpeO3d8NhqOSlUoNFBoMZ/wvfOLFQ3A36QrIwp 7QuxaLYGYcwp6iqicX2sixZMl/ti3ryk+17MoOfpiCaVuqw/9Lbm+phnCGwiZLb4veUR NysA== X-Forwarded-Encrypted: i=1; AJvYcCV3mZTP5edXH6nh2oRdp4CH0w+r3BDTAhN5wBqNRRh17hp8eJ0xoeR2keEvy+J6LVXpIpYqSJav6Q==@kvack.org X-Gm-Message-State: AOJu0Yw9mX49x4jPG4pNCJrsfeX2EIxemUZUDvkjaqWvCcbT6AsbNJt4 o07bIoBq5Hy5VRCjss0iMRsvlsLtDa3FWA4P0+YXmZVJ+7Tp7FSy+nA3rBJdWe2OCTmcGlGtUve vB7EWAHbgkooa+HlLOgPYAkb35SX1X5HxxIlR X-Google-Smtp-Source: AGHT+IHEYMbhMil+VLa0ulIQ/lG8oz8wKI3Q/bEp6d4Bg4xqziiefjRg+TkGeLT3n9lyrgnQropMb8sPfdRtxgSeG10= X-Received: by 2002:a17:907:868f:b0:a7d:8912:6697 with SMTP id a640c23a62f3a-a8a42f8afeemr108882766b.3.1725434566937; Wed, 04 Sep 2024 00:22:46 -0700 (PDT) MIME-Version: 1.0 References: <20240612124750.2220726-2-usamaarif642@gmail.com> <20240904055522.2376-1-21cnbao@gmail.com> In-Reply-To: From: Yosry Ahmed Date: Wed, 4 Sep 2024 00:22:11 -0700 Message-ID: Subject: Re: [PATCH v4 1/2] mm: store zero pages to be swapped out in a bitmap To: Barry Song <21cnbao@gmail.com> Cc: usamaarif642@gmail.com, akpm@linux-foundation.org, chengming.zhou@linux.dev, david@redhat.com, hannes@cmpxchg.org, hughd@google.com, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, shakeel.butt@linux.dev, willy@infradead.org, ying.huang@intel.com, hanchuanhua@oppo.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: joat7ch4nca3n4i3bpea98wx8foumx9q X-Rspam-User: X-Rspamd-Queue-Id: F1AE18000F X-Rspamd-Server: rspam02 X-HE-Tag: 1725434568-239156 X-HE-Meta: U2FsdGVkX1/fqknxRXjr5zF3R7YmY+6HCQ4ZWAzBsq6T+4aHZT4YZoYwjUBt7s2fH7g6dIEw66nIZOWAht0r7UTFtHSHly82lrs1c8pH1EvBOQPWTfztU3+Em9Ix1NML/N/9HAUamE9ldMHCULFXLNvAwJtEfVqMtj8Nwp1gQg0yk/IgceA6Zy5+astFtohbwdf1bIVZCGM/7J7lQgvkFlk8fcFjwBEmu0KGJ++SYvjq4WXO/rcX9xZDvs3+kfJksA2di2mhB7V4i0j9iBZTUatpkYmDCAisW4QlodflaV6FXLF9HU+BDXHFRTuEzyW7gy5R3x/Q9ZTfGjiz0yTET10AgjihHCcJ8AD8DumMnRwXKAx2dtgrrPIuR37Iub9f/RxXgJsiAZBSGBCvhbvdhIgecd++uY/vn9Z13rg7fPfMhz1rf7LxmaaBIXpSkOIUa/4lybToUxbou2GRnlYpUqMUOpA2v6UAqo3lR+x752uSkNKl/wb2yWgjeVTYWNNTmcBrWEbl4tVyX9FHPvbN0aIyDYIZLeNyjEq7Hr8lwycDUxQAw/mbusPF/E8BqRnacbVc5CTn4CnqpQBXdTvUG5/tCW2V7fDIoNxiOx0vACrrQdiaodZQErnIRBMWixUIx2SjL1knEDGMNOQ+eMX2M7DuuP3r2v9OOiz0c6VfdMYK6lLzyyeHrWSt7n+Yzg7A9qxMIf7YZffHp65NqjDgGaJCzk/5SCDGLGhGZEzjt9FQtHqvDSbjd1TvLu6e4ex2UE6+gHIL3fmPSOXhAXDwLwMYzGFIBnycute47fb8ETDzal25ZDI0+sJtuFZV+xdxdCBpss0kRwy087G5BM9x0CMX33ZNf5bkKSEkBOBgYWDRn91CSWwb+eMyyf9sjeFHPt3EKtUt+j7lhUBkVJSNBbfcSjDutqV30E3mIOVSz2NxCob2+MMmxF0id450EFdeXgT9hG7ZWT5othMNQaU jqvShZ0Q 9PHzx9uTTsrroN0nX64SK578GK3xQbWRSP30DTZZ+Wg0ZUdxYZkFjmfH6VSXaVf1jpoZcrG3oe4u8YiOOfv9/fA1sqKJIYHSaonry6PXpig2IHm6V3GY/3KpL/8bSoHFnfDipwE8sXX1Mc3f7OYmujW18vl8pgEeTBZ6w5maz1X4Fh0bz3g7eoMRtfL20cnJYEsp/WulsxCH2gpwZCKYzcBkBfBfi1UgHUMg4Zf+XK9AWp+IyTmlEJvBPJA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 Wed, Sep 4, 2024 at 12:17=E2=80=AFAM Barry Song <21cnbao@gmail.com> wrot= e: > > On Wed, Sep 4, 2024 at 7:12=E2=80=AFPM Yosry Ahmed wrote: > > > > [..] > > > > @@ -426,6 +515,26 @@ static void sio_read_complete(struct kiocb *io= cb, long ret) > > > > mempool_free(sio, sio_pool); > > > > } > > > > > > > > +static bool swap_read_folio_zeromap(struct folio *folio) > > > > +{ > > > > + unsigned int idx =3D swap_zeromap_folio_test(folio); > > > > + > > > > + if (idx =3D=3D 0) > > > > + return false; > > > > + > > > > + /* > > > > + * Swapping in a large folio that is partially in the zerom= ap is not > > > > + * currently handled. Return true without marking the folio= uptodate so > > > > + * that an IO error is emitted (e.g. do_swap_page() will si= gbus). > > > > + */ > > > > + if (WARN_ON_ONCE(idx < folio_nr_pages(folio))) > > > > + return true; > > > > > > Hi Usama, Yosry, > > > > > > I feel the warning is wrong as we could have the case where idx=3D=3D= 0 > > > is not zeromap but idx=3D1 is zeromap. idx =3D=3D 0 doesn't necessari= ly > > > mean we should return false. > > > > Good catch. Yeah if idx =3D=3D 0 is not in the zeromap but other indice= s > > are we will mistakenly read the entire folio from swap. > > > > > > > > What about the below change which both fixes the warning and unblocks > > > large folios swap-in? > > > > But I don't see how that unblocks the large folios swap-in work? We > > still need to actually handle the case where a large folio being > > swapped in is partially in the zeromap. Right now we warn and unlock > > the folio without calling folio_mark_uptodate(), which emits an IO > > error. > > I placed this in mm/swap.h so that during swap-in, it can filter out any = large > folios where swap_zeromap_entries_count() is greater than 0 and less than > nr. > > I believe this case would be quite rare, as it can only occur when some s= mall > folios that are swapped out happen to have contiguous and aligned swap > slots. I am assuming this would be near where the zswap_never_enabled() check is today, right? I understand the point of doing this to unblock the synchronous large folio swapin support work, but at some point we're gonna have to actually handle the cases where a large folio being swapped in is partially in the swap cache, zswap, the zeromap, etc. All these cases will need similar-ish handling, and I suspect we won't just skip swapping in large folios in all these cases.