Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5397631rdb; Sat, 16 Sep 2023 15:42:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHAJGP/cXGbIQqtxzlfmNsPIqFdqSfS9PbeFWX3BCky3OBNlwzV3SSGo5zDne/7H42pcjp X-Received: by 2002:a05:6a21:9986:b0:15a:4634:e4c with SMTP id ve6-20020a056a21998600b0015a46340e4cmr7459584pzb.5.1694904169341; Sat, 16 Sep 2023 15:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694904169; cv=none; d=google.com; s=arc-20160816; b=ebuWUgC8uKm7UMn7htSn5jZpml9G3JBgjExl5Lzrlpb7cTJfY5AwQ7f8JW8MJ5u7eV X+XKUzZy2Cw7VAzjdzjMgfG+s7MAkdmfb/0vzvoACpBTgFSQ0iythSi41YQDvGZQgD0v rg+Q5rCGLtXMkmY7v9prrvuNpjR5tz2uf5YNicLX3w0MJahzYZthdd+aukQW4OkXLq3c n8q4Z/NFQBVAyoBsK78t52Brxi0NQgGqjLlxAUhB+6tX3rDAV9FqE+1bj+qDhY33G5nF NYNam7Fu0aB0TEZFadJgcT+9ez9cTh8s/EPBPcedq7j1N5bIbHNIzmY+zIb8IuZ5gv4m hVkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=Kq86mg3eRdpsafcpXL3Gsx54l0Vjtu7ZVdR51WnNflM=; fh=XXIxWx48ZKGldy5VerkaoqCKTwUnyhbNc42Ig5F9uzc=; b=Bp3PnFiQMSEjvpgbMSIoaYevltAB59peitRLlMO8lac9KA8N1FNiHwa9ZI5fGljj6k zinNkKpAM/W/+qeD5XyVjhqMP51WNxgo0lFjO6eFLIFFKL9/ZNQKOaKW1k50+wo3Fbge BZ7Jy+61KJZRqyppr6cHRbteAcyO90F5v8yRiBepg5VIwCAOF1xX0vZ765ERQhrkRbbg 1E2HcLXpwnmg/gL/SjQUJuxtMt22SeC6W3eHL5mwhKsf/OUE7gj74nXN213Ljs/8D/nC AepPJGOjFVfgdLl+UraDD7Q9zLnzzl3xt8cHjH6QlzwNx2V2zrz4zvNJCob3UdQSU77a jtWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WrDpy1p6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l62-20020a639141000000b00565701e9a36si5396465pge.752.2023.09.16.15.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 15:42:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WrDpy1p6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7B24B833E85C; Fri, 15 Sep 2023 15:51:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237890AbjIOWui (ORCPT + 99 others); Fri, 15 Sep 2023 18:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238171AbjIOWu2 (ORCPT ); Fri, 15 Sep 2023 18:50:28 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF4312D44 for ; Fri, 15 Sep 2023 15:48:56 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-58dfe2d5b9aso36732027b3.1 for ; Fri, 15 Sep 2023 15:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694818136; x=1695422936; darn=vger.kernel.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=Kq86mg3eRdpsafcpXL3Gsx54l0Vjtu7ZVdR51WnNflM=; b=WrDpy1p6ueZ1/jU1o2pLHVMTh6H1cQLtnEkt0u1n1urkGTgbSYZHmbDBckyxVqdmdc 1ZBaKCFj4z1Ild10mjXgROKqhb0XFSDFByxAtB/J6uBbMag/Qh6x3BajcOVD43ieIj3k JhQsaYGoW0Ehj85ak5SN1dbQzlSTNB9zlJp0sNyq9IstqAG5wRPh9GvXc6h/vjCx2x5J fsdTwodyjV/lIJWMKEryQsdyxXpWIAJz0Q9+tiC7FpTqEwFKF7HZSUgXUGuXcbMzT02o MRkV6x625X5g2CHd+5CBXvkP9IQublkI8fwikJ888yIxmbbQg7Qu+mPdeWIRW+d9C07S P/mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694818136; x=1695422936; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kq86mg3eRdpsafcpXL3Gsx54l0Vjtu7ZVdR51WnNflM=; b=CG4q/C1rdBE7r9+sFkH/g5yEF3VWWN7kGQLTIVbZGSpCUmeEGL3QR3GsFtv4qA5pZc 4CWUzdOMRp/fEjxMQlGs5mBQmCkRN7KoUJ/oU5tiQPkpb26JI0ueW9aRoImIU9UZdAzn J6klaDowCyuNN0GtgeKeeb3qsvSGItQnnB6kVZy701xbYZuY+Rd+FlYkRNi1KEpE2LLu moAk6bxHBJDvn+kQmldQ9D+4Azphqd9a/bmOeMCPc49A1hw+XQOFcT9CT1bZDIX/m5/x xsXue4OLSJdQfh7Q08C4SRE6yqs+yg7o6VIMgDS5owBB91xEtzn+g8Yrt//6nkhlIw6K OssA== X-Gm-Message-State: AOJu0YwiVvCIK3fITIzVOy/dO4IyfI0Yq7EgfgkjVAPVRI83Q9MjK+gU b6aGWwLHWlnkcJATPDPb20hYpw== X-Received: by 2002:a81:6c4c:0:b0:56d:4d1e:74ab with SMTP id h73-20020a816c4c000000b0056d4d1e74abmr7022615ywc.23.1694818136008; Fri, 15 Sep 2023 15:48:56 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id z13-20020a81a24d000000b0054f9e7fed7asm1092349ywg.137.2023.09.15.15.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:48:54 -0700 (PDT) Date: Fri, 15 Sep 2023 15:48:46 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Matthew Wilcox cc: Hugh Dickins , Jens Axboe , Andrew Morton , "Kirill A . Shutemov" , Hannes Reineke , David Hildenbrand , John Hubbard , linux-mm@kvack.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] block: Remove special-casing of compound pages In-Reply-To: Message-ID: <1fa6119e-6e5-5e8-21d8-571814f6a99e@google.com> References: <20230814144100.596749-1-willy@infradead.org> <94635da5-ce28-a8fb-84e3-7a9f5240fe6a@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 15 Sep 2023 15:51:27 -0700 (PDT) On Fri, 15 Sep 2023, Matthew Wilcox wrote: > On Wed, Aug 16, 2023 at 01:27:17PM -0700, Hugh Dickins wrote: > > > This problem predates the folio work; it could for example have been > > > triggered by mmaping a THP in tmpfs and using that as the target of an > > > O_DIRECT read. > > > > > > Fixes: 800d8c63b2e98 ("shmem: add huge pages support") > > > > No. It's a good catch, but bug looks specific to the folio work to me. > > > > Almost all shmem pages are dirty from birth, even as soon as they are > > brought back from swap; so it is not necessary to re-mark them dirty. > > > > The exceptions are pages allocated to holes when faulted: so you did > > get me worried as to whether khugepaged could collapse a pmd-ful of > > those into a THP without marking the result as dirty. > > > > But no, in v6.5-rc6 the collapse_file() success path has > > if (is_shmem) > > folio_mark_dirty(folio); > > and in v5.10 the same appears as > > if (is_shmem) > > set_page_dirty(new_page); > > > > (IIRC, that or marking pmd dirty was missed from early shmem THP > > support, but fairly soon corrected, and backported to stable then. > > I have a faint memory of versions which assembled pmd_dirty from > > collected pte_dirtys.) > > > > And the !is_shmem case is for CONFIG_READ_ONLY_THP_FOR_FS: writing > > into those pages, by direct IO or whatever, is already prohibited. > > > > It's dem dirty (or not dirty) folios dat's the trouble! > > Thanks for the correction! Could it happen with anon THP? > They're not kept dirty from birth ... are they? Anon pages, THP or other, are not marked dirty from birth, right. But nor are they considered for freeing without writeout: shrink_folio_list() does add_to_swap() on them without considering dirtiness, and add_to_swap() does an unconditional folio_mark_dirty(). Well, not quite unconditional: it is conditional on allocating swap, but shrink_folio_list() just reactivates when swap is not allocated. So, I see no opportunity for data loss there. When it's read back from swap later on, the folio will be left clean while it matches swap: I haven't bothered to recheck the latest details of what happens when it's CoWed, or the swap is deleted, those details won't matter given the behavior above. But might there be a direct IO problem while that anon folio (large or small) remains clean in swapcache, when reclaim's pageout() might be liable to free it without rewriting? There ought not to be: get_user_pages()/follow_page_pte() have taken care of that for many years with the FOLL_TOUCH+FOLL_WRITE if (flags & FOLL_TOUCH) { if ((flags & FOLL_WRITE) && !pte_dirty(pte) && !PageDirty(page)) set_page_dirty(page); and follow_trans_huge_pmd() dirties the pmd when FOLL_TOUCH+FOLL_WRITE. I forget why follow_page_pte() prefers to dirty page rather than pte, but either approach should be good enough to avoid the data loss. However, I don't see equivalent FOLL_TOUCH+FOLL_WRITE code where get_user_pages_fast() goes its fast route; nor pin_user_pages_fast() used by lib/iov_iter.c; and it looks odd that pin_user_pages_remote() and pin_user_pages_unlocked() use FOLL_TOUCH but pin_user_pages() not. Problem? Not particularly for anon or for large, but for any? Or not a problem because of final set_page_dirty() or folio_mark_dirty() on release - only a problem while that PageCompound check remains? (Of course filesystems hate behind-the-back dirtying for other reasons, that they may lose the data without proper notice: separate discussion we'd better not get back into here.) I've spent much longer trying to answer this than I could afford, expect no more from me, back to you and GUP+PIN experts. Hugh