From patchwork Fri Jun 21 05:46:51 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: 13706866 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 C51CBC27C4F for ; Fri, 21 Jun 2024 05:42:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FE078D0134; Fri, 21 Jun 2024 01:42:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6598C8D012C; Fri, 21 Jun 2024 01:42:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45FA18D0134; Fri, 21 Jun 2024 01:42:44 -0400 (EDT) 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 10C9D8D012C for ; Fri, 21 Jun 2024 01:42:44 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BF33FC0912 for ; Fri, 21 Jun 2024 05:42:43 +0000 (UTC) X-FDA: 82253801406.22.1E24123 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf19.hostedemail.com (Postfix) with ESMTP id 88B411A0003 for ; Fri, 21 Jun 2024 05:42:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Dhhurl3c; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 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=1718948551; 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=HMk//fdr4CCccqqvWOhTBEl3kE7h3RRH1GcADQePr34=; b=5bBZtxAhuODO9kE5OCclbAoB38j+eh52gFU09Kt7BfHkqceb7+7w1Pm8fkYXogmbK8Tuhb q9bT3aIMEKPuEC8Vj7r7S2Mf8ztxjABWHPSL75yZRgkeRiIudeIJ6k1Kc2p8f22Zgf1EMp DWzffgL8fkViLyCthfzsJdiGAAITl30= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718948551; a=rsa-sha256; cv=none; b=hjKBGd8J793wCfBuKL/wzu+VsLdaB+2gn1yHInQ+mXn6Csyn33jYz+wmweD8ryC0hay/4T 7V+BXseOwq+1lFwJ1qlWkUUEzXDIEvanyOPjE0xrUBS5UqeWSNa5VelRjF2l1G9E+uOBbq eIRkdemM/XNTkLJKDfampLeUIA+4rlM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Dhhurl3c; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id D6A24CE0A66; Fri, 21 Jun 2024 05:42:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD57CC4AF07; Fri, 21 Jun 2024 05:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718948558; bh=dBoIzS7885VeKezN+gY+kbZ+dCan8vwvmHD8Z0kpVt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dhhurl3cF4nteYiqCwSt1qwbQI2OTdrwgXN3j6ATVB1DNAHIvWS+c7hY4e16dlN6l SxH+V4eiObBiqu3OQvjRDh3meSyWpVloR2DvITcgYW+xDaMzNhg4rPpvk8Z2qbUtb4 vq49YEJnL3gz6HL0yp/KvMpG+g0VlAPTdP7HpqIZQ0OD8X2JBdQtTe/NNaH7aI1jwx GJ6nWcnMBWe+rPxVnrWnC14CZ2CwSkeieja++9ODBJyzCVkpw1/9l3W8N0Y8nViDHj yMR1NaxKkFHtVdXydX5qGU06OsQZdVfO/0FgcSjo+HzwyZVOdr5jm050B9WkbdxTCy Sq5KFiKIWilwA== 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 11/15] mm/z3fold: use zpdesc in z3fold_alloc Date: Fri, 21 Jun 2024 13:46:51 +0800 Message-ID: <20240621054658.1220796-12-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621054658.1220796-1-alexs@kernel.org> References: <20240621054658.1220796-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 88B411A0003 X-Stat-Signature: 85qgjr7p7o9k677qhwhfpsrbcmaxissg X-Rspam-User: X-HE-Tag: 1718948561-756795 X-HE-Meta: U2FsdGVkX182sofXzxXO2nJiHEGCEgrsOvkA0+KAduJ0qIe37qBJ82zsTKjWoOWxjbQ7mHJ7YxGOThXeibIV3SdaDtJw42aN9SKh6THs0D9OcIpKRx5PUYQWf2Xo1rjCVljdr508DiUASWQ+hoDsdvw4b7JySXKrQWGWFb3PjlbijfZnwIxRt0RMyH6W0xdgLLTjYTedy8gtJaAc8wjyw0XL4fh0Z1M4jnwBXkfn2H/Rn7hvbvNk5VYInG5tVuHfj8H/Ok/md2jYW7toBiDbDm6EUNpscu4Bf1sIP/Sg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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 Convert page to zpdesc in z3fold_alloc func. Since both func use zpdesc now, we can pass zpdesc to init_z3fold_page(). And introduce zpdesc_trylock helper. This patch could save about 12KB object file size. Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Alex Shi --- mm/z3fold.c | 29 ++++++++++++++--------------- mm/zpdesc.h | 5 +++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index f164eb4e1139..e780143982c6 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -317,10 +317,9 @@ static inline void free_handle(unsigned long handle, struct z3fold_header *zhdr) } /* Initializes the z3fold header of a newly allocated z3fold page */ -static struct z3fold_header *init_z3fold_page(struct page *page, bool headless, +static struct z3fold_header *init_z3fold_page(struct zpdesc *zpdesc, bool headless, struct z3fold_pool *pool, gfp_t gfp) { - struct zpdesc *zpdesc = page_zpdesc(page); struct z3fold_header *zhdr = zpdesc_address(zpdesc); struct z3fold_buddy_slots *slots; @@ -1006,7 +1005,7 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, { int chunks = size_to_chunks(size); struct z3fold_header *zhdr = NULL; - struct page *page = NULL; + struct zpdesc *zpdesc = NULL; enum buddy bud; bool can_sleep = gfpflags_allow_blocking(gfp); @@ -1030,35 +1029,35 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, WARN_ON(1); goto retry; } - page = virt_to_page(zhdr); + zpdesc = page_zpdesc(virt_to_page(zhdr)); goto found; } bud = FIRST; } - page = alloc_page(gfp); - if (!page) + zpdesc = page_zpdesc(alloc_page(gfp)); + if (!zpdesc) return -ENOMEM; - zhdr = init_z3fold_page(page, bud == HEADLESS, pool, gfp); + zhdr = init_z3fold_page(zpdesc, bud == HEADLESS, pool, gfp); if (!zhdr) { - __free_page(page); + __free_page(zpdesc_page(zpdesc)); return -ENOMEM; } atomic64_inc(&pool->pages_nr); if (bud == HEADLESS) { - set_bit(PAGE_HEADLESS, &page->private); + set_bit(PAGE_HEADLESS, &zpdesc->zppage_flag); goto headless; } if (can_sleep) { - lock_page(page); - __SetPageMovable(page, &z3fold_mops); - unlock_page(page); + zpdesc_lock(zpdesc); + __SetPageMovable(zpdesc_page(zpdesc), &z3fold_mops); + zpdesc_unlock(zpdesc); } else { - WARN_ON(!trylock_page(page)); - __SetPageMovable(page, &z3fold_mops); - unlock_page(page); + WARN_ON(!zpdesc_trylock(zpdesc)); + __SetPageMovable(zpdesc_page(zpdesc), &z3fold_mops); + zpdesc_unlock(zpdesc); } z3fold_page_lock(zhdr); diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 06cfd33de330..9ead7a452f2a 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -63,6 +63,11 @@ static inline void zpdesc_lock(struct zpdesc *zpdesc) folio_lock(zpdesc_folio(zpdesc)); } +static inline bool zpdesc_trylock(struct zpdesc *zpdesc) +{ + return folio_trylock(zpdesc_folio(zpdesc)); +} + static inline void zpdesc_unlock(struct zpdesc *zpdesc) { folio_unlock(zpdesc_folio(zpdesc));