From patchwork Fri Jun 21 05:46:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 13706856 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 7978FC2BB85 for ; Fri, 21 Jun 2024 05:42:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DCEB8D012B; Fri, 21 Jun 2024 01:42:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03EBB8D0111; Fri, 21 Jun 2024 01:42:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5CD58D012B; Fri, 21 Jun 2024 01:42:13 -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 B862F8D0111 for ; Fri, 21 Jun 2024 01:42:13 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6AEB31208E3 for ; Fri, 21 Jun 2024 05:42:13 +0000 (UTC) X-FDA: 82253800146.04.D096893 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf08.hostedemail.com (Postfix) with ESMTP id 15DDB160005 for ; Fri, 21 Jun 2024 05:42:10 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KRbg5wZp; spf=pass (imf08.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718948526; a=rsa-sha256; cv=none; b=KWATXxzxlaEh6hzYAoMyQghEurSebHlCWObnCdoKfwnb3DSAWgsM+QlScBb5QqtkwKY4tm RJ3NoJsCHFSiLbmamYLCXDruCWk8ll+qHQPAWDpfTsTBc0LI2Fb5Kq8gLNIydBS64XDPVO usXes7XzEDTdaN984gzvg2t+I/mcAXk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KRbg5wZp; spf=pass (imf08.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718948526; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BkBVYVuMjV3319nLn+w3Yv8JYBQVj4axiEvQvyDorbc=; b=s+/3Eowumw0px0aRWovIgLof+u9lI5rpNCPA18zb+1gP5nx2GlLnVHdBkheaaeFqfF0O7N aZel2/f7bRKGD8tzG+YsY7et8oLA+H3o4vvM/xU0Npw+ObxmIF9NiCBwUjHjgdmBn+9Yk0 Me1c8QXe9whZ9SEoUYHhQ6tbWJEmRZA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 0CEC0CE2B50; Fri, 21 Jun 2024 05:42:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3DADC4AF0A; Fri, 21 Jun 2024 05:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718948527; bh=nrW0QvxLKLlDHZUd0Xa2UXqPdoTHBMmkz4AnWaU+jyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KRbg5wZpEC9mSEW33Mg+dxiP8pUoi07ZZ/5F/960HRxTGr8p88LrW+F7XECclmEQl c9eBg3G/dL2KRKCuhTn6ckQKH5geiK9dUhWc66Uvkf44QjZrkLszJJPW+rbg92AKJI sTIqfeF4GpOYKmdvdQY2sR4qJ1T9QBF3O9ZfqtwKW6DK1B8NpGP2pJZuN8C3EJwbjq fKzlvXmy0auuOFcFNp8iZeqNUXgq2lGT0nSv62pFsCeLR73b0y/mgXvSQAPlpq8wjA H0WmCMVCCZFAt1sLB4fTlXvI51DjEhP819kD3TdnzWezEAuF7mgPHBhTs9d6p7IhXN u46tfDHGJD5lA== From: alexs@kernel.org To: Vitaly Wool , Miaohe Lin , Andrew Morton , 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 Cc: Alex Shi Subject: [PATCH 01/15] mm/z3fold: add zpdesc struct and helper and use them in z3fold_page_isolate Date: Fri, 21 Jun 2024 13:46:41 +0800 Message-ID: <20240621054658.1220796-2-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621054658.1220796-1-alexs@kernel.org> References: <20240621054658.1220796-1-alexs@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 3a6kjdyfos8d7fyz3dobtnttwipxf9yt X-Rspamd-Queue-Id: 15DDB160005 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718948530-840269 X-HE-Meta: U2FsdGVkX1+GwZjKaFYOenKZ+kQJbtnx3N/K1d6lKSjK9FL8WeGElTkavgXwn9+S1Fs835zpmO71PrJ1S51hXm0rIEfpEdHwQK79xQei70RvI2+krNmffSiy7ErBnU+c7NMbMdRTlo80gNnwpv+8I5rUN32ZILx7/2ayh6Rr9m+2mtQScVnfmahhngFTxXmKmM/Aapd400FeCnozXkktU47jtNQST83qpJfPcO414Is1afwQB1GdJC1qgz6q0Cn5tKhZbayDjJVr7Kq1a+xGJlcLFbDtJxn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eCSVADrht+1a+ZQNF9p7tg= 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: From: Alex Shi The 1st patch here, we introduce some helper functions along with struct zpdesc, like zpdesc_page/zpdesc_folio/page_zpdesc and zpdesc_address similar with folio_address, and convert page to zpdesc in func z3fold_page_isolate. z3fold_page_isolate() hooked to page_isolate that the reason we could not fully remove page from its parameter for now. Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Suggested-by: David Hildenbrand Signed-off-by: Alex Shi --- mm/z3fold.c | 14 ++++++++------ mm/zpdesc.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 mm/zpdesc.h diff --git a/mm/z3fold.c b/mm/z3fold.c index 2ebfed32871b..b1229c0520f1 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -40,6 +40,7 @@ #include #include #include +#include "zpdesc.h" /* * NCHUNKS_ORDER determines the internal allocation granularity, effectively @@ -1251,22 +1252,23 @@ static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode) { struct z3fold_header *zhdr; struct z3fold_pool *pool; + struct zpdesc *zpdesc = page_zpdesc(page); - VM_BUG_ON_PAGE(PageIsolated(page), page); + VM_BUG_ON_PAGE(PageIsolated(zpdesc_page(zpdesc)), zpdesc_page(zpdesc)); - if (test_bit(PAGE_HEADLESS, &page->private)) + if (test_bit(PAGE_HEADLESS, &zpdesc->zppage_flag)) return false; - zhdr = page_address(page); + zhdr = zpdesc_address(zpdesc); z3fold_page_lock(zhdr); - if (test_bit(NEEDS_COMPACTING, &page->private) || - test_bit(PAGE_STALE, &page->private)) + if (test_bit(NEEDS_COMPACTING, &zpdesc->zppage_flag) || + test_bit(PAGE_STALE, &zpdesc->zppage_flag)) goto out; if (zhdr->mapped_count != 0 || zhdr->foreign_handles != 0) goto out; - if (test_and_set_bit(PAGE_CLAIMED, &page->private)) + if (test_and_set_bit(PAGE_CLAIMED, &zpdesc->zppage_flag)) goto out; pool = zhdr_to_pool(zhdr); spin_lock(&pool->lock); diff --git a/mm/zpdesc.h b/mm/zpdesc.h new file mode 100644 index 000000000000..d51785863596 --- /dev/null +++ b/mm/zpdesc.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* zpdesc.h: zswap.zpool memory descriptor + * + * Written by Alex Shi (Tencent) + */ +#ifndef __MM_ZPDESC_H__ +#define __MM_ZPDESC_H__ + +/* + * struct zpdesc - Memory descriptor for z3fold memory + * @flags: Page flags, PG_locked for headless z3fold memory + * @lru: Indirected used by page migration + * @zppage_flag: z3fold memory flags + * + * 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; + unsigned long _zp_pad_1; + unsigned long _zp_pad_2; + unsigned long zppage_flag; +}; +#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(private, zppage_flag); +#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))) + +static inline void *zpdesc_address(const struct zpdesc *zpdesc) +{ + return folio_address(zpdesc_folio(zpdesc)); +} + +#endif