From patchwork Thu Jul 13 04:20:24 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: 13311273 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 B4FBFEB64DD for ; Thu, 13 Jul 2023 04:21:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DED88E0003; Thu, 13 Jul 2023 00:21:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 468248E0001; Thu, 13 Jul 2023 00:21:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E2018E0003; Thu, 13 Jul 2023 00:21:23 -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 1C0CA8E0001 for ; Thu, 13 Jul 2023 00:21:23 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EFC20C010A for ; Thu, 13 Jul 2023 04:21:22 +0000 (UTC) X-FDA: 81005289204.13.5D08AB6 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf15.hostedemail.com (Postfix) with ESMTP id 1D4D6A000B for ; Thu, 13 Jul 2023 04:21:20 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=lf7AZa8e; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689222081; a=rsa-sha256; cv=none; b=b5prkYI4otc09wv4/2zNeWgpqSh3ILGp32ikekggvwJ3GbFy1eCEKVbKM0c2rMEYwHrBVy WNor0lpeChnz381+OBsw4TDE+KyY7wAMLISwF2H+x8aVS0z1F3s7TUR5wEiA7vgs1ijeDY nIEpi3G1dZDyB+k/Dslg2Zo4UWNZ3F4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=lf7AZa8e; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.178 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=1689222081; 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=LP5xQ6efjwHS47Oxl1IdTrKCp1PjMTJw03NOJIq6Awg=; b=gcfzDSm/KjJ+MMaWgz9UiSpgsql9pt+/vbhUcj91pkyc/WzDCmAYTA3hTDFYdHQyE92ZMq 0aPW9uzUF3kU80ptR0sp8na0+Q11sOzU5QDwJ3iSDdHOS9G8M5TwFbLSuDDO6AYOT5+NBu pEcqdAgZLINcmhoGcBohlxlpg6c+Pog= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-666e6ecb52dso168168b3a.2 for ; Wed, 12 Jul 2023 21:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689222080; x=1691814080; 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=LP5xQ6efjwHS47Oxl1IdTrKCp1PjMTJw03NOJIq6Awg=; b=lf7AZa8eID+bpbDGYm/7QEvzwEHh6v4zg3kNCWj8c5QyXrfMVbJVNMyjrKhdjmIr6t n+bP+RtxPOH6barvlyqo1EADq8+88sVBaIXeOtY8d4CbOu4dvt5MEfQrfWMNcwou+DGu BXBA5OPPHaMvCSejIv4nOX2PVYomkk7yshU0mCGwH8csmbEDebanQEvkyDqaTeKh7PmL WB1wJ275RzFYYecOIfu9U+tkcobqAn9P1hmhpJT+SsJQ0oOKgsbBJwoL5Ar6zPV5RJYh 9iaCciIY2AOdQZIpIVAH1JrqhDPoAjY80UBAmlXDDID8R4efwMaF9T5xCpseUc46O13L rxjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689222080; x=1691814080; 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=LP5xQ6efjwHS47Oxl1IdTrKCp1PjMTJw03NOJIq6Awg=; b=RMdhpAi2BKJRHl6Kxu8siL8aEG8Fg06Pp9BbJNG4fcVC01d1G7bKfJXcBjPH3A6lJ/ peLE4+qTgSu2fFfuKQtmOYV+XT9ehTWRDrkuNpnE7Etz9cMnKbKYrG1XK6vgIRuGfZso i58UBU9sO0047ZWeI2gSOu/uzPlos3lW7+P0wJGekl/2j6U1//2dGsQplo3Fc1CdNpWx 2ohJ/23Ro4i7uRde5mn0VuEk1x/Kg6dy35jaD7/efX4n569LIoyIM9VveCq2gRnWgftz 0sSSYKoKHpVrYmHJTsAecQaoEtypp231bHeJCCbMRIGC+cB8YCuPxrXoL5dvyJuZiYLZ BgNw== X-Gm-Message-State: ABy/qLZCMVR6WBrvlp5amRy7G3tH4HUH+Ccp9M3LTXKlq9Y6zRS2aEXB 6Q2eNEabZ9X97Lw9DCm6Bpu5+uvyjn/mfmDHI5KyQw== X-Google-Smtp-Source: APBJJlE3EDMrVhGu2+w99ghcjkXTfEgbRvc6vMguhTPtHAU43UkedDKKOy9zY8oR+2dKf2q4n7r4QQ== X-Received: by 2002:a05:6a00:2401:b0:666:ba76:eef5 with SMTP id z1-20020a056a00240100b00666ba76eef5mr364274pfh.8.1689222079876; Wed, 12 Jul 2023 21:21:19 -0700 (PDT) Received: from fedora.. ([1.245.179.104]) by smtp.gmail.com with ESMTPSA id u18-20020aa78392000000b006827c26f147sm4346601pfm.138.2023.07.12.21.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 21:21:19 -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 09/21] mm/zsmalloc: convert create_page_chain() and its user to use zsdesc Date: Thu, 13 Jul 2023 13:20:24 +0900 Message-ID: <20230713042037.980211-10-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1D4D6A000B X-Stat-Signature: bmyitgbf5m3i8z3ssysz91w5wzn9bafq X-HE-Tag: 1689222080-564257 X-HE-Meta: U2FsdGVkX18YsHvl3fcyA/Ob073oF7NoILOta0tP9PiX7+L2MxSIZ9aUdgVlqF/fUNt9K6kYgzWER8EB/LtRWY8vv+/YhmSICaXpMblahttp7yNMzWqbt3DcxclhnH6Td9Q5uYwVi60G36nkAJM4O4TBMEWNwuBgnrheYk9Kt56rSYJgnTKmZGvDywbJNdXc5RJWBYB70XgzXfEQ8hiGypT5Do3NhixnK9DoNrRr2U58vxowG1t9gkCr8q9ejd3eihL9Z8Z+o/Ylp7Imp8ZhaChsUuiAEc3mSMkG03N3+DM64VTC31lGDfffkm1n/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KMy4+x+I9Aub8lPF4FRbHTwkjd1unGM8mWBCldOtkToRbx7nmqE6dxwFrSXoaMbb2uj8UeGTBh1OOwd64Yn/eAhf2Kir3xsqYrmfTvUdaj7kHKv9kv1gL8FhTaB6GkpFsowxg5LnmxO2RghNuzLmv3auEOE7rU9/AVHQuYCwly+01/Z+qutuNfNuoQKeF5c8dC7hMjPz1wx2x+x4q8XQp150YVS4ZROCFzNN7kbPoTPjpaIa5eLJNu 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 a few helper functions for conversion. Convert create_page_chain() and its user replace_sub_page() to use zsdesc. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/zsmalloc.c | 120 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 39 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 06227da86afc..48bfdbbe3b1e 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -346,6 +346,48 @@ 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) +{ + zsdesc->zspage = zspage; +} + +static inline void zsdesc_set_first(struct zsdesc *zsdesc) +{ + SetPagePrivate(zsdesc_page(zsdesc)); +} + +static const struct movable_operations zsmalloc_mops; + +static inline void zsdesc_set_movable(struct zsdesc *zsdesc) +{ + __SetPageMovable(zsdesc_page(zsdesc), &zsmalloc_mops); +} + +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); + + return page_zsdesc(page); +} + +static inline void free_zsdesc(struct zsdesc *zsdesc) +{ + struct page *page = zsdesc_page(zsdesc); + + __free_page(page); +} + /* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */ static void SetZsHugePage(struct zspage *zspage) { @@ -1047,35 +1089,35 @@ static void init_zspage(struct size_class *class, struct zspage *zspage) } static void create_page_chain(struct size_class *class, struct zspage *zspage, - struct page *pages[]) + struct zsdesc *zsdescs[]) { int i; - struct page *page; - struct page *prev_page = NULL; - int nr_pages = class->pages_per_zspage; + struct zsdesc *zsdesc; + struct zsdesc *prev_zsdesc = NULL; + int nr_zsdescs = class->pages_per_zspage; /* * Allocate individual pages and link them together as: - * 1. all pages are linked together using page->index - * 2. each sub-page point to zspage using page->private + * 1. all pages are linked together using zsdesc->next + * 2. each sub-page point to zspage using zsdesc->zspage * - * we set PG_private to identify the first page (i.e. no other sub-page + * we set PG_private to identify the first zsdesc (i.e. no other zsdesc * has this flag set). */ - for (i = 0; i < nr_pages; i++) { - page = pages[i]; - set_page_private(page, (unsigned long)zspage); - page->index = 0; + for (i = 0; i < nr_zsdescs; i++) { + zsdesc = zsdescs[i]; + zsdesc_set_zspage(zsdesc, zspage); + zsdesc->next = NULL; if (i == 0) { - zspage->first_zsdesc = page_zsdesc(page); - SetPagePrivate(page); + zspage->first_zsdesc = zsdesc; + zsdesc_set_first(zsdesc); if (unlikely(class->objs_per_zspage == 1 && class->pages_per_zspage == 1)) SetZsHugePage(zspage); } else { - prev_page->index = (unsigned long)page; + prev_zsdesc->next = zsdesc; } - prev_page = page; + prev_zsdesc = zsdesc; } } @@ -1087,7 +1129,7 @@ static struct zspage *alloc_zspage(struct zs_pool *pool, gfp_t gfp) { int i; - struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE]; + struct zsdesc *zsdescs[ZS_MAX_PAGES_PER_ZSPAGE]; struct zspage *zspage = cache_alloc_zspage(pool, gfp); if (!zspage) @@ -1097,23 +1139,23 @@ static struct zspage *alloc_zspage(struct zs_pool *pool, migrate_lock_init(zspage); for (i = 0; i < class->pages_per_zspage; i++) { - struct page *page; + struct zsdesc *zsdesc; - page = alloc_page(gfp); - if (!page) { + zsdesc = alloc_zsdesc(gfp); + if (!zsdesc) { while (--i >= 0) { - dec_zone_page_state(pages[i], NR_ZSPAGES); - __free_page(pages[i]); + zsdesc_dec_zone_page_state(zsdescs[i]); + free_zsdesc(zsdescs[i]); } cache_free_zspage(pool, zspage); return NULL; } - inc_zone_page_state(page, NR_ZSPAGES); - pages[i] = page; + zsdesc_inc_zone_page_state(zsdesc); + zsdescs[i] = zsdesc; } - create_page_chain(class, zspage, pages); + create_page_chain(class, zspage, zsdescs); init_zspage(class, zspage); zspage->pool = pool; @@ -1856,29 +1898,29 @@ 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) + struct zsdesc *new_zsdesc, struct zsdesc *old_zsdesc) { - struct page *page; - struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE] = {NULL, }; + struct zsdesc *zsdesc; + struct zsdesc *zsdescs[ZS_MAX_PAGES_PER_ZSPAGE] = {NULL, }; + unsigned int first_obj_offset; int idx = 0; - page = get_first_page(zspage); + zsdesc = get_first_zsdesc(zspage); do { - if (page == oldpage) - pages[idx] = newpage; + if (zsdesc == old_zsdesc) + zsdescs[idx] = new_zsdesc; else - pages[idx] = page; + zsdescs[idx] = zsdesc; idx++; - } while ((page = get_next_page(page)) != NULL); + } while ((zsdesc = get_next_zsdesc(zsdesc)) != NULL); - create_page_chain(class, zspage, pages); - set_first_obj_offset(newpage, get_first_obj_offset(oldpage)); + create_page_chain(class, zspage, zsdescs); + first_obj_offset = get_first_obj_offset(zsdesc_page(old_zsdesc)); + set_first_obj_offset(zsdesc_page(new_zsdesc), first_obj_offset); if (unlikely(ZsHugePage(zspage))) - newpage->index = oldpage->index; - __SetPageMovable(newpage, &zsmalloc_mops); + new_zsdesc->handle = old_zsdesc->handle; + zsdesc_set_movable(new_zsdesc); } static bool zs_page_isolate(struct page *page, isolate_mode_t mode) @@ -1959,7 +2001,7 @@ static int zs_page_migrate(struct page *newpage, struct page *page, } kunmap_atomic(s_addr); - replace_sub_page(class, zspage, newpage, page); + replace_sub_page(class, zspage, page_zsdesc(newpage), page_zsdesc(page)); /* * Since we complete the data copy and set up new zspage structure, * it's okay to release the pool's lock.