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.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 5717AC35642 for ; Fri, 21 Feb 2020 09:07:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C49920679 for ; Fri, 21 Feb 2020 09:07:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a+kB5OdL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C49920679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9909F6B0010; Fri, 21 Feb 2020 04:07:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 942966B0032; Fri, 21 Feb 2020 04:07:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82F746B0036; Fri, 21 Feb 2020 04:07:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0163.hostedemail.com [216.40.44.163]) by kanga.kvack.org (Postfix) with ESMTP id 68CEF6B0010 for ; Fri, 21 Feb 2020 04:07:13 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E89F28248047 for ; Fri, 21 Feb 2020 09:07:12 +0000 (UTC) X-FDA: 76513555104.21.quilt83_46e31a439809 X-HE-Tag: quilt83_46e31a439809 X-Filterd-Recvd-Size: 6931 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Feb 2020 09:07:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582276029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LdIaN9rLgZRpM6IRH8HOljKzx/aTlF3QVXu9T0y+adg=; b=a+kB5OdLsb8cPDWHUeV7ezGHodtYujXNjdYTpmsZFUoImfXvywmFfcZnQ0aLovFdUI9cGz aK9K04lOyKFnNRr8fzvuxT05IDkmfz6L0u2kQuyV0/BbdmjIYS/qwKarnS7aND6j5J6KOX +tVyZ0vWEQajCvonGuu/0u36EuoMulc= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-tsO7XAcpPLeJVOrKUGzeGw-1; Fri, 21 Feb 2020 04:07:07 -0500 Received: by mail-qt1-f200.google.com with SMTP id c10so1180797qtk.18 for ; Fri, 21 Feb 2020 01:07:07 -0800 (PST) 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:in-reply-to; bh=GREwfrgxkk1HbO+SZaRpjMMVBwgQQJRkF803U5Z9C54=; b=h+14i9gJnApTHPVkzTP2F36ukyxzTZM+eQyDonXSFdImPIIlmaieo/vQ8dt58Ccy50 TYtQ5UE+c8xlDUSYwUk4I6Ub5JjULnhRmwoS365Nb4H5eQgFqxwZEP4crInK4Q5PL55a 9gHueVQl1MVaz9sCLnJBFsZv2sk6blzPz0uboaUsMXENPNDGMie+SIKdlhImLYlwhIXw tvJPoInvDP3irGHis/k6wFlZ48QNVXE01LiH9/KKxkza0RXcUtqfRQkmSjlFHYMDzkNU QxKzK2o6362n+MKDZKtGIjIiCE5uoz1NPtvuGlzj0g6vgVpi3B4Gfid2nvRiNlMQmlWs 953A== X-Gm-Message-State: APjAAAVi4RPJldvvlJcjmFu5/33XiBBfAqPTXlifEVpskBfjBy04l33O c/b2VH1qFxuW25GVdA3BttHXiaZAC49lGFY691RLXskzJVWsHqiCOkimc9lxWmrnVIP6Wnb250I Wm0IcqEt93r8= X-Received: by 2002:a37:a4cf:: with SMTP id n198mr1543814qke.194.1582276026622; Fri, 21 Feb 2020 01:07:06 -0800 (PST) X-Google-Smtp-Source: APXvYqx1yfT9Eg0qzuzZet7xGSWjuarIHmnyu/s75tE6f74fiWaY7L+P44sC2l0CgRisg/MBESaIGg== X-Received: by 2002:a37:a4cf:: with SMTP id n198mr1543800qke.194.1582276026376; Fri, 21 Feb 2020 01:07:06 -0800 (PST) Received: from redhat.com (bzq-109-67-14-209.red.bezeqint.net. [109.67.14.209]) by smtp.gmail.com with ESMTPSA id w1sm1262373qtk.31.2020.02.21.01.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 01:07:05 -0800 (PST) Date: Fri, 21 Feb 2020 04:07:00 -0500 From: "Michael S. Tsirkin" To: Alexander Duyck Cc: Yang Shi , David Hildenbrand , Hugh Dickins , "Kirill A. Shutemov" , Andrea Arcangeli , Andrew Morton , linux-mm , LKML Subject: Re: [v2 PATCH] mm: shmem: allow split THP when truncating THP partially Message-ID: <20200221040237-mutt-send-email-mst@kernel.org> References: <1575420174-19171-1-git-send-email-yang.shi@linux.alibaba.com> MIME-Version: 1.0 In-Reply-To: X-MC-Unique: tsO7XAcpPLeJVOrKUGzeGw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 Thu, Feb 20, 2020 at 10:16:54AM -0800, Alexander Duyck wrote: > On Tue, Dec 3, 2019 at 4:43 PM Yang Shi wrot= e: > > > > 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 ge= t > > 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 punc= h > > or MADV_DONTNEED in base page size granulairty if hugetlbfs is not used= . > > So, when using shmem THP as memory backend QEMU inflation actually does= n'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 >=20 > One question I would have is if this is really the desired behavior we > are looking for? >=20 > 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. >=20 > 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 >=20 > 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. >=20 > - Alex Well that would be racy right? It could be THP when you call the function, by the time you try to free it, it's already split up ... Two more points: 1. we can probably teach QEMU to always use the pbp machinery - will be helpful to reduce number of madvise calls too. 2. Something we should do is teach balloon to inflate using address/length pairs instead of PFNs. This way we can pass a full THP in one go. --=20 MST