Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3560226rdh; Thu, 28 Sep 2023 15:58:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHspIMu5sxL7ErrE9V4lJNqvcxQYO2car49T137cNm/pXtzAQSLaE7aPbHBBhQlE+fFN6Xa X-Received: by 2002:a17:902:ea0a:b0:1c5:634e:e12c with SMTP id s10-20020a170902ea0a00b001c5634ee12cmr2790700plg.37.1695941885737; Thu, 28 Sep 2023 15:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695941885; cv=none; d=google.com; s=arc-20160816; b=ooBoRSuTd5hLTTDOAzENqDQDEKEJ1cgU10Mq/TxLJMbSv6riDW8B4GvQwvhZgOolnE iy8nVjFYSX5hWiZrWhG99MjxJD1MRiaxvxJIOAypaR/ThI7/HrRFP8Hg5or5CL8E9War F8t2qyYSJzWX0jspIKHtr+cWjkCqlfX93r9HKt89ys/JPU9zrcr/2P9I+HNC2r7QEj/p Rj6teT4QhzaIbb4Q3cW4+k75e3dvBT8VJCNZDUtUzjUBW8/E16bAYBAXNVp4FayKu8Ph owhTd5D2AFb608ytLdIR2Z6nCrco69c2RGaVTKFX+E1NbvNA7rLUSVrcLSBPk05Ad4pz qqOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vdc/ydgmgNMsNbxoUCD1oiRqxp/qtZNwRhbMfUlTHN4=; fh=qamb2QH60dp6VEo3pCbdIXk7jsG+PcK07nx1WqBycxk=; b=X5t0Ybzd8h650kgLJe48GS88Jh1JX4MXPmFFuKdJ/F86fPRmKj4TeeH8uO8apoW5wF KoJ2wFqsl3OKUKEFN2e3OKiGGQz2fsryi1Rlcfru6Mt5dJK3XRqstMTVkKy3CGhP5hFt I/pqqRAgpyn3srmWg/5BtjruIQksurRoiYUgyriETv+tekJx1FTrMgIL25sBYOS/+Vvs gBhywmliwhrpvU01RiFu0jNzzY1pPJ6Eo1ncXurINcmqtpS7yCT5njSCNx8auUo+H8Vj x1IHB2lbjUm7B/mP6MsWW/bDuU8A4LH6G23CgGS6PyyAtuD0J8/defOg8pbBQ6G4NfaS gsvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fqq3HNnw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id j6-20020a170903024600b001bb0ff2b354si21222059plh.425.2023.09.28.15.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 15:58:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fqq3HNnw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 451FA80481BA; Wed, 27 Sep 2023 13:58:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbjI0U6A (ORCPT + 99 others); Wed, 27 Sep 2023 16:58:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjI0U57 (ORCPT ); Wed, 27 Sep 2023 16:57:59 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FFEE121 for ; Wed, 27 Sep 2023 13:57:57 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9b2b53e17feso263794666b.3 for ; Wed, 27 Sep 2023 13:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695848276; x=1696453076; darn=vger.kernel.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=vdc/ydgmgNMsNbxoUCD1oiRqxp/qtZNwRhbMfUlTHN4=; b=fqq3HNnwuzMATEopc63sstUn0Qc5YGE0qSuQB825KGT7fWnOaEicczs7piYF2mANvd KHtooO1Pqt8kMpjy4PN1us6/RWBqhy1rqYCItsdycaMfnTKMQdyfRddFQcSOr5U2EvVD VT8oALeMTUGVGdiuIPR/uM3heC30t+I/LyxiNgfFwbzxUqQT6ogXeKxd4qOOZoJ7wQA2 nobh3wZl70JsdUurdMeYmx1ox4AzaQlO4NmjB0b9rNYI++BAexoLBQowaCiIqsmjiaYu qUHqTUWNM0uufc2o+rFmHYE32445/kd7dh+DQdskibjweRrnSHrAr2Cy3N/l9sNzsFLh baWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695848276; x=1696453076; 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=vdc/ydgmgNMsNbxoUCD1oiRqxp/qtZNwRhbMfUlTHN4=; b=sWEqESv3G2KXsgaNbxawKOWH9ii7BGriGI9T82v+rr3t6rAZZlo7/Bt/eYH7w8jJ4E zgDZaYDYILVfwyHJRdpKoh5ESw21tr+HY3H0lx873gGi9vFLC4UYNAiiVeeEmxum218W fMm9PcPHlGh3Rro3Ws/A1p6aC6yMMm2VPaGvUaUHFecdKWCvInv9BgDOVHjGzVaE5Tgo sEceBOAYlVJRGCA7E4SKhUWoxuow5QqEeaAziTCkD+IBshmjLDnlB0L+A54yYHTKLDcq V+H5s+Z0pPBf5zK7eVHe9PY7F4DUHfRdGGfG9sHFnVxCV0eHyKcumF1Hj7s8G3gieu+f UHJQ== X-Gm-Message-State: AOJu0YymjS9lPjoXrGD0BAB7UUCAZM76vv4nXIpCpt2H6b8OETf9ddPk o8UJdtoUDw6HLigxTY4JJZ4pHXdAQVLKoC0OCT7aFg== X-Received: by 2002:a17:906:cc57:b0:99c:6825:ca06 with SMTP id mm23-20020a170906cc5700b0099c6825ca06mr2473711ejb.12.1695848275848; Wed, 27 Sep 2023 13:57:55 -0700 (PDT) MIME-Version: 1.0 References: <20230919171447.2712746-1-nphamcs@gmail.com> <20230919171447.2712746-2-nphamcs@gmail.com> <20230927205153.GB399644@cmpxchg.org> In-Reply-To: <20230927205153.GB399644@cmpxchg.org> From: Yosry Ahmed Date: Wed, 27 Sep 2023 13:57:17 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] zswap: make shrinking memcg-aware To: Johannes Weiner Cc: Nhat Pham , akpm@linux-foundation.org, cerasuolodomenico@gmail.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Chris Li Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 13:58:07 -0700 (PDT) On Wed, Sep 27, 2023 at 1:51=E2=80=AFPM Johannes Weiner wrote: > > On Mon, Sep 25, 2023 at 01:17:04PM -0700, Yosry Ahmed wrote: > > On Tue, Sep 19, 2023 at 10:14=E2=80=AFAM Nhat Pham = wrote: > > > + is_empty =3D false; > > > + } > > > + zswap_pool_put(pool); > > > + > > > + if (is_empty) > > > + return -EINVAL; > > > + if (shrunk) > > > + return 0; > > > + return -EAGAIN; > > > } > > > > > > static void shrink_worker(struct work_struct *w) > > > { > > > struct zswap_pool *pool =3D container_of(w, typeof(*pool), > > > shrink_work); > > > - int ret, failures =3D 0; > > > + int ret, failures =3D 0, memcg_selection_failures =3D 0; > > > > > > + /* global reclaim will select cgroup in a round-robin fashion= . */ > > > do { > > > - ret =3D zswap_reclaim_entry(pool); > > > + /* previous next_shrink has become a zombie - restart= from the top */ > > > > Do we skip zombies because all zswap entries are reparented with the ob= jcg? > > > > If yes, why do we restart from the top instead of just skipping them? > > memcgs after a zombie will not be reachable now IIUC. > > > > Also, why explicitly check for zombies instead of having > > shrink_memcg() just skip memcgs with no zswap entries? The logic is > > slightly complicated. > > I think this might actually be a leftover from the initial plan to do > partial walks without holding on to a reference to the last scanned > css. Similar to mem_cgroup_iter() does with the reclaim cookie - if a > dead cgroup is encountered and we lose the tree position, restart. > > But now the code actually holds a reference, so I agree the zombie > thing should just be removed. It might be nice to keep in shrink_memcg() as an optimization and for fairness. IIUC, if a memcg is zombified the list_lrus will be reparented, so we will scan the parent's list_lrus again, which can be unfair to that parent. It can also slow things down if we have a large number of zombies, as their number is virtually unbounded.