From patchwork Mon Feb 20 13:21:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 13146430 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 D2128C05027 for ; Mon, 20 Feb 2023 13:22:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C7976B0075; Mon, 20 Feb 2023 08:22:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 69D006B0078; Mon, 20 Feb 2023 08:22:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 516B86B007B; Mon, 20 Feb 2023 08:22:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 43C6E6B0075 for ; Mon, 20 Feb 2023 08:22:42 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1C4FAA0729 for ; Mon, 20 Feb 2023 13:22:42 +0000 (UTC) X-FDA: 80487734964.19.F6A6DEC Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf22.hostedemail.com (Postfix) with ESMTP id 27ED7C001D for ; Mon, 20 Feb 2023 13:22:39 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UHdrxgrp; spf=pass (imf22.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676899360; 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=25ubEDcvqtlbcUDXHLpY97pPX3i6N2AmkqsUOsE/gOw=; b=Y9AMAGlHPSCR1+V+4JrA7hWXPYadFSM3H3LIZa99AQ9jptxeMD09Z6ASMxEZFiu0vmGxcf wwlLPN8IHRVgXcyeKuI7igqfuSd9GQf66eUQE1x15L2k0lt2luWi5357K18hB7mzANeHbi 1MMIdyPuWX/gVC3nZGuRRfd0DIKucdg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=UHdrxgrp; spf=pass (imf22.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676899360; a=rsa-sha256; cv=none; b=Cav6vl/60DNJ9+HawqLPtSGxrbQjsA0h/+zT/8PSHSb0yDny8uY+HfzruwMc9ukMcqOCFo rcwlSAPaFetkTzmrtz6q0BoWecrBXcCBzEgT6azNNQeGb6Njs6MikgOu1Y8KRHYZAklEJE CLqn6xWl20XmvhI9Yw1Wyjb/HC+5WMk= Received: by mail-pl1-f181.google.com with SMTP id e5so2394261plg.8 for ; Mon, 20 Feb 2023 05:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=25ubEDcvqtlbcUDXHLpY97pPX3i6N2AmkqsUOsE/gOw=; b=UHdrxgrp0IvrkOTYA8RHpGNZwTil6H3+a5XqSpKvvLyLjAKezper0fnx7g+T9GvQ38 ipy1Ezf8kJh5e4JaUmc/8aRBf+cXhPijYy3zfUCbEzb1jCxVUwwFFUgeJSjQ+qNmM07T /PRKVVE5e6IFNsAGnVFn5bMxiBuySHcWgnSN+5n2Guv6V9Pt1zhfC0sik/ldEpoy8+gP k00bLezTq8096aQR9R9ktxnF4kJzVRicD4wcXaHJh0z+BY6sBv+/xpvqVYe3WcyIUnc8 o6aD61EPbZKuPLcc/bUc07VPDMg77qKBTeD/fGxr7xldMq9JuFvETVTNiqVwIZ1xJuWd JOOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=25ubEDcvqtlbcUDXHLpY97pPX3i6N2AmkqsUOsE/gOw=; b=f7vwJzcDSDbs1sYZjqPJTviEwe6eJ9SKUMZu2qXCpjaVbv5YEUKOkFYTgS4si5hnwd y4FJb2N1BtkLMfLV8qqFbo7/VJwEtYv2jQ0SmcrmUZJ0u1yx8rHKDCX5UeC1ai3reSYv 2gu+n4CDFcWjvngYDYq3lRdopK6702tZFd5dWgRC6L1cMocfIBBzJ382wRBnsc00YnUU heBuZ7KezcG/6neicd7dLP1hWdP1ib12VvjVW0epAOdr5FC6EdKVou4XOXQMBJgd5zx5 9sDOilbF/Z/SiOChZ2rinkyJk6TW9Hwy0Jh1DF2DWPwjqnk3XjHzlQtcd1RGppwSiH0z 4AkA== X-Gm-Message-State: AO0yUKX8oUCPvKArqy4eW9spmgGndmQrVwTxuHyRfmpl1oWdso3uEAmJ YnAkrkFCI9OVPygso2ALc3A= X-Google-Smtp-Source: AK7set/aXrtaYVuaiGcteULWSBlZk5B6OdOOxkIhfg+8YJr/Tj4oZzpeX2CVCa+OiINayP9Kek5VqA== X-Received: by 2002:a17:902:eccc:b0:19a:74c7:dcda with SMTP id a12-20020a170902eccc00b0019a74c7dcdamr3271176plh.15.1676899359025; Mon, 20 Feb 2023 05:22:39 -0800 (PST) Received: from test-ha.kr-central-1.c.kakaoi.io ([210.109.63.229]) by smtp.gmail.com with ESMTPSA id x2-20020a170902fe8200b0019c13d032d8sm6125436plm.253.2023.02.20.05.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 05:22:38 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Minchan Kim , Sergey Senozhatsky , Matthew Wilcox Cc: Andrew Morton , linux-mm@kvack.org, Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [RFC PATCH 02/25] mm/zsmalloc: add utility functions for zsdesc Date: Mon, 20 Feb 2023 13:21:55 +0000 Message-Id: <20230220132218.546369-3-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230220132218.546369-1-42.hyeyoo@gmail.com> References: <20230220132218.546369-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Stat-Signature: we5x97bpcdadg98zrtmp6ppb33cc3s8b X-Rspam-User: X-Rspamd-Queue-Id: 27ED7C001D X-Rspamd-Server: rspam06 X-HE-Tag: 1676899359-672095 X-HE-Meta: U2FsdGVkX1/fZu8Hv39zJ/SxiQGe7yP9bnNHZDWK3dK0vsgbvhPOWsg4ycpvNayBQont+DGK4M9/QYEq2ztxMpQQ5pERLwkBZYDoNSqRXKvcmfgaQDMZyOW/TMOZGyR8A3gIpa1mrol/7rKHxaGWm+73J61KVw9z75R9K5wnBxcJhnoKSllDkd0FIDpCHVG0wCHqa5FNyHCx1P9Rn7TALOSKbJKLFLmzV/F4otf3NUeg1fxJVx3Mduw0OsG1CAOw0NFvjV9KcVxQ/QPdDIrm3cOLU1R4JI/lUHvDvYGO06fdetXYTLimO1X1SRpjoy6Hx/SzeQeTC8nkezzzG+DWszN6Sue1grPP+MpQijBSt2MmUSHcA+4mTT6+USbapZnauGShTsuVOCp2bqY9SuIoa5WKAl4RlAA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moFRtAFpNMwfaRAFM2D8EBqkETHSEX8aaOzq0YzP/Y9uZyyLCkAxIrhtmt29PfWINupwKhiRfMw4Q== 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: Introduce utility functions for zsdesc to avoid directly accessing fields of struct page. zsdesc_page() is defined this way to preserve constness. page_zsdesc() does not call compound_head() because zsdesc is always a base page. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/zsmalloc.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index e2e34992c439..4af9f87cafb7 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -332,6 +332,124 @@ ZSDESC_MATCH(_refcount, _refcount); #undef ZSDESC_MATCH static_assert(sizeof(struct zsdesc) <= sizeof(struct page)); +#define zsdesc_page(zdesc) (_Generic((zdesc), \ + const struct zsdesc *: (const struct page *)zdesc, \ + struct zsdesc *: (struct page *)zdesc)) + +static inline struct zsdesc *page_zsdesc(struct page *page) +{ + return (struct zsdesc *)page; +} + +static inline unsigned long zsdesc_pfn(const struct zsdesc *zsdesc) +{ + return page_to_pfn(zsdesc_page(zsdesc)); +} + +static inline struct zsdesc *pfn_zsdesc(unsigned long pfn) +{ + return page_zsdesc(pfn_to_page(pfn)); +} + +static inline struct zspage *zsdesc_zspage(const struct zsdesc *zsdesc) +{ + return (struct zspage *)page_private(zsdesc_page(zsdesc)); +} + +static inline int trylock_zsdesc(struct zsdesc *zsdesc) +{ + return trylock_page(zsdesc_page(zsdesc)); +} + +static inline void unlock_zsdesc(struct zsdesc *zsdesc) +{ + return unlock_page(zsdesc_page(zsdesc)); +} + +static inline struct zone *zsdesc_zone(struct zsdesc *zsdesc) +{ + return page_zone(zsdesc_page(zsdesc)); +} + +static inline void wait_on_zsdesc_locked(struct zsdesc *zsdesc) +{ + wait_on_page_locked(zsdesc_page(zsdesc)); +} + +static inline void zsdesc_get(struct zsdesc *zsdesc) +{ + struct folio *folio = (struct folio *)zsdesc; + + folio_get(folio); +} + +static inline void zsdesc_put(struct zsdesc *zsdesc) +{ + struct folio *folio = (struct folio *)zsdesc; + + folio_put(folio); +} + +static inline void *zsdesc_kmap_atomic(struct zsdesc *zsdesc) +{ + return kmap_atomic(zsdesc_page(zsdesc)); +} + +static inline void zsdesc_set_zspage(struct zsdesc *zsdesc, struct zspage *zspage) +{ + set_page_private(zsdesc_page(zsdesc), (unsigned long)zspage); +} + +static inline void zsdesc_set_first(struct zsdesc *zsdesc) +{ + SetPagePrivate(zsdesc_page(zsdesc)); +} + +static inline bool zsdesc_is_locked(struct zsdesc *zsdesc) +{ + return PageLocked(zsdesc_page(zsdesc)); +} + +static inline bool zsdesc_is_isolated(struct zsdesc *zsdesc) +{ + return PageIsolated(zsdesc_page(zsdesc)); +} + +static inline void zsdesc_inc_zone_page_state(struct zsdesc *zsdesc) +{ + inc_zone_page_state(zsdesc_page(zsdesc), NR_ZSPAGES); +} + +static inline void zsdesc_dec_zone_page_state(struct zsdesc *zsdesc) +{ + dec_zone_page_state(zsdesc_page(zsdesc), NR_ZSPAGES); +} + +static inline struct zsdesc *alloc_zsdesc(gfp_t gfp) +{ + struct page *page = alloc_page(gfp); + + zsdesc_inc_zone_page_state(page_zsdesc(page)); + return page_zsdesc(page); +} + +static inline void free_zsdesc(struct zsdesc *zsdesc) +{ + struct page *page = zsdesc_page(zsdesc); + + zsdesc_dec_zone_page_state(page_zsdesc(page)); + __free_page(page); +} + +static const struct movable_operations zsmalloc_mops; + +static inline void zsdesc_set_movable(struct zsdesc *zsdesc) +{ + struct page *page = zsdesc_page(zsdesc); + + __SetPageMovable(page, &zsmalloc_mops); +} + /* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */ static void SetZsHugePage(struct zspage *zspage) { @@ -2012,8 +2130,6 @@ static void dec_zspage_isolation(struct zspage *zspage) zspage->isolated--; } -static const struct movable_operations zsmalloc_mops; - static void replace_sub_page(struct size_class *class, struct zspage *zspage, struct page *newpage, struct page *oldpage) {