From patchwork Thu Dec 5 17:49:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13895906 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 25F6BE77170 for ; Thu, 5 Dec 2024 17:50:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D59C6B019A; Thu, 5 Dec 2024 12:50:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8840D6B019D; Thu, 5 Dec 2024 12:50:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 660E76B019E; Thu, 5 Dec 2024 12:50:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 45CC86B019A for ; Thu, 5 Dec 2024 12:50:24 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 76C70121788 for ; Thu, 5 Dec 2024 17:50:06 +0000 (UTC) X-FDA: 82861643298.27.904C69A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id 6022FC0005 for ; Thu, 5 Dec 2024 17:49:57 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OzDD7MDy; dmarc=none; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733420990; a=rsa-sha256; cv=none; b=OUtLkzl95k2TOPb/6P/taRkqwJYs+Rdmy/isR8QwYPwG8LvJIzhnjQtwkzMKtsNN7JTXyb L/CaykmuczoZYoWPG/BW2x1bhR46573qXbxDBpYgpETF+9mt01nebpVKKXcMlzBiIJKvn5 XLO6BnIryCHumd3ZGhqm841qyJ5sZdU= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OzDD7MDy; dmarc=none; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733420990; 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=0Tc+hr3l1ay6sXsQgfONXbNVWWG0dupWjQT5pbW/O6E=; b=ObwrWuRz8Cki/gWityzLbg1oUBk+IgOiPL13uZxa/iupTxcC+4YO+/HItgMopbKGAM/2GT oFqml+2pkKDuqAo86LHNGFHA60OdDfBs8akm2sJhqS/3lhk+NcYy0vECFlKy41hC6/fnn/ kQKxKTOm/lzxlIJyDNMI8Vb+u+bM95g= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=0Tc+hr3l1ay6sXsQgfONXbNVWWG0dupWjQT5pbW/O6E=; b=OzDD7MDy3Y3dZb6gbb1H5YwWPF wwqRi/Jp70sdF2Y0qH8CyAdLumV3L1k5sAb5jJqxMIRoa6DtxPntdy7P/PrcbTwI9OwVm++rmskaK +Pq4ehteCDDkZEOAUki3ClocYO3iAjCiuUpxu+rlls+nW59a9QV4iMLSGhQclvR7N5AEJU6tpQxrE +qjD8tUB3O1M613y8xsJc5XXWzwInTmZLiTsKI3gVDPYTHLGwCnB5IAY5/an9sBDZemrd0g/YGUft BQpQkALzCakS16M5WRMwGHMVVIgm4l/9LuXngQWh8rys383R7YwaDRdfMUtxXj0giYmoKysaG84Ag NIhDbTSA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tJFzG-0000000DN7o-3v98; Thu, 05 Dec 2024 17:50:02 +0000 From: "Matthew Wilcox (Oracle)" To: Minchan Kim , Sergey Senozhatsky Cc: Alex Shi , linux-mm@kvack.org, Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH v8 06/21] mm/zsmalloc: convert create_page_chain() and its users to use zpdesc Date: Thu, 5 Dec 2024 17:49:43 +0000 Message-ID: <20241205175000.3187069-7-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241205175000.3187069-1-willy@infradead.org> References: <20241205175000.3187069-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: 1qos4u4hamkjcjbcxbnx7o3fsn35agaz X-Rspam-User: X-Rspamd-Queue-Id: 6022FC0005 X-Rspamd-Server: rspam08 X-HE-Tag: 1733420997-280339 X-HE-Meta: U2FsdGVkX18WLD92FE147cMZRoQvwxjr4P8HiN4txD+OyvTa+Wt++zVsa3Pef3DHjzPtOskBTCD658omPtkwvA8o/EVsbL38PJykH+FhlPmR9gwzNz8PtyrxPrGA1zv9i+7txyfXyylHxv9Uwd+vzuuGq1QlHUzmOrmsxbIx4FUh6393VEqG/M2+XvAOsYqGxdfmVN/f0lepdQKj/7ksVUdEAqNSk0aOlhucWuQEXFxTGMQmUmdBFoNlpLFTohwruP2/GqwmKR+oK/KDXsXlvWlXF0cFm+WBiaKjP0B1QKNFDA3srojswWB++ojbuOjmvAwGc2EBL3Xe0U18LlIlJ9zFZaTAJ6SzeEtmeXSNDMRgr1xI3LqVnRTcm4TMHux21KiCeh61n+vY24/TQtUCbKPZcc2keNshlYlHNRJPkn6vO6qTUfftcFVkdIwBKJG0KdO2s5lWXrO82V6rxVie40jILCPpkRJK4qfsT4l5biFJWglc9lluwc+RtGe2gqZJ7jeUXRtyKMarMa7ZeaUgyBHc3wUvQY2mC4Mi9NLzj9v8UMvnjJgNHB+Kc35jV1Swb+ORIuOkinnohfL+AK8faayzWLLjQkREuFBliDFhtXSU0qMZVtP5Fq6NGFNg9CW4HFxWAOdQmQ/NDCRvCITdC4LhC4hGHNrNxJeXkeoxNBLVodl+11e4Zl1qTrstBeny29TLRY1r/cUGR+q1PLenEdvYG2tgNtUwErLrIM/vByTJLye/Kk1mPV1zZ1yXTiCRHU51lWNo5vpMENawB8TdgOFSbztJ6DIqQQ23WEa8ka5pKmG0g5xS1yt5WV+Od5yhDZGOMSHTo6CsFBQ3PrV1wGcYQiUqkHyPzOr1Two86ySu3zJndjuqIXtMP1JATtb9zhKKQ2vfyhGMbNuoR+VRSttNyNjuw1podWo9NoMlw1ivcDKFav00ePJHVrQV4dhQnFKUTRYFhDOIzfUiY6W sLsAj2Rs pEs0n1/0SCX60mL95tUlqiixVO9j9m9an8KAfm2faV13QIyitznY4t5Bnuq2a18QJAQJdKM7TIjgwgdE8DUVUN+HjsKd/RSGvOVZTzYdWJPj/7xoCnnI3e+uq538BBCp1jdB+MIR5h/Nvt2YkzEQx5svsvXsbLjFu/CFHYb291zMS7qZTnjeCCy0iqveyTd9gTQjXXjN3bHOPGCVG5isv4EFBwML+OqDyiEDh1rZkY5mB82lQnK6HG3ADRBkLkHUa/X0wgIdKpVipoAGODLHwSs7mef36Awu2aWPakbiPwkVSk1rSMiO4RI+YiCO+WL5W8rN3lzV9U9aHgbKLnGnCi7q7rQ== 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 Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/zpdesc.h | 6 +++ mm/zsmalloc.c | 109 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 76 insertions(+), 39 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 937de815a4ac..0387f5771dc6 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -110,4 +110,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 af8a6cd6b814..6beb7cce4c31 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -246,6 +246,35 @@ struct zs_pool { atomic_t compaction_in_progress; }; +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); +} + +static inline struct zpdesc *alloc_zpdesc(gfp_t gfp) +{ + struct page *page = alloc_page(gfp); + + return page_zpdesc(page); +} + +static inline void free_zpdesc(struct zpdesc *zpdesc) +{ + struct page *page = zpdesc_page(zpdesc); + + __free_page(page); +} + struct zspage { struct { unsigned int huge:HUGE_BITS; @@ -955,35 +984,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; } } @@ -995,7 +1024,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) @@ -1005,25 +1034,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 = alloc_zpdesc(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_zpdesc(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; @@ -1744,26 +1773,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) @@ -1836,7 +1867,7 @@ static int zs_page_migrate(struct page *newpage, struct page *page, } kunmap_local(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.