Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2109815yba; Sat, 27 Apr 2019 14:49:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnD+AVPOn8H8ey2SCoLs6yKXIVNR+ZhToxgHvCnZgBaYumHR680GoD4pIiQEtRe30Whjwl X-Received: by 2002:a63:5d3:: with SMTP id 202mr3616562pgf.363.1556401774178; Sat, 27 Apr 2019 14:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556401774; cv=none; d=google.com; s=arc-20160816; b=uf0pZZ/XNL0StkKvCmVot7cIW8ZYWVkWgv3KSz0aBvnYZM0tpoT7wsbMriDZILacTi W12HjMGUZpqAq6yiHXWvDOu6FhCJTqj+wYA8gjqmGkeMuAoibzQa2OwoDLEGe64NKp1m xYV9EYj1vAx1o+KJ3LllhU8pkEulpmPamoArNKdYvRNmzQ81V57OVPsBbwya2nI3zamA jHorJzkqILMR0A6ptI0a/SMJesslqDTalUNd0uToEFSwQiWw+lldYHwfS7zFOGHBfYwN R/RVpOglZxTuqr698B8etZmYarIUSzsmJyyOk+iIPVMeBP9hTWUC8dkfSIJD3z2CSj3S ya9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lGCktDZhO9yy3XwpF+5iW72ZtqBr/yzzAAemZw+ANno=; b=sEFNe43thTilZERlIpCsoahxaBHisi0zU+nxW8QCyN9R/NsmjKfmBc+8crd6DFmaXz uPPcTM7VG8eM0Cz6AKXBZnS6RFPTFVo9shEVEDQunaZI1S9WBZF0V/ZgGff+vdv8PZCm RfNzY2h5XbP1/Ts9AooO5Dp6SwrAftp3DMcQUuG7/8hscPdpfNtn/AExR+TZKVQTZkTL b2/3CylUx2Xj693WySAUzJyp0EhzuX99lIag7avyjdiY3MZ7m6SzQ1vS4jBej52xmljJ KP/3a6H97QGxhs1DrcFGRXVUlV7EOkRE33jKPibn/7Em7lTqGx7iqneYW3LVTPby8QP4 fsyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nBfVQdii; 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 i27si27497854pgl.305.2019.04.27.14.49.07; Sat, 27 Apr 2019 14:49:34 -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=@gmail.com header.s=20161025 header.b=nBfVQdii; 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 S1726302AbfD0Vp2 (ORCPT + 99 others); Sat, 27 Apr 2019 17:45:28 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34770 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbfD0Vp2 (ORCPT ); Sat, 27 Apr 2019 17:45:28 -0400 Received: by mail-lj1-f196.google.com with SMTP id s7so3305851ljh.1; Sat, 27 Apr 2019 14:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lGCktDZhO9yy3XwpF+5iW72ZtqBr/yzzAAemZw+ANno=; b=nBfVQdiiDHLlyYAMKPP1SB8AEc1d2M2RhQvdXGd+0DzqYdCk8c2HazrDkmKHGvFPBx 0QvRX11bOc2bHJcgsnXSDaQ15M3iPbRqfFypWlPoNK8Oc083IOuxoMg/Sj0NcpdWh4e6 +ki1KzpwcOtMk7GVVRMUVDsQVuLRhTRhsK+T8YKKyEC6fvm2EzHNS0WzVYGmMdRQ5x5U BTk5og+1poxtymZIlfkksmDAwSdarFvPKM3gG3Eha7cb14jlcV+7oNSPOhjmWVQANSzL hz8WMjAD6/EwfAi2oiObemfZYc5inSDtczsU6M7SEYNdWcPtjUtfViCj99tnKEb7WQjy c3Dw== 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:user-agent; bh=lGCktDZhO9yy3XwpF+5iW72ZtqBr/yzzAAemZw+ANno=; b=JEgylmg9dZkL1wGkrF/7+hpKI1Jq1kyn+ghWyzWzrHQaO7qqSPHCeHSWtaaxmXgN5e qudOimJOcfDOu4P9BmA7yZtBZ0GsT+JUUHipfUYV9L2yVy1eslLO+zMJeBCO4YG/fipt YK46nwO+B9qsfBHI/r7CgO94ARv+f6OO9YMpCzVQP3MtLOes6QULc0X+2XAXUoN/b0Ym QR54vd2AIsJhloVMIPa/SudE8o82VSR6Zg7FG85ZbWGl4J+BR6OYvyvbDKIEeWoxKzTo DC0oCoyNfF18+rbJqV7+sxAJnuEupoc1uyUOZt+cydemV1HF72kHCj8olr/y8UicZNpV FZGw== X-Gm-Message-State: APjAAAUYac0GQpC7gbmOnhi5i3/QqIi5jEZ5SBneeE6QnbXZyEzGD+ls nQK0pTJSB/9A4OXidYEc9g== X-Received: by 2002:a2e:808e:: with SMTP id i14mr28243920ljg.103.1556401526026; Sat, 27 Apr 2019 14:45:26 -0700 (PDT) Received: from avx2 ([46.53.240.140]) by smtp.gmail.com with ESMTPSA id n28sm5977383lfi.79.2019.04.27.14.45.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Apr 2019 14:45:25 -0700 (PDT) Date: Sun, 28 Apr 2019 00:45:22 +0300 From: Alexey Dobriyan To: Joel Savitz Cc: linux-kernel@vger.kernel.org, Andrew Morton , Vlastimil Babka , "Aneesh Kumar K.V" , Michael Ellerman , Ram Pai , Andrea Arcangeli , Huang Ying , Sandeep Patil , Rafael Aquini , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2] fs/proc: add VmTaskSize field to /proc/$$/status Message-ID: <20190427214522.GA7074@avx2> References: <1556305328-2001-1-git-send-email-jsavitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1556305328-2001-1-git-send-email-jsavitz@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 26, 2019 at 03:02:08PM -0400, Joel Savitz wrote: > In the mainline kernel, there is no quick mechanism to get the virtual > memory size of the current process from userspace. > > Despite the current state of affairs, this information is available to the > user through several means, one being a linear search of the entire address > space. This is an inefficient use of cpu cycles. You can test only a few known per arch values. Linear search is a self inflicted wound. prctl(2) is more natural place and will also be arch neutral. > A component of the libhugetlb kernel test does exactly this, and as > systems' address spaces increase beyond 32-bits, this method becomes > exceedingly tedious. > For example, on a ppc64le system with a 47-bit address space, the linear > search causes the test to hang for some unknown amount of time. I > couldn't give you an exact number because I just ran it for about 10-20 > minutes and went to go do something else, probably to get coffee or > something, and when I came back, I just killed the test and patched it > to use this new mechanism. I re-ran my new version of the test using a > kernel with this patch, and of course it passed through the previously > bottlenecking codepath nearly instantaneously. > > This patched enabled me to upgrade an O(n) codepath to O(1) in an > architecture-independent manner. > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -74,7 +74,10 @@ void task_mem(struct seq_file *m, struct mm_struct *mm) > seq_put_decimal_ull_width(m, > " kB\nVmPTE:\t", mm_pgtables_bytes(mm) >> 10, 8); > SEQ_PUT_DEC(" kB\nVmSwap:\t", swap); > - seq_puts(m, " kB\n"); > + SEQ_PUT_DEC(" kB\nVmSwap:\t", swap); > + seq_put_decimal_ull_width(m, > + " kB\nVmTaskSize:\t", TASK_SIZE >> 10, 8); > + seq_puts(m, " kB\n"); All fields in this file are related to the task. New field related to "current" will stick like an eyesore.