Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1008489yba; Fri, 3 May 2019 14:18:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKVqMdpcMyNnC1hNdYPNHi6UpndfkXgraT/bldH11A58qf+XA9i8RTi/Lxizw8VAXr9Ahz X-Received: by 2002:a62:41db:: with SMTP id g88mr13630501pfd.201.1556918338685; Fri, 03 May 2019 14:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556918338; cv=none; d=google.com; s=arc-20160816; b=kdc6OH1s1Y6vIPCkmTY17TLuwT2dCZduprBqfznwFEWeS/Wo3lZMmaGKymomx9Aasw 58BMOB3MFgsaQtgHu2B6fUwdCUkdsvyO0EdRElPEsZ5YJpkpk7GDHPX6OpwQmXDM3Rob M7ylZHsWuJ1hnYgGG52SyyD+H2L+Q/o4xv7UrGn8toN+4sXYql+cHE+/4TXDbmUpPK0W a2XUnpKB8QUaihOqPPfYINKkoOFHSENc91P8mw7A9BXUpULTzB9SGRO/7P3/YLZlE1nX Pccc181Dtmt9ZNQElSARWR7um+Vb2r6WjEjH50RXh8JFJ5813MLGPZqKt8gIqBSK6rlZ OuGQ== 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=k4AJX+XLIQ3TE92X2ItqBrCbyi0kkAlpOWU5Nyv4b/o=; b=geevn9Vbxcrr2eC+yMTRhMuO1ETXcpJaZ+UqOIosyw4oKSBp1oeAxFlZ++aYrkbHfb qTBk7UbqHv1lIO8pbp3rjBpaXKlp4c+FFSxTASFog/M8IYUScYk3LJfs51ShKDNsEpSm PFMjr0q+fnD33VrN0mO0/awc5ghm3B4tEJ6y+6NW6bgP+0YyBOj48HrFYaHwl2qNuVeR LNZURFSqTzB9oWZxpIj9R3dV69KEEiztSPnWd9KeRYOwmTqdKccjcN4HYYliY1fX+9FZ YtzErBvBh6iKPx2xeLaeWaPZXo/GbmQ62ceNcZ8ybo/3rQzzXPJHlCLs3WJNuWRRaoY3 XfCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AZjEJwtD; 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 v23si3900050pfm.186.2019.05.03.14.18.43; Fri, 03 May 2019 14:18:58 -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=AZjEJwtD; 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 S1726878AbfECUtS (ORCPT + 99 others); Fri, 3 May 2019 16:49:18 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43440 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbfECUtS (ORCPT ); Fri, 3 May 2019 16:49:18 -0400 Received: by mail-pg1-f196.google.com with SMTP id t22so3252692pgi.10 for ; Fri, 03 May 2019 13:49:17 -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=k4AJX+XLIQ3TE92X2ItqBrCbyi0kkAlpOWU5Nyv4b/o=; b=AZjEJwtDPHysF3UiBAKH8WwzJMEuQjIC+GtLdL8ndbQCEHxgvbgbIDptq2MM2mUNOV Qi5ZLvzmgNs7jMzxE3e90kveKl/WXaJ8u7NtsF3x6YL/x0uYVlkocb20MXNbUh49k41I 9fkytR+n3AyxiLACeXZ9TmXeRVwPhDs+MpkMvTAfLsjoYlK8usYGOpUpQN4yFmv3QQst jJyaVqTb4je2HOS20O34HQE8bLB4h9ATwptrTlvz+yc2PExJeUXXb0k4zrU4wPaD7O09 qZ6WSCWnRTgQs7EJs5n3NU9p8xHVKdNRPlX2vXXdPEWcgQHlLj8SguD9hCwHafblaCQ7 i+9Q== 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=k4AJX+XLIQ3TE92X2ItqBrCbyi0kkAlpOWU5Nyv4b/o=; b=R6G8wcoWLLyv7fXLWzZHuEtm7OxTDwBsCK0vKp9LCPqfW3FK/P+iEiUvkvuHsr3Z3c oFuCDzXRl2rXfnsMBJPsUjrav5pmb1Pw2CDjQdTDKTSBq3tCsMXU86iU4L3vY62VjjwZ nNq96oWAyhHjZMSxCga2z+2BMz9UAUNJbkYVPRipupNyQu8tqPmtuWqW9dbwWHlnl6hU Vykwr3k1OsAffFFKfHN3gZ5ML7smmoh4xHm5zQ96uus7tG3gLXcIsCTVXeryMlYtnfIr N1drJmSV4Pu0Z44rdZ3nPo4UtjGKSgSZYxdmIkR/rVe84Faz0npzZ/1iByZ7IbH99Vgf KqpQ== X-Gm-Message-State: APjAAAVggiv4kqmX8H1LIApf77S/o4uaAfXG/Hrr8BWtyh+KfiYcBZl5 pDnPTo0m3qBdZDd1nYiIPUQ= X-Received: by 2002:aa7:8383:: with SMTP id u3mr13739318pfm.245.1556916557178; Fri, 03 May 2019 13:49:17 -0700 (PDT) Received: from localhost ([208.54.5.135]) by smtp.gmail.com with ESMTPSA id 18sm4283751pfp.18.2019.05.03.13.49.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 13:49:15 -0700 (PDT) Date: Fri, 3 May 2019 13:49:12 -0700 From: Yury Norov To: Joel Savitz Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Masami Hiramatsu , Waiman Long , Mauro Carvalho Chehab , Kristina Martsenko , Andrew Morton , Cyrill Gorcunov , Kees Cook , "Gustavo A. R. Silva" , YueHaibing , Micah Morton , Yang Shi , Jann Horn , Alexey Dobriyan , Rafael Aquini , Michael Kerrisk , David Laight Subject: Re: [PATCH v3 0/2] sys/prctl: expose TASK_SIZE value to userspace Message-ID: <20190503204912.GA5887@yury-thinkpad> References: <1556907021-29730-1-git-send-email-jsavitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1556907021-29730-1-git-send-email-jsavitz@redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 03, 2019 at 02:10:19PM -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. > > 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. > > As such, I propose that the prctl syscall be extended to include the > option to retrieve TASK_SIZE from the kernel. > > This patch will allow us to upgrade an O(n) codepath to O(1) in an > architecture-independent manner, and provide a mechanism for future > generations to do the same. So the only reason for the new API is boosting some random poorly written userspace test? Why don't you introduce binary search instead? Look at /proc//maps. It may help to reduce the memory area to be checked. > Changes from v2: > We now account for the case of 32-bit compat userspace on a 64-bit kernel > More detail about the nature of TASK_SIZE in documentation > > Joel Savitz(2): > sys/prctl: add PR_GET_TASK_SIZE option to prctl(2) > prctl.2: Document the new PR_GET_TASK_SIZE option > > include/uapi/linux/prctl.h | 3 +++ > kernel/sys.c | 23 +++++++++++++++++++++++ > 2 files changed, 26 insertions(+) > > man2/prctl.2 | 10 ++++++++++ > 1 file changed, 10 insertions(+) > -- > 2.18.1