Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1114497ybf; Fri, 28 Feb 2020 14:30:18 -0800 (PST) X-Google-Smtp-Source: APXvYqz70nLO5HoF+5WxPZi+DoYZYfbcmdu6auzqpZOpAZCiJjs5/HeY/64RHfSr7Pg3sPWpm3lW X-Received: by 2002:aca:4a86:: with SMTP id x128mr2204485oia.29.1582929018301; Fri, 28 Feb 2020 14:30:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582929018; cv=none; d=google.com; s=arc-20160816; b=livayZAho7bwnBF5dW82QcQ1Uf933OaoaHtatYCWMhq9GN2mm8XFvl3/8P+ReyiSIO +VX8b2WPBr1ne59hJW90JK1nIdTTnPPAj2m1PEhfRHq2N+IhyaiGldQknIhLFOFuExXy gTBzwnFjkPa6GR7TB7SQnNnWyhXSXo+t68HN6JNqxZpl/6Zbn7SX4tF1hcaCxl8Y++nK dQU+hakQuDhPQIwsOW61z3aFGa1xLgsblpwhFWk+SeVKtVNuAO41n8aCcaiDddD76ZzO EYJwAKluGf6uP276QzO4MCW4Ef5Be2Au6UVaVXVC2Q5j20IhsfIdKFZS3e5QCxVGMfAo QuMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=NBFn8r3iI2X+MqFC5qPdxTHRTSXiMYP64toQbU8Kh+I=; b=zOizl+ij0OScoUludX4vNfqSlgk+E9Gf0PHV1jm2Y7yvES+z927AzPbkwkkubgZUuf FPNLCQ9Egrql2gs+hcGUQAExeMdfFt1+Vbzlfoy9KbcFyTKDXQp12k6Thr8TR4P23rWY AjcvmYhcObqg0TwhLrVTww8cl5iFcexCBghylthamPOHK2KSNONdcyjC2rTF86jaxA4/ /7cYlra9Et84kwxy31G4DWLbY7zqfdNtOKmub+mRjBnTbyMJveWKFgp0Tov5hBS01N6o DqVtYr4H6QLwya70K9+lgWPt95RChaQsGT40QIWrwL5sAwxjXa8QrVZA/s8Wt344Qa1g /+1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v25si2356428otq.93.2020.02.28.14.30.06; Fri, 28 Feb 2020 14:30:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726527AbgB1W2l (ORCPT + 99 others); Fri, 28 Feb 2020 17:28:41 -0500 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:41492 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725957AbgB1W2k (ORCPT ); Fri, 28 Feb 2020 17:28:40 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04396;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0TrAtt5r_1582928912; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TrAtt5r_1582928912) by smtp.aliyun-inc.com(127.0.0.1); Sat, 29 Feb 2020 06:28:36 +0800 Subject: Re: [PATCH] huge tmpfs: try to split_huge_page() when punching hole To: "Kirill A. Shutemov" , Matthew Wilcox Cc: Hugh Dickins , Andrew Morton , Alexander Duyck , "Michael S. Tsirkin" , David Hildenbrand , "Kirill A. Shutemov" , Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20200227084704.aolem5nktpricrzo@box> <20200228042646.GF29971@bombadil.infradead.org> <20200228125407.5lnmjtnvlcnniokt@box> From: Yang Shi Message-ID: <28448f09-3418-e0ad-b974-c540f2e7332b@linux.alibaba.com> Date: Fri, 28 Feb 2020 14:28:31 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20200228125407.5lnmjtnvlcnniokt@box> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/28/20 4:54 AM, Kirill A. Shutemov wrote: > On Thu, Feb 27, 2020 at 08:26:46PM -0800, Matthew Wilcox wrote: >> On Thu, Feb 27, 2020 at 08:04:21PM -0800, Hugh Dickins wrote: >>> It's good to consider the implications for hole-punch on a persistent >>> filesystem cached with THPs (or lower order compound pages); but I >>> disagree that they should behave differently from this patch. >>> >>> The hole-punch is fundamentally directed at freeing up the storage, yes; >>> but its page cache must also be removed, otherwise you have the user >>> writing into cache which is not backed by storage, and potentially losing >>> the data later. So a hole must be punched in the compound page in that >>> case too: in fact, it's then much more important that split_huge_page() >>> succeeds - not obvious what the fallback should be if it fails (perhaps >>> in that case the compound page must be kept, but all its pmds removed, >>> and info on holes kept in spare fields of the compound page, to prevent >>> writes and write faults without calling back into the filesystem: >>> soluble, but more work than tmpfs needs today)(and perhaps when that >>> extra work is done, we would choose to rely on it rather than >>> immediately splitting; but it will involve discounting the holes). >> Ooh, a topic that reasonable people can disagree on! > Hugh wins me over on this. > > Removing PMDs will not do much as we track dirty status on compound page > level. > > I see two reasonable options for persistent filesystem to handle the > punch hole: > > - Keep the page and PMD mappings intact, but trigger writeback if page > is dirty. After the page is clean we can safely punch hole in the > storage. Following write access to the area would trigger > page_mkwrite() which would allocate storage accordingly. > > This is reasonable behaviour if we allow to allocate THPs not fully > covered by space allocated on disk. > > - Try to split the page or drop it completely from the page cache (after > write back if need) before punching the hole. Fallback to the first > scenario if we cannot split or get rid of the page. > > I cannot say I strongly prefer one approach over another. The first one > fits better with THP attitude: pay for performance with memory (and > storage I guess). The second may work better if resources is limited. I'm afraid any approach which would not drop page cache may get us end up being in the same situation as what Hugh or my patch is trying to solve. IMHO the latter one might be preferred. > >> The current prototype I have will allocate (huge) pages and then >> ask the filesystem to fill them. The filesystem may well find that >> the extent is a hole, and if it is, it will fill the page with zeroes. >> Then, the application may write to those pages, and if it does, the >> filesystem will be notified to create an on-disk extent for that write. >> >> I haven't looked at the hole-punch path in detail, but presumably it >> notifies the filesystem to create a hole extent and zeroes out the >> pagecache for that range (possibly by removing entire pages, and with >> memset for partial pages). Then a subsequent write to the hole will >> cause the filesystem to allocate a new non-hole extent, just like the >> previous case. >> >> I think it's reasonable for the page cache to interpret a hole-punch >> request as being a hint that the hole is unlikely to be accessed again, >> so allocating new smaller pages for that region of the file (or just >> writing back & dropping the covering page altogether) would seem like >> a reasonable implementation decision. >> >> However, it also seems reasonable that just memset() of the affected >> region and leaving the page intact would also be an acceptable >> implementation. As long as writes to the newly-created hole cause the >> page to become dirtied and thus writeback to be in effect. It probably >> wouldn't be as good an implementation, but it shouldn't lose writes as >> you suggest above. >> >> I'm not sure I'd choose to split a large page into smaller pages. I think >> I'd prefer to allocate lower-order pages and memcpy() the data over. >> Again, that's an implementation choice, and not something that should >> be visible outside the implementation. > Copying over the data has the same limitation as split: you need to get > refcounts to the well-known state (no extra pins) before you can proceed. > So it will not be never-fail operation. > >> [1] http://git.infradead.org/users/willy/linux-dax.git/shortlog/refs/heads/xarray-pagecache