From patchwork Thu Jul 13 04:20:16 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: 13311265 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 343AEC001B0 for ; Thu, 13 Jul 2023 04:21:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5A228D0001; Thu, 13 Jul 2023 00:20:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B974C6B007D; Thu, 13 Jul 2023 00:20:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E88A8D0001; Thu, 13 Jul 2023 00:20:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8A1456B007B for ; Thu, 13 Jul 2023 00:20:59 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 60B4D1A00DF for ; Thu, 13 Jul 2023 04:20:59 +0000 (UTC) X-FDA: 81005288238.23.F69B44E Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by imf30.hostedemail.com (Postfix) with ESMTP id 77BC280004 for ; Thu, 13 Jul 2023 04:20:57 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=OmNB2v7c; spf=pass (imf30.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.167.180 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=1689222057; 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=JDYdNA9lDVtoD8B2uXnOlmCKBsx14i431NGid1vWIJk=; b=kSl362G9My8H0OdmrxQRbCouZy62Nzv72271+ZqiczEPXoiSZGLqTZFszaCLU7G3AdZ/ZQ pcY39vh3/gGD0cDZgTlQduQ6uxLbcdwy2Rlo+3ph6UJknGyvfhPnCAx6L5ZE07KHtd40Hs tg1z1N50574TENLpfZpAX21NrESoXH0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=OmNB2v7c; spf=pass (imf30.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.167.180 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=1689222057; a=rsa-sha256; cv=none; b=NYBSXZvzySqjpLyQBVcTEj/0vxpw90y/2IG8WgD5hBpxPMjuBjTYLb7XSNivLUOu1pSYbL NZizNepp/z4q1Wqb8dfkjwCBb6mRd3jP062nlSHoBpAaQZSiw8nAUuWpS9/ZJs1jz+5I64 gEXUO3NkmgVUjRyl/cGyZZe9Tkj/QU4= Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3a3e1152c23so273643b6e.2 for ; Wed, 12 Jul 2023 21:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689222056; x=1691814056; 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=JDYdNA9lDVtoD8B2uXnOlmCKBsx14i431NGid1vWIJk=; b=OmNB2v7cPzjVbjCrPHesJGkG5OJ1x1rIpPnLFGkHy+8vUnmdOeiKvfhZnn6H9NJFu7 tjvfzbEKpbhx4EHl53IwQ9rpc1UZNnL1xzNCh5xu44eiS8/Xq+kyQUF0+xh6PU2Zg7Ej KwQhjbRoGatW4uiCRRA6RjICwcrolxwLBciT9JtjbWh/Z8HecM2mRJKFjspy2Q7x0oES PpLTX6U/XS/x2THUtSOszV9RZo0XzKKz+KoLi/FH7+fIwzNjLslWgoiBStNeNMKUYQ1U od21C3PGMosTsyePKwlzjYtOXcv5nFXdISwYjt7DfWwxEnq31xqijLaDKuRDUeC8kiBA GjpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689222056; x=1691814056; 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=JDYdNA9lDVtoD8B2uXnOlmCKBsx14i431NGid1vWIJk=; b=IziH5x60MUMoXM9oR36pUoq4z8T41I3nrPsA5QxaptxbBi0MwpuJdQyJhSvxq2jlfP KS8fGmCvwOy98PjWK5tnuGMutYlRdZ2w9xv389MAbcZ1/aazTzkRFxwz6Y52BQFSWISd 1vPSW7nGWmS06Ccue7qN3FYS6moR2hefG7vYPXjd06en3I85UGDOWAuCUVf8YiaaCWHk BykDZB6+hRKeB6u6AsMsCDIY8Xng11x7Z1ZQlac3EyJ76coYwMhbw1hHPwy7jURFRzLp kX6fktNcc+5xh/e5nNeK5sfV5gB9rSj6f3eSijkLF1L4dK3g9dAAwE/Y4Hcdg3OSHoap s1bA== X-Gm-Message-State: ABy/qLZ4wR/SdmKfoTMqYwLqr5hRgPNe+N3W4021me2Ghd4slxaliu0Q /UfEuoD0N5zIZor4crhEEdw= X-Google-Smtp-Source: APBJJlHQxzKWeFUb/2UkMXGmNGKuylqY/krdL/0xjSDkichAxJjhqdaXBt4aeDVvXdaDtSe6XlZmbw== X-Received: by 2002:a05:6808:1b1e:b0:3a1:c841:f026 with SMTP id bx30-20020a0568081b1e00b003a1c841f026mr675089oib.27.1689222056477; Wed, 12 Jul 2023 21:20:56 -0700 (PDT) Received: from fedora.. ([1.245.179.104]) by smtp.gmail.com with ESMTPSA id u18-20020aa78392000000b006827c26f147sm4346601pfm.138.2023.07.12.21.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 21:20:55 -0700 (PDT) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Minchan Kim , Sergey Senozhatsky Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox , Mike Rapoport , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [RFC PATCH v2 01/21] mm/zsmalloc: create new struct zsdesc Date: Thu, 13 Jul 2023 13:20:16 +0900 Message-ID: <20230713042037.980211-2-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713042037.980211-1-42.hyeyoo@gmail.com> References: <20230713042037.980211-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 77BC280004 X-Rspam-User: X-Stat-Signature: kcjhxnrwfkt9tw179r5ugsqms8rjem4n X-Rspamd-Server: rspam01 X-HE-Tag: 1689222057-186999 X-HE-Meta: U2FsdGVkX19UmnMi91CX3Xu/gwOLvdEicv1ieMCq/EZlLMy1THWpNS8993M2UzwaqqNCVcbVqeHcDtEqUugdRLyosD8M6MoDqWxWUT3u6F/XSnvHgDoiMXO57rfZTzlMJ+Izwesn1frtzUGiylabzAVXwpBJh+Ms3Xu9bFDPzkiUVu+PRK6O5aOFWCHPxtC6RFCQkQT4D8gcYa+PGq/dgs75L6qA3Dpgfy5ztYPHFrlj6s/o8w761KyqySlF5qJzp9ybQ2AL1zS0NUIjzvRQ4bolaNhyZprTQ4Og0V3wncSqSKH19DDjrWIWyYu4EjysmuS4pFakm57h7vJ6CRGXirYXlAlh7Vymax60j9XeQsVGJIBgHQ+Yjr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DjpmjV/kKQ2HpSxayWihXD/cX3wtbZ4+Vp8SHJBdiADVHai0FCjM0FUAAnQDt3brN0NpvtIkgZuTEyWWrHqceZSm8hNDsZY= 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: Currently zsmalloc reuses fields of struct page. As part of simplifying struct page, create own type for zsmalloc called zsdesc. Remove comments about how zsmalloc reuses fields of struct page, because zsdesc uses more intuitive names. Note that zsmalloc does not use PG_owner_priv_v1 after commit a41ec880aa7b ("zsmalloc: move huge compressed obj from page to zspage"). Thus only document how zsmalloc uses PG_private flag. It is very tempting to rearrange zsdesc, but the three words after flags field are not available for zsmalloc. Add comments about that. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/zsmalloc.c | 63 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 32f5bc4074df..2204bea4f289 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -11,23 +11,6 @@ * Released under the terms of GNU General Public License Version 2.0 */ -/* - * Following is how we use various fields and flags of underlying - * struct page(s) to form a zspage. - * - * Usage of struct page fields: - * page->private: points to zspage - * page->index: links together all component pages of a zspage - * For the huge page, this is always 0, so we use this field - * to store handle. - * page->page_type: first object offset in a subpage of zspage - * - * Usage of struct page flags: - * PG_private: identifies the first component page - * PG_owner_priv_1: identifies the huge component page - * - */ - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt /* @@ -264,6 +247,52 @@ struct mapping_area { enum zs_mapmode vm_mm; /* mapping mode */ }; +/* + * struct zsdesc - memory descriptor for zsmalloc memory + * + * This struct overlays struct page for now. Do not modify without a + * good understanding of the issues. + * + * Usage of struct page flags on zsdesc: + * PG_private: identifies the first component zsdesc + */ +struct zsdesc { + unsigned long flags; + + /* + * Although not used by zsmalloc, this field is used by non-LRU page migration + * code. Leave it unused. + */ + struct list_head lru; + + /* Always points to zsmalloc_mops with PAGE_MAPPING_MOVABLE set */ + struct movable_operations *mops; + + union { + /* linked list of all zsdescs in a zspage */ + struct zsdesc *next; + /* for huge zspages */ + unsigned long handle; + }; + struct zspage *zspage; + unsigned int first_obj_offset; + unsigned int _refcount; +}; + +#define ZSDESC_MATCH(pg, zs) \ + static_assert(offsetof(struct page, pg) == offsetof(struct zsdesc, zs)) + +ZSDESC_MATCH(flags, flags); +ZSDESC_MATCH(lru, lru); +ZSDESC_MATCH(mapping, mops); +ZSDESC_MATCH(index, next); +ZSDESC_MATCH(index, handle); +ZSDESC_MATCH(private, zspage); +ZSDESC_MATCH(page_type, first_obj_offset); +ZSDESC_MATCH(_refcount, _refcount); +#undef ZSDESC_MATCH +static_assert(sizeof(struct zsdesc) <= sizeof(struct page)); + /* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */ static void SetZsHugePage(struct zspage *zspage) {