From patchwork Thu Dec 5 17:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13895889 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 80B97E7716E for ; Thu, 5 Dec 2024 17:50:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E9636B016D; Thu, 5 Dec 2024 12:50:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 798A16B0170; Thu, 5 Dec 2024 12:50:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EAF26B0172; Thu, 5 Dec 2024 12:50:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3266C6B016D for ; Thu, 5 Dec 2024 12:50:07 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 717C11A160D for ; Thu, 5 Dec 2024 17:50:06 +0000 (UTC) X-FDA: 82861643844.02.260D919 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id 60DB0A001B for ; Thu, 5 Dec 2024 17:49:48 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qbZSmH5D; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733420994; 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=fcJ6cZyqlI8kYhrx6tlQPh4Zb+MB5UuATNGQ59JcAWs=; b=Cr3as9FMxeYfpy2TrycSgDmm7SVyfBo0nvfuIbr2vD4zgDfh4eLs2Nx0beRED3lCxuahUf PbGLYCdwDASkgUJnBOYxXda6QTQqPrhf8jClsfC19/fFiQtP9tkE24+xDGN/VHUmElnffD jZi1IiWyQ0qHH14yf5672hs838a5PHA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733420994; a=rsa-sha256; cv=none; b=LL2mnRYgf7ImgSYwWOGIaD9CbvwsoMe75o3Gg2Qf39SlbhxA+vw2eVR27oyqco1IUJNayE bkaiZEUqPm0GfI3wXDxgU+LmWJyTdXXAIfLwAauEosUgaB3r/u0joE4Tq+l/qW8uDly1Ak YFs0Iwx68SIBSccvmZ/9XgaDdiDZWSM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qbZSmH5D; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=fcJ6cZyqlI8kYhrx6tlQPh4Zb+MB5UuATNGQ59JcAWs=; b=qbZSmH5DLc9tWQawTtY0cKavfi 7NgXmaaALQ381FoK4izKQ10noORt2Iynb+R541C8P27oG6l4bQTKSrImFy3SrsioOCxVg2xBZcYtr OBDfzTYX7SQpkDzWjIuZQM8sm56tuFKJRVNcXYj4CYYxFvIq6JiDTvn+NgdhKhv+1jd4H2Anty3pp 94DdtpaS0kuIvGDyq5GfKdFrUQidmNhPQOLiN7RXk/c5Wg7QPmu9265aQMfA6zIN4ma/4MKindWZd bJf8fhcB0Pz3Yhn6graqGoOMxTWz9i+Syo0/VXNGJ6cja07N9K/72GFmJtdeiXqhihsg5UAzH4nx8 cT2tqLhA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tJFzH-0000000DN8F-1XC4; Thu, 05 Dec 2024 17:50:03 +0000 From: "Matthew Wilcox (Oracle)" To: Minchan Kim , Sergey Senozhatsky Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, Alex Shi Subject: [PATCH v8 10/21] mm/zsmalloc: add zpdesc_is_isolated()/zpdesc_zone() helper for zs_page_migrate() Date: Thu, 5 Dec 2024 17:49:47 +0000 Message-ID: <20241205175000.3187069-11-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-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 60DB0A001B X-Stat-Signature: hfa8mabjcgn88m6sqwbmux1s93adya4q X-Rspam-User: X-HE-Tag: 1733420988-393788 X-HE-Meta: U2FsdGVkX1/M02szS1YMvknEeD2iLGfeQM0IACuWgdRmLCELlvRL8JaHCUi58xgAou3M3lOzx8VgXOp665BhKCtoh2/NvzBfsmjMfV6zsmLWiGhAZV+Tqd5EbY6ClZefrxJQT0rDiABRDa6UybJPZ1QKfF0l9Qsu2wrhH+rrkoVebRWeT7lz/HZc+cdDBaXJsLc5f7GRq2nMlh/LDdER++LCd2y1UgBoHxE1KaeBlGiYZCFIKXfMNgr4FBNuHjIMgs+I4JjTTgeHlzaPC05nnKxqypy1xw4+vCRI1PDoxvXMDtfMCl4fCeUrWbWgDUQtPJCuYgUqcSQuORv7nHw/j+h3exyX8KKoV75bz4c01Vj6TBYs1KULiGCNzTpVC6I9npEcv4eFA4l5FsMeUWVfm5zd0epVTtEeRov20zgK8trSctA0D+ZBHmNErucJ3mZMjEDvRqfWDk8C4Zck9+lLtwEeHpEsl4fFDORMvR8oRrS8FmUaIu42VBDG8oPTATF66LroWfmQspOBatANIF8+AwwvjtA19vdhO/g9J/MhrLG9A74aMYqDK5/cJpO41zmlXrEa/cAMnUQ2MEcMbwTtWhSB7qQcc5n51+N1jsgtY6c9ESCWTjKs8plYOPgufcArWQv7pyOREtCOrcm8wQwq4AHG1bAJr2LShXWTV9y4Bzs26t0zPL882qqcdu4Po3U0Abdpm1ksfG7F6AV0O1bVVszeNf/iJu+9H1WsriRp9r4/72VnBSmr5zpDwem/x+sCHAyJq4dQnpdCW2uALSJsf+gUxwy1LhQ9f4o0d8hg/MVJuJN1tDs/jKXHY7CzzqGlZksUsv2H9B08Ne5r1v9HtnIoStWTxmErzC2DEDt9054i8HVURQHTr3QPbX4c9KzHMmJ3h/ppsZocFNkEu2ej/miFjt/xCJirv8jodqCbNSGsOwXBtSTYVzQCyOJIc50YjyUM8CdIZYWzXBr5THW HEZS8T4h FEzhKxwF7ILZYZ+mWSk2Ode2Fadonab5E0/KtuwCkXu79vWOcdLgpF3uFTSiiLZbMO611HBa2g1BHfZkT1XoGU7WueAJCQfGgBVFIdVczePtFQsiwayr4HqZW5F9Srr3yhdk6hMzx+nJa+BASR7RfEBCBrhY//dy5kLCLGhx3hjVMSUo6OjLKAQycwp0SRBQgI5UceVikJ/BCDKMTMB/FMNiU4u14ZNWzEL/jSZVy0Xw40f2E/TVtoiQnjc0v3CobxlqyJRzV6ONBbhgXxLG4mvo7Anve+rr+Hgp6yl4ZVWzw0uveqz29Ap9x3GiEUhWkqMbH1PjBXRX4Twknz7t8j/1pzw== 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 0387f5771dc6..7d59bc2587bf 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -116,4 +116,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 6145f7169c67..d8f2f8e5c877 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1815,19 +1815,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; /* @@ -1844,30 +1846,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_local_page(page); + offset = get_first_obj_offset(zpdesc_page(zpdesc)); + s_addr = kmap_local_zpdesc(zpdesc); /* * Here, any user cannot access all objects in the zspage so let's move. */ - d_addr = kmap_local_page(newpage); + d_addr = kmap_local_zpdesc(newzpdesc); copy_page(d_addr, s_addr); kunmap_local(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_local(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. @@ -1876,14 +1878,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; }