Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp34931lqe; Tue, 26 Mar 2024 19:25:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhGx3/hhtNsq4jArocmPhWK2pQLjLn7gK8Y4XdYcFELu8IjDxE4RAyWQQxuRCroXGfedOPIKFMazDS9P3KXT2UaXyn/QzskW5dkjA3+A== X-Google-Smtp-Source: AGHT+IG5JBOfNgSPMB9aINnoNF6MMniGi68qvPAb17/Y0iTnWRY9QH5XRqamhYaeX6ReliCJRTfF X-Received: by 2002:a25:3607:0:b0:dcd:1b8f:e6d3 with SMTP id d7-20020a253607000000b00dcd1b8fe6d3mr9901127yba.48.1711506351772; Tue, 26 Mar 2024 19:25:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711506351; cv=pass; d=google.com; s=arc-20160816; b=pJvcjTLQBPjHBWvMUb4PdkoMGRb7d++Yiurs03124jdpPogK+pxq2UOOr9202cir9+ 4ypONaZjWdYzI75UH4mmmoG8bTHNo6/63/w7pqF4n8XibJwryD7vyRh4Lr+TeE2uCjLK GM4yhoFmo6APJfsSA53O9aBVaNDpIYjOYhhHpT8RCiud2++v2q/UZY+s9PXTz+G3imeW 7VzE8M3qci86lKB2h/rrmQj5rQ6FGfaJb4o4cZY5jUDo0d/nwz33RAovEynqaV0hvDcV 88OX6bYgVGZetzx6qSYqi/J2g9C2MLv9YGrWdBymFmIh7tpYgmrGq/GOSMBw6XSRcnTu ge/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=toVz9Slq6rIwBWxbkYIDUn9vUvSsS1ey1uAF2j5dJmk=; fh=+6tuBzjp2pMpjT9dj+vXx1AyjiCreJh73RbziTYZDRw=; b=MSegke7usP7agc8xnUQC/mm+yU/fp7O+K9dve2HR/WXdqseCbFnzrPEUTC0C7E9Fs4 /V6mzfzjmGsT7Tm2JodqwSEbclGRzA9YtDbPpoEcDDkgb7KGc6xINnlKiltL8tZU5z38 sxzUAZ26oxOz0YoesEDzX0FPrPCKphzpSXjVu1ze1IXz0dvbyfiuYNUr+93H5vBcfGEh xaMiDcn2+jDahtiyf+2rG+dBJuX3bL/Z55W9cHMAlNxFoVknLOdP3Qcpd6WoQc958TEb 7P/ZJT3Sulc9A8HNFcTGQnpKW4osXzb/0IKmEXRLX6rJhV1+/AjVKPP16nc/Rd+x0Tau wp2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=B6ELc9Rf; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-120212-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c20-20020a63d514000000b005dc905460d6si11181796pgg.315.2024.03.26.19.25.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 19:25:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120212-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=B6ELc9Rf; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-120212-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D1EDFB21C32 for ; Wed, 27 Mar 2024 02:25:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 039E7208CB; Wed, 27 Mar 2024 02:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="B6ELc9Rf" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38C8D1D558 for ; Wed, 27 Mar 2024 02:25:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711506342; cv=none; b=h3VZF8nUva5VaBz3YDuHgLgmnOGYAjUOf9wyN5qwAZwn8DpBRt6liYOebNLI4obNTvbEByvL7nC5QwAelAwqrqczQOWzDdNg/OwMyAw1/NMqYBbGJDG/mQ47hioi89oWM9GNP2uyJIZOXdB3lQwbMYCCAOAtnr+gZZ+Lv3UPtxg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711506342; c=relaxed/simple; bh=W1pMnaJdpxIwGtfutYxyuW2Wco1yDNydnZPYws4jAvk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hqPNpQag9fE5wq0wc9pYXaxBxlFxMA/rF6Jk0NPXFiY2mxXVKLqKOBG13IDV1K6A/SXK/Ieiqd9bc864Obq6pR3+dd1nS+zSB3caqzZybkvCH3AZYZy4dx7x579y5O93H/79OgUm+hKFg9Q5oC8nuhTYnuaSVECRt3VSI7NvsI8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=B6ELc9Rf; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <5e394253-4f01-4172-998e-bbf3d82de6b9@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711506338; h=from:from: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; bh=toVz9Slq6rIwBWxbkYIDUn9vUvSsS1ey1uAF2j5dJmk=; b=B6ELc9RfvCchRRhzKH81eaisSD9A1eUgkJm7YGdpCuPmUBD6IpKVJNJ6ZXM9pmT5dQVWrJ n+kSomt7yclc3Gm7S9HOnf3KMyF0YfgitxJ6nsi9PK2gpc0fqdh+x/WC6Th9/a2mk3wpHy mxsKUvSIfuje7Qw7XBj9lOapPgNbzXk= Date: Wed, 27 Mar 2024 10:25:22 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC PATCH 2/9] mm: zswap: refactor storing to the tree out of zswap_store() Content-Language: en-US To: Yosry Ahmed , Andrew Morton Cc: Johannes Weiner , Nhat Pham , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240325235018.2028408-1-yosryahmed@google.com> <20240325235018.2028408-3-yosryahmed@google.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20240325235018.2028408-3-yosryahmed@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2024/3/26 07:50, Yosry Ahmed wrote: > Refactor the code that attempts storing to the xarray, handling erros, > and freeing stale entries into a helper. This will be reused in a > following patch to free other types of tree elements as well. > > Signed-off-by: Yosry Ahmed > --- > mm/zswap.c | 42 ++++++++++++++++++++++++++---------------- > 1 file changed, 26 insertions(+), 16 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 1cf3ab4b22e64..ff1975afb7e3d 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -827,6 +827,30 @@ static void zswap_entry_free(struct zswap_entry *entry) > atomic_dec(&zswap_stored_pages); > } > > +/********************************* > +* zswap tree functions > +**********************************/ > +static int zswap_tree_store(struct xarray *tree, pgoff_t offset, void *new) > +{ > + void *old; > + int err; > + > + old = xa_store(tree, offset, new, GFP_KERNEL); > + err = xa_is_err(old); Seems to use xa_err() to return errno, xa_is_err() just return a bool. > + if (err) { > + WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err); > + zswap_reject_alloc_fail++; > + } else if (old) { > + /* > + * We may have had an existing entry that became stale when > + * the folio was redirtied and now the new version is being > + * swapped out. Get rid of the old. > + */ > + zswap_entry_free(old); > + } > + return err; > +} > + > /********************************* > * compressed storage functions > **********************************/ > @@ -1396,10 +1420,10 @@ bool zswap_store(struct folio *folio) > swp_entry_t swp = folio->swap; > pgoff_t offset = swp_offset(swp); > struct xarray *tree = swap_zswap_tree(swp); > - struct zswap_entry *entry, *old; > struct obj_cgroup *objcg = NULL; > struct mem_cgroup *memcg = NULL; > unsigned long max_pages, cur_pages; > + struct zswap_entry *entry; > > VM_WARN_ON_ONCE(!folio_test_locked(folio)); > VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); > @@ -1485,22 +1509,8 @@ bool zswap_store(struct folio *folio) > entry->swpentry = swp; > entry->objcg = objcg; > > - old = xa_store(tree, offset, entry, GFP_KERNEL); > - if (xa_is_err(old)) { > - int err = xa_err(old); > - > - WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err); > - zswap_reject_alloc_fail++; > + if (zswap_tree_store(tree, offset, entry)) > goto store_failed; > - } > - > - /* > - * We may have had an existing entry that became stale when > - * the folio was redirtied and now the new version is being > - * swapped out. Get rid of the old. > - */ > - if (old) > - zswap_entry_free(old); > > if (objcg) { > obj_cgroup_charge_zswap(objcg, entry->length);