From patchwork Wed Jul 3 04:06:07 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: 13721087 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 36EF1C30653 for ; Wed, 3 Jul 2024 04:02:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B88466B00AF; Wed, 3 Jul 2024 00:02:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B11576B00B0; Wed, 3 Jul 2024 00:02:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 988F26B00B1; Wed, 3 Jul 2024 00:02:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 723536B00AF for ; Wed, 3 Jul 2024 00:02:17 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 21AE180714 for ; Wed, 3 Jul 2024 04:02:17 +0000 (UTC) X-FDA: 82297093914.03.72E8BCD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 78F7240013 for ; Wed, 3 Jul 2024 04:02:15 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TUNlomcQ; spf=pass (imf27.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=1719979304; 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=nORsaZlIaUA3idoDw8T4vH/VEYYd+wWIyfYZsPkiZ18=; b=zmh303lC6CbMEDWa1cD+8R6J6zu2Y3D4NdMQL2iHnydOO62v/7Cp4Ck9yYPdE2ZlL8Zl56 zj/0yNfpE38EJ4hTxdb+ToLkvc8hjIUlCs9N+JqVNuItz1rg2YZnAcPYOxDncknOxrWtm0 wFo33LcTL0IFFpJKv/7h9hDGLK8htSk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TUNlomcQ; spf=pass (imf27.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=1719979304; a=rsa-sha256; cv=none; b=DXz5DDW6fGPVX/ldomJ5HBfiSPH/Ywztiz4BCNSvXQAFBCtACWeKaIF6WimcjEAEYzNjQw ZvStFvQX9Urp2AcrEbDE8ss0+NkQz+t4uI50RoXoZqMV4ZEaQVfYWvHwd5WJro4bvrUBND jfv//FekV+ighCvMom6jwd3m6l7kyGk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B4EBA620DD; Wed, 3 Jul 2024 04:02:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2527FC4AF0C; Wed, 3 Jul 2024 04:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719979334; bh=vsXuVfMJsSuMD7UFdk0WVE3RDVFvIl+YscGm1B7bHVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TUNlomcQNEckWzE3pkdaNY/jWZemVDlbi9bxsdknLLDnG7+ZhTC6n5f1YKOBHPscF BhxNJlC+MBOjvNvdjcvvweVfGrQI08RQxthpm10H45a59hqsrL4GTJMugS9+1KtZdn 4M+riFrBTzpbHYxAIryEuoUqrDZckEejZCNBzptjOWLMeGv1EBzgq2ScxBviaaWrQ6 QWZDoYbgUQhGonitWAa/cUrUYW0++s9TjxH7obnaIBdamvY460PdXvBVLA6X1x6nkS B4DRFGqaiG9bq5kwyikisFoKGiRznLujqLzzynay9P0uddufucPKK3vVj2EgfV4as3 vtHSH2B65Q+mg== 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 17/20] mm/zsmalloc: convert get/set_first_obj_offset() to take zpdesc Date: Wed, 3 Jul 2024 12:06:07 +0800 Message-ID: <20240703040613.681396-18-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: rspam06 X-Rspamd-Queue-Id: 78F7240013 X-Stat-Signature: qfmd5wewhedjr7wx3xb9i5cxqm3rdjpq X-Rspam-User: X-HE-Tag: 1719979335-84735 X-HE-Meta: U2FsdGVkX18cTUjOdozzpBxU8qphNth/kNMI4DTmYYc7Ggy/thNRIAG8RZdFaTFdJ9SKORxPZo24/LwBmXt3f/UG2TCM7P25lYgU1RFaFH8FW1wEIvGd/WJlu6/kCMMBsO9ADEY9lMFImK9iHIulvZH7RlfChUqhdMzU+x0ylDFI0t2wZNqUshiBICdujK99cgfKrPrgP0SZnu+45JtshUXCOj/FSnzu3izVa5+XgubysrDJ/AGg1ZkUMWKTGHf0zpQCK8NtBKtrKpw073yTfBhkJBUDy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ZcDxMRRo908nxD55apU2vaECrQm4ywZ 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 | 6 +++++- mm/zsmalloc.c | 32 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 6de3c5d095bd..296cb1ff944b 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_SLAB_OBJ_EXT unsigned long memcg_data; #endif @@ -45,6 +48,7 @@ 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(memcg_data, memcg_data); #undef ZPDESC_MATCH static_assert(sizeof(struct zpdesc) <= sizeof(struct page)); diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 8b713ac03902..0493f953fcb5 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -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); /*