From patchwork Mon Jul 8 06:33:31 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: 13726198 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 7F27DC3271E for ; Mon, 8 Jul 2024 06:29:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B7ED6B00A8; Mon, 8 Jul 2024 02:29:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0410D6B00A9; Mon, 8 Jul 2024 02:29:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFBBF6B00AA; Mon, 8 Jul 2024 02:29:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BFB0E6B00A8 for ; Mon, 8 Jul 2024 02:29:21 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7D6F7A3172 for ; Mon, 8 Jul 2024 06:29:21 +0000 (UTC) X-FDA: 82315608522.21.6D8FE16 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id D6EDA4000F for ; Mon, 8 Jul 2024 06:29:19 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hebeQ3k0; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1720420127; 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=tp79eLWX50qbmgcw+JNCh0sTs81YDiRvHuTLRpwVokc=; b=qqEdrgkZacW2cn7vmKvpPkzIBQJJVM4cTy0Gw1CUdJcj8adpTdwvjpcQTvI2TEYw7EwveI dPo0ki15pM7677PQLi4yVAtz47PUhTeIEi/iqf+pS6f9nB1gxT13WLTOMRwEYHnw3e7Pv4 vus41R63Ygg8xZhkaA1BGv8bAV6xQ3Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720420127; a=rsa-sha256; cv=none; b=wBfeps8v3qmhw7BUMRutUfpYCminAEdiiUDvxEYkaKIUPd5nqBf38ef9Fxr0mTUw5bPELF 8BjS+MIxU2SsF7pwC9dDSQYwA1x+O5EJdn72J3TstNbIXVVYCO2JuLU4DoSD20bFQ2gAPM rcNJTzylCvzmtZzFVBz/9PoOhgR5W/I= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hebeQ3k0; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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 1D05E60AD9; Mon, 8 Jul 2024 06:29:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6E61C116B1; Mon, 8 Jul 2024 06:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720420158; bh=eLEoZgV0ypx4IcCw8JtJdFgQAqXajv6Dsx6/oMszAA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hebeQ3k0Iltjd3ERyywf5cF9ODSAm8MNeYFZ8QxgekeMq8VG+m6vhC9W32CO4ABH+ VNQ5WsibBUHoCie0KvD+wxpe1WwWSm8Mz8PAfB/bZT2Sf2qGd6xr+Q9NIGJ/m62uwG o3gZug61V9v0A0bPozSxKy3eoUDzZ8U/L9/FYbbPgp2F+wsCcYJJ8qqBYoHl1nEXZY iI5i+1DBM8BbNOgDhV6ZehdXQXE80fsySTLO/uiZ8Sb6krWbmGzBEH6jr98MU30fHI vbfw3bUjscXkgBXIjC5Ar39fojb32Wmqggul321fu6Sr4qllQHUwE+bEWRbsjTo/jz exGZ62Z3odasg== 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 v3 10/20] mm/zsmalloc: add zpdesc_is_isolated/zpdesc_zone helper for zs_page_migrate Date: Mon, 8 Jul 2024 14:33:31 +0800 Message-ID: <20240708063344.1096626-11-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240708063344.1096626-1-alexs@kernel.org> References: <20240708063344.1096626-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D6EDA4000F X-Stat-Signature: qintinb9yg64toui6ztuzy7jxmq9icgu X-Rspam-User: X-HE-Tag: 1720420159-622186 X-HE-Meta: U2FsdGVkX1/uvZAGQ+4eIrr0J+2bApgYdn6DUKOAgcxdewdy1L2IhqQ/RHo7AkBTnRw/y0WrNaNHF6hAyaavxljWJfVeyZeUPYqYIy6qRwkjehYyuGdR8VUDK/P4rV/fvADEsVky9eKzvmFyVniK77pAGDGuqXhcGcfYcIw3vlpK40Qef6EJ4g0AEE7Lcuw6k+D7I5PXwhFLNO6X2Pb0K3OwOTm2LXIBZyAYbM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UmsCsmKXV77zSwGdp9Xe6yzM6wl6LZx9XT8qmbNM1ZNsebpVRZ2zRhFhrpYQpNHGeD2aUQG 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 (Tencent) --- 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 2293453f5d57..ad04c8337cae 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -108,4 +108,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; }