From: Yosry Ahmed <yosryahmed@google.com>
To: Nhat Pham <nphamcs@gmail.com>
Cc: Usama Arif <usamaarif642@gmail.com>,
akpm@linux-foundation.org, hannes@cmpxchg.org, david@redhat.com,
ying.huang@intel.com, hughd@google.com, willy@infradead.org,
chengming.zhou@linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH v3 1/2] mm: store zero pages to be swapped out in a bitmap
Date: Tue, 11 Jun 2024 11:46:56 -0700 [thread overview]
Message-ID: <CAJD7tkZdtK3CB_0bt_+EMNCc8+7FF3jPv4VwA2u8PntrC=1jrA@mail.gmail.com> (raw)
In-Reply-To: <CAKEwX=PnwjmZKPLX2=ubD6+-+ZAqpXnczkHe4=1QY1hizOE8WQ@mail.gmail.com>
[..]
> > @@ -1336,6 +1347,7 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry)
> > count = p->swap_map[offset];
> > VM_BUG_ON(count != SWAP_HAS_CACHE);
> > p->swap_map[offset] = 0;
> > + clear_bit(offset, p->zeromap);
>
> Hmm so clear_bit() is done at the swap_entry_free() point. I wonder if
> we can have a problem, where:
>
> 1. The swap entry has its zeromap bit set, and is freed to the swap
> slot cache (free_swap_slot() in mm/swap_slots.c). For instance, it is
> reclaimed from the swap cache, and all the processes referring to it
> are terminated, which decrements the swap count to 0 (swap_free() ->
> __swap_entry_free() -> free_swap_slots())
>
> 2. The swap slot is then re-used in swap space allocation
> (add_to_swap()) - its zeromap bit is never cleared.
I do not think this can happen before swap_entry_free() is called.
Note that when a swap entry is freed to the swap slot cache in
free_swap_slot(), it is added to cache->slots_ret, not cache->slots.
The former are swap entries cached to be later freed using
swap_entry_free().
>
> 3. swap_writepage() writes that non-zero page to swap
>
> 4. swap_read_folio() checks the bitmap, sees that the zeromap bit for
> the entry is set, so populates a zero page for it.
>
> zswap in the past has to carefully invalidate these leftover entries
> quite carefully. Chengming then move the invalidation point to
> free_swap_slot(), massively simplifying the logic.
I think the main benefit of moving the invalidation point was avoiding
leaving the compressed page in zswap until swap_entry_free() is
called, which will happen only when the swap slot caches are drained.
>
> I wonder if we need to do the same here?
next prev parent reply other threads:[~2024-06-11 18:47 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 12:15 [PATCH v3 0/2] " Usama Arif
2024-06-10 12:15 ` [PATCH v3 1/2] " Usama Arif
2024-06-10 13:07 ` Matthew Wilcox
2024-06-10 13:56 ` Usama Arif
2024-06-10 14:06 ` Matthew Wilcox
2024-06-10 14:14 ` Usama Arif
2024-06-10 14:33 ` Usama Arif
2024-06-10 17:57 ` Yosry Ahmed
2024-06-10 18:36 ` Usama Arif
2024-06-10 18:47 ` Yosry Ahmed
2024-06-11 11:49 ` Usama Arif
2024-06-11 15:42 ` Yosry Ahmed
2024-06-11 16:52 ` Usama Arif
2024-06-11 17:51 ` Yosry Ahmed
2024-06-11 18:43 ` Usama Arif
2024-06-11 18:39 ` Nhat Pham
2024-06-11 18:46 ` Yosry Ahmed [this message]
2024-06-11 18:53 ` Nhat Pham
2024-06-11 18:50 ` Usama Arif
2024-06-11 19:33 ` Nhat Pham
2024-06-12 10:42 ` Usama Arif
2024-06-10 12:16 ` [PATCH v3 2/2] mm: remove code to handle same filled pages Usama Arif
2024-06-13 21:21 ` [PATCH v3 0/2] mm: store zero pages to be swapped out in a bitmap Yosry Ahmed
2024-06-14 9:22 ` Usama Arif
2024-06-14 9:28 ` Yosry Ahmed
2024-06-13 21:50 ` Yosry Ahmed
2024-06-13 22:41 ` Shakeel Butt
2024-06-13 22:59 ` Yosry Ahmed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJD7tkZdtK3CB_0bt_+EMNCc8+7FF3jPv4VwA2u8PntrC=1jrA@mail.gmail.com' \
--to=yosryahmed@google.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=usamaarif642@gmail.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox