From patchwork Wed Jul 3 04:06:00 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: 13721080 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 912FCC30653 for ; Wed, 3 Jul 2024 04:01:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 260266B00A1; Wed, 3 Jul 2024 00:01:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E9A66B00A2; Wed, 3 Jul 2024 00:01:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 039F36B00A3; Wed, 3 Jul 2024 00:01:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D24206B00A1 for ; Wed, 3 Jul 2024 00:01:52 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 883B9120725 for ; Wed, 3 Jul 2024 04:01:52 +0000 (UTC) X-FDA: 82297092864.08.25C46B7 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 45849140002 for ; Wed, 3 Jul 2024 04:01:49 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G0B04OIt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719979291; a=rsa-sha256; cv=none; b=dZPID4YcwJBun8m5ji9fRxZH0rhcWObp2Q8DLUhDqzWe9Ot1KhaOGlKH8EJOnmbg8jtxSp DP5ruO1j5P1OgOZ31+rGTjWyaqO3REhjoeDXXRWFNI5f6BId+R8pX7sQTfMkgXKJRQrcqQ X0cP4HHYx50Kl62nFWq1S0JbgDEZg+c= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G0B04OIt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1719979291; 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=SP6hImZmIrRQvoib1xZzKsa1/Sewrov2fmekSGish90=; b=yiQOMKWT8UdxtdrX52TgFIfxNrs94M6dRyLvqY/2jmLOwpyO+nMGIlRh+b8dV1H/q03p8p v1cq5B2QYcrZ50gUJH4ZLfk4prxjjoNEGiJcRXfPTcmd4vSB74vNJ8mMIpeUGn3eMxhlM3 1O+wsCTLW3WPF2VjClfw40cahcEcH1g= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A7F21CE1DEB; Wed, 3 Jul 2024 04:01:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF65AC32781; Wed, 3 Jul 2024 04:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719979307; bh=X6q7HiV/JKEJWx8fJkY9r9rnNkPwseyxy5Uf/fZ/T2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G0B04OItwHRPyh+8sULIxpolV9zSD+VmOfgGiZ3Y3gonxy225OS8tS5EBr//Ixoi9 CGJLSxDUAUyX0z+bVgXNHpaQFluz/fuqNE+w2SNDereXSgVjKrHUl5iUM9F+xalXIg HUj4yZYZT2U2YtJvt7grh2npA+NoNsjvRWnII0qLazNTDES26JXJqTmwLz90DAg0G0 c/YrOuXaWyExREG3YPDdvo751cKKvV7kcj8kaFVEH/LpVWeNFJO0YWnOtY/qa7UjP+ z7d1o1kNYc+2puqu1lkayptxyVMKKn9z4kj7znaF0PH6/Ey8uz6qESrnX9LdeDE3NA JoLmzRg7/SuGw== 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 v2 10/20] mm/zsmalloc: add zpdesc_is_isolated/zpdesc_zone helper for zs_page_migrate Date: Wed, 3 Jul 2024 12:06:00 +0800 Message-ID: <20240703040613.681396-11-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240703040613.681396-1-alexs@kernel.org> References: <20240703040613.681396-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 45849140002 X-Stat-Signature: op6sjihqxf6qopjhg6kgsp3c5763yxk4 X-Rspam-User: X-HE-Tag: 1719979309-551392 X-HE-Meta: U2FsdGVkX1858yy1Y8UnZ2N1RcMSVO+rzZGyKFRNgzwwdVuBQy5ZHzY2fFaQwOQk3o0m8wa3FTP1fug+y6G3Lz0CLlBPcY7n54BvlSJO8l4ncMVgHso2eiMWBNDv0o/91XLiZrrml9AFVgotqHqqoDCuZpxvQiwY5IzTb02oCBtdlkqjfjTcmgl627Vvxx1hLIqVkl49pSUCmEo6om0AdXz7enMO7sJ//Eo3xC/lvn8kpqv26Z+0VeB0+2Q0J50z0lZS0K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nQetkmwTUyKgSA== 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 a2e320f24dd4..61d7ba0c626e 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -106,4 +106,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 7aa4a4acaec9..9bc9b14187ed 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1830,19 +1830,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; /* @@ -1859,30 +1861,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. @@ -1891,14 +1893,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; }