Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp956474ybv; Thu, 20 Feb 2020 10:17:36 -0800 (PST) X-Google-Smtp-Source: APXvYqyCACVFK/a65t/e7vQ//UrnuSz/TpFiUw0ZnvqH7AHs5o2DkGBDh9wBKEjkbg23iEColTG4 X-Received: by 2002:a9d:34c:: with SMTP id 70mr23193568otv.174.1582222655916; Thu, 20 Feb 2020 10:17:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582222655; cv=none; d=google.com; s=arc-20160816; b=XP9nZhcM3NVrpM7Hxb/CheLEw8L05ewGVfHLr1dvz2OuZlozJ/inbgTWmXUDQcfYte E1xLmXO9vdld/XReCJv2+mAoTBLlonlP6MpfKQYWE5M1aA4b8vZf+ekP0TNFgGnN5aOm d7NOM/uTTAmODEAnY9GciGRwl+82/Gs+JeF7wy3J1WFuUez1t4qlmp1YlromF+kmVXan D/4doqSRNwUKk+hayDcYPsy4+GmABzeG66+O2Mqp6GIRiZ0iVGLF8PnTbuBUaNGVGfJp rAraik+V1ZOAP2KFvB2ad2zxXWSBsM5S7nUYjO/mOCI8akE4emaMIUHlx3OAxxkynmIn Lztg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bkxRzQQdsIgezztPpGEXgB6Tbmhl9XsKSgHs8oMS58Y=; b=OUlgKloPrEhs5PW/QnB8jpmK8ASSFYmhponk5z0uvN62XLjTKiPgmHJRHWJOOSf44I vHfROjsTZF62ziwXfe3X4iG0IumwjmIg6Aar1Ewdhh35Rv1mORbxpnT77clZBfHLsf4G AfpGSHOhSO23KXJKe10+/Cp7LtLFeAX1A/emcDtX9MuTFmJAVFW/kbwCyLMiLPpn1I+M zMfF65EtEqYjAaDC3hB4YxwYMiVZ8IfZ6EOF2ITfk1uNvZr00eAAAb1MKXkAYLHnvonB nhB9KR9HyCEJ3pO3odVrAwhLIgjFTkgwxDHAmQflfUGjaxSVdzq8kNLUAuSPTi6azO4K zpOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jQemFjxS; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si89684otf.32.2020.02.20.10.17.23; Thu, 20 Feb 2020 10:17:35 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jQemFjxS; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728217AbgBTSRG (ORCPT + 99 others); Thu, 20 Feb 2020 13:17:06 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:38075 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbgBTSRG (ORCPT ); Thu, 20 Feb 2020 13:17:06 -0500 Received: by mail-io1-f67.google.com with SMTP id s24so5745466iog.5 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=tdO4hXUAhfQSa88HFh8ttBOHPAPgBnnY3Ef1Vzdd5Xer+i+gog/4foZM1JXxkL8M8Y 4nsDQKW09zH3UrFr6yMQdqrobPlrDqvTrXnedAPB0tE3/eWVQ+a86OafdfNdgZ/zV4R1 hiVs+9GLcYohgpcg1x7xJF747+2vKeksNaFNbJ7pyykYem+wf4iqpsqTRSXbH0K8l12y 4nMdMHEjNGNolGiClwI2PHJ3PZ5l8Q8417wAKYOvFNWfwo/qHlfU7rzSNQn7sJg0kLBC v4L9xeipWF5GvTez5ibm908BCzUY1eQUMk/5hZ36rWETQVkkNT1U3/VASzsWpNews+Q7 etyA== X-Gm-Message-State: APjAAAUTVp5jrNo0xazAxPshF+nGhPnOinCkEGtkIPUemK8FtY9Mk3fX GBmooakaP95cDwEbNr9Mxjb6l0v89AmLDaZJXfY= 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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