From patchwork Tue Aug 6 02:22:53 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: 13754323 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 F1424C3DA7F for ; Tue, 6 Aug 2024 02:18:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F6136B0089; Mon, 5 Aug 2024 22:18:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A3BD6B009E; Mon, 5 Aug 2024 22:18:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D12C6B009F; Mon, 5 Aug 2024 22:18:20 -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 422D46B0089 for ; Mon, 5 Aug 2024 22:18:20 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 09012140836 for ; Tue, 6 Aug 2024 02:18:20 +0000 (UTC) X-FDA: 82420211160.09.59F247C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 4C5071A0018 for ; Tue, 6 Aug 2024 02:18:18 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CNjv4Yt9; spf=pass (imf19.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 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=1722910636; 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=7v3g5GxWR0jl5mkBSc+FR4m7cJUyvgF1oZpCugoaep4=; b=TE2UpcZwaXVb4IUNyktnvKutZym/zEejWWp5Y1ANGnfGGJpQICAtCN+3nGcx8zE/FD8x1e 6dIw1sjTmLUyUEUTtclnKcN9+TXw39NUU54JbYwChs45hyu+PrgUzgt247lPE9iHYV1+EP H/Q5B5yZzVgG7gKN43WgcNvEREqskTQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722910636; a=rsa-sha256; cv=none; b=OfY+yNkFw39c8nBi1E/dXDEKLnuwDSALdGCbyKMR84cDe0IY5Jc/3S1i5EmJnIqlD5mDyj u96W7gxEELj2OncK5pzPfC/e3sYPBKrg4GjZcVLs+mSWdgPLUAJJn9SmNKeHbG2klpIMYS kx+uhD6n81R1lpypbOmU1wIntSNWt38= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CNjv4Yt9; spf=pass (imf19.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 917D760ED0; Tue, 6 Aug 2024 02:18:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EF94C4AF0B; Tue, 6 Aug 2024 02:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722910697; bh=Hcz6YDLKpn+zwSbhAqxdxpFHMpHIDCe8idbfi+gvSSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CNjv4Yt9eT8l1U83xyPDy6BZuirk5dnxQU81nTlT/y5ULIt1rjedy+R5ACeEBWVBi VjVKk5NmdQP/WWEUzGqrzT/Ogyykzw74HoNE1d2Bb7YfG/8xWI5ax3dCf6Xr7roZDJ Dk0iu3z0Ib7D4ATLidLr6RPt6z1oEzNj6mPt1ao36Kolg7F5BG4mpOYNep/gw6xur2 NfdoPAuQsnTHxwzxtvJfi1g/1TMDQVBATGFt2nKp1jWMG6DhjD9cuTQKfitgFhUrXi I8gLccD4SMhAWkrUe+LA6YXXw2sZJsJLCqF2lkEQ87ruSuH8FI/KSKK6CgG2hLMUbn LHxQHsK6dtWzQ== 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, Yosry Ahmed , nphamcs@gmail.com Cc: Alex Shi Subject: [PATCH v5 06/21] mm/zsmalloc: convert create_page_chain() and its users to use zpdesc Date: Tue, 6 Aug 2024 10:22:53 +0800 Message-ID: <20240806022311.3924442-7-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806022311.3924442-1-alexs@kernel.org> References: <20240806022143.3924396-1-alexs@kernel.org> <20240806022311.3924442-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4C5071A0018 X-Stat-Signature: hf4kdmmgjiuw5ryii1iywfqw81tirgs8 X-HE-Tag: 1722910698-977852 X-HE-Meta: U2FsdGVkX1+7MnAhifGowOc1BQkH454qw9Z4/uZ8OzqGYFbjx4aYSAhS27szO6A03xkQJOPVzN2CMQl9oRxsgX4BMeptMPchzvsxGDkWBvTrrLgreZm/Vsyh8K8tENpqmeiVFlq6FgldCpUo/L9WhVCM3/Be7MSNigKpMWud8bEVt69TMZQQPs4R5QoZ4U3jdELS4ZAYJYHn2FMEPOPd0eYPZ3EvlucfSyQAB5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BD/6O73dBiDMq+AjxqnKUdj3eqHQP54iifJmKZsa+es5+A9HrvEKS8BqU3FPyFrx1IqJ 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 Introduce a few helper functions for conversion to convert create_page_chain() to use zpdesc, then use zpdesc in replace_sub_page() too. Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Alex Shi --- mm/zpdesc.h | 6 ++++ mm/zsmalloc.c | 95 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 62 insertions(+), 39 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 2101de23d16d..6a01e09e4beb 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -107,4 +107,10 @@ static inline struct zpdesc *pfn_zpdesc(unsigned long pfn) { return page_zpdesc(pfn_to_page(pfn)); } + +static inline void __zpdesc_set_movable(struct zpdesc *zpdesc, + const struct movable_operations *mops) +{ + __SetPageMovable(zpdesc_page(zpdesc), mops); +} #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 7421d7678880..33a4f7d026e3 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -248,6 +248,21 @@ static inline void *zpdesc_kmap_atomic(struct zpdesc *zpdesc) return kmap_atomic(zpdesc_page(zpdesc)); } +static inline void zpdesc_set_first(struct zpdesc *zpdesc) +{ + SetPagePrivate(zpdesc_page(zpdesc)); +} + +static inline void zpdesc_inc_zone_page_state(struct zpdesc *zpdesc) +{ + inc_zone_page_state(zpdesc_page(zpdesc), NR_ZSPAGES); +} + +static inline void zpdesc_dec_zone_page_state(struct zpdesc *zpdesc) +{ + dec_zone_page_state(zpdesc_page(zpdesc), NR_ZSPAGES); +} + struct zspage { struct { unsigned int huge:HUGE_BITS; @@ -954,35 +969,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 zpdesc *zpdescs[]) { int i; - struct page *page; - struct page *prev_page = NULL; - int nr_pages = class->pages_per_zspage; + struct zpdesc *zpdesc; + struct zpdesc *prev_zpdesc = NULL; + int nr_zpdescs = 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 zpdesc->next + * 2. each sub-page point to zspage using zpdesc->zspage * - * we set PG_private to identify the first page (i.e. no other sub-page + * we set PG_private to identify the first zpdesc (i.e. no other zpdesc * 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_zpdescs; i++) { + zpdesc = zpdescs[i]; + zpdesc->zspage = zspage; + zpdesc->next = NULL; if (i == 0) { - zspage->first_zpdesc = page_zpdesc(page); - SetPagePrivate(page); + zspage->first_zpdesc = zpdesc; + zpdesc_set_first(zpdesc); if (unlikely(class->objs_per_zspage == 1 && class->pages_per_zspage == 1)) SetZsHugePage(zspage); } else { - prev_page->index = (unsigned long)page; + prev_zpdesc->next = zpdesc; } - prev_page = page; + prev_zpdesc = zpdesc; } } @@ -994,7 +1009,7 @@ static struct zspage *alloc_zspage(struct zs_pool *pool, gfp_t gfp) { int i; - struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE]; + struct zpdesc *zpdescs[ZS_MAX_PAGES_PER_ZSPAGE]; struct zspage *zspage = cache_alloc_zspage(pool, gfp); if (!zspage) @@ -1004,25 +1019,25 @@ 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 zpdesc *zpdesc; - page = alloc_page(gfp); - if (!page) { + zpdesc = page_zpdesc(alloc_page(gfp)); + if (!zpdesc) { while (--i >= 0) { - dec_zone_page_state(pages[i], NR_ZSPAGES); - __ClearPageZsmalloc(pages[i]); - __free_page(pages[i]); + zpdesc_dec_zone_page_state(zpdescs[i]); + __ClearPageZsmalloc(zpdesc_page(zpdescs[i])); + __free_page(zpdesc_page(zpdescs[i])); } cache_free_zspage(pool, zspage); return NULL; } - __SetPageZsmalloc(page); + __SetPageZsmalloc(zpdesc_page(zpdesc)); - inc_zone_page_state(page, NR_ZSPAGES); - pages[i] = page; + zpdesc_inc_zone_page_state(zpdesc); + zpdescs[i] = zpdesc; } - create_page_chain(class, zspage, pages); + create_page_chain(class, zspage, zpdescs); init_zspage(class, zspage); zspage->pool = pool; zspage->class = class->index; @@ -1753,26 +1768,28 @@ static void migrate_write_unlock(struct zspage *zspage) 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 zpdesc *newzpdesc, struct zpdesc *oldzpdesc) { - struct page *page; - struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE] = {NULL, }; + struct zpdesc *zpdesc; + struct zpdesc *zpdescs[ZS_MAX_PAGES_PER_ZSPAGE] = {NULL, }; + unsigned int first_obj_offset; int idx = 0; - page = get_first_page(zspage); + zpdesc = get_first_zpdesc(zspage); do { - if (page == oldpage) - pages[idx] = newpage; + if (zpdesc == oldzpdesc) + zpdescs[idx] = newzpdesc; else - pages[idx] = page; + zpdescs[idx] = zpdesc; idx++; - } while ((page = get_next_page(page)) != NULL); + } while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL); - create_page_chain(class, zspage, pages); - set_first_obj_offset(newpage, get_first_obj_offset(oldpage)); + create_page_chain(class, zspage, zpdescs); + first_obj_offset = get_first_obj_offset(zpdesc_page(oldzpdesc)); + set_first_obj_offset(zpdesc_page(newzpdesc), first_obj_offset); if (unlikely(ZsHugePage(zspage))) - newpage->index = oldpage->index; - __SetPageMovable(newpage, &zsmalloc_mops); + newzpdesc->handle = oldzpdesc->handle; + __zpdesc_set_movable(newzpdesc, &zsmalloc_mops); } static bool zs_page_isolate(struct page *page, isolate_mode_t mode) @@ -1845,7 +1862,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_zpdesc(newpage), page_zpdesc(page)); /* * Since we complete the data copy and set up new zspage structure, * it's okay to release migration_lock.