Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1663185ybv; Fri, 21 Feb 2020 01:14:49 -0800 (PST) X-Google-Smtp-Source: APXvYqwG4gS80H31o3O/OQ93/T1BPkGFr4d7KNV1YKcYBBuKCp57JSRTq/p+fEXTeeilzKO1IXNQ X-Received: by 2002:a9d:20a:: with SMTP id 10mr26385303otb.319.1582276489704; Fri, 21 Feb 2020 01:14:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582276489; cv=none; d=google.com; s=arc-20160816; b=qzm2+vuD067OTK75lq1TfRLZfh8tMhyegawvlpoCiv81uRtA/O8ufyalTopVL6IH/u B2woNAxXfekz6wegYo/hINps+fAqr1d028+AxhQ3E2dqskVutjg/H1FhLDyceIwMJtCT GyqfaD5bkIAS2ppo+5gxfzd2SSCBiAHvJdpaW4IwMe/zyq1EzPVIC8eHkauUXZorpSco l7HV1mNaHZCBcu5z4s4tTV1GAVNvGWrFDwMZyfjM/XdKQCrBw0s2Io+CSLget0H8708g bk+9BylEEVicBbYMLAoNVPu67EPeugujAe4adVw+f1pWYY1u7CdYOVmbg16w3abf6UNn ETdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=GREwfrgxkk1HbO+SZaRpjMMVBwgQQJRkF803U5Z9C54=; b=QRgk9n4NrR06d1yaraWvivzVq6IN6WQ/vVw3OVR0fScuv1S8y4MgOgYQ6lKjyo5/JT YN1MDSsuHGZBu+aQB/EkxlyyRMeN7u+CSza7JpT5QXq1S1j/Mjy37uwWH40OzjrqbO5t VZxMBkOHFi+felcRsDyjqTz64Y+ootBu/ukGxyBFzCAD29rOGVOatP5keM+FKbehwTCs i9prpt1IQRLyQ8ZaoeIFkBtZyRrVN5d/RH6+qf1M+Mbh9COE4D+/Gk37CJlficUiWTyA SwgU0LwTzg/GGGRhRTA5/2LlSY/mbYBStx5JNSRe7ISh771H13ltsb/pGY4uQjtKJiK4 1BRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=clLQ6l6T; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w17si1155767oti.75.2020.02.21.01.14.37; Fri, 21 Feb 2020 01:14:49 -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=@redhat.com header.s=mimecast20190719 header.b=clLQ6l6T; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727742AbgBUJHL (ORCPT + 99 others); Fri, 21 Feb 2020 04:07:11 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20781 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727629AbgBUJHL (ORCPT ); Fri, 21 Feb 2020 04:07:11 -0500 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: in-reply-to:in-reply-to:references:references; bh=GREwfrgxkk1HbO+SZaRpjMMVBwgQQJRkF803U5Z9C54=; b=clLQ6l6Tr8GG4aVn4CDeGiYvneqFOjvjKL5nahXLPoMUsgTWIOQkMmFQzhifry8nfG+Cao /UOoL0vGN9jkWlKREiOf4+VsXW/4grj6jRqSo0I9kp2PB8cwGM3jSUx2lqSmZDCFdGDP9z ilCwVQ5Pfcc/0xzrgrRGeNhXzqhj7UA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-302-x6k32M7WOVWOg9Nm-d5hjw-1; Fri, 21 Feb 2020 04:07:07 -0500 X-MC-Unique: x6k32M7WOVWOg9Nm-d5hjw-1 Received: by mail-qv1-f72.google.com with SMTP id p3so916169qvt.9 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=UGJaxlszWYRHGP0nc/qWcHbppke+5F6U0szu/XIYEtPmxCHBxRc62V7nbKSlFGbxTF o2R5Cz3EcH1GddZcvwyBFY5+C9pqhb4q7DK30xwtZMVyMGyDN5pMcY9iIp/XHTvqmvaT uVUP0EHF5ARZuZssVZ4ut8UfEtWEWFhOQ3JFfbhfDXw93xlvWkQtEOty3Je1PJurMhAi 7SweoHhLRZMCMf2KqYInLhgXvYnI4BOnQPvgQG8KAWWyJSyNq7amMw5u0IxD0D0QFgYd UYjZjqaGxXMnqZsKllIHWRbvRCcn/g+SJBp+uQebwbh2P62yDdaW4VpF0ppARrgzplYt 9+rw== X-Gm-Message-State: APjAAAWNNBZ2+PioCJh3O4hXrwSmbdtpk8/WViIG+0ZLE5Q8t50VL6w+ Plo3+8VSlee5UcaDQa94rGofuZvh7D0VhSKl5Liwix3/xJDYxytQuP5YJfbQhVZyyLqUeQ5dKP1 SWJak74HwJGEn8PLB7Tp9LA05 X-Received: by 2002:a37:a4cf:: with SMTP id n198mr1543819qke.194.1582276026622; Fri, 21 Feb 2020 01:07:06 -0800 (PST) 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 20, 2020 at 10:16:54AM -0800, 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. > > - 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. -- MST