Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp41653lqh; Thu, 30 May 2024 13:21:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXUa065NIa8a9uaPO+8NSBT8z9/7DTSCQUBNOj4MA4uiaWZaIVmh//pqQgTjL1yBOkDNdmOBYjPE/r++uqAYbun8JTrKmEHMtyN01H/eg== X-Google-Smtp-Source: AGHT+IE1AUU6jH75JOAvTGzDfLr4sX2b1dYro511aDKwNbxdq0KkVgSYLzwWpR9KT8x0cqt/m59i X-Received: by 2002:ac8:7d43:0:b0:43a:4ad9:51e5 with SMTP id d75a77b69052e-43ff35ecf82mr621921cf.5.1717100490162; Thu, 30 May 2024 13:21:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717100490; cv=pass; d=google.com; s=arc-20160816; b=VSv64Yb1jXq+pV95umlsHTS7aLieSXkAjUVlLGEccnVdmTSFR0IVpHaHXiOBnE/BNO SxOq2SBb/w9purfI2JhnAb+6jd4iqch+VfFJbvY+i90xuXFa75UGBcORFfjGGoqS1CKM 5w2RjQnVJjJr1rDoYWl94Mh/O7jj7DVwM3QD6Ms4lc+c2AHCFMSZ6+P7oOAKMvq/DY4z zfUXrYcfQoZgVqmnVK0AMHzLEOvRf4bRVaC/3JtcST0lGXes2Ykjd/8ZD5h/n/UqzqGG OOAgiUoTLgxgNelDBlTBJ/NTqbKn85QfnQiAWXo2iL0eV6hi8nTK+HhMVYhiYhXA22Np yAUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=7OTWf97i9msDaAtUbKTlawU5KSwt/tocxmyS3gYffoM=; fh=3DLVxx0pHTcM5CBTkgNCIN8pXg2zglGm8zXvv3Eo1mM=; b=rZmhl2o5irO99cvtpZ7Hdn3O7P2PceyjjhWn90+Vq7fFmuPlR4GaM5OIjZv0OgiUhn 3s+5oLN1ykIvTS5NMHHiHy2GQ5PM+b/bnYzweAiI1nmOCJ9Y+oB5MNmEFjE4rBIS822j 7jSNgP4ee9yvCScSXOuzvjKSgxHKCOfAgWs6nUwFLnunH50SpmDJo0bBRiseJW4rabW+ CSsBnNyDWUpJQ2sC0cmOxesmWQbPPVAFJKy9vTsiHHst5WpZdkSmlVWshV2Y4BT5mp0H ApdDc2vzFC6IC+qGBaVQGtisYj0vrJixrx46hqFGwcPkbXwlQre919BYbFXlSU3yhgM6 T8Vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="DaqdWv6/"; 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-195872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195872-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. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff257f0c5si3571271cf.498.2024.05.30.13.21.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 13:21:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="DaqdWv6/"; 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-195872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195872-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 C7C271C243B3 for ; Thu, 30 May 2024 20:21:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6987158D6F; Thu, 30 May 2024 20:16:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DaqdWv6/" Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 B3DCE17B4F2 for ; Thu, 30 May 2024 20:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717100215; cv=none; b=RFn2mL3bZih1YqS1M7EoAnLSfPu5yJUZp+qRiX9en2ip94TBz64BUzNWRpAiKvKj8Vy+c+uOsrSrLNw/uvtkMYZILHCs5VcrnaJ4bKFJcfNzTT+c/CQwliS4jZBZ95u8EzjpElB0YLUkx+jyrRCsDlY3fDZq3YdyzN5XyDfuZEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717100215; c=relaxed/simple; bh=w/LlhHGvNr9h36RirGQv+V9ut5ip0myLpxA0mSnObZQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=J1XHPPA+uWwuW5cHVFlLziuVrOKcSRBdFLWwo98IR2hKsl6Vb4KBoYy1q379SOYB6fnpdGHtclyRpCkdXW3mw3ZegJDaKIZFaoun9Bf0mXlM8Hw684No438hBWCXUpKOZtQmMurul6DOzqiN7RWVw+fh7Yw8Yl00cGc0GjccyAc= 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=DaqdWv6/; arc=none smtp.client-ip=209.85.218.51 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-f51.google.com with SMTP id a640c23a62f3a-a62972c88a9so140854966b.1 for ; Thu, 30 May 2024 13:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717100204; x=1717705004; 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=7OTWf97i9msDaAtUbKTlawU5KSwt/tocxmyS3gYffoM=; b=DaqdWv6/LcQ9h42zhRV2fJ6CiQZXO6NhuN2qzzUo/z2TRSTM6baz/YqV4e40YVhtz4 VUkik5pfuhut8yVtUlXr12sj4EzSVxlxrxDaBIvSlde79Jqu64qN26zuh8wW4QVqBZEL /PzNNpaINagJ1w8G/ubHP0a9nxVLbV3qWKoqxzDL05Hr5dcTrPLj8ZV2+zj4O+IudTJW cvZ1krMzS7Om9i38jQd8nKLv/GEeNOz5FaA/+sKhPFfa3TyMra4mvl+uBSSBTuk8buiP OR+toEhjfRxybnXoM3bLSpI+r9BBpEZYL9GKtiADxN8ASP8jv2UfXiuEN3Sh8VlpW0VN Ah8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717100204; x=1717705004; 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=7OTWf97i9msDaAtUbKTlawU5KSwt/tocxmyS3gYffoM=; b=VWkTeka4xK343wXWGl9ilXE+rhuF95flccVXCFVkhSzLwc1xZVxNDG771oqDuYogDG zaarskfQw8JESWVd4e+u6S3MRhjq555jqRNvRb3dD1vco7La9DD9qkt9O7e9lodozVMC 0Zzp4lbdgtBGHp6R9dd8rdP+Baa4CABGWSxim9plv3huEtOS9ZU+D+iprmb/BZZFi5P4 f/DsOzwSe/PUyd3f/i2ZxMVGSR5Nl7qdOiziDfd+4TKBHZ1gDG870TuVWiV5NHv+0T8o tRJYoYnuMChu5a+QXNUmVzyGl+veTTEdF/GXeUuP2Vf8Wx7Zrv7caCfeUR41KLNfW1vE FnYQ== X-Forwarded-Encrypted: i=1; AJvYcCWFraXN7ozn9RhV3W6mApsDkmycy6NzV17q2LNfX04BRwGHCtZJfPgdtRYIypY93s/ilphiS+DyVQDGUqJ6R9L/Ys5B+G9LICYJDdpG X-Gm-Message-State: AOJu0YzWCWeV1JxRpN5WqEeTs4iYwVJCC175uhtVzruwpll9Kc8HB9bb Gm3gbTg1sRxsBB4f7yR8F0Jv6BN2liwOp5cWpxcnGWwVNxHlxt+SACITGoQDoMqFaZ6jgaEcS2q +I7eXYsqSTlOwgAzba21u1tYNKDLG5+d+LztDWxpiDibg6jz7+xyT X-Received: by 2002:a17:906:abd0:b0:a5a:8a63:9fee with SMTP id a640c23a62f3a-a65e8d2b827mr209645766b.3.1717100203599; Thu, 30 May 2024 13:16:43 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240530102126.357438-1-usamaarif642@gmail.com> <20240530102126.357438-2-usamaarif642@gmail.com> <20240530122715.GB1222079@cmpxchg.org> In-Reply-To: From: Yosry Ahmed Date: Thu, 30 May 2024 13:16:04 -0700 Message-ID: Subject: Re: [PATCH 1/2] mm: store zero pages to be swapped out in a bitmap To: Matthew Wilcox Cc: Johannes Weiner , Usama Arif , akpm@linux-foundation.org, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Hugh Dickins , Huang Ying Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 30, 2024 at 1:04=E2=80=AFPM Matthew Wilcox wrote: > > On Thu, May 30, 2024 at 09:24:20AM -0700, Yosry Ahmed wrote: > > I am wondering if it's even possible to take this one step further and > > avoid reclaiming zero-filled pages in the first place. Can we just > > unmap them and let the first read fault allocate a zero'd page like > > uninitialized memory, or point them at the zero page and make them > > read-only, or something? Then we could free them directly without > > going into the swap code to begin with. > > I was having similar thoughts. You can see in do_anonymous_page() that > we simply map the shared zero page when we take a read fault on > unallocated anon memory. > > So my question is where are all these zero pages coming from in the Meta > fleet? Obviously we never try to swap out the shared zero page (it's > not on any LRU list). So I see three possibilities: > > - Userspace wrote to it, but it wrote zeroes. Then we did a memcmp(), > discovered it was zeroes and fall into this path. It would be safe > to just discard this page. > - We allocated it as part of a THP. We never wrote to this particular > page of the THP, so it's zero-filled. While it's safe to just > discard this page, we might want to write it for better swap-in > performance. My understanding is that here we check if the entire folio is zero-filled. If the THP is still intact as a single folio, we will only apply the optimization if the entire THP is zero-filled. If we are checking a page that used to be part of a THP, then I think the THP is already split and swap-in performance would not be affected. Did I miss anything here? > - Userspace wrote non-zeroes to it, then wrote zeroes to it before > abandoning use of this page, and so it eventually got swapped out. > Perhaps we could teach userspace to MADV_DONTNEED the page instead? Why wouldn't it be safe to discard the page in this case as well? > > Has any data been gathered on this? Maybe there are other sources of > zeroed pages that I'm missing. I do remember a presentation at LSFMM > in 2022 from Google about very sparsely used THPs. Apart from that, we may also want to think about shmem if we want a general approach to avoid swapping out zero pages.