Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2443846rdb; Mon, 20 Nov 2023 10:53:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJs5ooTby6n7o3AbkXs+S6qPWp54cCKP//WBpQlndw1rTkYzfTSK0nIpqSukQKJcy+HBaG X-Received: by 2002:a17:902:a412:b0:1cc:4ff3:c837 with SMTP id p18-20020a170902a41200b001cc4ff3c837mr5691795plq.68.1700506414168; Mon, 20 Nov 2023 10:53:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700506414; cv=none; d=google.com; s=arc-20160816; b=Ky21uSLJdXI35WSzNtQgwmrivqA6Wi/EpMq3hu/VZ1YJfUlQH7QtT7eVkjZUIrmfnM LuEn92DPPRJfPBPZvNQYGDwlXCh2rZHvKgiRFw2EMLkfbRuGXlRiAJ0UDiNNLv3CN6q+ N3VVx1A9zQB+V2WtLBayiCTo1O5abm0evyg1QabzSymsl3OQ3t13lRlLDdGsT9+fPBw1 iZIk4XXrPGK/V0SsRCmHpL1prAgQKCfRypvgd9M50ofhiY2ai451gJbo2qN5nBCqIDWI sZT4SZLER1Gbk6mwQFxgyEaAdQ4ovQYmEoWVVgPaKD0L7oI1CLc6uzrZn97KJ6ISGZMu rsmQ== 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=9CBhC1m0OhsuzwJIA2sP5RLtq30X0JjG4f15SHsDupg=; fh=wvfcfNmB/0livP+I1tI8F1oO+6bhIix/c5rNjWy6LhY=; b=tlqnIq4nZs6ar6tacma3NZ+fJ5Xv2kUhlvZJOjIDFx6FEsenu/JmyMmINiRK4wFlHu JrimMMVU4ZVsO6TqdKD6Jnty6i/I2JVyusSx4J6/F5u4/2U5iK+b2VMvq4BVUeMF8bcg u92ISACdLoPqxq/SS0+A/b+yH3Z1BQ4Iufmjjz1aG3+h+8FDQKoi3m+sq9MhbeM1i1cZ H1XKQqk3Czbmj5keKgf+eC3UR78SL6T29p7nbuP3PYQfKBzW0QKoRJoLMw9MBPqAPRKf VCZTvISgLT1MLFHMN7bT47dzYq1U+MlidChsCDiFrIcgwbjwdW04wsN72VLsligm2IKq whIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1VYh8PRs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id f16-20020a170902ce9000b001cf6a1be230si764106plg.451.2023.11.20.10.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 10:53:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1VYh8PRs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 9FFBB80A90E7; Mon, 20 Nov 2023 10:53:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232297AbjKTSxM (ORCPT + 99 others); Mon, 20 Nov 2023 13:53:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbjKTSxL (ORCPT ); Mon, 20 Nov 2023 13:53:11 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 933F1C8 for ; Mon, 20 Nov 2023 10:53:07 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a00a9c6f1e9so83964266b.3 for ; Mon, 20 Nov 2023 10:53:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700506386; x=1701111186; 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=9CBhC1m0OhsuzwJIA2sP5RLtq30X0JjG4f15SHsDupg=; b=1VYh8PRsnpa+tRsrWdJOj0O9M5QlZEdSm0fA9bAJUQi8zXYJdebGSyayU8GyNH6yFW NXqMCf30ok6wmRjTFPApaT0B2FkVBzbMC6qUv1hwt6eojcDtRyf0Sc6pff522wwTHK+M dYMJ8x9u3JK2b2X3ZiJABPrBMaXLrK8s0uxv+0c6IEIcQ1mfslWkaQBhvYG9J5Xw8Nm7 QZSPTIZvyQxJ1uhi4RhVORycUKZPyftskEoxVP7I+SAUTU1qdBIxpzqVFsqiqiywI5gy GWsYFLkNiZhu+vBSVcOxQyBltcHLtaVPjODkUaDUp/OQxWiWkmN3FLR4n1gqEciLA3r1 Rr4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700506386; x=1701111186; 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=9CBhC1m0OhsuzwJIA2sP5RLtq30X0JjG4f15SHsDupg=; b=xGEKC8SXLGksAkl650eICcax4G9VbpbuT7JXyDFK1p+bR5DxjFsW/drJML33CneKKf hERtqtIKh15szspL+1ODKZdhWzm6LBV5Cfze+Q/WF6wuZufSoJqE7N+RGLJDcBX2Yur+ j7K8sPhtNqk4gyofGUpuQV2BnXOS5aQ3PSExnACBKe58Ci66ghMaIQUqDsz+bHKnQPHA 2tODBkuGcmn0OgFlmuDn3OlPa6br5b3e+bpdfz7DFb0AR+ek01FwZIovWc0sX8EOhz/x DhBlvaU6JjbkS+n2gHw0VIBKW+YU8DJDke8e+I/vvZsIuUBQeQvSqtWdbSaNkaAlxeLe zdMg== X-Gm-Message-State: AOJu0Ywc5oCciXdznxckjV1uStQT62dlTXtcHroAUqSuQwu/AZK/BLNj Ru1iQ3tOgYOye3zudIDW6BCiowrfgWYnzjPJlsu84gjf8leLr+l/pnPC7FaV X-Received: by 2002:a17:906:52c1:b0:9dd:d85e:b23f with SMTP id w1-20020a17090652c100b009ddd85eb23fmr5763192ejn.67.1700506385805; Mon, 20 Nov 2023 10:53:05 -0800 (PST) MIME-Version: 1.0 References: <20231113130601.3350915-1-hezhongkun.hzk@bytedance.com> <8734x1cdtr.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <8734x1cdtr.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Yosry Ahmed Date: Mon, 20 Nov 2023 10:52:25 -0800 Message-ID: Subject: Re: [PATCH] mm:zswap: fix zswap entry reclamation failure in two scenarios To: "Huang, Ying" Cc: Chris Li , Zhongkun He , Andrew Morton , Johannes Weiner , Nhat Pham , Seth Jennings , Dan Streetman , Vitaly Wool , linux-mm , LKML 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,T_SCC_BODY_TEXT_LINE, 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 10:53:22 -0800 (PST) On Sun, Nov 19, 2023 at 7:20=E2=80=AFPM Huang, Ying = wrote: > > Chris Li writes: > > > On Thu, Nov 16, 2023 at 12:19=E2=80=AFPM Yosry Ahmed wrote: > >> > >> Not bypassing the swap slot cache, just make the callbacks to > >> invalidate the zswap entry, do memg uncharging, etc when the slot is > >> no longer used and is entering the swap slot cache (i.e. when > >> free_swap_slot() is called), instead of when draining the swap slot > >> cache (i.e. when swap_range_free() is called). For all parts of MM > >> outside of swap, the swap entry is freed when free_swap_slot() is > >> called. We don't free it immediately because of caching, but this > >> should be transparent to other parts of MM (e.g. zswap, memcg, etc). > > > > That will cancel the batching effect on the swap slot free, making the > > common case for swapping faults take longer to complete, righ? > > If I recall correctly, the uncharge is the expensive part of the swap > > slot free operation. > > I just want to figure out what we are trading off against. This is not > > one side wins all situations. > > Per my understanding, we don't batch memcg uncharging in > swap_entry_free() now. Although it's possible and may improve > performance. Yes. It actually causes a long tail in swapin fault latency as Chris discovered in our prod. I am wondering if doing the memcg uncharging outside the slots cache will actually amortize the cost instead. Regardless of memcg charging, which is more complicated, I think we should at least move the call to zswap_invalidate() before the slots cache. I would prefer that we move everything non-swapfile specific outside the slots cache layer (zswap_invalidate(), arch_swap_invalidate_page(), clear_shadow_from_swap_cache(), mem_cgroup_uncharge_swap(), ..). However, if some of those are controversial, we can move some of them for now. When draining free swap slots from the cache, swap_range_free() is called with nr_entries =3D=3D 1 anyway, so I can't see how any batching is going on. If anything it should help amortize the cost. > > -- > Best Regards, > Huang, Ying