From patchwork Thu Nov 30 10:12:23 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: 13474199 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 4857BC10DC1 for ; Thu, 30 Nov 2023 10:13:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEB1A6B0457; Thu, 30 Nov 2023 05:13:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A9A8B6B0458; Thu, 30 Nov 2023 05:13:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93BBA6B0459; Thu, 30 Nov 2023 05:13:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7EDC46B0457 for ; Thu, 30 Nov 2023 05:13:09 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5A9A5C0132 for ; Thu, 30 Nov 2023 10:13:09 +0000 (UTC) X-FDA: 81514207698.19.96E2ABD Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 76765180008 for ; Thu, 30 Nov 2023 10:13:07 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FlbUfkIh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701339187; 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=2h/f1F9fKvv2WfwxbmzHcgOXSHro6vTsEKLDmgFNvxE=; b=KtdrJA7Z54tjmKCMSepvxmUfZkcANd9dJItMUY48KEm15ptUFRK0D+XOD2MhjJaogTq6m1 grABTg7cHVw1PaWAD2j4V3jNQRSO9G0qR2UrXJRnX71fTVtRhAq6ICib0En2mSpXhQQQ91 dwZK2meQgXj3ZBe8/CURpe35KkpQfzQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FlbUfkIh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701339187; a=rsa-sha256; cv=none; b=nMx8+Nic8klC0Jc/iS/j3xe8yqcO3Im9Cdhtc63H4oL0uSf7fETx6bKOCOy8Th1eFZoSQY cKUkruFwGeR+h7H33jBf+RvoI7XSU04D/TbQqsYKlII9QkJLmjbGmb/5cY1zjnA8Bgrv7i 2rJ7x6VlWtf4zPLIf//9BMfH1xyPIFE= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6cddc59e731so685324b3a.1 for ; Thu, 30 Nov 2023 02:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701339186; x=1701943986; darn=kvack.org; 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=2h/f1F9fKvv2WfwxbmzHcgOXSHro6vTsEKLDmgFNvxE=; b=FlbUfkIhdzHiUxcTkTEbVCK0lcW9JDwE79hGqrS2kTD89qPFF8vhcqEOjw/K1R6Lk0 dlGQWheL4L3IY8Fs0AHWKjMaINBuNbOCcQQpjr5fykltn1voUgDgOJMmuGizVv3pYk3e jG5BzuFMmZLv3ubXP3MaaFBt98giDAyap9YHdhwPdTh8XkMGm+x4sJ2ZDCHFW3anPsgI COEu8WnJTIQCMolV6rBobsq7T00Fy2jht4jS88NpKgDtoAWnBUEa0fD8y/AKYeX281vk bBpNpGavmuWf4MNgOFcD0TJt3PnHFiQPfQVBUC9oFnQlz/PmOTset+PntG1bOL9nzim8 wy2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701339186; x=1701943986; 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=2h/f1F9fKvv2WfwxbmzHcgOXSHro6vTsEKLDmgFNvxE=; b=uSLCBzoCOVyqkRVcM1DbLVfUNFMtWBTPOHfJpuS+4rv0huvAMp6Tl3RuCTO1d2GSHG P/+gcur843iOotPTmqFpStJIJ0PQLP1cQfK8bWT5mqBmjYONc8eUt3Uer4ohOj1R1TJS EHFDrn3dDXTkVjRgOLwROfIE9CvqBHF/8eHTQxFnsDnR3ARkXTHV+8t/kkMyjLYzp/8M CrGVMhvKO6Q9bJmrqYIdhO++5G/HKZfvk+kmnRSPA7bWd/SyTlCwUbZZoEFJkiDSiBAP tBga1aa0BFLAloAcPQzFRtJooHO8AKWcuUtjmOTg/12wAT4xunTmhAKNbhVQBLaiM9Sz C73g== X-Gm-Message-State: AOJu0YzetsEsh3WI99pckM2dXU93u5PXNAdzidPDWEyb9ewcuzOAqZlG oZVYRfiFJf6WoK3sIzRq04s6Y7j1px4= X-Google-Smtp-Source: AGHT+IGyrl4qadlT8BFmM6NervDzr5nWt4c2GSSWUXePbBbF7UCO53Hy1sMP5F2FrQJ1h5Yyb6Yk6A== X-Received: by 2002:a05:6a00:1d81:b0:6b6:7a04:6f9 with SMTP id z1-20020a056a001d8100b006b67a0406f9mr20989074pfw.28.1701339186247; Thu, 30 Nov 2023 02:13:06 -0800 (PST) Received: from localhost.localdomain ([1.245.180.67]) by smtp.gmail.com with ESMTPSA id r27-20020aa78b9b000000b006900cb919b8sm841402pfd.53.2023.11.30.02.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:13:05 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Minchan Kim , Sergey Senozhatsky Cc: Matthew Wilcox , Mike Rapoport , Yosry Ahmed , linux-mm@kvack.org, Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [RFC PATCH v3 02/21] mm/zsmalloc: add utility functions for zsdesc Date: Thu, 30 Nov 2023 19:12:23 +0900 Message-Id: <20231130101242.2590384-3-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231130101242.2590384-1-42.hyeyoo@gmail.com> References: <20231130101242.2590384-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 76765180008 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 18d5hqe3oy9q5hftsr4bmo3396rj3uto X-HE-Tag: 1701339187-23730 X-HE-Meta: U2FsdGVkX1+xFmzBCnEiudjf33fTcCtJPwvMHDD/WtxvWDEtryr4Os6q2nlAt4HT1uSdXKpCNguPhMgAWQ/ImONAJA3YxyBWeS012ECfrGW4/dwQWU/mumje/s721dDZF0WxLNTN4+v5HoIvcl7YBonqy73L/CutQR2AmM8jL25aLaybZy4m9aqrfvC6YOjH333p/4PZG8XWX2IrG4a7KjtZXXUrhyiQUX0CgxNiEUt60SH0UXDCICy+x+Ht4spnPzkhQeJMLcNLTfSItaHvxcDzFqzYsqYupoZLNOio40XXOr+JI229HN5DB/V/gtjj6WYbbYKlE8O0F1FPr6ZEe/m43IT9BVQ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a7W287B5LphaQY7e1uzyj4hZPRaK5o2nEDRenKkSRCkzEuub6TtZUZHAk5FBEWZK3YuZkZlMdK4wgOfBw9d73xK2E/fiexP+bS8Qp++Ip5vdKigddkDq4CM= 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: Introduce basic utility functions for zsdesc to avoid directly accessing fields of struct page. More helpers will be defined later. zsdesc_page() is defined with _Generic 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 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 60ce2a4dfeeb..47df9103787e 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -274,6 +274,39 @@ ZSDESC_MATCH(_refcount, __page_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 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); +} + struct zspage { struct { unsigned int huge:HUGE_BITS;