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 4C0F3C27C77 for ; Tue, 11 Jun 2024 15:47:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B58C76B009A; Tue, 11 Jun 2024 11:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B07616B00AF; Tue, 11 Jun 2024 11:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A9166B00B5; Tue, 11 Jun 2024 11:47:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 78E966B009A for ; Tue, 11 Jun 2024 11:47:54 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 22A9D1A157B for ; Tue, 11 Jun 2024 15:47:54 +0000 (UTC) X-FDA: 82219038468.23.25C1ABB Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf06.hostedemail.com (Postfix) with ESMTP id 5EC8D18000F for ; Tue, 11 Jun 2024 15:47:51 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=weILGyPq; spf=pass (imf06.hostedemail.com: domain of yosryahmed@google.com designates 209.85.167.181 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=1718120871; 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=jpM+X0foseE+HCoQOOJMRUvbhVQW/GLwLX9rUTKHX0Q=; b=uM5WzpQt2XewAcZ66c0efZk4vxjHK2lzsHWrQRmL6BKrh+Sz50Kz9zlWbdFnOC6jFQXczL wARlOmzteSo+DZPY73EykqEGFlhBGWWjmsKoQTt4HG15UtniLZhad4d/i9MTJ+SoBbtcR1 pWofj9EZSRsMMI5iJUNy1ibAVSLRK50= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718120871; a=rsa-sha256; cv=none; b=G3UvWaBq7DlYlN91lyMP+rN3VRaLV3+96fuQNzjE+eLmfO8p4QeaTCZfhVZbxlHvVQoU9W UIlwy9hqHbS6CpfSDXuIVfGe2+PVu4PvlXWjHNIt14NkS5n8Hwwjw4BD0Y34wxJpt/XLqB Zyq94eMAg120WzqdO4KolwDoeJQp1VI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=weILGyPq; spf=pass (imf06.hostedemail.com: domain of yosryahmed@google.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3d218ea7750so708751b6e.3 for ; Tue, 11 Jun 2024 08:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718120870; x=1718725670; 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=jpM+X0foseE+HCoQOOJMRUvbhVQW/GLwLX9rUTKHX0Q=; b=weILGyPqDjVP02BpmnpjqhGzGmsvoKrSenfEouyc6Rwp0yVoRNW7jBmuWg30ikHwNo 4Lk0Dtgs9UtP4d58p9K1prudpgH17wQqNH8vEsHmBPffEITjPSPRyu9oWuCMhBOpxP7H lm2qHkXMpqJCBhzUjI20SnbClgkDr3JnAekL6KINoSQ27smjn20iDLSUQf0NGKUwXumW AIek6WfaTs3Vw7jx71l/FA0hv4r4KU3Qo2jr2KU77ar2mTbLwc8nHK4U9ZTgwAH2yFtG XO16nMLZNvChei2u1UQckLC3MxqCOb8hpeY9OQTWCiq+6mkQHTYkfd2M4bLi6dLtB2MM irCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718120870; x=1718725670; 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=jpM+X0foseE+HCoQOOJMRUvbhVQW/GLwLX9rUTKHX0Q=; b=enVjWSV478ONjMN5mad0AYj+T9QX2XJHI/ToBS05tdkJDyT3KdiTtvmpFadROski5u 6LIyMj1vSibFbB+Fp0htCqsGn50OovevpGoaxGSC/H3ZfQM/4wDpja1kuqyJbIXKh6M2 TE++obTYYrzEbICXf7zZLS9sEb6cnKDm9T98yx4TEVg8Jv/tf/zRb13qpiWz3dAGANv+ 423jXSXJPJSrxpOh3e6m99YSSrgKCa4mwJvvBGVMC0c6esJBAPuTFJte/yazlPzrTnr3 jmC/kTg+EGGrmMwzwFIIjlkSUtAkMwP9laN8r+/CCW+UNtsTQ0wyvMbAzyy6ax+64eSB hReg== X-Forwarded-Encrypted: i=1; AJvYcCUSBs7wCpDPG6098AMFD4cYhAySKfOEjfdcokP+4YHTMI4WIeMVhhq01D3pQWSYf4c0vsdIQ+aH7V4IlxATLxBm/iw= X-Gm-Message-State: AOJu0Yzvf80KIoQpVYsu03ce3p9+3swXMM4f5+cNaAh9ZAe+LlUDwXm7 CH1E9wTVWWJFsaKJeZLGSHpbOn+HRwGB5vThfpraZU3TMJ0G14Uz5b6TQ3Wdx47rcTuMj7KUeph 2asncnc0OnK/ZTGBp19fVkAUWqqi616OWv1Hy X-Google-Smtp-Source: AGHT+IGsUm8uoXy2Frod9+g47BSX/WQwflOqQo3V7ZvgfN5VWQw8m8zz9XQk2EJ6h60boQrBDC7OiaZYSjlc+6BkQ24= X-Received: by 2002:a05:6808:3196:b0:3d2:314b:cd0f with SMTP id 5614622812f47-3d2314bd006mr4312540b6e.3.1718120870066; Tue, 11 Jun 2024 08:47:50 -0700 (PDT) MIME-Version: 1.0 References: <20240608023654.3513385-1-yosryahmed@google.com> <2821278f-bc94-c147-d0fe-8cc52dbdccb1@redhat.com> <811778e4-6af4-563a-757e-83fec207e79f@redhat.com> In-Reply-To: <811778e4-6af4-563a-757e-83fec207e79f@redhat.com> From: Yosry Ahmed Date: Tue, 11 Jun 2024 08:47:10 -0700 Message-ID: Subject: Re: [PATCH v2] mm: zswap: handle incorrect attempts to load of large folios To: =?UTF-8?Q?Mika_Penttil=C3=A4?= Cc: Andrew Morton , Johannes Weiner , Nhat Pham , Chengming Zhou , Baolin Wang , Barry Song <21cnbao@gmail.com>, Chris Li , Ryan Roberts , David Hildenbrand , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 5EC8D18000F X-Rspam-User: X-Rspamd-Server: rspam08 X-Stat-Signature: wgyiu5ky97qdj555q94yw3h3j3kbxq9r X-HE-Tag: 1718120871-444800 X-HE-Meta: U2FsdGVkX19reJUungdTYEDuEx+Iv+w6x7ocVsC5zySSofDhHyQOFedwfZotPxCStV0JN7wsA6EIbCQdU23cXG3cySbEL0fKTEbbm0nXegizC+r3+ErtsqDqY5eWF1EiOew9rWfAbBQRrcVWeecHZp0smeP2vLAW5+xQL0nM0ujR/x+mpWqJXgPZlBKEhXV+yR8ewyQLxfIERCN1zAWa7XnVAtxl+8VHVIBfIz0SryqIsv8stp9JWrQQEt9g/9UdTtPdJKLAME52oA65MSGHdPnXiD631U+B85rBmFim9sR+kH+cxns/252k4vIr7lZzPwlTSS2+ePsnUkhJaQGUBoxUJo7s4opKUdikd907gzDrS4giP4kYn4dl7ypipKfj13vFu6e/JZru63ChLeEO0RRpo0AYMROrxi5+zFIodhhtFgXV3Wwq+jQ0MraMderEbHXAXxdUX2B44ywYlComU6btM3CidufAPEpzn90OtzqL5RPWrqaZW8lhJkj3EOBZyOo+ixZO6HBGwgyAU29lvqqJXM49zQUi5qTSGJYsVXsCTTnyRAy0WjSN8TKMLbO7xVvSa0Pt3DEs7jdbo1+sFgzqGzpzY8NnBa+uw5F6VvpbqePLN1x+kJ520ivWbVg0lktsrXXH3ta0Xc/h0fdkaYe2UvkBHYvANvd46Xm2vU+gfYHrH+GYgL5Hn96gJfi9m8RUF9yEO6Ixxee9T5GPJPWdiHimiejqM4kY1Go4zFuBf6GAzLoku1W3lGtvohVa+QslY8bTYbBPHmP0KUTsohf1u5SS07NPJ1RsNUgRkB19YA82zLBnIJ+QuaPZutdij4B6t3EOZRqMv1qFhWySw4SRBm+EdIe4r4SgijTE/sx6d4zCki8IoInR9tYCyUFZN2HZvF2qQVEVybneB9jfJx17BBOVuJ/EkEJ4wxdZhaiUQ7Aw+lzqYWKIg0sgQRu97rZF8D6oU+/laxhIehs tw3L+MEk S5ACvusSCZ7tnmVUx/Kj9k09kdm6Kw8ncNBFuj7OPb9yCoU5byON4e4U8AwCLi8AeEzWpZ7rQ5ujZSrn4lsIt7S1pKocVZ43/LGm5sG2aBnCgU8/4LchidEdxrb/ergeucLMkpISHu+fZmD/2LSHXC9zPQJMzK/9Dhnd2 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 Mon, Jun 10, 2024 at 9:14=E2=80=AFPM Mika Penttil=C3=A4 wrote: > > > On 6/10/24 20:35, Yosry Ahmed wrote: > > On Fri, Jun 7, 2024 at 9:08=E2=80=AFPM Mika Penttil=C3=A4 wrote: > >> On 6/8/24 05:36, Yosry Ahmed wrote: > >>> diff --git a/mm/zswap.c b/mm/zswap.c > >>> index b9b35ef86d9be..ebb878d3e7865 100644 > >>> --- a/mm/zswap.c > >>> +++ b/mm/zswap.c > >>> @@ -1557,6 +1557,26 @@ bool zswap_load(struct folio *folio) > >>> > >>> VM_WARN_ON_ONCE(!folio_test_locked(folio)); > >>> > >>> + /* > >>> + * Large folios should not be swapped in while zswap is being u= sed, as > >>> + * they are not properly handled. Zswap does not properly load = large > >>> + * folios, and a large folio may only be partially in zswap. > >>> + * > >>> + * If any of the subpages are in zswap, reading from disk would= result > >>> + * in data corruption, so return true without marking the folio= uptodate > >>> + * so that an IO error is emitted (e.g. do_swap_page() will sig= fault). > >>> + * > >>> + * Otherwise, return false and read the folio from disk. > >>> + */ > >>> + if (folio_test_large(folio)) { > >>> + if (xa_find(tree, &offset, > >>> + offset + folio_nr_pages(folio) - 1, XA_PRES= ENT)) { > >>> + WARN_ON_ONCE(1); > >>> + return true; > >>> + } > >> How does that work? Should it be xa_find_after() to not always find > >> current entry? > > By "current entry" I believe you mean the entry corresponding to > > "offset" (i.e. the first subpage of the folio). At this point, we > > haven't checked if that offset has a corresponding entry in zswap or > > not. It may be on disk, or zwap may be disabled. > > Okay you test if there's any matching offset in zswap for the folio. > > > >> And does it still mean those subsequent entries map to same folio? > > If I understand correctly, a folio in the swapcache has contiguous > > swap offsets for its subpages. So I am assuming that the large folio > > swapin case will adhere to that (i.e. we only swapin a large folio if > > the swap offsets are contiguous). Did I misunderstand something here? > > Yes I think that is fair assumption for now. But also saw your v3 which > doesn't depend on this. Yeah Barry pointed out that we want to warn if a large folio reaches zswap and there is a chance that it is in zswap (i.e. zswap was enabled), even if it happens that the folio is not in zswap during swapin. This gives wider coverage and is cheaper when zswap is disabled than the lookups. We will also need to check if zswap was ever enabled in the large folio swapin series anyway, so the helper introduced in v3 should be helpful there as well.