From patchwork Mon Jul 29 11:25:29 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: 13744740 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 7CC0AC3DA4A for ; Mon, 29 Jul 2024 11:21:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A03BC6B00B2; Mon, 29 Jul 2024 07:21:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B3CB6B00B3; Mon, 29 Jul 2024 07:21:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 805136B00B5; Mon, 29 Jul 2024 07:21:16 -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 58ACF6B00B3 for ; Mon, 29 Jul 2024 07:21:16 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1C76B1C1068 for ; Mon, 29 Jul 2024 11:21:16 +0000 (UTC) X-FDA: 82392548952.26.72A1F53 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 63F031C002D for ; Mon, 29 Jul 2024 11:21:14 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WKtVL170; 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=1722252071; 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=3Cdy16gcWU1T1yBZr30RCaoUoqkrgtx34tTJp2WzbPU=; b=FY91zBsxFdjNif/84A9sqvYXFOG44qS7DTUGPkMQqjahDfLY6jdvn+dJvqrf6d7H2u7mM2 T2QwYBPhvsJMqep2komnaAciWykw3h1016tlnzgEYndDcGPBZRW2qn32PlHIHAGSWyc92C fGMPxIlMqO+k3sl3ULkMNO1qupcdBLE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WKtVL170; 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=1722252071; a=rsa-sha256; cv=none; b=LY8OH08XduGzxI8c6xM6HWmmTOz+Z/UM1Fv0dtzlMwOn+COh/dwzOCnaWHv0tRRTNuxD4V eJ1YKRnctoARj0SQSPaOld8Gj3H8vRmucyYZ6XptWrKy+DYXWZ39PB95RFSXZLxC9tPLzj Dv/U+nFuWTkQHNM+LoWcK2L1Srll1YM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7C561617A5; Mon, 29 Jul 2024 11:21:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 693D1C4AF11; Mon, 29 Jul 2024 11:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722252073; bh=Itfg7R6iNeKIMJsSCXaa7VK0PRdQ2psxEdNvilX7MGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WKtVL170fOP1O4XLSDWo1F250iq5RJ80EenjRyd7ZFOT2WvuJuInoIyx92SwRS7Cc pbrGzXYKmIIAT4QtnvMB8ThaarUUedL3E5+TlS+UtYM+YJsxN2p5XSlso+e1SHSb5M xTUP2ijw2w7jJF69q2NiOoesk4j1NPgHOtJ1w0TS2tjj2RqoWf5SEtWI/DS+hgTA/t jwIzd+zFQpYJUj4XC3xJkx35hp9rlt9Ju0MpE+vnq/J8BM6koz0K0BkDwwpac68UpE 0W/f4fyzHaM9zCNTqtvtVyYatxW07+UpA2zA8fi8x/CPXDjyEwZFw9NR4VBwQLbWRv TGyKYh/tyozJw== 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 v4 17/22] mm/zsmalloc: convert get/set_first_obj_offset() to take zpdesc Date: Mon, 29 Jul 2024 19:25:29 +0800 Message-ID: <20240729112534.3416707-18-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240729112534.3416707-1-alexs@kernel.org> References: <20240729112534.3416707-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hjj7rcwnweg9p1578ktk38myy19hqq9t X-Rspamd-Queue-Id: 63F031C002D X-Rspamd-Server: rspam11 X-HE-Tag: 1722252074-576062 X-HE-Meta: U2FsdGVkX19a1bEClZLm8wT2eqD5d/nnsh4CmyqpJ3PoA84QMWl2GB+wg9ez/lNmpd7csz0r5AT1xg2BrP+ysi+uVCQXNq1CoEWFUg7oqyil1xs4rN/K44LM9h+nxTTD7bWTPtqEcZIFntAznDb8E6vQaxeHwMPR91NeP7hJMVlauJ7a3E+QYOY+D6onJ7vs2kauIeTxTMrGcnT5QxTOPDi7zbvZZdCcBX9WoXqkftvd2oUWtpMl21OxFTMkRCnjgYlzvd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TYRIKehSFNx+IO0DXAqLJiP70pn1FdQbp212hUhVctWOiot 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: Alex Shi 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 | 7 ++++++- mm/zsmalloc.c | 36 ++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 72c8c072b4c8..f64e813f4847 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -15,6 +15,8 @@ * @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 + * @_refcount: Indirectly use by page migration * @memcg_data: Memory Control Group data. * * This struct overlays struct page for now. Do not modify without a good @@ -31,7 +33,8 @@ struct zpdesc { unsigned long handle; }; struct zspage *zspage; - unsigned long _zp_pad_1; + unsigned int first_obj_offset; + atomic_t _refcount; #ifdef CONFIG_MEMCG unsigned long memcg_data; #endif @@ -45,6 +48,8 @@ ZPDESC_MATCH(mapping, mops); ZPDESC_MATCH(index, next); ZPDESC_MATCH(index, handle); ZPDESC_MATCH(private, zspage); +ZPDESC_MATCH(page_type, first_obj_offset); +ZPDESC_MATCH(_refcount, _refcount); #ifdef CONFIG_MEMCG ZPDESC_MATCH(memcg_data, memcg_data); #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 8b713ac03902..bb8b5f13a966 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -20,8 +20,8 @@ * zpdesc->next: links together all component pages of a zspage * For the huge page, this is always 0, so we use this field * to store handle. - * page->page_type: PG_zsmalloc, lower 16 bit locate the first object - * offset in a subpage of a zspage + * zpdesc->first_obj_offset: PG_zsmalloc, lower 16 bit locate the first + * object offset in a subpage of a zspage * * Usage of struct zpdesc(page) flags: * PG_private: identifies the first component page @@ -494,26 +494,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) @@ -850,7 +850,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); } @@ -934,7 +934,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); @@ -1589,7 +1589,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) { @@ -1784,8 +1784,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); @@ -1840,7 +1840,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); /*