Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp33091lqh; Thu, 30 May 2024 13:04:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWrzSCRRznYTKDKWfiLYymx4QpyYdyNtvUqgnws3PZvKZRe+FT+SPu3JCxjx4MmEZSB7eefXrGSevdj6QRjhUnsgTjfm1erqmbHfmxCg== X-Google-Smtp-Source: AGHT+IHZAgE5msxHAADtG1namq91LPh8lSkSzQc5qLtqvB5K1yV1CF+DZxwtW86ra8G2eWT5jEYs X-Received: by 2002:a05:622a:130f:b0:43e:3d64:8c0 with SMTP id d75a77b69052e-43fe922367bmr43177871cf.0.1717099470911; Thu, 30 May 2024 13:04:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717099470; cv=pass; d=google.com; s=arc-20160816; b=Tm/e/K4ZnrvaMXUXV6UjYLQV5XMX93OrfokTAgY8VGtB388badgRfbTJS7X1xfLfZj EgXZ7LszXfznZLm4mEyz2Ubf0GwskIhbLfQ6wTMWdgF+RTqGLr3fbJrIP70bBQc9t3hf 0sECOREFVtSiVxbyS8hWCM06cnMKqkeWalbfsHESd3btEexQFShkKVMQ6R+Q8dRlmFs2 nzu1MC5DeZlzZs2498yUgAc1noBalJUumIJRYZQcWUikHE1xrWLdEEsLxG9PlCTU/VrW NZWZ+oqGaRdH+7yO6Ik84OaPueEJdUkcWt4QOps7QC/B6L3Epm85LSE8C0n7o30mlK/t rIPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/bBYT7UwHhY6mRNtfgkO0poVUMVNoTkDOtlF1Z4cO0U=; fh=yhwLfaFBQgpqC/X4HaCEmzBinx+VOxEV4p13yHXriio=; b=IF5MQUAQPkcksAjyr1X52LjQ9C15jJ4c/JpvC9u55cq4AZH2Yhv9yQ+WYtXPEHyTwR zvC3IiPqfvasNt33RlnT9Db2Ycv45Kg9TUqplL+MFLZw543deD8jHSnI56IC/B388JDR pEI6ZrlhbmpKT2b1xY3RWnd6YnCAkx5Xiv5Igp5hcwpwpTUWG3fPYS66RGyWgP+f+/0I d4NjhDaiIw5pRNk8O4fBKrZly3rQTkTV4c6XzWZecYoyBVPZjANZslZwGPj1ZyGOIuzw 0KyMv6o+V/V0DUjzFR4y6xTjChXz6O2ThoiAyqRrMaGFHfxl07CUto6Kdj0PmcVMVxip D0jQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=e2f1bkq9; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-195850-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195850-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff2469031si3336551cf.385.2024.05.30.13.04.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 13:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195850-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=@infradead.org header.s=casper.20170209 header.b=e2f1bkq9; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-195850-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195850-linux.lists.archive=gmail.com@vger.kernel.org" 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 9FE831C23F9B for ; Thu, 30 May 2024 20:04:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C6E25589B; Thu, 30 May 2024 20:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="e2f1bkq9" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB98F74040 for ; Thu, 30 May 2024 20:04:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717099464; cv=none; b=KRNOz58zroGKzsDyycNQq0ALypMyIUcT1UcJWTwQGtI8tVoSgEuA/VzDl0JA+8LqXNt/8Q6BLXaK2LE3/X3J0NOb1SSCfeY/VR9ZCg7dJ7qTMUd31nZNYCoGzoDCkL1ovTctb+KpbUzJcAwLI7LLPSGNTg6d3a5RsO+85twSDFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717099464; c=relaxed/simple; bh=Z3eZx9NDsXnWgYkipyZqSi7f5PAiQBZLb7hkodlWvDQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hqgbZvNXaC6uptTAY9PbrTjsD8IoHiGP7cJHibRCINf46XszvQxuelY5yaV3p4Bg3LVho/cY7JsBE/RiUIzTjebc/e7vPZ7qo5QsbN8RdHMtzjpOE5lxdsqOtj0X6J5mGfGZXw9YvseKjjgU+3pbtn6/BG4w9JWqTdMgFru3a+A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=e2f1bkq9; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/bBYT7UwHhY6mRNtfgkO0poVUMVNoTkDOtlF1Z4cO0U=; b=e2f1bkq9uLx1zHBflnppPaiMxj tR+yCUYGJP/XdDgupBQXMJjQMTmumVo1XdwR9sW5Uxt4Vj1fxw7llefMQYoc5MLxkh8o9JHsCk9xr 6bm8mBedCA5W7GA9K69t2NckzSxWpT5qRcyZCfzHEigaeaAMwWdkrHMvSFriTeNacuUkvI9tUFi6F rm+EBY3E7mr5xUVqw2AUXnxVPfUocX47U7dsczxJIHllBmfSiJ+CsHUcxQMsZPryLMrkbc7Kn5qNp elo7tVXEZ+uKSN8i6UiwOKpv/eSZbz1Lpj+QI14rMMEagjSInP673raxVagl8UqtlQmBSiAEBQ7Lk 5UyClcwA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCm0W-0000000B7ep-1RqI; Thu, 30 May 2024 20:04:16 +0000 Date: Thu, 30 May 2024 21:04:16 +0100 From: Matthew Wilcox To: Yosry Ahmed 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 Subject: Re: [PATCH 1/2] mm: store zero pages to be swapped out in a bitmap Message-ID: References: <20240530102126.357438-1-usamaarif642@gmail.com> <20240530102126.357438-2-usamaarif642@gmail.com> <20240530122715.GB1222079@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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. - 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? 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.