From patchwork Fri Jun 28 03:11:32 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: 13715403 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 545A2C2BD09 for ; Fri, 28 Jun 2024 03:07:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E56A6B00B8; Thu, 27 Jun 2024 23:07:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2973E6B00B9; Thu, 27 Jun 2024 23:07:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C3056B00BA; Thu, 27 Jun 2024 23:07:55 -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 DDAE76B00B8 for ; Thu, 27 Jun 2024 23:07:54 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A10A41A149E for ; Fri, 28 Jun 2024 03:07:54 +0000 (UTC) X-FDA: 82278812868.09.837E66D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id F2D001C000D for ; Fri, 28 Jun 2024 03:07:52 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Kn8GoGgZ; spf=pass (imf18.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 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=1719544064; 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=cLzn0lEwP9g6CtaSp7tP7hd1tIoDPUEGDmoCjPN3erE=; b=6FN2YJQ+kqrgbYmrHrI7pzBd1DZPVR71NJqAajTKGDhlVYQZXCcsxa1uhbg9p2BBd1hUa8 6H7PZLi9XRq6HUUEehBXiKrAVFeqwrncGFzkTtVQfpieWxLy9X3IkLeBc5VJsXZJKmt/rr oCiGzP74IUiI1LtAT6YkXVg1Uibkb/8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Kn8GoGgZ; spf=pass (imf18.hostedemail.com: domain of alexs@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719544064; a=rsa-sha256; cv=none; b=eeZAXOIJBMOd/v9K10tW6DQYVfQVahio7gEu78x2iBA9W05xMWP00BQPTRuviyuKUJOlz/ cRoeZvF7Ci0kpKGarbBCbq+PHieAukW/AmRmxBMOcyoKvuVthF6e3YTBovBW6/cxFg+bbx mshjNVMD3Cx9ys6tedWrItCnTNzX7V8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2AB9D61DDD; Fri, 28 Jun 2024 03:07:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7603C116B1; Fri, 28 Jun 2024 03:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719544071; bh=BULUfQtc3EjNlGEEdYDtph/07BaO7bkwBtlyH1/5iBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kn8GoGgZJ1gvzJR2ncaJOTr4cft0ptFYqqqvbtAwTpCfjfvz4TvWV5uAi2Eez6HFe fKUWmp/Ts+D6L4Djx91kxmxRNiKIpJnkx8+z1/ZcZdL8U1zcxymua+7Gi4mAGVdSPM JORUVVR6FgEOCUCxesPq43knn7yJph28Reeb3A8CaTzJ0LJYlKmw1JaZJKOtO85Pce R/zlvqlS7vVfrxk14GzwY82GipQfBVN9n7LaPjttYrKJmpNLAq4aXSGvIaD6Gh5t+u QRlJ7PvfPSXp5TlA6TInbxbPPsrHJyyGJD7s2T5vpgnRSaqu8yy/uWEXSp7AbPLic2 7bibTnUJh3iLA== 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 17/20] mm/zsmalloc: convert get/set_first_obj_offset() to take zpdesc Date: Fri, 28 Jun 2024 11:11:32 +0800 Message-ID: <20240628031138.429622-18-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240628031138.429622-1-alexs@kernel.org> References: <20240628031138.429622-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: F2D001C000D X-Stat-Signature: 17zuembbwoifj5ewjomhzdb14a1tdy6z X-HE-Tag: 1719544072-351474 X-HE-Meta: U2FsdGVkX1+1Jgy9kDRw74a+TVIAI9PFc3P5wDIn85Pzojz9C0q7Hil4NhTm/+vIuW5Av+l/UMW2vJ/YVxBJFuFWBRaVhlLCzWZ1ifs5WXAGDN06GGhPiTyHDwCmyKyi4gSpwHMKGpn0vlXI11aVKr7URtRMWkVXdjXiL9agfgSAz1Ckkdx4vlfv6dbMuduoRjdxrgUwy+vlAGM840rKn+imhGKiddpfaYaYPg0+EDpI32TbT7a0epQ8oQzfqbqL5mfErzIzos5bN0NMXcnKN9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Kfaag1sPJKrlQCFt5 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> Now that all users of get/set_first_obj_offset() are converted to use zpdesc, convert them to take zpdesc. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Alex Shi --- mm/zpdesc.h | 3 +++ mm/zsmalloc.c | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 186ff9711ffb..17941774c46e 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -14,6 +14,7 @@ * @next: Next zpdesc in a zspage in zsmalloc zpool * @handle: For huge zspage in zsmalloc zpool * @zspage: Pointer to zspage in zsmalloc + * @first_obj_offset: First object offset in zsmalloc zpool * * This struct overlays struct page for now. Do not modify without a good * understanding of the issues. @@ -29,6 +30,7 @@ struct zpdesc { unsigned long handle; }; struct zspage *zspage; + unsigned int first_obj_offset; }; #define ZPDESC_MATCH(pg, zp) \ static_assert(offsetof(struct page, pg) == offsetof(struct zpdesc, zp)) @@ -38,6 +40,7 @@ ZPDESC_MATCH(lru, lru); ZPDESC_MATCH(index, next); ZPDESC_MATCH(index, handle); ZPDESC_MATCH(private, zspage); +ZPDESC_MATCH(page_type, first_obj_offset); #undef ZPDESC_MATCH static_assert(sizeof(struct zpdesc) <= sizeof(struct page)); diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 951292dbcae4..3ce49f0372cc 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -496,26 +496,26 @@ static struct zpdesc *get_first_zpdesc(struct zspage *zspage) #define FIRST_OBJ_PAGE_TYPE_MASK 0xffff -static inline void reset_first_obj_offset(struct page *page) +static inline void reset_first_obj_offset(struct zpdesc *zpdesc) { - VM_WARN_ON_ONCE(!PageZsmalloc(page)); - page->page_type |= FIRST_OBJ_PAGE_TYPE_MASK; + VM_WARN_ON_ONCE(!PageZsmalloc(zpdesc_page(zpdesc))); + zpdesc->first_obj_offset |= FIRST_OBJ_PAGE_TYPE_MASK; } -static inline unsigned int get_first_obj_offset(struct page *page) +static inline unsigned int get_first_obj_offset(struct zpdesc *zpdesc) { - VM_WARN_ON_ONCE(!PageZsmalloc(page)); - return page->page_type & FIRST_OBJ_PAGE_TYPE_MASK; + VM_WARN_ON_ONCE(!PageZsmalloc(zpdesc_page(zpdesc))); + return zpdesc->first_obj_offset & FIRST_OBJ_PAGE_TYPE_MASK; } -static inline void set_first_obj_offset(struct page *page, unsigned int offset) +static inline void set_first_obj_offset(struct zpdesc *zpdesc, unsigned int offset) { /* With 16 bit available, we can support offsets into 64 KiB pages. */ BUILD_BUG_ON(PAGE_SIZE > SZ_64K); - VM_WARN_ON_ONCE(!PageZsmalloc(page)); + VM_WARN_ON_ONCE(!PageZsmalloc(zpdesc_page(zpdesc))); VM_WARN_ON_ONCE(offset & ~FIRST_OBJ_PAGE_TYPE_MASK); - page->page_type &= ~FIRST_OBJ_PAGE_TYPE_MASK; - page->page_type |= offset & FIRST_OBJ_PAGE_TYPE_MASK; + zpdesc->first_obj_offset &= ~FIRST_OBJ_PAGE_TYPE_MASK; + zpdesc->first_obj_offset |= offset & FIRST_OBJ_PAGE_TYPE_MASK; } static inline unsigned int get_freeobj(struct zspage *zspage) @@ -852,7 +852,7 @@ static void reset_zpdesc(struct zpdesc *zpdesc) ClearPagePrivate(page); zpdesc->zspage = NULL; zpdesc->next = NULL; - reset_first_obj_offset(page); + reset_first_obj_offset(zpdesc); __ClearPageZsmalloc(page); } @@ -936,7 +936,7 @@ static void init_zspage(struct size_class *class, struct zspage *zspage) struct link_free *link; void *vaddr; - set_first_obj_offset(zpdesc_page(zpdesc), off); + set_first_obj_offset(zpdesc, off); vaddr = zpdesc_kmap_atomic(zpdesc); link = (struct link_free *)vaddr + off / sizeof(*link); @@ -1593,7 +1593,7 @@ static unsigned long find_alloced_obj(struct size_class *class, unsigned long handle = 0; void *addr = zpdesc_kmap_atomic(zpdesc); - offset = get_first_obj_offset(zpdesc_page(zpdesc)); + offset = get_first_obj_offset(zpdesc); offset += class->size * index; while (offset < PAGE_SIZE) { @@ -1789,8 +1789,8 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage, } while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL); create_page_chain(class, zspage, zpdescs); - first_obj_offset = get_first_obj_offset(zpdesc_page(oldzpdesc)); - set_first_obj_offset(zpdesc_page(newzpdesc), first_obj_offset); + first_obj_offset = get_first_obj_offset(oldzpdesc); + set_first_obj_offset(newzpdesc, first_obj_offset); if (unlikely(ZsHugePage(zspage))) newzpdesc->handle = oldzpdesc->handle; __zpdesc_set_movable(newzpdesc, &zsmalloc_mops); @@ -1845,7 +1845,7 @@ 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(zpdesc_page(zpdesc)); + offset = get_first_obj_offset(zpdesc); s_addr = zpdesc_kmap_atomic(zpdesc); /*