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=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 43F8FC11D0C for ; Thu, 20 Feb 2020 18:17:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 02D702051A for ; Thu, 20 Feb 2020 18:17:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jQemFjxS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02D702051A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A083B6B0007; Thu, 20 Feb 2020 13:17:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B8FC6B000E; Thu, 20 Feb 2020 13:17:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A7CF6B0010; Thu, 20 Feb 2020 13:17:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id 70B276B0007 for ; Thu, 20 Feb 2020 13:17:07 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 212498248D52 for ; Thu, 20 Feb 2020 18:17:07 +0000 (UTC) X-FDA: 76511312094.04.feast44_5b2f7b1253a4c X-HE-Tag: feast44_5b2f7b1253a4c X-Filterd-Recvd-Size: 5405 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 18:17:06 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id n21so5713729ioo.10 for ; Thu, 20 Feb 2020 10:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bkxRzQQdsIgezztPpGEXgB6Tbmhl9XsKSgHs8oMS58Y=; b=jQemFjxSgs+RoEzDujDqc912isO0FUO0iIwvqLQJMChzH/Gmf/croCHJidjUYYZCqQ lw9uK4DfNAdkD1ouXwdr9zyhQ6VigKaKkJPZg1+hgfKhT0C3+Xe5FoiZ7heBU+OjjsM0 y2DEJ/IzOZHgfE4ixY90KY5gtlpiaqKTeoWx6VCXN3DN+yfIpjZ6uo6KCNllAS1sQ8sU HGKU1F1G01iyehjfju6BPOSbJ4Atfis29U0cvBqqebpduIoBhW1PKPZ8qlV3lTgYLKLM 2X4HqP62mlgsviOvsMA2/YpXRxYbtLOTyR4K+l+JmAp36GrNmP2ZVf7QND7JYCMmW/x+ gboA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bkxRzQQdsIgezztPpGEXgB6Tbmhl9XsKSgHs8oMS58Y=; b=Hr8Kdi8pi+a5kB1cJKq4Q5+APXEyICSukON+zDfwT2TZUCAtF8NecBbUJ3ecxyhtO5 A2W3BVxOIMomO5gbAOW8Y1vARhubYo+Ix5+QerYff+w/FHtQDSczG7pisizKa44nd/d8 5ou3GK7yrQKQoDVAT/5daIEGnSwUVP/9EEIc/MYjsARvUf1TALyq8c7bDLJcdKBgpKZi 8jS+xvRQqqoMGLfAu5zo4vMqhP5ZSRzIoU+0zeaLPkIUCVJ4tSy63Mp0A6eSvePY2uTQ gSqsBiqbb3YcncKJBFL93tyMLJos1idNjsWlTkhAy4s9jblWXRYvwa0O+1H3fuxejskQ zirg== X-Gm-Message-State: APjAAAXruxiguaSdb6/T29+eu39oTOLe3w42ZsX9pzzL11Tv3oEPxQD8 9zMZtxqvQxhy0xl9Vk+/y9d0y2Pc93rX+be/nMU= X-Google-Smtp-Source: APXvYqysOLP0nXkKrh7QibdX9lVVNj1wUJPOGTNbIYlXM9+byhTu1Mczx/ZINDwIE2aoIO/UgYE+T2O1d6xPrMxlzu8= X-Received: by 2002:a6b:6205:: with SMTP id f5mr26192797iog.42.1582222625697; Thu, 20 Feb 2020 10:17:05 -0800 (PST) MIME-Version: 1.0 References: <1575420174-19171-1-git-send-email-yang.shi@linux.alibaba.com> In-Reply-To: <1575420174-19171-1-git-send-email-yang.shi@linux.alibaba.com> From: Alexander Duyck Date: Thu, 20 Feb 2020 10:16:54 -0800 Message-ID: Subject: Re: [v2 PATCH] mm: shmem: allow split THP when truncating THP partially To: Yang Shi , "Michael S. Tsirkin" , David Hildenbrand Cc: Hugh Dickins , "Kirill A. Shutemov" , Andrea Arcangeli , Andrew Morton , linux-mm , LKML Content-Type: text/plain; charset="UTF-8" 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, 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. - Alex