Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2570271rdb; Wed, 15 Nov 2023 04:54:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0CiDKkzOd3N/xFX3KD7QIZuEenH1qJZmOOffd16hnWb0aZE2H0pW4Co6FzEHEDoj0S5nn X-Received: by 2002:a17:903:3296:b0:1cc:4fbe:9278 with SMTP id jh22-20020a170903329600b001cc4fbe9278mr4764192plb.50.1700052876288; Wed, 15 Nov 2023 04:54:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700052876; cv=none; d=google.com; s=arc-20160816; b=mhTOsclB6PozbDlJFQnxLdXE+vG3zL16rwUVBulO9Nub4axOdGtcwxHl7+GyCKptZb IVzBwl5QzvblzZwMgj6DacumoCZthubVIQT5bjD5kzK71duiYUsB87qQp2ZjH2p/+pDV elKv8r4LJNGlnMwCe6+22+8FVEzXclVw3+DdtwN033so4QFoiJT3wIbzVOKI8uCNdNzc IuNyZfymicWLnM6zh3ukAXIEZHM9NMLEBlISnywT+kv3wIJV5DS7Oa58NmN5Y8ea6FbB 4CxNq3nvSzHUxSebncy1FK7+ObltiIEU9i2y6L5Qq7y51asA8Xoh5DBSUulHs0bnFeaW bHug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MuyikNx6ChSG02AxULm8OQDXCsKtdigfSeQkNQXENcI=; fh=Z/slWphgmX6QJKb1htDfNZvLrT1b2fPU4vG8qFrGdBs=; b=Jtjk6gI5fIrBSrqVtMbbhk8lJYbbidn67ReViYLHCmu7hdw2Vi2uR983Tj8KeEnzij M5r77kDwzhS+bjgjulegXYX8VPI2bDk6b+9ZiQEygBK0FqXoBCNYM3YYWXB7hwifMBEn pO0Jl68tejbyWbzVMz2WMLCN5492o+Tsz7u+DaViJd4InLItTBsXW4BRnTKGo65Rtarn XEgyndxk5lVaHdUTvFZ2CnePCQGt/PNs0rnMLixix2Vps2OHXEX5uBdyjl9n34eQkAiG IgGDPeEHHOekAjyhCdGaB2LRKjQJWwIR+6WzNMwc8Kl5WJAbxGB3jL2QaP/7TxujKprf o9Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=dO167f3B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id jc11-20020a17090325cb00b001c589ba4a04si9683634plb.24.2023.11.15.04.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 04:54:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=dO167f3B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 028FF80242A0; Wed, 15 Nov 2023 04:54:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343821AbjKOMyW (ORCPT + 99 others); Wed, 15 Nov 2023 07:54:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343837AbjKOMyU (ORCPT ); Wed, 15 Nov 2023 07:54:20 -0500 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE39E130 for ; Wed, 15 Nov 2023 04:53:54 -0800 (PST) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2c594196344so87478021fa.3 for ; Wed, 15 Nov 2023 04:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1700052833; x=1700657633; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MuyikNx6ChSG02AxULm8OQDXCsKtdigfSeQkNQXENcI=; b=dO167f3B9fSrQBcST8qA+z2TRvLvQkL5SDaVJuj0+n2BufBUMQGK1qfhEj9YTj/7yG 2OG2iJx5EHoV9bS3Y/kFjZdochY/jZzleccanb9P7agjRvkdD9+FqfBrZ6ELtwDEmoQL 1jPiNXjdV+xBD30jzcAFTU5mUdVpOOGk4t7xPaR9LnQVRUBs2p8w8gwpmCzYVG7aaMzY CctxN5EpgAeK67CeWoOy5hZxyyxJ7Eu1MbfEGjSqBcPy+j84FCDpn5XdVCI1GbZwEEWW k/wpCaI2MCkptauPv8PLMBZyBUQrR4o+m/pg8VSHvUth3xJsdzDpJVZSlTJ7nQvxanu0 UqGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700052833; x=1700657633; h=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=MuyikNx6ChSG02AxULm8OQDXCsKtdigfSeQkNQXENcI=; b=cmfdL9s3cESy/A1ypDJ5nYysHJVmoZuyAdsuim11FGhVdIN/IBAADb2obTZnx38sE9 iHyqIGEJ3dL1UJm1kXaJw1KzonE1tm71YmYrZwjrJlBX1WrdbHaBM1guqta5Xia4/Moq jm/f2ikJO0T1pmmn0rJdqyAO4SJkrRMddoES7aVxILQd9qW6tUVnQ2Ij09LCL6M36THT FXN0vW9hU4vtuGrPQMjtg1ghQoDz70daNF7ftpmmDB1jBaU9BmNp5+2PZ3Sc3est6JlJ d+JXtWZ36424pVEaK6sS8hlHD2PB1kMRk40H6D8VpMvWFiR2DJQ4QfPBrwTqOWSNbtuu r9hw== X-Gm-Message-State: AOJu0YyJmE/a7U708qi7NTAeyxACAnfETTZXYmw+Rblv6EDf95l60PMm LfanXIcnAgr5jBFChJxcCDwkcpEUUGXjbkWkL8rPg53ih/0RH5BOibk= X-Received: by 2002:a2e:b607:0:b0:2c5:18ed:1802 with SMTP id r7-20020a2eb607000000b002c518ed1802mr4063420ljn.34.1700052833082; Wed, 15 Nov 2023 04:53:53 -0800 (PST) MIME-Version: 1.0 References: <20231113130601.3350915-1-hezhongkun.hzk@bytedance.com> In-Reply-To: From: =?UTF-8?B?6LS65Lit5Z2k?= Date: Wed, 15 Nov 2023 20:53:40 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm:zswap: fix zswap entry reclamation failure in two scenarios To: Yosry Ahmed Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, nphamcs@gmail.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ying Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 04:54:34 -0800 (PST) > For case (1), I think a cleaner solution would be to move the > zswap_invalidate() call from swap_range_free() (which is called after > the cached slots are freed) to __swap_entry_free_locked() if the usage > goes to 0. I actually think conceptually this makes not just for > zswap_invalidate(), but also for the arch call, memcg uncharging, etc. > Slots caching is a swapfile optimization that should be internal to > swapfile code. Once a swap entry is freed (i.e. swap count is 0 AND > not in the swap cache), all the hooks should be called (memcg, zswap, > arch, ..) as the swap entry is effectively freed. The fact that > swapfile code internally batches and caches slots should be > transparent to other parts of MM. I am not sure if the calls can just > be moved or if there are underlying assumptions in the implementation > that would be broken, but it feels like the right thing to do. Good idea, This is indeed a clear solution. I'll try it in another patch later. > > For case (2), I don't think zswap can just decide to free the entry. > > In that case, the page is in the swap cache pointing to a swp_entry > which has a corresponding zswap entry, and the page is clean because > it is already in swap/zswap, so we don't need to write it out again > unless it is redirtied. If zswap just drops the entry, and reclaim > tries to reclaim the page in the swap cache, it will drop the page > assuming that there is a copy in swap/zswap (because it is clean). Now > we lost all copies of the page. > > Am I missing something? > Ah, my bad. Missed the step of marking the page as dirty. Please have a look, just like zswap_exclusive_loads_enabled, set page dity so that it can be pageout again. if (!page_was_allocated) { if (!count) { set_page_dirty(page); ret = 0; } else ret = -EEXIST; put_page(page); } Thanks for your feedback, Yosry.