linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chengming Zhou <zhouchengming@bytedance.com>
To: Nhat Pham <nphamcs@gmail.com>, Yosry Ahmed <yosryahmed@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 6/6] mm/zswap: zswap entry doesn't need refcount anymore
Date: Sat, 3 Feb 2024 13:09:46 +0800	[thread overview]
Message-ID: <10f4fb80-a385-4c1e-974b-24057922ca62@bytedance.com> (raw)
In-Reply-To: <CAKEwX=P0Mov3Aqazy8eLkC23wxpocVDf5oyQ6gJA1sK-Zv-BMw@mail.gmail.com>

On 2024/2/3 06:44, Nhat Pham wrote:
> On Fri, Feb 2, 2024 at 2:37 PM Yosry Ahmed <yosryahmed@google.com> wrote:
>>
>> On Fri, Feb 2, 2024 at 2:33 PM Nhat Pham <nphamcs@gmail.com> wrote:
>>>
>>> On Thu, Feb 1, 2024 at 7:50 AM Chengming Zhou
>>> <zhouchengming@bytedance.com> wrote:
>>>>
>>>> Since we don't need to leave zswap entry on the zswap tree anymore,
>>>> we should remove it from tree once we find it from the tree.
>>>>
>>>> Then after using it, we can directly free it, no concurrent path
>>>> can find it from tree. Only the shrinker can see it from lru list,
>>>> which will also double check under tree lock, so no race problem.
>>>>
>>>> So we don't need refcount in zswap entry anymore and don't need to
>>>> take the spinlock for the second time to invalidate it.
>>>>
>>>> The side effect is that zswap_entry_free() maybe not happen in tree
>>>> spinlock, but it's ok since nothing need to be protected by the lock.
>>>>
>>>> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
>>>
>>> Oh this is sweet! Fewer things to keep in mind.
>>> Reviewed-by: Nhat Pham <nphamcs@gmail.com>
>>>
>>>> ---
>>>>  mm/zswap.c | 63 +++++++++++---------------------------------------------------
>>>>  1 file changed, 11 insertions(+), 52 deletions(-)
>>>>
>>>> diff --git a/mm/zswap.c b/mm/zswap.c
>>>> index cbf379abb6c7..cd67f7f6b302 100644
>>>> --- a/mm/zswap.c
>>>> +++ b/mm/zswap.c
>>>> @@ -193,12 +193,6 @@ struct zswap_pool {
>>>>   *
>>>>   * rbnode - links the entry into red-black tree for the appropriate swap type
>>>>   * swpentry - associated swap entry, the offset indexes into the red-black tree
>>>> - * refcount - the number of outstanding reference to the entry. This is needed
>>>> - *            to protect against premature freeing of the entry by code
>>>> - *            concurrent calls to load, invalidate, and writeback.  The lock
>>>> - *            for the zswap_tree structure that contains the entry must
>>>> - *            be held while changing the refcount.  Since the lock must
>>>> - *            be held, there is no reason to also make refcount atomic.
>>>>   * length - the length in bytes of the compressed page data.  Needed during
>>>>   *          decompression. For a same value filled page length is 0, and both
>>>>   *          pool and lru are invalid and must be ignored.
>>>> @@ -211,7 +205,6 @@ struct zswap_pool {
>>>>  struct zswap_entry {
>>>>         struct rb_node rbnode;
>>>>         swp_entry_t swpentry;
>>>> -       int refcount;
>>>
>>> Hah this should even make zswap a bit more space-efficient. IIRC Yosry
>>> has some analysis regarding how much less efficient zswap will be
>>> every time we add a new field to zswap entry - this should go in the
>>> opposite direction :)
>>
>> Unfortunately in this specific case I think it won't change the size
>> of the allocation for struct zswap_entry anyway, but it is a step
>> nonetheless :)
> 
> Ah, is it because of the field alignment requirement? But yeah, one
> day we will remove enough of them :)

Yeah, the zswap_entry size is not changed :)

If later xarray conversion land in, the rb_node would be gone, so
one cacheline will be enough.

struct zswap_entry {
	struct rb_node             rbnode __attribute__((__aligned__(8))); /*     0    24 */
	swp_entry_t                swpentry;             /*    24     8 */
	unsigned int               length;               /*    32     4 */

	/* XXX 4 bytes hole, try to pack */

	struct zswap_pool *        pool;                 /*    40     8 */
	union {
		long unsigned int  handle;               /*    48     8 */
		long unsigned int  value;                /*    48     8 */
	};                                               /*    48     8 */
	struct obj_cgroup *        objcg;                /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	struct list_head           lru;                  /*    64    16 */

	/* size: 80, cachelines: 2, members: 7 */
	/* sum members: 76, holes: 1, sum holes: 4 */
	/* forced alignments: 1 */
	/* last cacheline: 16 bytes */
} __attribute__((__aligned__(8)));


      reply	other threads:[~2024-02-03  5:09 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 15:49 [PATCH 0/6] mm/zswap: optimize zswap lru list Chengming Zhou
2024-02-01 15:49 ` [PATCH 1/6] mm/zswap: add more comments in shrink_memcg_cb() Chengming Zhou
2024-02-01 17:45   ` Johannes Weiner
2024-02-01 23:55   ` Yosry Ahmed
2024-02-02 22:25   ` Nhat Pham
2024-02-01 15:49 ` [PATCH 2/6] mm/zswap: invalidate zswap entry when swap entry free Chengming Zhou
2024-02-01 17:49   ` Johannes Weiner
2024-02-01 20:56   ` Nhat Pham
2024-02-02  0:11   ` Yosry Ahmed
2024-02-02  8:10     ` Chengming Zhou
2024-02-01 15:49 ` [PATCH 3/6] mm/zswap: stop lru list shrinking when encounter warm region Chengming Zhou
2024-02-01 17:51   ` Johannes Weiner
2024-02-01 18:10   ` Nhat Pham
2024-02-02  0:15   ` Yosry Ahmed
2024-02-02  8:12     ` Chengming Zhou
2024-02-01 15:49 ` [PATCH 4/6] mm/zswap: remove duplicate_entry debug value Chengming Zhou
2024-02-01 17:55   ` Johannes Weiner
2024-02-02  8:18     ` Chengming Zhou
2024-02-02 22:17   ` Yosry Ahmed
2024-02-02 22:28   ` Nhat Pham
2024-02-03  4:29     ` Chengming Zhou
2024-02-01 15:49 ` [PATCH 5/6] mm/zswap: only support zswap_exclusive_loads_enabled Chengming Zhou
2024-02-01 18:12   ` Johannes Weiner
2024-02-02  1:04     ` Yosry Ahmed
2024-02-02 12:57     ` Chengming Zhou
2024-02-02 16:26       ` Johannes Weiner
2024-02-03  4:33         ` Chengming Zhou
2024-02-02 22:15       ` Yosry Ahmed
2024-02-02 22:31       ` Nhat Pham
2024-02-01 15:49 ` [PATCH 6/6] mm/zswap: zswap entry doesn't need refcount anymore Chengming Zhou
2024-02-02  1:11   ` Yosry Ahmed
2024-02-02 13:00     ` Chengming Zhou
2024-02-02 16:28   ` Johannes Weiner
2024-02-02 22:33   ` Nhat Pham
2024-02-02 22:36     ` Yosry Ahmed
2024-02-02 22:44       ` Nhat Pham
2024-02-03  5:09         ` Chengming Zhou [this message]

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=10f4fb80-a385-4c1e-974b-24057922ca62@bytedance.com \
    --to=zhouchengming@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=yosryahmed@google.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