From patchwork Tue Aug 13 08:45:56 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: 13761559 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 17011C52D7C for ; Tue, 13 Aug 2024 08:41:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4ABD6B00B0; Tue, 13 Aug 2024 04:41:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AC9A6B00AD; Tue, 13 Aug 2024 04:41:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FF1F6B00B0; Tue, 13 Aug 2024 04:41:52 -0400 (EDT) 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 5B3956B00AD for ; Tue, 13 Aug 2024 04:41:52 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D6C721206CE for ; Tue, 13 Aug 2024 08:41:51 +0000 (UTC) X-FDA: 82446579222.11.AFF553D Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf20.hostedemail.com (Postfix) with ESMTP id 9C5191C0025 for ; Tue, 13 Aug 2024 08:41:49 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dOOxP1Wv; spf=pass (imf20.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1723538439; 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=vU9lypoqlsum1LdSoQWmMsAo23xxIBWq3aYARm1N1tc=; b=HzfdHp/nYomsh+irk71UvlJOtjspc3DYketE1SOCEq3B4DLvPJbSftpHVD8issvtJM4CZE /wa2nyn3XmwY432RLi9MOr01avxDc5dEYlKRhAiR1hKKHTY60TdGDOTAVeOsQDyy9eS22u wvxRJbw4d4b3R7/kPh9tAq8T9b6VXTk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723538439; a=rsa-sha256; cv=none; b=EgVPhOZK55dxon8qK/Gecun0yPYzQGlzJ4Cw82syhGFnhCuHgRmyc6774Bo/YELGQRbCev egI0yqj8tHjDJGlXgHmjZgBxzsvSPhqUBEiBnL6Bvz7d9wxl6RqPU4K1W/HOmzs50tjnP4 k92IH6Oy68MN7GpxJQplrKwcOFdZru8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dOOxP1Wv; spf=pass (imf20.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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 sin.source.kernel.org (Postfix) with ESMTP id B17B0CE1235; Tue, 13 Aug 2024 08:41:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45719C4AF10; Tue, 13 Aug 2024 08:41:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723538505; bh=UmY8mz0Mo/B8gMn4RPUMsn8q8kByucvcQFpc8ROaoN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dOOxP1WvR4nlRS/PNgkaS23vVd55SRWG+qIRE209IfYLyLsqGZjR7PklKPuEYICYJ XeL5/VZs+2k81LiQUCMDbY4hJfhw4fIletndPnqrB4P0GXkBkofSmpzqnXYOO081Vr 3SsdAS8ceOfC1hyNu2WdynXMx5o2fHHL46sbzY8uTYIY+G2F3A8bGMOAObdCoZUTPj C9KAAb+2OfoGY1Y25Imog1SooutwDOnDEry17xuJOhHxDogxrQXQUpB1DLISTIjOhT YiZI9A/IdZ7bhzYUmI36JbUZqh/Bs9jLalJ5FRfHyT+W2uibxDS6T1OFyvVi1gHpmq ZRXdWlzPjK9Sw== 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 v6 10/21] mm/zsmalloc: add zpdesc_is_isolated()/zpdesc_zone() helper for zs_page_migrate() Date: Tue, 13 Aug 2024 16:45:56 +0800 Message-ID: <20240813084611.4122571-11-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813084611.4122571-1-alexs@kernel.org> References: <20240813084611.4122571-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9C5191C0025 X-Stat-Signature: trreaqw4gq8r73m9i939zo7hzjiiz6ua X-HE-Tag: 1723538509-809587 X-HE-Meta: U2FsdGVkX18Is247OO+GB83TX1IeTFpgCvR9ekcd8nL+j426CvbvOX2mATua8pdK/64UlWcjwCQP8d/MsjBJ9bI2F14rLTagxPEr9bv2ApWaw9kgAj/wiBqkGugb//ay90NC13Faf+RaPRm5/SEKItOVwrmb//kwAzRcU4XCf1TxJ/bwiv/HwRDl2ZB19wILhpnro/gNtoXa/bjq8RajBe1UsHBOXmor97xDHpBBEk7Z5uj0MtgNE8Gso9LPxL+krbIRTgkluY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gVMKlV+MzhS094vovZs9bpTRiM3HjqSdtA== 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: Hyeonggon Yoo <42.hyeyoo@gmail.com> To convert page to zpdesc in zs_page_migrate(), we added zpdesc_is_isolated()/zpdesc_zone() helpers. No functional change. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Alex Shi --- mm/zpdesc.h | 11 +++++++++++ mm/zsmalloc.c | 30 ++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 3a65a7d494b7..4b42d8517fcb 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -114,4 +114,15 @@ static inline void __zpdesc_set_movable(struct zpdesc *zpdesc, { __SetPageMovable(zpdesc_page(zpdesc), mops); } + +static inline bool zpdesc_is_isolated(struct zpdesc *zpdesc) +{ + return PageIsolated(zpdesc_page(zpdesc)); +} + +static inline struct zone *zpdesc_zone(struct zpdesc *zpdesc) +{ + return page_zone(zpdesc_page(zpdesc)); +} + #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index cb90defd3c0a..65c4252412b3 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1824,19 +1824,21 @@ static int zs_page_migrate(struct page *newpage, struct page *page, struct size_class *class; struct zspage *zspage; struct zpdesc *dummy; + struct zpdesc *newzpdesc = page_zpdesc(newpage); + struct zpdesc *zpdesc = page_zpdesc(page); void *s_addr, *d_addr, *addr; unsigned int offset; unsigned long handle; unsigned long old_obj, new_obj; unsigned int obj_idx; - VM_BUG_ON_PAGE(!PageIsolated(page), page); + VM_BUG_ON_PAGE(!zpdesc_is_isolated(zpdesc), zpdesc_page(zpdesc)); /* We're committed, tell the world that this is a Zsmalloc page. */ - __SetPageZsmalloc(newpage); + __SetPageZsmalloc(zpdesc_page(newzpdesc)); /* The page is locked, so this pointer must remain valid */ - zspage = get_zspage(page); + zspage = get_zspage(zpdesc_page(zpdesc)); pool = zspage->pool; /* @@ -1853,30 +1855,30 @@ static int zs_page_migrate(struct page *newpage, struct page *page, /* the migrate_write_lock protects zpage access via zs_map_object */ migrate_write_lock(zspage); - offset = get_first_obj_offset(page); - s_addr = kmap_atomic(page); + offset = get_first_obj_offset(zpdesc_page(zpdesc)); + s_addr = zpdesc_kmap_atomic(zpdesc); /* * Here, any user cannot access all objects in the zspage so let's move. */ - d_addr = kmap_atomic(newpage); + d_addr = zpdesc_kmap_atomic(newzpdesc); copy_page(d_addr, s_addr); kunmap_atomic(d_addr); for (addr = s_addr + offset; addr < s_addr + PAGE_SIZE; addr += class->size) { - if (obj_allocated(page_zpdesc(page), addr, &handle)) { + if (obj_allocated(zpdesc, addr, &handle)) { old_obj = handle_to_obj(handle); obj_to_location(old_obj, &dummy, &obj_idx); - new_obj = (unsigned long)location_to_obj(newpage, + new_obj = (unsigned long)location_to_obj(zpdesc_page(newzpdesc), obj_idx); record_obj(handle, new_obj); } } kunmap_atomic(s_addr); - replace_sub_page(class, zspage, page_zpdesc(newpage), page_zpdesc(page)); + replace_sub_page(class, zspage, newzpdesc, zpdesc); /* * Since we complete the data copy and set up new zspage structure, * it's okay to release migration_lock. @@ -1885,14 +1887,14 @@ static int zs_page_migrate(struct page *newpage, struct page *page, spin_unlock(&class->lock); migrate_write_unlock(zspage); - get_page(newpage); - if (page_zone(newpage) != page_zone(page)) { - dec_zone_page_state(page, NR_ZSPAGES); - inc_zone_page_state(newpage, NR_ZSPAGES); + zpdesc_get(newzpdesc); + if (zpdesc_zone(newzpdesc) != zpdesc_zone(zpdesc)) { + zpdesc_dec_zone_page_state(zpdesc); + zpdesc_inc_zone_page_state(newzpdesc); } reset_page(page); - put_page(page); + zpdesc_put(zpdesc); return MIGRATEPAGE_SUCCESS; }