Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp545190lqp; Tue, 11 Jun 2024 11:47:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrmueAAvfEf6XRdkjM2sPe61I4HGgpBUPyruzxZjApRrTQmeTGEDD7SFVq2n4j+1CYStM5tknJoUL9+njffylJvCyoZ1+S2A0uOcEBBA== X-Google-Smtp-Source: AGHT+IHa2wfS3oowtT7sdC9kGbXh0zPNLRznCSkR4+HM2RxyZ+PixI+COLsSjGKhL4w3/Vi8+PK5 X-Received: by 2002:a25:a168:0:b0:dfb:128d:79e5 with SMTP id 3f1490d57ef6-dfb128d7bdfmr9001475276.13.1718131665874; Tue, 11 Jun 2024 11:47:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718131665; cv=pass; d=google.com; s=arc-20160816; b=qMIUTdV57UXXxQGeCvlbkJWoVbQ3ckAqSe/vFLqzFg5BH/iU+rpAqBit8AtiDQWuWq CB50t/+D7Ch9xCYrvPkVV5ECKpsAe4pnmXqB4KwC6Dk67XqxCrYfXmLRCY5ipQCumUIH rLgsxOhuj0Kam/TKfHYusMEPltzzmDguMeXyHQc0ytR/YWzIqwT3Sx7rO3Q5GMOqosuP wcyZmNHA4gK+LS/YsBXUaLvnVwBrTecZEymeK8NlNuWWzC1/dfKz3XDn+nhbLUF2tg6J 3Vi+pX75J+9XZGURLO2C6e8MJzwEOCr7KpK1D8qbzilwNj1o3iyMAIHKX6CZZhI3nXxc YB2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=JNeYgHGOcCIEUgcCulHv8MogYMF1pawsllmpPlBDkvY=; fh=iT37L1W4NpPZ9A9nlrU4NviTBXEjvtpaCKXMcW1Jel8=; b=Z0cUX37lj1RdUzQwmxjg0sIDXsVvqIMFeYx7RS5RP5OVBvZQvsh+LD+D4R9LNqF2dD qpSO3PfE6Dr4n3oE+i1jq4xwxfKmLkuPscexBS0savflsURSivJ5HxR+ikvPMTWp8HC5 R083yCgjehudbpE6C5QHHk3GAkGPEeF9sm315LItf/XfoS5VD87/sf4UuVE6pHf7NLdc o4D7EOemYpBl5Q64cDZAVCWbAYScepO4TwzlsraQODpvQd2rDmcqGU9rzA+wzEIhasU3 M2/K09BUzEhK/ylDm17ZA5eEGGPvjMZGWDiiTIWfY9LGa89nX6qZvDoY/j/XixuGYwT7 4EcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ewdcFDLv; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-210461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-44120f92f36si33985111cf.808.2024.06.11.11.47.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 11:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ewdcFDLv; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-210461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 85C691C2410F for ; Tue, 11 Jun 2024 18:47:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D18196D1D7; Tue, 11 Jun 2024 18:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ewdcFDLv" Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E55340856 for ; Tue, 11 Jun 2024 18:47:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718131659; cv=none; b=DpuXvEWW0WfpW9bCmxgPsXLjg3W31bVCApbJnW0AKH4IKUGDvYTIR3qnw9eGq8BCY5hPoDKsqJbLPbVtUconNMR+0xlxF/WDxing1oLSJ4MqHqOR6hSMacrrcwPNrTYBr58W0RRk4DgoAEwz32m6rzc4/zUB2aXHk/QhD3OycJg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718131659; c=relaxed/simple; bh=CuJAwLG9LD8w9aYyFBwyEggR06cYlNMKlS01h950GC0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=aVDEmftKe4DIA5HGx7cXBhZPVWoA9fs6ncuA5gGrFVNrKuQPrKspkzYmvpeZ7PkW+0t0upgNMGObbjTmf0mt9VVxmMCFjoVoDThFUfEf/r0vrnLZzgldoUsBVbI0aQuAaj1AASk+64MddFnX9jWznLeyW6XrlqaJU3NUstL8lSc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ewdcFDLv; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a6f13dddf7eso371460666b.0 for ; Tue, 11 Jun 2024 11:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718131656; x=1718736456; 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=JNeYgHGOcCIEUgcCulHv8MogYMF1pawsllmpPlBDkvY=; b=ewdcFDLv38Ii9fsRVigY5jYc3LoHzchxhuPUuyyWBpA4M4Vb6jXW2WwMZ7ACgdwNom 0Gvsagc5Rg6k2ovzBTCiO7+vYj1bF27mabH/rW8vH+RZwtCMJVa7hp7wu/T9AZG026QR TtZm1Bd/4Hn/0a6yxULMiFnMAGuNhrGCcoKWrV4NC+JSXXZQZ3ngjo8BAGkCKAuYgjTF +KZXWWR4RhMN/VlEKvdoRyd+Nf2dRroPJUTYkiqwBGAkYqgArUAHBQeaDyBlYN2VOGWs 9oeKSjoysjUBN1cm1xtiqph3ASR+DL3JBMYAwpgF+fYqdXx+Dx4kVZ39Fsu6FO1GiAVT CQcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718131656; x=1718736456; 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=JNeYgHGOcCIEUgcCulHv8MogYMF1pawsllmpPlBDkvY=; b=s4B9eN1FeSsRPhCuJQL31VuzR8iheSBaBgLhyXw82QGkxzuOHIWoUHZ+hyXpE6LLKi ATb7YDrB0KDAMJX+pi0Z140SDeTLy6v0pjuDiabmV9D1mm7Vj2muUjDaULZ+LdqEV9// Zs22lE8flDW77P90TpTB/pOYJe8vAuNUafvgHhjI7AdVag66wRJ5OXJn+21NYtqcZQtO HcI3eludd7Bnwyi/PM85hGrDmolqyiV0ZJW4kiUl2OZ2Nw0CY7FRSk//RsO3RxE1anSO GjbR3JxnNbycCwZDQ8kQ3P7AIDo1+u31YJcTzT1C3FxJEphxr20mCRQLInRozerQWH8/ iz+w== X-Forwarded-Encrypted: i=1; AJvYcCVrNiQmke/obFfcZPHy580TOkB5MGeAr+1IdtSfAp8Xl20JPowPKYZmOJR8meavM9F6BSj2L2Cev/1SLMdd5f/rDRRdDQZ2pPEB7GBj X-Gm-Message-State: AOJu0YxfHhrvkDJRlXnVfdeGILvUF86spxSuiReqzKiTNHyNL6iRcz2s y7z922VKH/KHInB+k7MrzURR2yey/IUNmetgPXs4FFcnWGAGmf1zQq3EV5zCCuudp2zxmaxkhev +yfZeubDU8IyagQg+ystCb7hVJgraj8d4EMrH X-Received: by 2002:a17:906:a082:b0:a59:dd90:baeb with SMTP id a640c23a62f3a-a6cdb6d16demr818238766b.48.1718131655412; Tue, 11 Jun 2024 11:47:35 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240610121820.328876-1-usamaarif642@gmail.com> <20240610121820.328876-2-usamaarif642@gmail.com> In-Reply-To: From: Yosry Ahmed Date: Tue, 11 Jun 2024 11:46:56 -0700 Message-ID: Subject: Re: [PATCH v3 1/2] mm: store zero pages to be swapped out in a bitmap To: Nhat Pham Cc: Usama Arif , akpm@linux-foundation.org, hannes@cmpxchg.org, david@redhat.com, ying.huang@intel.com, hughd@google.com, willy@infradead.org, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" [..] > > @@ -1336,6 +1347,7 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry) > > count = p->swap_map[offset]; > > VM_BUG_ON(count != SWAP_HAS_CACHE); > > p->swap_map[offset] = 0; > > + clear_bit(offset, p->zeromap); > > Hmm so clear_bit() is done at the swap_entry_free() point. I wonder if > we can have a problem, where: > > 1. The swap entry has its zeromap bit set, and is freed to the swap > slot cache (free_swap_slot() in mm/swap_slots.c). For instance, it is > reclaimed from the swap cache, and all the processes referring to it > are terminated, which decrements the swap count to 0 (swap_free() -> > __swap_entry_free() -> free_swap_slots()) > > 2. The swap slot is then re-used in swap space allocation > (add_to_swap()) - its zeromap bit is never cleared. I do not think this can happen before swap_entry_free() is called. Note that when a swap entry is freed to the swap slot cache in free_swap_slot(), it is added to cache->slots_ret, not cache->slots. The former are swap entries cached to be later freed using swap_entry_free(). > > 3. swap_writepage() writes that non-zero page to swap > > 4. swap_read_folio() checks the bitmap, sees that the zeromap bit for > the entry is set, so populates a zero page for it. > > zswap in the past has to carefully invalidate these leftover entries > quite carefully. Chengming then move the invalidation point to > free_swap_slot(), massively simplifying the logic. I think the main benefit of moving the invalidation point was avoiding leaving the compressed page in zswap until swap_entry_free() is called, which will happen only when the swap slot caches are drained. > > I wonder if we need to do the same here?