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 B78BFCF9C6B for ; Tue, 24 Sep 2024 19:15:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BE486B00AB; Tue, 24 Sep 2024 15:15:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06EFA6B00AC; Tue, 24 Sep 2024 15:15:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9F0B6B00AD; Tue, 24 Sep 2024 15:15:39 -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 CC3AD6B00AB for ; Tue, 24 Sep 2024 15:15:39 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7789C4036E for ; Tue, 24 Sep 2024 19:15:39 +0000 (UTC) X-FDA: 82600585998.07.18BED6A Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf12.hostedemail.com (Postfix) with ESMTP id 9F3E240005 for ; Tue, 24 Sep 2024 19:15:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Ar3TMKIC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727205240; a=rsa-sha256; cv=none; b=u7eC+8uo+ZlhNxV8+bAp++6lEV8t9THgCX/JG0uCByoUT9co4j0IlClz1hsNA6kN02IS9z FZMIuBDF0NiMDIChz3kfVBW+i+EbyzMrFXscYlSSuF05xXQoN1k6Vi2wh9AEzryK4jJi8d doYkyhHZm4QS6nlxBDTrCgxa3CPbShk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Ar3TMKIC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727205240; 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=ohErbOrqDbKeoqxTroGQO2Ip0GopqiDtJKn6+41MyK4=; b=tLthjQVirQbO/osKaYeQu/HPr2ZjhUmR1goV4NIVN3P0E1HjAqCK6zQ4CjtuwEQHX1ZHyK 3hDzrBgjt8C4kxi8PZ5+xKqUlxagLvlLNfEJl5RIv1+YLWfYRimwPSBK2ojGnvE3rGwlko hpQ0PfhaLd2OvLzD0eFU1/WHOkqPFag= Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a8d6d0fe021so972529766b.1 for ; Tue, 24 Sep 2024 12:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727205336; x=1727810136; 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=ohErbOrqDbKeoqxTroGQO2Ip0GopqiDtJKn6+41MyK4=; b=Ar3TMKIC54QmQB8g11g+EPEaB74c6s48VFFc/gBGZf/IBQ3BiStRrDwwoXOdI2o1mF K8x2cEkHXnYmv7lPeisYfwMlETg3KTZbGqCGSsNDk7mF55AoqRKAmat1gUkKCtIgICRc yt5SKRzVcZ0OMsN5Q0hy+CweYoEyxu+hRKxYFgRC4maPwxqudCkjsVFhOqBiadBt+2aX KFOWFsQhFNZ2s4OCAM8vbyhUmWFs5t+9PyRyCVff8rtUzXTUCzFS747MPMJ10WEN5AVI FIqgpPinEOiTn/kv3OUA3zpgX0hiSrcxhmQwAtKgBKVvLtqzjzLFtp1JVydkbg640QvH k3Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727205336; x=1727810136; 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=ohErbOrqDbKeoqxTroGQO2Ip0GopqiDtJKn6+41MyK4=; b=cvBh9iIx9otK4QNxV2YlxjMzLL2L5lvNuCiq88StxDoq7BOooVn350qja6LpIFFosU z+bTeBRWOBgYr5BRZf5L+DykKxzAqNdmcv7GNeLpTsanF7p1nzenecRnaddGXAiE5Cwq WOuulAFyVFi5eXGUZKBp+WI8FNu4Kb/xNAbMXSN2rNqG6SAfuQ6lE/oFchiT0BmoEhVM RrmMKRk9/wn41ajemZkpZPhZikveCdblKRHIO8kVN7C6XX3F9Czh27yWa1dyHT3S1h5k +5eAy3aQ8JsVuJIlRz5+0sKabFI+VrOgisnhMgP8BiDvC9hwYq5ma4fsSRLkr/Jx8mC6 ZbQg== X-Forwarded-Encrypted: i=1; AJvYcCXH0k02jtlLA7nrgU0XpeGzD/Wv6W63xok+tW3LnWvnw79UXO55WMqrCcF451M+r0qhh1tWeQl25g==@kvack.org X-Gm-Message-State: AOJu0YzrUB7WvrPZh9aNY7E7Vr/i62aFeHMRBGT8LZH490qWXPxTn6fV YcbiM2Gii/0op2tfkPyl0NDocB+rZ3kJQJ46Dc432gD11HlmJ5HJzsKeZyzcrl6Nn544gC48w8O fzuJbFWvd9oVYReLMuF1EByNa5wD/j56ehDM/ X-Google-Smtp-Source: AGHT+IEwnxpMOsvFRpmsVDRwussKueirUorwya1m0dfAD6zodQXaWMM3Fg6VJTN1aIfBg5r4BWVDhLEJjP9duglTWo8= X-Received: by 2002:a17:907:e262:b0:a8d:55ce:fb97 with SMTP id a640c23a62f3a-a93a03269e7mr31142466b.11.1727205335714; Tue, 24 Sep 2024 12:15:35 -0700 (PDT) MIME-Version: 1.0 References: <20240924011709.7037-1-kanchana.p.sridhar@intel.com> <20240924011709.7037-4-kanchana.p.sridhar@intel.com> In-Reply-To: <20240924011709.7037-4-kanchana.p.sridhar@intel.com> From: Yosry Ahmed Date: Tue, 24 Sep 2024 12:14:59 -0700 Message-ID: Subject: Re: [PATCH v7 3/8] mm: zswap: Refactor code to store an entry in zswap xarray. To: Kanchana P Sridhar Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, shakeel.butt@linux.dev, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org, nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9F3E240005 X-Stat-Signature: odthijujjqaqjafuyt3athc7h7xnr6my X-Rspam-User: X-HE-Tag: 1727205337-113114 X-HE-Meta: U2FsdGVkX18MTl3MUSO+PWUR/KCj8pHlUSLj4IAn9eKfs4zkznORExfNjy14B6C0pr7TuTbg9LmitjOaIX+7CWq0s+/s1Zt9DZ92CoMgAaZqfBk0ANHM6vbTgBti+7GqAbCe0PhXZxvEBRvDe/yC5EgZ9cZnPH2MiEcp76t5jKt4Zv0y6Ox+RAaq+4Nvn8YB87La/QXnCeO3+U8UYSHSeabi9WP7M2+Fn29qnOeUNS2kYfXpkKHtkOA+hEZYSlUffkfalAf/CKfyQZaUkBh3Ubp2OjnU2GNs3Cb9psbSeEZiBWddEd9AfEGZWCGblg9jgFR5kpTKaXSt6zzA087vpXGWsAb5oFPFaleizM4sfVWTn4QXfkQOBPNdt7H324Qf7/Gmr9t5DFtGTLuFQNBMQYSISSEsdBSoxLnnJGMO63PQ6Kf533TKwQ7dtb+c2ASqO9C4Cq9XfYGSL3gBZt1o3bJNRoRiKCqoLSbtDYwO+ObIVPmEsKl1/Z3m0zC4P5GypZX4qniDnzHTC/cKoAMoDBZR7ve9iHUn9FG+PD2ylNxPsMTnn3tuiGl3w4B4qM3ZG1CrLkUO1eplI4kNcJKrk/iTMnqbUOGkfsyg5M/nPVYoSOCSrl6pOSD9uGe+rczEn1EDFQbI/x52gmcOtXQFrl67ibOroy4V+mb7G5S7cJrZE0cXbkl4UihFwBxA/U2tm8rEt8/bsDQkak4mFrutzH2UbGquApqGE5MpdQBbAICSBClb9P8He4yXAq/XqdByu98KXjaZnt5fqd79U1ZF0ntV5KXOiMFVFv9qRPdrKQgK9TzGzOHhRD11DA3bVJfFjooKsNcNlThIcHEXkQoADNOqfANBRRwYwx2IXkAjW0AO0rtT2FD8LZssczjFUadKxeVXAofkdrNY0Y9GBkStbqQQSZqTnnFd6/x1RCU0seZtkHizfaTcJkY0Ns8BsSDCTGkhv/6X5pO2gVd3zyW teXz//qG 54iRYXA2Nzicy8mWPJEkOeiSYBU5GYd6N/+sXrFBSQGCuFNfSZjPOa7hbJW50afsd9Ny1qsoeS+EQ9G8OdXuaqgG2CK/+/pHy7JK+RmaXG2IVlThFNzIWFAfUBcxYsRrx2RkmDN+XmS5KOznf7aQjISrZdKkqTUuSlKqcM4BFAnRA7fgU3P2CNk5SFegqxcRUTX2HARwtGRoTYziVUALrCRmqWBtJoN/evkHJ 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 Mon, Sep 23, 2024 at 6:17=E2=80=AFPM Kanchana P Sridhar wrote: > > Added a new procedure zswap_store_entry() that refactors the code > currently in zswap_store() to store an entry in the zswap xarray. > This will allow us to call this procedure for each storing the swap > offset of each page in an mTHP in the xarray, as part of zswap_store() > supporting mTHP. > > Also, made a minor edit in the comments for 'struct zswap_entry' to delet= e > the description of the 'value' member that was deleted in commit > 20a5532ffa53d6ecf41ded920a7b0ff9c65a7dcf ("mm: remove code to handle > same filled pages"). > > Signed-off-by: Kanchana P Sridhar > --- > mm/zswap.c | 51 ++++++++++++++++++++++++++++++++++----------------- > 1 file changed, 34 insertions(+), 17 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 59b7733a62d3..fd35a81b6e36 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -190,7 +190,6 @@ static struct shrinker *zswap_shrinker; > * section for context. > * pool - the zswap_pool the entry's data is in > * handle - zpool allocation handle that stores the compressed page data > - * value - value of the same-value filled pages which have same content > * objcg - the obj_cgroup that the compressed memory is charged to > * lru - handle to the pool's lru used to evict pages. > */ > @@ -1404,12 +1403,44 @@ static void shrink_worker(struct work_struct *w) > /********************************* > * main API > **********************************/ > + > +/* > + * Returns true if the entry was successfully > + * stored in the xarray, and false otherwise. > + */ > +static bool zswap_store_entry(struct xarray *tree, > + struct zswap_entry *entry) I think zswap_tree_store() is a more descriptive name. > > +{ > + struct zswap_entry *old; > + pgoff_t offset =3D swp_offset(entry->swpentry); Reverse xmas tree where possible please (longest to shortest declarations). > > + > + old =3D xa_store(tree, offset, entry, GFP_KERNEL); > + No need for the blank line here. > + if (xa_is_err(old)) { > + int err =3D xa_err(old); > + > + WARN_ONCE(err !=3D -ENOMEM, "unexpected xarray error: %d\= n", err); > + zswap_reject_alloc_fail++; > + return false; > + } > + > + /* > + * 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); > + > + return true; > +} > + > bool zswap_store(struct folio *folio) > { > swp_entry_t swp =3D folio->swap; > pgoff_t offset =3D swp_offset(swp); > struct xarray *tree =3D swap_zswap_tree(swp); > - struct zswap_entry *entry, *old; > + struct zswap_entry *entry; > struct obj_cgroup *objcg =3D NULL; > struct mem_cgroup *memcg =3D NULL; > > @@ -1465,22 +1496,8 @@ bool zswap_store(struct folio *folio) > entry->objcg =3D objcg; > entry->referenced =3D true; > > - old =3D xa_store(tree, offset, entry, GFP_KERNEL); > - if (xa_is_err(old)) { > - int err =3D xa_err(old); > - > - WARN_ONCE(err !=3D -ENOMEM, "unexpected xarray error: %d\= n", err); > - zswap_reject_alloc_fail++; > + if (!zswap_store_entry(tree, 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); > -- > 2.27.0 >