Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5389223yba; Tue, 30 Apr 2019 14:02:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrKSR+QYNaVjVqqRW8T1oIhEI8BdUNUtXmVMZnh2BT82knm1J4QTfumDuSxGJtfKJZDplh X-Received: by 2002:a63:4f41:: with SMTP id p1mr69597649pgl.63.1556658165664; Tue, 30 Apr 2019 14:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556658165; cv=none; d=google.com; s=arc-20160816; b=lu2V+V3Wwm1HMIkH08rV2goUuYD5O8Pg7eCgkuBejojd9J12joferY28P7/yZI89XR y8//oCXcTIXFp4SXsuMNYaHp4ejJXHBpBr2TbyZzCKGL39BnD2pAHd/RqTpdYnu1/l2i pyKfKv7cgiJRfQJLRsjnOIjFkEokpUlG8gluKr2eJoPo/igLZRz99rQQLg6DLzgAum9z sFW6bGwuJY02aXVd+DWs3dCkS9g8mP2+Lwvhbaod3xbv3vgRrOnqHLzCYtE5AW8sxvjA iG6tWSQRO3DWVdUugnaK/Bk87GbutQlWno4IKRI2sRg9HKkavBhY5CWc66Yagw0JHwis 9UHA== 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; bh=AxeD0t/KcIvQA7AtfwSjOeFDBlvqqlxzBx10CN2QVNI=; b=YVKJ1pnhGriSGsp4N/dlSPzrzd4teVsXL9555K725+ekcqSJaVClsFgBNo2L0twy33 lRQHQcs1h/tIMjWGC1pghwDZd0vZ+EyS+iQzA6cku4QPavlVrPU6pfxFRuqYgqX9Xizj 4WSkvBH4sCt/MwwrdNvAimIHAldU1Fx0seplvUYMfgBTHMvIJ83Pu0LNWIRIonK5SDHc p9zp1gZvmzitUn90whunTNQsX0hX6YR+dUk/gaxH5Syro4LPi0AS/J6Fp4p2bi2JVW9Q b3joR/Fp9v//72cbQ282uygz0CBIVP0wNUDGJ5n4oJhn1lRPURp14hmjoYLL2vYFieHT fRgw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 a3si23780199pgm.455.2019.04.30.14.02.29; Tue, 30 Apr 2019 14:02:45 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726053AbfD3VBe (ORCPT + 99 others); Tue, 30 Apr 2019 17:01:34 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:36703 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbfD3VBd (ORCPT ); Tue, 30 Apr 2019 17:01:33 -0400 Received: by mail-oi1-f193.google.com with SMTP id l203so12481018oia.3 for ; Tue, 30 Apr 2019 14:01:33 -0700 (PDT) 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=AxeD0t/KcIvQA7AtfwSjOeFDBlvqqlxzBx10CN2QVNI=; b=f/xwyP61OP2lmvK608TFukrcfV6SYz9abIZ59O4FWLi/2K+20SOhlCKJD11umqhZHC LQC8E1nfu0FFwErygLvtDx59XXMqkDVSc1NnykOskbLEySACgTjmx+4GaD2zkPbuinUH 39BE+gEvZLmjtW7E0MacS5iviBBJ5EQ9kQFrxXkbYFLmdDlqZ5FVcVs7qLKJQLczSKFG 8MHxinaQo+xVyU9H/8PAkL5H/BvmsTXSXYKupb9vay9Ssf1zituHbpgi9aBuSNacM5vn Sldl1Axn3Js8sYQ1YX2aeBtADg7tztrVKfgbsgnQeTV6TyF2ksSm2tHxN+Hxz/Si31lu ed0A== X-Gm-Message-State: APjAAAXCr0FIPcgpDg0gxmY5n1aWWY5ZS5QBO2HINl570kLzCKGhNOL4 8qLYp3GHSUKkZpSnkle3mkzBHTJeqPZfqJVun50GGQ== X-Received: by 2002:aca:61d7:: with SMTP id v206mr4682848oib.97.1556658092881; Tue, 30 Apr 2019 14:01:32 -0700 (PDT) MIME-Version: 1.0 References: <1556305328-2001-1-git-send-email-jsavitz@redhat.com> <20190427214522.GA7074@avx2> In-Reply-To: <20190427214522.GA7074@avx2> From: Joel Savitz Date: Tue, 30 Apr 2019 17:01:21 -0400 Message-ID: Subject: Re: [PATCH v2] fs/proc: add VmTaskSize field to /proc/$$/status To: Alexey Dobriyan 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 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 Good point Alexey. Expect v3 shortly. Best, Joel Savitz On Sat, Apr 27, 2019 at 5:45 PM Alexey Dobriyan wrote: > > 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.