linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vishal Moola <vishal.moola@gmail.com>
To: alexs@kernel.org
Cc: Vitaly Wool <vitaly.wool@konsulko.com>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	minchan@kernel.org, willy@infradead.org,
	senozhatsky@chromium.org, david@redhat.com, 42.hyeyoo@gmail.com,
	Yosry Ahmed <yosryahmed@google.com>,
	nphamcs@gmail.com
Subject: Re: [PATCH v4 01/22] mm/zsmalloc: add zpdesc memory descriptor for zswap.zpool
Date: Fri, 2 Aug 2024 11:52:04 -0700	[thread overview]
Message-ID: <66ad2ad7.170a0220.3a8e93.6a32@mx.google.com> (raw)
In-Reply-To: <20240729112534.3416707-2-alexs@kernel.org>

On Mon, Jul 29, 2024 at 07:25:13PM +0800, alexs@kernel.org wrote:
> From: Alex Shi <alexs@kernel.org>

I've been busy with other things, so I haven't been able to review this
until now. Thanks to both you and Hyeonggon for working on this memdesc :)

> The 1st patch introduces new memory decriptor zpdesc and rename
> zspage.first_page to zspage.first_zpdesc, no functional change.
> 
> We removed PG_owner_priv_1 since it was moved to zspage after
> commit a41ec880aa7b ("zsmalloc: move huge compressed obj from
> page to zspage").
> 
> And keep the memcg_data member, since as Yosry pointed out:
> "When the pages are freed, put_page() -> folio_put() -> __folio_put() will call
> mem_cgroup_uncharge(). The latter will call folio_memcg() (which reads
> folio->memcg_data) to figure out if uncharging needs to be done.
> 
> There are also other similar code paths that will check
> folio->memcg_data. It is currently expected to be present for all
> folios. So until we have custom code paths per-folio type for
> allocation/freeing/etc, we need to keep folio->memcg_data present and
> properly initialized."
> 
> Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> Signed-off-by: Alex Shi <alexs@kernel.org>
> ---
>  mm/zpdesc.h   | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  mm/zsmalloc.c | 21 ++++++++--------
>  2 files changed, 76 insertions(+), 11 deletions(-)
>  create mode 100644 mm/zpdesc.h
> 
> diff --git a/mm/zpdesc.h b/mm/zpdesc.h
> new file mode 100644
> index 000000000000..2dbef231f616
> --- /dev/null
> +++ b/mm/zpdesc.h
> @@ -0,0 +1,66 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* zpdesc.h: zswap.zpool memory descriptor
> + *
> + * Written by Alex Shi <alexs@kernel.org>
> + *	      Hyeonggon Yoo <42.hyeyoo@gmail.com>
> + */
> +#ifndef __MM_ZPDESC_H__
> +#define __MM_ZPDESC_H__
> +
> +/*
> + * struct zpdesc -	Memory descriptor for zpool memory, now is for zsmalloc
> + * @flags:		Page flags, PG_private: identifies the first component page
> + * @lru:		Indirectly used by page migration
> + * @mops:		Used by page migration
> + * @next:		Next zpdesc in a zspage in zsmalloc zpool
> + * @handle:		For huge zspage in zsmalloc zpool
> + * @zspage:		Pointer to zspage in zsmalloc
> + * @memcg_data:		Memory Control Group data.
> + *

I think its a good idea to include comments for the padding (namely what
aliases with it in struct page) here as well. It doesn't hurt, and will
make them easier to remove in the future.

> + * This struct overlays struct page for now. Do not modify without a good
> + * understanding of the issues.
> + */
> +struct zpdesc {
> +	unsigned long flags;
> +	struct list_head lru;
> +	struct movable_operations *mops;
> +	union {
> +		/* Next zpdescs in a zspage in zsmalloc zpool */
> +		struct zpdesc *next;
> +		/* For huge zspage in zsmalloc zpool */
> +		unsigned long handle;
> +	};
> +	struct zspage *zspage;

I like using pointers here, although I think the comments should be more
precise about what the purpose of the pointer is. Maybe something like
"Points to the zspage this zpdesc is a part of" or something.

> +	unsigned long _zp_pad_1;
> +#ifdef CONFIG_MEMCG
> +	unsigned long memcg_data;
> +#endif
> +};

You should definitely fold your additions to the struct from patch 17
into this patch. It makes it easier to review, and better for anyone
looking at the commit log in the future.

> +#define ZPDESC_MATCH(pg, zp) \
> +	static_assert(offsetof(struct page, pg) == offsetof(struct zpdesc, zp))
> +
> +ZPDESC_MATCH(flags, flags);
> +ZPDESC_MATCH(lru, lru);
> +ZPDESC_MATCH(mapping, mops);
> +ZPDESC_MATCH(index, next);
> +ZPDESC_MATCH(index, handle);
> +ZPDESC_MATCH(private, zspage);
> +#ifdef CONFIG_MEMCG
> +ZPDESC_MATCH(memcg_data, memcg_data);
> +#endif
> +#undef ZPDESC_MATCH
> +static_assert(sizeof(struct zpdesc) <= sizeof(struct page));
> +
> +#define zpdesc_page(zp)			(_Generic((zp),			\
> +	const struct zpdesc *:		(const struct page *)(zp),	\
> +	struct zpdesc *:		(struct page *)(zp)))
> +
> +#define zpdesc_folio(zp)		(_Generic((zp),			\
> +	const struct zpdesc *:		(const struct folio *)(zp),	\
> +	struct zpdesc *:		(struct folio *)(zp)))
> +
> +#define page_zpdesc(p)			(_Generic((p),			\
> +	const struct page *:		(const struct zpdesc *)(p),	\
> +	struct page *:			(struct zpdesc *)(p)))
> +
> +#endif

I'm don't think we need both page and folio cast functions for zpdescs.
Sticking to pages will probably suffice (and be easiest) since all APIs
zsmalloc cares about are already defined. 

We can stick to 1 "middle-man" descriptor for zpdescs since zsmalloc
uses those pages as space to track zspages and nothing more. We'll likely
end up completely removing it from zsmalloc once we can allocate
memdescs on their own: It seems most (if not all) of the "indirect" members
of zpdesc are used as indicators to the rest of core-mm telling them not to
mess with that memory.


  reply	other threads:[~2024-08-02 18:52 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-29 11:25 [PATCH v4 00/22] " alexs
2024-07-29 11:25 ` [PATCH v4 01/22] " alexs
2024-08-02 18:52   ` Vishal Moola [this message]
2024-08-05  4:06     ` Alex Shi
2024-08-08 18:21       ` Vishal Moola
2024-08-09  1:57         ` Alex Shi
2024-08-02 19:30   ` Matthew Wilcox
2024-08-05  4:36     ` Alex Shi
2024-07-29 11:25 ` [PATCH v4 02/22] mm/zsmalloc: use zpdesc in trylock_zspage/lock_zspage alexs
2024-08-02 19:02   ` Vishal Moola
2024-08-05  7:55     ` Alex Shi
2024-07-29 11:25 ` [PATCH v4 03/22] mm/zsmalloc: convert __zs_map_object/__zs_unmap_object to use zpdesc alexs
2024-07-30  9:38   ` Sergey Senozhatsky
2024-07-29 11:25 ` [PATCH v4 04/22] mm/zsmalloc: add and use pfn/zpdesc seeking funcs alexs
2024-07-29 11:25 ` [PATCH v4 05/22] mm/zsmalloc: convert obj_malloc() to use zpdesc alexs
2024-07-29 11:25 ` [PATCH v4 06/22] mm/zsmalloc: convert create_page_chain() and its users " alexs
2024-08-02 19:09   ` Vishal Moola
2024-08-05  8:20     ` Alex Shi
2024-08-08 18:25       ` Vishal Moola
2024-08-09  1:57         ` Alex Shi
2024-07-29 11:25 ` [PATCH v4 07/22] mm/zsmalloc: convert obj_allocated() and related helpers " alexs
2024-07-29 11:25 ` [PATCH v4 08/22] mm/zsmalloc: convert init_zspage() " alexs
2024-07-29 11:25 ` [PATCH v4 09/22] mm/zsmalloc: convert obj_to_page() and zs_free() " alexs
2024-07-29 11:25 ` [PATCH v4 10/22] mm/zsmalloc: add zpdesc_is_isolated/zpdesc_zone helper for zs_page_migrate alexs
2024-07-29 11:25 ` [PATCH v4 11/22] mm/zsmalloc: rename reset_page to reset_zpdesc and use zpdesc in it alexs
2024-07-29 11:25 ` [PATCH v4 12/22] mm/zsmalloc: convert __free_zspage() to use zdsesc alexs
2024-07-29 11:25 ` [PATCH v4 13/22] mm/zsmalloc: convert location_to_obj() to take zpdesc alexs
2024-07-29 11:25 ` [PATCH v4 14/22] mm/zsmalloc: convert migrate_zspage() to use zpdesc alexs
2024-07-29 11:25 ` [PATCH v4 15/22] mm/zsmalloc: convert get_zspage() to take zpdesc alexs
2024-07-29 11:25 ` [PATCH v4 16/22] mm/zsmalloc: convert SetZsPageMovable and remove unused funcs alexs
2024-07-29 11:25 ` [PATCH v4 17/22] mm/zsmalloc: convert get/set_first_obj_offset() to take zpdesc alexs
2024-07-29 11:25 ` [PATCH v4 18/22] mm/zsmalloc: introduce __zpdesc_clear_movable alexs
2024-07-30  9:34   ` Sergey Senozhatsky
2024-07-30 11:38     ` Alex Shi
2024-07-29 11:25 ` [PATCH v4 19/22] mm/zsmalloc: introduce __zpdesc_clear_zsmalloc alexs
2024-07-29 11:25 ` [PATCH v4 20/22] mm/zsmalloc: introduce __zpdesc_set_zsmalloc() alexs
2024-08-02 19:11   ` Vishal Moola
2024-08-05  8:28     ` Alex Shi
2024-07-29 11:25 ` [PATCH v4 21/22] mm/zsmalloc: fix build warning from lkp testing alexs
2024-08-02 19:13   ` Vishal Moola
2024-08-05  8:38     ` Alex Shi
2024-07-29 11:25 ` [PATCH v4 22/22] mm/zsmalloc: update comments for page->zpdesc changes alexs
2024-07-30  9:37   ` Sergey Senozhatsky
2024-07-30 11:45     ` Alex Shi
2024-07-31  2:16       ` Sergey Senozhatsky
2024-07-31  4:14         ` Alex Shi
2024-08-01  3:13           ` Sergey Senozhatsky
2024-08-01  3:35             ` Matthew Wilcox
2024-08-01  8:06               ` Alex Shi
2024-07-30 12:31 ` [PATCH 23/23] mm/zsmalloc: introduce zpdesc_clear_first() helper alexs

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=66ad2ad7.170a0220.3a8e93.6a32@mx.google.com \
    --to=vishal.moola@gmail.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexs@kernel.org \
    --cc=david@redhat.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=vitaly.wool@konsulko.com \
    --cc=willy@infradead.org \
    --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