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 X-Spam-Level: X-Spam-Status: No, score=-2.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5F44C432C0 for ; Thu, 28 Nov 2019 11:35:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 44D2F21775 for ; Thu, 28 Nov 2019 11:35:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="jXLwhfyT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44D2F21775 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D1C266B051F; Thu, 28 Nov 2019 06:35:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCBF86B0520; Thu, 28 Nov 2019 06:35:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBC136B0521; Thu, 28 Nov 2019 06:35:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id A35606B051F for ; Thu, 28 Nov 2019 06:35:00 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 65BDE180AD806 for ; Thu, 28 Nov 2019 11:35:00 +0000 (UTC) X-FDA: 76205479560.09.house54_82f097448bc62 X-HE-Tag: house54_82f097448bc62 X-Filterd-Recvd-Size: 7593 Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 Nov 2019 11:34:59 +0000 (UTC) Received: by mail-lj1-f194.google.com with SMTP id e28so3940464ljo.9 for ; Thu, 28 Nov 2019 03:34:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=XOqt1jA1mHDLa304qf2rgZ/MgYLbFa3pf/BnMQUaDUU=; b=jXLwhfyTQDXvRp9KdmQMJpPvWCMrvfQGfjoalvLtnweIxV6eaWL6+FxOW54SN3/lCi O8wSfDPhKFc69w1M5A955/eZVWOjKZCY/VB7lrcL39YTZx+dE4acIA6eJOzhzHS4CzKa VCxz0bz0HA6fDAJnVxCT0n7LlVuwO7g3xojM1ysv1c/UlW/yOQavAWvsJMFoopU+AeCa yrGiEyCYkuRjGYQcrkmvfPA3+2JFT3nyOxyLG+kO5sEvy+SMFWuPQEby779MxARBw7+0 4+N8ie63zkjuc/DuanK9ypI5ccyxAyMBz4aB6uafa3Kb/4C7OcOLaXQfXzQudgKPd0RU QYKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=XOqt1jA1mHDLa304qf2rgZ/MgYLbFa3pf/BnMQUaDUU=; b=rjRYnczs2vRx3Ld9VicXoMwoR2pa0QYe4KAtiZTEOoZVw04ypi6719beZnVW4oFd40 U0ESl3CxP1nOGWMKFYxctn7MUUPHLKmN78Pgv5ovuVqR5GGNBkN+bfQxEYIo4Uu+TB8i 6O1ipTD5rsLfuFwlpFihAg1cbAYqH8plSJ5jyuGsgj3OU/78puZdj4FNXpGracxewJaQ 3DbNzmmZHO/6ebin/aOY/p78z/kvHABduXSxRTtWSgo4V6kW87vYzpftvXfli9EoGr1P sWvIdJpIvAXjhkzLyvHP2MRKOumEch6ELpDt762Jz9FA6rfB8dq5laqD7rnxrD02V7Ha qmnw== X-Gm-Message-State: APjAAAUmYJWIMinJJMN5GIyIgmvJCVbq4DVXxCLTd6C7LZThLqBrj3op JULwKfKn8XFZPfBsmAWQBD9jZA== X-Google-Smtp-Source: APXvYqxtsM0j/fet/8Hd0wppyL5kmHFHQSC8L5N/GAw4xOFXmFoZ5D9szeElJt5bgd2+LoHbl99hcA== X-Received: by 2002:a2e:8e27:: with SMTP id r7mr34842858ljk.101.1574940898131; Thu, 28 Nov 2019 03:34:58 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id f11sm4228455lfa.9.2019.11.28.03.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 03:34:57 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 6B5A310188A; Thu, 28 Nov 2019 14:34:56 +0300 (+03) Date: Thu, 28 Nov 2019 14:34:56 +0300 From: "Kirill A. Shutemov" To: Hugh Dickins Cc: Yang Shi , kirill.shutemov@linux.intel.com, aarcange@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] mm: shmem: allow split THP when truncating THP partially Message-ID: <20191128113456.5phjhd3ajgky3h3i@box> References: <1574471132-55639-1-git-send-email-yang.shi@linux.alibaba.com> <20191125093611.hlamtyo4hvefwibi@box> <3a35da3a-dff0-a8ca-8269-3018fff8f21b@linux.alibaba.com> <20191125183350.5gmcln6t3ofszbsy@box> <9a68b929-2f84-083d-0ac8-2ceb3eab8785@linux.alibaba.com> <14b7c24b-706e-79cf-6fbc-f3c042f30f06@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Content-Transfer-Encoding: quoted-printable 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 Wed, Nov 27, 2019 at 07:06:01PM -0800, Hugh Dickins wrote: > On Tue, 26 Nov 2019, Yang Shi wrote: > > On 11/25/19 11:33 AM, Yang Shi wrote: > > > On 11/25/19 10:33 AM, Kirill A. Shutemov wrote: > > > > On Mon, Nov 25, 2019 at 10:24:38AM -0800, Yang Shi wrote: > > > > > On 11/25/19 1:36 AM, Kirill A. Shutemov wrote: > > > > > > On Sat, Nov 23, 2019 at 09:05:32AM +0800, Yang Shi wrote: > > > > > > > Currently when truncating shmem file, if the range is parti= al of > > > > > > > THP > > > > > > > (start or end is in the middle of THP), the pages actually = will > > > > > > > just get > > > > > > > cleared rather than being freed unless the range cover the = whole > > > > > > > THP. > > > > > > > Even though all the subpages are truncated (randomly or > > > > > > > sequentially), > > > > > > > the THP may still be kept in page cache.=A0 This might be f= ine for > > > > > > > some > > > > > > > usecases which prefer preserving THP. > > > > > > >=20 > > > > > > > But, when doing balloon inflation in QEMU, QEMU actually do= es hole > > > > > > > punch > > > > > > > or MADV_DONTNEED in base page size granulairty if hugetlbfs= is not > > > > > > > used. > > > > > > > So, when using shmem THP as memory backend QEMU inflation a= ctually > > > > > > > doesn't > > > > > > > work as expected since it doesn't free memory.=A0 But, the = inflation > > > > > > > usecase really needs get the memory freed.=A0 Anonymous THP= will not > > > > > > > get > > > > > > > freed right away too but it will be freed eventually when a= ll > > > > > > > subpages are > > > > > > > unmapped, but shmem THP would still stay in page cache. > > > > > > >=20 > > > > > > > To protect the usecases which may prefer preserving THP, in= troduce > > > > > > > a > > > > > > > new fallocate mode: FALLOC_FL_SPLIT_HPAGE, which means splt= ting THP > > > > > > > is > > > > > > > preferred behavior if truncating partial THP.=A0 This mode = just makes > > > > > > > sense to tmpfs for the time being. >=20 > Sorry, I haven't managed to set aside enough time for this until now. >=20 > First off, let me say that I firmly believe this punch-split behavior > should be the standard behavior (like in my huge tmpfs implementation), > and we should not need a special FALLOC_FL_SPLIT_HPAGE to do it. > But I don't know if I'll be able to persuade Kirill of that. >=20 > If the caller wants to write zeroes into the file, she can do so with t= he > write syscall: the caller has asked to punch a hole or truncate the fil= e, > and in our case, like your QEMU case, hopes that memory and memcg charg= e > will be freed by doing so. I'll be surprised if changing the behavior > to yours and mine turns out to introduce a regression, but if it does, > I guess we'll then have to put it behind a sysctl or whatever. >=20 > IIUC the reason that it's currently implemented by clearing the hole > is because split_huge_page() (unlike in older refcounting days) cannot > be guaranteed to succeed. Which is unfortunate, and none of us is very > keen to build a filesystem on unreliable behavior; but the failure case= s > appear in practice to be rare enough, that it's on balance better to gi= ve > the punch-hole-truncate caller what she asked for whenever possible. I don't have a firm position here. Maybe you are right and we should try to split pages right away. It might be useful to consider case wider than shmem. On traditional filesystem with a backing storage semantics of the same punch hole operation is somewhat different. It doesn't have explicit implications on memory footprint. It's about managing persistent storage. With shmem/tmpfs it is lumped together. It might be nice to write down pages that can be discarded under memory pressure and leave the huge page intact until then... [ I don't see a problem with your patch as long as we agree that it's desired semantics for the interface. ] --=20 Kirill A. Shutemov