From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28D48CD1292 for ; Thu, 4 Apr 2024 15:35:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BA8D6B0082; Thu, 4 Apr 2024 11:35:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76A596B0083; Thu, 4 Apr 2024 11:35:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 631336B0087; Thu, 4 Apr 2024 11:35:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 452D16B0082 for ; Thu, 4 Apr 2024 11:35:10 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EBD1F1C1126 for ; Thu, 4 Apr 2024 15:35:09 +0000 (UTC) X-FDA: 81972247938.12.00917C8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf11.hostedemail.com (Postfix) with ESMTP id DAF8E40019 for ; Thu, 4 Apr 2024 15:35:06 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Uablszne; spf=none (imf11.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712244907; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=o173cPm3x4N4BtzsbHJzP7zM2DQecRIIJF1q/7iemmA=; b=eKCUZOwCTGuKzC6tAwLRRuarjIlFXDdpba0GJnCm/WMcVmrWVIPY1dThoR3HYLY9H8XQlx iEbEg4fW9Qip8OZ6jtSFHharOLPAKiBEXtbSPDv0mBZ4J0GrpFWwwOJzchpcoKdSCKIsqO CqBDwAUZUWwRfcAyX3aSVotLjdvmOaw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Uablszne; spf=none (imf11.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712244907; a=rsa-sha256; cv=none; b=v0K6JwZrqxz82+cG9yoxHOJh9GhsykAQYg8aHsjCocwPHh5YFMeXmcSZXWERBl9NIdaDTu cPDiUv8VDQCBrWQzdNXXF+qJVjnDuC/ZSypoHzMRBWpVrdk8UJe7soJsxif7iFB+O/1C1Q lEY8vT1kN3FKMea1RQSwBckOBplZnu8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=o173cPm3x4N4BtzsbHJzP7zM2DQecRIIJF1q/7iemmA=; b=UablsznepM4yvPQwSar6OOEuph Tb4rzRodEgjrBvFvzHB3ZJtWOw7vLwFW2agHn2R4V0NSS40SA2MZUoRmSKs0tPXfWcQw9zJxBwMUQ WeTUnT8ms69IygPJ5AMmpyJovSAoRoqN/QysbPKymUsmfsaTfuBYetVwcSi3KXiEjAPcnw6F4EruS aAdAkJ3bb8BO5d60MknAPrWI3/jehNQNMvRhg2YZUA6AwyTygBgCVqlaocaFFop6KkwOoSHFqeE6O 9HOmGVI+No8LRr3eO1LRoaA1oTUKtD6ZvsYNY6mF3cdXVHLD80yvuj9eDKF0wzSXX0ZfbRa2R030N om1Am+/w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsP7H-00000008KzU-1el0; Thu, 04 Apr 2024 15:35:03 +0000 Date: Thu, 4 Apr 2024 16:35:03 +0100 From: Matthew Wilcox To: "yueyang.pan@epfl.ch" Cc: linux-mm@kvack.org Subject: Re: Some questions about shrink_folio_list Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: DAF8E40019 X-Rspam-User: X-Stat-Signature: 85arjufkgaoq1shifxfznh8wiwnatd3c X-Rspamd-Server: rspam01 X-HE-Tag: 1712244906-383353 X-HE-Meta: U2FsdGVkX18pLNaATHQn5kCk2AHtqm971q+mQhGNMq0uxgDxNpyTUunK8WGB1cM2t9CRgAOLkgv7giISQHubTRJBnuoAhSNg04nEGA9GRtEurrNTBVK2zz3gYJtgU+6M2euvY85HvpCZKlaKrp/J2Hn+6bRmuygPPvss35zSa/z6BrnUssEpSwPrXB9Cj6cSH24fvfCQWojwY0m+vwx8B8Eb9TwXddUVxZYDX1VvGT8MnyeylgnZoaeW1THBkpXwRNjIV0BaYNgAzh1auf60K8Ux2CoCr/oigkwn/EPL/j098XfRn0NToifjM9oyvf45f2FuklCp0MylFLHWS0LzTwXHAsrebIrdcJcUCAjHMuw2tKEQOMd6j0bQ+brtK8qYNoniSqBOfJwFTGCQtAm+IlUesZx0mK+KyIUtGSOpUl3sWdk0MvtWrZiuHSTnTRoqs+TIeGz2Fe8Pc/bmWHNkPdzuoYf/wR2lRLOGCB1DilwiF8EAlCoMysLzJa6qZNyFI8wCsjfmO0Jf4x4+t35LB8bJVNjirR2KmmIBhB25Zde8HB3Y5yrk2V4u3FlAre3WUv+TBDR/5PsSXe36lAj5XqPag96E5b1rPbI5PxSkRzXTZAZqJVrzsKVnSA03yRC3dKlsPzO0gnqb7fUlEMP0xLujWR1zt8/JjBFz7w+utO90+cbFTalYZOXIrnwIGaqixsdyNX6917xT3OIYxyKPBW0YNKGYi1K2N/ITLxjL+wqu4ggtJH/ufzj8W1qJh03gmaBkInjSsFGaHa+3hHNG3s3wxqUZR/Bj4avqyy0UxbJgfBQNX2dJF0wTojQoALdQlv3FBIC/YFBf7DlvjNFXTG8x69dej0FetAPAGx8F1pX3u+j7brDjYt5dzcrOGWr+RMNoGaS5X3Y= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Apr 03, 2024 at 10:06:16PM +0000, yueyang.pan@epfl.ch wrote: > Dear Matthew, > I am Yueyang Pan a PhD student from EPFL, and I am currently > checking the swap code in the kernel. Sorry to bother you because this > email should go to Mel Gorman. He did not reply to me so I turned to > you for some help. Hi Yueyang, You'd probably have more luck if you cc'd the mailing list. Somebody other than Mel might have answered you. Added it now. > 1) I have some questions about `try_to_unmap_flush_dirty`. I > wonder why this is necessary in shrink_folio_list because in > the folio_check_references, we have already checked that the PTEs > pointing to this page does not have any access bit set. The current > shrink_folio_list then unmaps the page, clears the dirty bit, issues > the TLB flush if the dirty bit was set previously and then starts > to write the page to the swap. I wonder why here we cannot take an > opportunistic approach. My understanding is that if we don’t unmap the > page and perform flush, when there is a concurrent write to the page, > both the access bit and dirty bit will be set (because the dirty bit > is cleared) so we can simply check the access bit again after pageout > to see whether we can free this page or not. > I checked the git blame and saw Mel's commit in 2015 where he > mentioned that it was better to assume a writeable entry exist > in TLB but I wonder why this can be true if we have already use > folio_check_references to check the PTE access bit. Does this imply > even if the folio_check_references gives no reference there can be > still entries in the TLB? This is far outside my realm of expertise. I suspect it's possible that there can be stale entries in the TLB if ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH. > 2) I have some questions at the end of shrink_folio_list before the > ref_folios are spliced again back to folio_list. What if at the same > time, there is another function trying to free the page or mlock > the page? Will this page be circulated again in the inactive LRU > list and being double freed since the page lock was released at the > list_splice? Because from what I understood, the mlock will take the > page directly from the inactive/active list the page is in and move > the page to the mlock list but at this moment the page does not reside > in either of the list. I think the answer is that these folios have their LRU flag cleared throughout shrink_folio_list() so they cannot be mlocked? static struct lruvec *__mlock_folio(struct folio *folio, struct lruvec *lruvec) { /* There is nothing more we can do while it's off LRU */ if (!folio_test_clear_lru(folio)) return lruvec;