From patchwork Fri Jun 21 05:46:42 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: 13706857 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 B9251C27C4F for ; Fri, 21 Jun 2024 05:42:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BA208D0111; Fri, 21 Jun 2024 01:42:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A6868D012C; Fri, 21 Jun 2024 01:42:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D2558D0111; Fri, 21 Jun 2024 01:42:14 -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 173378D012C for ; Fri, 21 Jun 2024 01:42:14 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A8C421C1811 for ; Fri, 21 Jun 2024 05:42:13 +0000 (UTC) X-FDA: 82253800146.20.D3A8A62 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 046DD120010 for ; Fri, 21 Jun 2024 05:42:11 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YFwfQUXj; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718948521; 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=Xb3FItqMbWC/nmhMdP1LRKxYgkuWTMw07TV2wI4SFZ4=; b=tka6x+53YQQVtVXfBWye66Pz33quk0OkKkC6PEiOw2ZlGe+qmNrv3MUEVucGgJxh3LujJy pbDU4JpAxEOcuxe6Q2GR1TwfwCcKt6D118SpbrDNuEh1yWYDMuWSdjaHngVZwsbW4XJkOJ lrZxiHXHqrktZ1PK5e2hHlGAC8rAZGI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718948521; a=rsa-sha256; cv=none; b=C/BdVm/vmsmVAd2kVoZFoq7wJMC2F2BNNXP82caZQ9M955F233S2Usc03QpeSFR9WxAwzg ImaSYDnNHb9N4hlaHAyjGdsltLj5FcJ1Jj2tJqPWJVil3SEumb8n8u406dpMjWbKMhzTX5 1unsUvB9biTURwcjKXTubsjhWiYxAHY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YFwfQUXj; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B3BE462110; Fri, 21 Jun 2024 05:42:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E15D1C4AF07; Fri, 21 Jun 2024 05:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718948530; bh=lFp9hPza5pPU6dl5Bp6oDNXPAe1FxKDcyrPF29XpEYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YFwfQUXjaoVLS24SUVu4YvOrADDzlqMCpnmBV2Rt9lcarvqJAYcoeVvBBvZyEFcSG KGp68SU8RbPtBYJ0klurNhr77ppUHrZZJoq6fEbsZSRQ46nP4EpcSXTNWC0Zj4P8jv 7VnR4u6r0N7uF+UzuFsJGa4F019JtVvNXMbiibkCiDuyt+A3TtkgePnKr8f8sbXfea 79oztsDbLI2MuKg2Bmquh568/GbNejiYViESoUfL7kBDMZTEpPDLSwh6n7xrYyYJPr qovChvVpaBRXEMqycHMZRrIDiyieHrI5RQLwOEPxF45O2eupXrulXqajYm/UeTflAW 2vOA+yRTrYNNA== 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 Cc: Alex Shi Subject: [PATCH 02/15] mm/z3fold: use zpdesc in z3fold_page_migrate Date: Fri, 21 Jun 2024 13:46:42 +0800 Message-ID: <20240621054658.1220796-3-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621054658.1220796-1-alexs@kernel.org> References: <20240621054658.1220796-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 046DD120010 X-Stat-Signature: gor1yxa3w36ssdi5axsm5n6fib8grb5x X-Rspam-User: X-HE-Tag: 1718948531-240159 X-HE-Meta: U2FsdGVkX1/yFQwFSJNsQgTgEiocQesQzMv519uStANTMxxjfmXezSq0ZI/0v29HVIKt46IG0fwhqJ4Vz81RE/L66/aGerihYjEm5pMfHen2DjtQAtNQ2fxL1Cxgqor6uCb+xOXJlwcPDDzHRIceWd8OHD+YodF3J3je1u1ZkVkqDWqrORN4G7eiY1x3SLaCONzBvLhLjkoQu9vCE9N24vpgT0d7V0kPubsXoqVECXB6OYlO/FnEQzpGKgdtyJ3TmJZ9Y7H3vRAb1OIuSbQOPJdZsVeSgHj8AyX5ENa4KsGD5Ka2teDAIw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.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 Convert page to zpdesc in z3fold_page_migrate. And introduce zpdesc_get/put base on folio_get/put helpers, since z3fold only deal with single pages. This patch could save about 12Kbytes. Signed-off-by: Alex Shi --- mm/z3fold.c | 30 ++++++++++++++++-------------- mm/zpdesc.h | 10 ++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index b1229c0520f1..b7f86c1b57a3 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1290,18 +1290,20 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page, { struct z3fold_header *zhdr, *new_zhdr; struct z3fold_pool *pool; + struct zpdesc *zpdesc = page_zpdesc(page); + struct zpdesc *newzpdesc = page_zpdesc(newpage); - VM_BUG_ON_PAGE(!PageIsolated(page), page); - VM_BUG_ON_PAGE(!test_bit(PAGE_CLAIMED, &page->private), page); - VM_BUG_ON_PAGE(!PageLocked(newpage), newpage); + VM_BUG_ON_PAGE(!PageIsolated(zpdesc_page(zpdesc)), zpdesc_page(zpdesc)); + VM_BUG_ON_PAGE(!test_bit(PAGE_CLAIMED, &zpdesc->zppage_flag), zpdesc_page(zpdesc)); + VM_BUG_ON_PAGE(!PageLocked(zpdesc_page(newzpdesc)), zpdesc_page(newzpdesc)); - zhdr = page_address(page); + zhdr = zpdesc_address(zpdesc); pool = zhdr_to_pool(zhdr); if (!z3fold_page_trylock(zhdr)) return -EAGAIN; if (zhdr->mapped_count != 0 || zhdr->foreign_handles != 0) { - clear_bit(PAGE_CLAIMED, &page->private); + clear_bit(PAGE_CLAIMED, &zpdesc->zppage_flag); z3fold_page_unlock(zhdr); return -EBUSY; } @@ -1309,10 +1311,10 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page, z3fold_page_unlock(zhdr); return -EAGAIN; } - new_zhdr = page_address(newpage); + new_zhdr = zpdesc_address(newzpdesc); memcpy(new_zhdr, zhdr, PAGE_SIZE); - newpage->private = page->private; - set_bit(PAGE_MIGRATED, &page->private); + newzpdesc->zppage_flag = zpdesc->zppage_flag; + set_bit(PAGE_MIGRATED, &zpdesc->zppage_flag); z3fold_page_unlock(zhdr); spin_lock_init(&new_zhdr->page_lock); INIT_WORK(&new_zhdr->work, compact_page_work); @@ -1321,9 +1323,9 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page, * so we only have to reinitialize it. */ INIT_LIST_HEAD(&new_zhdr->buddy); - __ClearPageMovable(page); + __ClearPageMovable(zpdesc_page(zpdesc)); - get_page(newpage); + zpdesc_get(newzpdesc); z3fold_page_lock(new_zhdr); if (new_zhdr->first_chunks) encode_handle(new_zhdr, FIRST); @@ -1331,16 +1333,16 @@ static int z3fold_page_migrate(struct page *newpage, struct page *page, encode_handle(new_zhdr, LAST); if (new_zhdr->middle_chunks) encode_handle(new_zhdr, MIDDLE); - set_bit(NEEDS_COMPACTING, &newpage->private); + set_bit(NEEDS_COMPACTING, &newzpdesc->zppage_flag); new_zhdr->cpu = smp_processor_id(); - __SetPageMovable(newpage, &z3fold_mops); + __SetPageMovable(zpdesc_page(newzpdesc), &z3fold_mops); z3fold_page_unlock(new_zhdr); queue_work_on(new_zhdr->cpu, pool->compact_wq, &new_zhdr->work); /* PAGE_CLAIMED and PAGE_MIGRATED are cleared now. */ - page->private = 0; - put_page(page); + zpdesc->zppage_flag = 0; + zpdesc_put(zpdesc); return 0; } diff --git a/mm/zpdesc.h b/mm/zpdesc.h index d51785863596..7fde29645331 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -48,4 +48,14 @@ static inline void *zpdesc_address(const struct zpdesc *zpdesc) return folio_address(zpdesc_folio(zpdesc)); } +static inline void zpdesc_get(struct zpdesc *zpdesc) +{ + folio_get(zpdesc_folio(zpdesc)); +} + +static inline void zpdesc_put(struct zpdesc *zpdesc) +{ + folio_put(zpdesc_folio(zpdesc)); +} + #endif