Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2181316ybv; Fri, 21 Feb 2020 10:25:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxuScC0Yk8C4s02z8T9R/+Ev2GQY7dQpAyCKq+x7FjfihuDD0IAZvSeIppS6/m+wwSeFZSc X-Received: by 2002:aca:ec15:: with SMTP id k21mr3065530oih.35.1582309557153; Fri, 21 Feb 2020 10:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582309557; cv=none; d=google.com; s=arc-20160816; b=iQUlBVg7Z5CQ4Td9S+QhgGfZxYPlDUsHbIlSKKLgQ+m4pMmWLr19nMmn4S02uwnF7V B5t/HWXHSujOu9rF86bjcUrKW7ZWzbLVWn8amZ+pgkXcwhZAT5QEZ5GPBS8F2LyHoHCX 0k2Tw6Tf3h47ZHLS9WrWlw/xTpK07ekISXt1nXfDLlCaGIYE7QAdUiac5P8HcC3gf+kB LEMLpSeCoOsKd1yIF1be5DiWSVTNndHFTyK9yUInYhOsE0pD+Hm7s6v4k7AsoKPg6Rky AdssAclSady845NDdvwPQIe9QL5trWy98T7vzpmlgHwhuio5wN1T1N2s4Qut5RVvA/KW SD/g== 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=CnUqsHb0qVf8YceLTwZISB+nLiwN2zVgnI+vvvLwA7U=; b=xReO9kb2kTIJ2zChh/GK2z/y8JR5QVVZMAJQ6uZCICOCrikpNKMQMXpvW4o+v0wwU8 dgrMbCnDEX6BdrQAplcs79yMaVdtwUPTzDkS9X+czPG6Ec47dhnfpZBR6soH9ecDdmVG SfOrruonSpGoDVH5d3Q91asm3h5FWmVT00l4jFpXJDA6rUNj8KcHeljRuv8WPY4olqbZ pMoBMWGh+lIaBggRIzh0qFArfNqabuPFS4ZW8tv5t58AKtN3HwVWas1xs2kFG7J1JrLv uHQQN/XZKSG22Plriwp0F1U9cluoNkgU/fWxmRBetRFYSD+1BV4vzo3rqgsSXFAKABr3 Eq9w== 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 l140si1154507oib.114.2020.02.21.10.25.44; Fri, 21 Feb 2020 10:25:57 -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 S1729589AbgBUSYW (ORCPT + 99 others); Fri, 21 Feb 2020 13:24:22 -0500 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:54280 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbgBUSYW (ORCPT ); Fri, 21 Feb 2020 13:24:22 -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=e01e04400;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0TqXYzc5_1582309453; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TqXYzc5_1582309453) by smtp.aliyun-inc.com(127.0.0.1); Sat, 22 Feb 2020 02:24:16 +0800 Subject: Re: [v2 PATCH] mm: shmem: allow split THP when truncating THP partially To: Alexander Duyck , "Michael S. Tsirkin" , David Hildenbrand Cc: Hugh Dickins , "Kirill A. Shutemov" , Andrea Arcangeli , Andrew Morton , linux-mm , LKML References: <1575420174-19171-1-git-send-email-yang.shi@linux.alibaba.com> From: Yang Shi Message-ID: <9b8ff9ca-75b0-c256-cf37-885ccd786de7@linux.alibaba.com> Date: Fri, 21 Feb 2020 10:24:11 -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: 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/20/20 10:16 AM, Alexander Duyck wrote: > On Tue, Dec 3, 2019 at 4:43 PM Yang Shi wrote: >> Currently when truncating shmem file, if the range is partial 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. This might be fine for some >> usecases which prefer preserving THP. >> >> But, when doing balloon inflation in QEMU, QEMU actually does 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 actually doesn't >> work as expected since it doesn't free memory. But, the inflation >> usecase really needs get the memory freed. Anonymous THP will not get >> freed right away too but it will be freed eventually when all subpages are >> unmapped, but shmem THP would still stay in page cache. >> >> Split THP right away when doing partial hole punch, and if split fails >> just clear the page so that read to the hole punched area would return >> zero. >> >> Cc: Hugh Dickins >> Cc: Kirill A. Shutemov >> Cc: Andrea Arcangeli >> Signed-off-by: Yang Shi > One question I would have is if this is really the desired behavior we > are looking for? > > By proactively splitting the THP you are likely going to see a > performance regression with the virtio-balloon driver enabled in QEMU. > I would suspect the response to that would be to update the QEMU code > to identify the page size of the shared memory ramblock. At that > point I suspect it would start behaving the same as how it currently > handles anonymous memory, and the work done here would essentially > have been wasted other than triggering the desire to resolve this in > QEMU to avoid a performance regression. > > The code for inflating a the balloon in virtio-balloon in QEMU can be > found here: > https://github.com/qemu/qemu/blob/master/hw/virtio/virtio-balloon.c#L66 > > If there is a way for us to just populate the value obtained via > qemu_ram_pagesize with the THP page size instead of leaving it at 4K, > which is the size I am assuming it is at since you indicated that it > is just freeing the base page size, then we could address the same > issue and likely get the desired outcome of freeing the entire THP > page when it is no longer used. If qemu could punch hole (this is how qemu free file-backed memory) in THP unit, either w/ or w/o the patch the THP won't get split since the whole THP will get truncated. But, if qemu has to free memory in sub-THP size due to whatever reason (for example, 1MB for every 2MB section), then we have to split THP otherwise no memory will be freed actually with the current code. It is not about performance, it is about really giving memory back to host. > > - Alex