From patchwork Thu Nov 30 10:12:30 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: 13474206 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 4622CC4167B for ; Thu, 30 Nov 2023 10:13:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D36F46B0466; Thu, 30 Nov 2023 05:13:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE48A6B0467; Thu, 30 Nov 2023 05:13:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B915F6B0468; Thu, 30 Nov 2023 05:13:29 -0500 (EST) 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 A22AF6B0466 for ; Thu, 30 Nov 2023 05:13:29 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 811E2A0168 for ; Thu, 30 Nov 2023 10:13:29 +0000 (UTC) X-FDA: 81514208538.12.9DE8729 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 943364000B for ; Thu, 30 Nov 2023 10:13:27 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=g9gomZSz; spf=pass (imf11.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.176 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=1701339207; 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=uS3iDho6P/vCdQ1q75iaR0pr3ux5IXne/kUUf4KBVRE=; b=H/STMP1Whr+iLSSyF7UN0Z0y/eoymKcao/OWZ3SrGZy9jfALSjw0aRr5VBVuVYM9CDY42m k/fxLgNPsaRP4ZaD6J05h25Zxyntlt6ky7ByajE2lR9oWzk6U54+rMKCIZB4KBK2FINPUA ITAOvygaijV2Dw4jj1hdbrZPJp+JujU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=g9gomZSz; spf=pass (imf11.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.176 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=1701339207; a=rsa-sha256; cv=none; b=7padoZkogFEwdo+ngtr1qCypTCP5iVsmhHI8WC6dmTvIeMSdBddfICmAej5O9vTWMtrNRU rFX49MNLJXOEgCEFt4GN/VnBsag6wlASLRz50/56Hq8qc0ZHuAlCl/87zwqqoubW7W8k72 0TnOjsvJjhORe2FsIAOkk/uZnX80QQY= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5bdb0be3591so610170a12.2 for ; Thu, 30 Nov 2023 02:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701339206; x=1701944006; 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=uS3iDho6P/vCdQ1q75iaR0pr3ux5IXne/kUUf4KBVRE=; b=g9gomZSz3zalfDh9lyQt2hiDrOTM2ny+OlQgAXv6QMR6+m3S9EwEZzT1UiLw52Pr+V Rp44fsJVrEFaqViFSRoAgATF7r6ZHW3hatlTX9a392CkukFLbF8B/F7Y56VGpECvUfpZ QSCG7OV+0qUZvdZvrm/UGzjnTMSKyS1Pb0fcEb0qaQ2h2VM2PDFbh6FeKC5mXKDhugJ0 QNwccb6ZrmeHjE52NMpYk8Oa4SbKGNnKutt2fGAvNGxOz10EJcjOspIV76g8ppAX4qun UuyPexUwQmr0++V6xlqWGvhA/SL4cQxgQA2A1mCXjtc6Hbdl1Z5r2Sc/qkkNq78ZC/Qm Ajqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701339206; x=1701944006; 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=uS3iDho6P/vCdQ1q75iaR0pr3ux5IXne/kUUf4KBVRE=; b=DWvdYCS5O47SzKPQ11z+/xGcH0FaOZGJszJK2pIt1Hl9Iug9Zxo8FqF6e7FNODNP7+ wMsGheIG9KwciJRdfSsljqWIKoQ02LnCdMIJPPh2v6/GZlqgbOJh1tbeUVzbQLoJgq5z sY+ga0WygSFzvmYLf6G5shaMJq1DBg6r1iciss1ijpiZgo/jr8tBX5hdVyu11sDd0nkG 1FVciidBc3VuFXaoGLXcXZBXEC6YiNmi6h9Iq/qPLFZToqFT+hYpiO9/FJIwPS+Z2xht MlKLaENBvrJpexThh/LHP+iDLz+VrHiR/ppZXFYplQgBHADV9vkKt24EIXlayIaDSPGM CUdA== X-Gm-Message-State: AOJu0YzXFt+Un4h2GGDCEh73IoZ95z3RXXmwcl//ojKrgdz6IRKY0Fzq e9spJiy+LZxuaamBnuIfK6A= X-Google-Smtp-Source: AGHT+IF3DNy59mcHbuwsXrz0BX30OCL6//xSDQgckfW+hFwaYy3O9GK0VJbDAZH6EXT9wPfwaBzNJQ== X-Received: by 2002:a05:6a20:3d14:b0:18c:18d4:d931 with SMTP id y20-20020a056a203d1400b0018c18d4d931mr24409041pzi.34.1701339206235; Thu, 30 Nov 2023 02:13:26 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:13:25 -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 09/21] mm/zsmalloc: convert create_page_chain() and its users to use zsdesc Date: Thu, 30 Nov 2023 19:12:30 +0900 Message-Id: <20231130101242.2590384-10-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: 943364000B X-Rspam-User: X-Stat-Signature: s4hhgxps6mih1p9ku58mjg6z9ahyxhm7 X-Rspamd-Server: rspam01 X-HE-Tag: 1701339207-586006 X-HE-Meta: U2FsdGVkX1+/sjcw9/draGR4Do6k18wOqvIqg5iL+6UEdOHVgc5vHphto2oWmO8+LV6zwVcwJ0g5jp1mqvyGPtD6CdyBG0Oe+NxY1I66FjzMjAs441xhtMhEvY8zCGH+4vQppNatwmJpFn23dMAWxApZQaDI4r4H6enJt/fawPHdOUj9+52+Xd/uHHgXi8QukXcru6ISs2c9BS8rSulPw+6aMZ6KlDsrrpqUcGN1zpgBWvBoB+O46Mmr7VERZSrrjPVmjRfcq5CgrpYDo49uNr0NODAztBwKI1JxupWvvPNj+JwXdex2vUjDzw2D6h13b9aPwN/c5BBkOjAUJVA/8i0QyfVU3RX3M3N1bjyZMQoOFH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SGUb4O8ouGhiF2De7k+ynAJdcnVkml3zB2yC0Yrwl9jJxjawMbm41ThAviA1CcYY7cQ6U31eGErlHemiMiT3cc8bwMpKJmdNj8WqMhGtrTpfS42L4gctXo49V1loU2bP6uiDPqq+tgE8dA6q93oYEhD4tcOVIUQKELERSQnohOMUXZxzwrudHy02dvnIT9IL 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 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 74ed0477f40e..1b5b9322ec21 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -327,6 +327,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); +} + struct zspage { struct { unsigned int huge:HUGE_BITS; @@ -1051,35 +1093,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; } } @@ -1091,7 +1133,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) @@ -1101,23 +1143,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; @@ -1860,29 +1902,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) @@ -1965,7 +2007,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)); dec_zspage_isolation(zspage); /* * Since we complete the data copy and set up new zspage structure,