Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2273393ybv; Mon, 24 Feb 2020 02:23:31 -0800 (PST) X-Google-Smtp-Source: APXvYqzBLHPskOFyHJ/lZF2r5ixqok8M+TpKt+62D2GImOu54SLG6y1HkT0/GzKA0R4KqQjFVbfh X-Received: by 2002:a9d:7d93:: with SMTP id j19mr41345897otn.102.1582539811492; Mon, 24 Feb 2020 02:23:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582539811; cv=none; d=google.com; s=arc-20160816; b=OKRuTPJaqyAjxVUGxBGyJOJ5SVLQUIfnqx6WaPE7TfpKYnF4MvOTf0RDxdm4/41opl qxteXW9SwxRrNAyb2HssDISA3Rl5ORMyOwkVQCvRoeL5f0vUuM1V3DaU46/a66rxgpK8 hm4cjMzaIjFlOK0CiBDv86IVpedCfdHsvzUchK0yONiNrETKbFiMgsNtG7NjucAQBamw BKMFqtnp1nmh1EN55JeZbTAH17U1ZHXDEsePi6Vs6Bt2Y5auZweFjsdoffbKwgadb9uy L4joEj3bJN7RFcxCRzKPNPEMA/YmGLKq4xL6K0Ng/+05IzQP7uI+QHoUCMx45pLM5CY5 rmoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:from:references:cc:to:subject :dkim-signature; bh=9rgk9Zdx+FYiuqh5+++l0IjJ99Bb5VPxuLSjFzEaQAI=; b=G2DWXfgJKyZAxkK+jwizIXY4KOpMatgFuHaMlzE1gbbE8FfJET/lH2hZ3pSvD3/wS4 E8eMKNtvM7OCR17rNfD4Nuhtj+blDXDd5qbaxacTKQoZ5WFW317dbmOUK5KWnyF+C1AP 1+R41JsuuRMyO5ucGctRbIPjdBqXIFeaQCdLc+I8I73frj83QHui5+dXFGU58pZjq8Pq aDeQHI1SOAvyayUJSuodfJxLH2l17oLxm+ziYy61OinCRMsCXhVqp/jMufRcWBPvf5Tw RIkSirFgJ6nlcmcBj2f4qFYRPcsvbRrkiYfmlxAEXMwH0nz0xIg9hERW3gCGVFkJoCkt uFFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M3w8vzuW; 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 o13si6001317otp.27.2020.02.24.02.23.17; Mon, 24 Feb 2020 02:23:31 -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=M3w8vzuW; 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 S1727351AbgBXKWn (ORCPT + 99 others); Mon, 24 Feb 2020 05:22:43 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:27469 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727312AbgBXKWm (ORCPT ); Mon, 24 Feb 2020 05:22:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582539761; 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:autocrypt:autocrypt; bh=9rgk9Zdx+FYiuqh5+++l0IjJ99Bb5VPxuLSjFzEaQAI=; b=M3w8vzuWI8r2Ha7UCaxrSXPlP93Ye5iwXzHuiuvFx6/B6M11+g7Qbgt8wIRaoLKzXF0VUt 3oluD+EoJwExWkWd7IhE2j0jMJ+Ivy68dHOswO5SOKYeVP8eNfOVAhxuXWxpcVBmRyXq6V hGxCQVwt9S3DfrYR+GnYYuHbAaqi8DA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-37-JB8S9JRBOzy_WqCBWxRRrg-1; Mon, 24 Feb 2020 05:22:37 -0500 X-MC-Unique: JB8S9JRBOzy_WqCBWxRRrg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C85E107ACC4; Mon, 24 Feb 2020 10:22:36 +0000 (UTC) Received: from [10.36.118.8] (unknown [10.36.118.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C92C91853; Mon, 24 Feb 2020 10:22:28 +0000 (UTC) Subject: Re: [v2 PATCH] mm: shmem: allow split THP when truncating THP partially To: Alexander Duyck Cc: "Michael S. Tsirkin" , Yang Shi , Hugh Dickins , "Kirill A. Shutemov" , Andrea Arcangeli , Andrew Morton , linux-mm , LKML References: <1575420174-19171-1-git-send-email-yang.shi@linux.alibaba.com> <20200221040237-mutt-send-email-mst@kernel.org> From: David Hildenbrand Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= mQINBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jf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z5+ZIc6MSyGUozASX+bmIuPeIecc9UsFRatc91LuJCKMkD9Uv GOcWSeFpLrSGRQ1Z7EMzFVU//qVs6uzhsNk0RYMyS0B6oloW3FpyQ+zOVylFWQCzoyyf227y GW8HnXunJSC+4PtlL2AY4yZjAVAPLK2l6mhgClVXTQ/S7cBoTQKP+jvVJOoYkpnFxWE9pn4t H5QIFk7Ip8TKr5k3fXVWk4lnUi9MTF/5L/mWqdyIO1s7cjharQCstfWCzWrVeVctpVoDfJWp 4LwTuQ5yEM2KcPeElLg5fR7WB2zH97oI6/Ko2DlovmfQqXh9xWozQt0iGy5tWzh6I0JrlcxJ ileZWLccC4XKD1037Hy2FLAjzfoWgwBLA6ULu0exOOdIa58H4PsXtkFPrUF980EEibUp0zFz GotRVekFAceUaRvAj7dh76cToeZkfsjAvBVb4COXuhgX6N4pofgNkW2AtgYu1nUsPAo+NftU CxrhjHtLn4QEBpkbErnXQyMjHpIatlYGutVMS91XTQXYydCh5crMPs7hYVsvnmGHIaB9ZMfB njnuI31KBiLUks+paRkHQlFcgS2N3gkRBzH7xSZ+t7Re3jvXdXEzKBbQ+dC3lpJB0wPnyMcX FOTT3aZT7IgePkt5iC/BKBk3hqKteTnJFeVIT7EC+a6YUFg= Organization: Red Hat GmbH Message-ID: <939de9de-d82a-aed2-6a51-57a55d81cbff@redhat.com> Date: Mon, 24 Feb 2020 11:22:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >>> 1. we can probably teach QEMU to always use the pbp >>> machinery - will be helpful to reduce number of madvise calls too. >> >> The pbp machinery only works in the special case where the target page >> size > 4k and the guest is nice enough to send the 4k chunks of a targ= et >> page sequentially. If the guest sends random pages, it is not of any u= se. >=20 > Honestly I hadn't looked that close at the code. I had looked it over > briefly when I was working on the page reporting logic and had decided > against even bothering with it when I decided to use the scatterlist > approach since I can simply ignore the pages that fall below the > lowest order supported for the reporting. Yes, it's rather a hack for a special use case. >=20 >>> >>> 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. >> >> The balloon works on 4k pages only. It is expected to break up THP and >> harm performance. Or if that's not possible *do nothing*. Similar to >> when balloon inflation is inhibited (e.g., vfio). >=20 > Yes, but I think the point is that this is counter productive. If we > can allocate something up to MAX_ORDER - 1 and hand that to the > balloon driver instead then it would make the driver much more > efficient. We could basically just work from the highest available > order to the lowest and if that pushes us to the point of breaking up > THP pages then at that point it would make sense. Us allocating the > lower order pages first just makes it more difficult to go through and > compact pages back up to higher order. The goal should really always > be highest order to lowest order for inflation, and lowest to highest > for deflation. That way we put pressure on the guest to compact its > memory making it possible for us to squeeze it down even smaller and > provide more THP pages for the rest of the system. While the initial inflate path would be fine, I am more concerned about deflation/balloon compaction handling (see below, split to order-0 pages). Because you really want to keep page compaction working. Imagine you would allocate higher-order pages in your balloon that are not movable, then the kernel would have less higher/order pages to work with which might actually harm performance in your guest. I think of it like that: Best performance is huge page in guest and host. Medium performance is huge page in guest xor host. Worst performance is no huge page. If you take away huge pages in your guest for your balloon, you limit the cases for "best performance", esp. less THP in your guest. You'll be able to get medium performance if you inflate lower-order pages in your guest but don't discard THP in your host - while having more huge pages for THP available. You'll get worst performance if you inflate lower-order pages in your guest and discard THP in your host. >=20 >> There was some work on huge page ballooning in a paper I read. But onc= e >> the guest is out of huge pages to report, it would want to fallback to >> smaller granularity (down to 4k, to create real memory pressure), wher= e >> you would end up in the very same situation you are right now. So it's= - >> IMHO - only of limited used. >=20 > I wouldn't think it would be that limited of a use case. By having the > balloon inflate with higher order pages you should be able to put more > pressure on the guest to compact the memory and reduce fragmentation > instead of increasing it. If you have the balloon flushing out the > lower order pages it is sitting on when there is pressure it seems > like it would be more likely to reduce fragmentation further. As we have balloon compaction in place and balloon pages are movable, I guess fragmentation is not really an issue. >=20 >> With what you suggest, you'll harm performance to reuse more memory. >> IMHO, ballooning can be expected to harm performance. (after all, if y= ou >> inflate a 4k page in your guest, the guest won't be able to use a huge >> page around that page anymore as well - until it compacts balloon >> memory, resulting in new deflate/inflate steps). But I guess, it depen= ds >> on the use case ... >=20 > I think it depends on how you are using the balloon. If you have the > hypervisor only doing the MADV_DONTNEED on 2M pages, while letting it > fill the balloon in the guest with everything down to 4K it might lead > to enough memory churn to actually reduce the fragmentation as the > lower order pages are inflated/deflated as we maintain memory > pressure. It would probably be an interesting experiment if nothing > else, and probably wouldn't take much more than a few tweaks to make > use of inflation/deflation queues similar to what I did with the page > reporting/hinting interface and a bit of logic to try allocating from > highest order to lowest. >=20 Especially page compaction/migration in the guest might be tricky. AFAIK it only works on oder-0 pages. E.g., whenever you allocated a higher-order page in the guest and reported it to your hypervisor, you want to split it into separate order-0 pages before adding them to the balloon list. Otherwise, you won't be able to tag them as movable and handle them via the existing balloon compaction framework - and that would be a major step backwards, because you would be heavily fragmenting your guest (and even turning MAX_ORDER - 1 into unmovable pages means that memory offlining/alloc_contig_range() users won't be able to move such pages around anymore). But then, the balloon compaction will result in single 4k pages getting moved and deflated+inflated. Once you have order-0 pages in your list, deflating higher-order pages becomes trickier. E.g., have a look at the vmware balloon (drivers/misc/vmw_balloon.c). It will allocate either 4k or 2MB pages, but won't be able to handle them for balloon compaction. They don't even bother about other granularity. Long story short: Inflating higher-order pages could be good for inflation performance in some setups, but I think you'll have to fall back to lower-order allocations + balloon compaction on 4k. --=20 Thanks, David / dhildenb