From mboxrd@z Thu Jan 1 00:00:00 1970 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 B86F0C0218D for ; Fri, 31 Jan 2025 08:24:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 495D92800EA; Fri, 31 Jan 2025 03:24:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41EC42800E9; Fri, 31 Jan 2025 03:24:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BEC52800EA; Fri, 31 Jan 2025 03:24:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0B0EC2800E9 for ; Fri, 31 Jan 2025 03:24:46 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 84A2DAD606 for ; Fri, 31 Jan 2025 08:24:45 +0000 (UTC) X-FDA: 83067060930.20.3F539BE Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by imf05.hostedemail.com (Postfix) with ESMTP id 9010D10000D for ; Fri, 31 Jan 2025 08:24:43 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i0yLJH4z; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.167.47 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738311883; a=rsa-sha256; cv=none; b=14ad1Cjc7Mht39wUpPis6Y+kJ7UES+nBwtx7JaKLbMMM1IZn02nx9T/447idSvpi2mJ7VX w679kSGbBWIN4u9RJwQ0V3a7Pd2NIHIFvpmE2O8bwFSlgiqu2SrnFuVo5vgvpCCBUqNDOk 1MYFiepuoKCrvIwoyJKPx81lsz+2NTI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i0yLJH4z; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.167.47 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738311883; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Kn4Bs4pX/u0eoj4XGaHfVzDs+lXLx9/eSSMcCmrDTWQ=; b=MwsQF69c/m1zi935Kx77fI7giT+Thu7yoTfqWDQXDkec5Pw0LaIISZxtiF0OKPSA9Nnhbx aPSvD3wemrG+y2kpG84OqceyxuBmkh6OLRgpTXPUWZpJswvBT+/IvLzZ8hc5x1LA/+01DQ uBr2tSSVXzremKOUmmDZWd7pg7MGTlc= Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-53e384e3481so1527778e87.2 for ; Fri, 31 Jan 2025 00:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738311882; x=1738916682; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Kn4Bs4pX/u0eoj4XGaHfVzDs+lXLx9/eSSMcCmrDTWQ=; b=i0yLJH4zyOavcp9xD0zOAakgoDfJGyloVQcbwaikvs1qpdHHglVF95ry1MuhmY7zkK Z20c6V14FD+o2pu/gGiKYPbo/g/60X4csROAHRaW6gRtdPWgHA0xFpCHIbKvN8xtFFhj cYCmvdkDv+Orz6D5V8i0GM0dieJrGyM4TI7mb8Znp+vZ1RqBRqbBWj9a9ZKzK9Cgfxj9 XjJlB71ajMFpeNnF0jFgTv6Zg6y8dpb/8wkssI9A3n/7wHmcmumaLqWz1d9qB82vs1Ns tCzcPrK4QvLyQ1eeNVsKS61MvP6QnVQeYjv3P6f74uX/iRw/ITw0LOjEW8OQi/JVssZv YrXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738311882; x=1738916682; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kn4Bs4pX/u0eoj4XGaHfVzDs+lXLx9/eSSMcCmrDTWQ=; b=YusGTn/XVH6UH7VEMkaNhu2haxQQ1bf+7l8whs7fwGFE4DPqokyDu7MLfxYMrkGVy2 eDu1Guy1EiVRrOTMoifVHYkH+RiO3swQNDHQUU9eOfGI0x7hF8tLDJqyA2MiCNRFMfbn ZvKf3x2aVD85xg/xvYAd4pzy8a6f9Epb8zaT6Lh110lsp3nHARbaaJA553MwSvZAo2Tr KMBB7OOebsDuVV99e4YGD424NGiSg9n1GsRQPGTQFwyCMIx92pdXUS3Jqwbsn28gKS66 QlE3xVQYd9SHnp2HdOVvChs/SHbIWU+Xv6oNhvY5vi4Ok21hEmbKS1JEXjpfAZYAMeR9 +8aw== X-Gm-Message-State: AOJu0YzkbFTGuuXRedtCaISI0wDt+xKA0CBXofk570rABhtecTsY2dCh yOHyuobPI8kOR9z4RKgyH0I5UkSwe0oY8hmBxDLp4bt4N49f5sGPrWxb4pkf9o5lxfFiDKArVSD CYLsjGfVRLjwVtQeJl6FuecV/9mo= X-Gm-Gg: ASbGncv/fQaLEC9obbIGRmSM09OrGGv3ntbTE9lzyHnU+t/05R1+NkKU//fz8ZsATvl qpH7/L0WbfpG+ej3e9AiGhfI3wY1hIJFcHssm9gZ2P+UTEGfCdw1TPZ1qQnLub49ELQxqdHZxPy eH9H4TK8DOHR2ZxjY320OhR+T0N/gzFg== X-Google-Smtp-Source: AGHT+IFEBGhvkUEti+KQb8RJgTeRYhv8sHp5+HiO2A2ndrkOihp7lV5PDZtAYSaVtuo47VggO864Qh1Kq3GEFbdV07g= X-Received: by 2002:a19:7611:0:b0:542:297f:4ec9 with SMTP id 2adb3069b0e04-543e4be9838mr2784224e87.14.1738311881380; Fri, 31 Jan 2025 00:24:41 -0800 (PST) MIME-Version: 1.0 References: <20250131082037.2426-1-42.hyeyoo@gmail.com> In-Reply-To: <20250131082037.2426-1-42.hyeyoo@gmail.com> From: Hyeonggon Yoo <42.hyeyoo@gmail.com> Date: Fri, 31 Jan 2025 17:24:29 +0900 X-Gm-Features: AWEUYZltufNhnAjrhgkK9HwtE5WPrpTD_4-j0BPOZsceaw8cj5IejHdRvCxmh5o Message-ID: Subject: Re: [PATCH mm-hotfixes] mm/zswap: refactor zswap_store_page() To: Kanchana P Sridhar , Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Andrew Morton Cc: linux-mm@kvack.org, Yosry Ahmed Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9010D10000D X-Stat-Signature: ejbtnnnzpqmofqzwnfhbxbgnd85qkndk X-Rspam-User: X-HE-Tag: 1738311883-586925 X-HE-Meta: U2FsdGVkX19thOesD0dmDWhkXQ67Js5Uw6GsAJm2SLiJ68vbH7IT99lIIB8jGqgynV1xlzvuFO5S0vbo0FZA1Co9cpUIk2PZiaHlZ7oN0N1P9rCEhCaxEn416tLR4PHJV75QBhbHISJoo6fm/gbFFsQ/HAGlQ2TMe3YY4WITo3DRY5Ub3uWOPBSMWOW9Eps63RF5uss+Pek9vJNOwS5O59cJ74CYmoPft4IK2Uxvr0o3OA2k1+Flr3mssRhKw+fj69bHQy4HNbpUrR7DiwBlTjxYI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01TZn/AlOOWoZ1KeZTtRHTy1eX1xbIGcX9SyRkdLzrj1cpeSa9euO9Z4psRMDBbwydg75W1ylDG6WVv 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: On Fri, Jan 31, 2025 at 5:21=E2=80=AFPM Hyeonggon Yoo <42.hyeyoo@gmail.com>= wrote: > > Change zswap_store_page() to return a boolean value, where true > indicates the page is successfully stored in zswap, and false otherwise. > > Since zswap_store_page() no longer returns the size of the entry, > remove 'bytes' variable from zswap_store(), and jump to the put_pool labe= l > when it fails. > > Move the objcg charging and the incrementing of zswap_store_pages > just after the tree store is successful. > At that point, there's no chance of failure, and the freeing path > will certainly uncharge zswap memory and decrement the counter. > > Suggested-by: Yosry Ahmed > Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > --- Uh, I was trying to send it in-reply-to this: https://lore.kernel.org/linux-mm/20250129100844.2935-1-42.hyeyoo@gmail.com Andrew, could you please fold it into the patch? No major functional difference, just adjusted Yosry's comments. > mm/zswap.c | 31 +++++++++++++++---------------- > 1 file changed, 15 insertions(+), 16 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index f0bd962bffd5..ac9d299e7d0c 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1445,9 +1445,9 @@ static void shrink_worker(struct work_struct *w) > * main API > **********************************/ > > -static ssize_t zswap_store_page(struct page *page, > - struct obj_cgroup *objcg, > - struct zswap_pool *pool) > +static bool zswap_store_page(struct page *page, > + struct obj_cgroup *objcg, > + struct zswap_pool *pool) > { > swp_entry_t page_swpentry =3D page_swap_entry(page); > struct zswap_entry *entry, *old; > @@ -1456,7 +1456,7 @@ static ssize_t zswap_store_page(struct page *page, > entry =3D zswap_entry_cache_alloc(GFP_KERNEL, page_to_nid(page)); > if (!entry) { > zswap_reject_kmemcache_fail++; > - return -EINVAL; > + return false; > } > > if (!zswap_compress(page, entry, pool)) > @@ -1483,13 +1483,17 @@ static ssize_t zswap_store_page(struct page *page= , > > /* > * The entry is successfully compressed and stored in the tree, t= here is > - * no further possibility of failure. Grab refs to the pool and o= bjcg. > - * These refs will be dropped by zswap_entry_free() when the entr= y is > - * removed from the tree. > + * no further possibility of failure. Grab refs to the pool and o= bjcg, > + * charge zswap memory, and increment zswap_stored_pages. > + * The opposite actions will be performed by zswap_entry_free() > + * when the entry is removed from the tree. > */ > zswap_pool_get(pool); > - if (objcg) > + if (objcg) { > obj_cgroup_get(objcg); > + obj_cgroup_charge_zswap(objcg, entry->length); > + } > + atomic_long_inc(&zswap_stored_pages); > > /* > * We finish initializing the entry while it's already in xarray. > @@ -1504,22 +1508,19 @@ static ssize_t zswap_store_page(struct page *page= , > entry->pool =3D pool; > entry->swpentry =3D page_swpentry; > entry->objcg =3D objcg; > - if (objcg) > - obj_cgroup_charge_zswap(objcg, entry->length); > entry->referenced =3D true; > if (entry->length) { > INIT_LIST_HEAD(&entry->lru); > zswap_lru_add(&zswap_list_lru, entry); > } > - atomic_long_inc(&zswap_stored_pages); > > - return entry->length; > + return true; > > store_failed: > zpool_free(pool->zpool, entry->handle); > compress_failed: > zswap_entry_cache_free(entry); > - return -EINVAL; > + return false; > } > > bool zswap_store(struct folio *folio) > @@ -1566,10 +1567,8 @@ bool zswap_store(struct folio *folio) > > for (index =3D 0; index < nr_pages; ++index) { > struct page *page =3D folio_page(folio, index); > - ssize_t bytes; > > - bytes =3D zswap_store_page(page, objcg, pool); > - if (bytes < 0) > + if (!zswap_store_page(page, objcg, pool)) > goto put_pool; > } > > -- > 2.47.1 >