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 45848C77B7E for ; Tue, 2 May 2023 15:49:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2F476B0071; Tue, 2 May 2023 11:49:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B89A6B0074; Tue, 2 May 2023 11:49:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 859E26B0075; Tue, 2 May 2023 11:49:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by kanga.kvack.org (Postfix) with ESMTP id 60E3F6B0071 for ; Tue, 2 May 2023 11:49:00 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683042540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Br0MpFInBQrIw0DpV8B2e9x3mnRHV0K37BmIG0WD7TQ=; b=BD8YAc68tbidgqIt1I9Gu5VgoaDgG0snahm/bJX9V63FwUVr3qK8uroAvQErEff5aI7Vtf ssOtrjaXHGWAOR8grxGZP9/eOBKPhm85riQBatpSqvu46YGSo2I/Se6ykQA+TEDViKeL8Q h/miKYQfP2wxLJOCURJkskPdFdvlRWU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-153-bfbdOkk5NaOCZD-FiFxExA-1; Tue, 02 May 2023 11:48:59 -0400 X-MC-Unique: bfbdOkk5NaOCZD-FiFxExA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74e0a11dce7so17607185a.1 for ; Tue, 02 May 2023 08:48:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683042538; x=1685634538; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Br0MpFInBQrIw0DpV8B2e9x3mnRHV0K37BmIG0WD7TQ=; b=PLD7C+WxfY9ZUfuo0q3MEqJPiPcBhEBB6RqLEo/A2pw6Mi2UsV5JPhV7l1OlLjb33D TEy897FXRngUqCu2xLVYBTVZ6PinLCT7aHYbYBafOIWrOV5LZZ3fHFk+EiX2vVV7GqxT TI/CTpy8QTart5D6hTnRlZNYiwx7NhwjDyCXjaUiIbSEXvi/lNziyfg/mmcDIx/P1WYS ArVP0q0r/c+fuNdfHyhoQAxth3Gbbs+fJaGgEWpHUliR7eu0ccWzMlVAS7Y3Dvy75AlO 43IN7DZrMDYP10R61W0zcZQ3rJIjOFyRa+m0Ghl6ums4RaDcWzUWu+CdG4ROLbH4Jr9O kp/g== X-Gm-Message-State: AC+VfDxnZKI5Ov8GuPT899ZycVZAR7k9FJsbYJfPpNMaisYdoEjgpPL9 dtX2/5ntj4Sx6l5waG+HJwWf+7vavWsBnA4Tbl8akLomGZ/nUSCrkRva96UrphaFCadjOQOTQIs Yo5j1SWzbbWM= X-Received: by 2002:ac8:58cc:0:b0:3ef:5395:a161 with SMTP id u12-20020ac858cc000000b003ef5395a161mr4620251qta.4.1683042538731; Tue, 02 May 2023 08:48:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lsEBCDMgHg06jVLbZ4MJcPg10vJkI9VEzcjlDZEIx+F5bCvb3a8wNGloJehkR3kc4/LBCPA== X-Received: by 2002:ac8:58cc:0:b0:3ef:5395:a161 with SMTP id u12-20020ac858cc000000b003ef5395a161mr4620211qta.4.1683042538401; Tue, 02 May 2023 08:48:58 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id j4-20020ac86644000000b003dffd3d3df5sm10435398qtp.2.2023.05.02.08.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 08:48:57 -0700 (PDT) Date: Tue, 2 May 2023 11:48:56 -0400 From: Peter Xu To: David Hildenbrand Cc: Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Lorenzo Stoakes , Andrew Morton , Christoph Hellwig Subject: Re: [PATCH] mm: Do not reclaim private data from pinned page Message-ID: References: <20230428124140.30166-1-jack@suse.cz> <8dba1912-4120-cb3d-6e10-5fc18459e2ac@redhat.com> MIME-Version: 1.0 In-Reply-To: <8dba1912-4120-cb3d-6e10-5fc18459e2ac@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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: On Tue, May 02, 2023 at 05:33:22PM +0200, David Hildenbrand wrote: > On 02.05.23 17:26, Peter Xu wrote: > > On Fri, Apr 28, 2023 at 02:41:40PM +0200, Jan Kara wrote: > > > If the page is pinned, there's no point in trying to reclaim it. > > > Furthermore if the page is from the page cache we don't want to reclaim > > > fs-private data from the page because the pinning process may be writing > > > to the page at any time and reclaiming fs private info on a dirty page > > > can upset the filesystem (see link below). > > > > > > Link: https://lore.kernel.org/linux-mm/20180103100430.GE4911@quack2.suse.cz > > > Signed-off-by: Jan Kara > > > --- > > > mm/vmscan.c | 10 ++++++++++ > > > 1 file changed, 10 insertions(+) > > > > > > This was the non-controversial part of my series [1] dealing with pinned pages > > > in filesystems. It is already a win as it avoids crashes in the filesystem and > > > we can drop workarounds for this in ext4. Can we merge it please? > > > > > > [1] https://lore.kernel.org/all/20230209121046.25360-1-jack@suse.cz/ > > > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > > index bf3eedf0209c..401a379ea99a 100644 > > > --- a/mm/vmscan.c > > > +++ b/mm/vmscan.c > > > @@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, > > > } > > > } > > > + /* > > > + * Folio is unmapped now so it cannot be newly pinned anymore. > > > + * No point in trying to reclaim folio if it is pinned. > > > + * Furthermore we don't want to reclaim underlying fs metadata > > > + * if the folio is pinned and thus potentially modified by the > > > + * pinning process as that may upset the filesystem. > > > + */ > > > + if (folio_maybe_dma_pinned(folio)) > > > + goto activate_locked; > > > + > > > mapping = folio_mapping(folio); > > > if (folio_test_dirty(folio)) { > > > /* > > > -- > > > 2.35.3 > > > > > > > > > > IIUC we have similar handling for anon (feb889fb40fafc). Should we merge > > the two sites and just move the check earlier? Thanks, > > > > feb889fb40fafc introduced a best-effort check that is racy, as the page is > still mapped (can still get pinned). Further, we get false positives most > only if a page is shared very often (1024 times), which happens rarely with > anon pages. Now that we handle COW+pinning correctly using > PageAnonExclusive, that check only optimizes for the "already pinned" case. > But it's not required for correctness anymore (so it can be racy). > > Here, however, we want more precision, and not false positives simply > because a page is mapped many times (which can happen easily) or can still > get pinned while mapped. Ah makes sense, thanks. Acked-by: Peter Xu This seems not obvious, though, if we simply read the two commits. It'll be great if we mention it somewhere in either comment or commit message on the relationship of the two checks. -- Peter Xu