Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1134139ybb; Thu, 28 Mar 2019 21:00:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlNfHohUdgvy0DBOuOYCwayB2sidSTaLFHlqj3tZxdGSt35Rp3678nLUibZ90xWqj095oK X-Received: by 2002:a62:480d:: with SMTP id v13mr45609879pfa.125.1553832050684; Thu, 28 Mar 2019 21:00:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553832050; cv=none; d=google.com; s=arc-20160816; b=xEd7XtZMnSzIID6HXVZF7etzjnI75pPLZNuNyUeYOxwHXOU+++hP/wvpAZaIWp8U8o iyl5vltjhoyyaT3S44vsV9zVYpvyXPWB/7M2GqVA3TFi5ffQyeQVszKhSXKp8qjb1lfq G+ams/Gfe37bfhluRJ4GVnTwGiuIylir+D2KDqtE+fJmx2mj0YWJkIW7ZDjoxyzAxY79 wqEClNqUWSO++4L1JMrModuMR8We3gAV7qdr4VuZZk7AedJ/gFxJhhesETH4C1vaGlKy 2GOgkoCs3d5ZKa/WLEKjlxBFAdDJ6lo+zsJKjEtMMus4ojzUGIVR8QF7bEwLxlTRR7R9 t2pQ== 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=sodBEomwfUZX4txDWtjSVMZxEBAIq/0o8L2NFyjYD0g=; b=ccWyJGoTgLD1JiLQm0Ky+61Su/yAjD1MYKWwduFOt3vjQZqzMHB90MYlFCHrx72mga P6s5LITFCC83prgjCVx/5NZjRGNTwRe0/E1PMd236dH8VkA6k9BKbFa/PrIZ5x+UIlET W81/4vAehRGrmaMtcg0eoMqk+5gm7j6rpDuPyaTlsbFIr/8PsgZf4a4VtJEa3avkkshp MjDIKMuB3M1cCBO3iKy/jahMB6AR7vUjhcLEhWY4et6RAtYLQjfS86tfPTXgI7/fUqI3 bwdD+3J5Er4JE8jO7IuiBQZjEvJV46mZeCp3GSZGhgSScMcsLnIkVR/rNRBlCCLau1QK BpvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EkcTR7Mh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si946543pgc.156.2019.03.28.21.00.34; Thu, 28 Mar 2019 21:00:50 -0700 (PDT) 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=@google.com header.s=20161025 header.b=EkcTR7Mh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728589AbfC2D75 (ORCPT + 99 others); Thu, 28 Mar 2019 23:59:57 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:34844 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726250AbfC2D75 (ORCPT ); Thu, 28 Mar 2019 23:59:57 -0400 Received: by mail-yw1-f67.google.com with SMTP id d132so234099ywa.2 for ; Thu, 28 Mar 2019 20:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sodBEomwfUZX4txDWtjSVMZxEBAIq/0o8L2NFyjYD0g=; b=EkcTR7MhCLUJ3wg1Mkfze+pvFsS9FB7+CPtJTkogY2qjrCBEdYGc1kiyAGuFvCKbFX /i3X0AdR8j1gSbjYvOqorKAxMkFweTtSd3UfZW6lzzItqCBTx2wG/e8X0/Sv6auOmel6 3w4v/O/rNX74uhId2sTheecpJUaZGonuf10NeAc9RXnfWan/Dgxn/0a5psLOH55uOZvZ rG4OaN15bq3MAiQGV7Q4jjmSOldrVYzzDyky9mMZ3oozjvW/EHRclj7HEPvtKOAMk1ZC LpTpok6yvbeh61jPs1j2Nb1prK/UfFE9QnuBubIq8wY6AwhnFDjcQnN0Pw/PpbcWXRiI qrFQ== 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=sodBEomwfUZX4txDWtjSVMZxEBAIq/0o8L2NFyjYD0g=; b=gV76e1WhA4UI7ZGFq9Qpg/cQiynjMgj86jTmop76nD+rKB/o+RuBOMkbYj0WF0viVk SyOKrbOn8SFRrHWcopRx+Y3Rnh3xsFMSXs4wdC8o/AxPcVBmhG2ge9FCzvLP6xKLKYfD 6VYgP56FNcNXPre8dGdCcPi2B6zoAFOEeEauqA6V+3NXmguVexgoZvNAprmLBgdDC2CX JbmCX2WfPqWmT01tH4OU+BrCaUZe3TBYdgOKEeKhj+YFID1/KGfIOHVV8/vakhdI/rOc q4h2xQcbEHTPrpAUSFcNVyQKhIuIZbCXTerwS/RYe4XPFXoIpk8pj8RCAqXKuAkVwxUV xG+g== X-Gm-Message-State: APjAAAX70HKqdwCvBqW1W/e6lTkj1VxpYTQ2YdvujQJ3I2sEKJeVCeOh HaFkoZPzx2AXZDodtPg7C9U0uri6B36/lgXusUQC2Q== X-Received: by 2002:a81:1b52:: with SMTP id b79mr39274302ywb.285.1553831996530; Thu, 28 Mar 2019 20:59:56 -0700 (PDT) MIME-Version: 1.0 References: <20190329012836.47013-1-shakeelb@google.com> <20190329023552.GV10344@bombadil.infradead.org> In-Reply-To: <20190329023552.GV10344@bombadil.infradead.org> From: Shakeel Butt Date: Thu, 28 Mar 2019 20:59:45 -0700 Message-ID: Subject: Re: [RFC PATCH] mm, kvm: account kvm_vcpu_mmap to kmemcg To: Matthew Wilcox Cc: Johannes Weiner , Vladimir Davydov , Michal Hocko , Andrew Morton , Paolo Bonzini , Ben Gardon , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Linux MM , kvm@vger.kernel.org, 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 Thu, Mar 28, 2019 at 7:36 PM Matthew Wilcox wrote: > > On Thu, Mar 28, 2019 at 06:28:36PM -0700, Shakeel Butt wrote: > > A VCPU of a VM can allocate upto three pages which can be mmap'ed by the > > user space application. At the moment this memory is not charged. On a > > large machine running large number of VMs (or small number of VMs having > > large number of VCPUs), this unaccounted memory can be very significant. > > So, this memory should be charged to a kmemcg. However that is not > > possible as these pages are mmapped to the userspace and PageKmemcg() > > was designed with the assumption that such pages will never be mmapped > > to the userspace. > > > > One way to solve this problem is by introducing an additional memcg > > charging API similar to mem_cgroup_[un]charge_skmem(). However skmem > > charging API usage is contained and shared and no new users are > > expected but the pages which can be mmapped and should be charged to > > kmemcg can and will increase. So, requiring the usage for such API will > > increase the maintenance burden. The simplest solution is to remove the > > assumption of no mmapping PageKmemcg() pages to user space. > > The usual response under these circumstances is "No, you can't have a > page flag bit". > I would say for systems having CONFIG_MEMCG_KMEM, a page flag bit is not that expensive. > I don't understand why we need a PageKmemcg anyway. We already > have an entire pointer in struct page; can we not just check whether > page->mem_cgroup is NULL or not? PageKmemcg is for kmem while page->mem_cgroup is used for anon, file and kmem memory. So, page->mem_cgroup can not be used for NULL check unless we unify them. Not sure how complicated would that be. Shakeel