Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4880937pxb; Tue, 5 Oct 2021 12:23:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxhobXgqyX/5K1uW/r7v5W7LqO6EERIERHdvJcwsaLMiLStsdbcH5gRS+86N1KNvPWRJ8Q X-Received: by 2002:a17:906:700f:: with SMTP id n15mr26398958ejj.319.1633461817050; Tue, 05 Oct 2021 12:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633461817; cv=none; d=google.com; s=arc-20160816; b=tRIvB+RgzrSelxaWUcAyxVinISun1F5joJFP9X+Y105IT850j5gZPCI8nrI35tAdgx HIG14suIJ+diMUdz86i3iz8oeigWQAAKZY1Vb6MVXGk0AfMsLUVCHYPQ7R433MPhxC19 PWNuSrSbnj8igYMHQav+ZbBfGYZX0wyV0sZrZjm6zVQggteHaiB5D8b8W5y6pvMa3qJl WaYhkHJdMN0Q8RNv5Y6SHCt8Bj44hJRPZvc2Qb8yqp2mrCfJiWfNApW2BBwNeH16eVBY P5wIet171gchwvo0fzhDmld0EFPo67CI5nr+Xw58UBK4N8EBA5SKns+Lv8IKV9h+Mrit yX0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7y0UQJo2ebCqon0Bb7OI4csD0ePdDv5zBX9x3Gtz6Mg=; b=ohRZNXY2WwpjKNqRrUkkudTlM4eIPPsMKS3ckh0E1aYGgf3EJgaAqoEYAzvi/aDhjk od8qY3dr722lEBeIE3zNBAiv1pMd7FLl3MAlavwUccSKCSjx/rhAftKA1+LSDMLFN5sh ftr2fS7STj8JxMr/4KTN79q9e4uG0txgrNV9+2/TVhPgcweiwwXbYHC50u8mRn0NWkZy VGpLI6OGZJ3lVlX5B+FtEP0eUgS6zWARPXqq/xcK6ahB3/Bu1F2jUL1VHN4yh9/CQ+ZT 1CdrnTlltZrl8sTmZoONW/kx982Xad2FMokhT8eOtxp0mi/b7LyAFOiR3DKUj9q7WZbv AyCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ftC3Y73k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si21062214ejb.547.2021.10.05.12.22.54; Tue, 05 Oct 2021 12:23:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ftC3Y73k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235224AbhJETXV (ORCPT + 99 others); Tue, 5 Oct 2021 15:23:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235101AbhJETXT (ORCPT ); Tue, 5 Oct 2021 15:23:19 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC1E5C061753 for ; Tue, 5 Oct 2021 12:21:28 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id t11so86662plq.11 for ; Tue, 05 Oct 2021 12:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7y0UQJo2ebCqon0Bb7OI4csD0ePdDv5zBX9x3Gtz6Mg=; b=ftC3Y73kipN8EROGIeJDV8NTUjflmrLwE19qsFs3y5p12F2JvJ1fDy3W7Ypic1NX81 2v3cMbEpRUcZWhC6ttcRhGFCOMwikEjPQa8wJrz32tAVOxWEOBLrUobOQT01GkU2+fRm W4qbRjDRbrdUfClhtSjntPBzH4/bRmjW/H1v8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7y0UQJo2ebCqon0Bb7OI4csD0ePdDv5zBX9x3Gtz6Mg=; b=cmjsgnBNDOkms2q2NNqYnVOZJ2ZvV8aFuC2Cbr/IgTs1KePsPDT1iHodwG145aEFjB 9mZ3uNcLwb1Tz4U1f5ROiBrLQ77LD1Te2/1o9xvoQ2MONi7eBB+H3fSL9sHBq20y4R7D JSvri/LBhuCMTa4Cu8nyBt42QC5gwJMEGpsV8CrpTox5QXxsl4oox68cI/oXa6iArCX6 zpB+te03taih7nVmHVMakq7ebAmdJgPG3a2MatXIx1d5QSOmBIaz17O3nE0B65LDWXjh iQkYD5vtK5SBPICdSFQ8Y+V09zp1xxFiVc9KygxN4G6FMVNZCGbWubKJY4DqWvtUkv5o 3d4Q== X-Gm-Message-State: AOAM533+rizmiUhcKhcS5G32I2VKjL3jr/vmPwyhX4ZvoT5/hW3rnCnA n6xylYOgZ4IX0N1KM8YSR3erKP2Owo8oYQ== X-Received: by 2002:a17:90a:ead3:: with SMTP id ev19mr5828725pjb.136.1633461688139; Tue, 05 Oct 2021 12:21:28 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y3sm19257860pfr.140.2021.10.05.12.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 12:21:27 -0700 (PDT) Date: Tue, 5 Oct 2021 12:21:26 -0700 From: Kees Cook To: Suren Baghdasaryan Cc: Pavel Machek , Andrew Morton , Colin Cross , Sumit Semwal , Michal Hocko , Dave Hansen , Matthew Wilcox , "Kirill A . Shutemov" , Vlastimil Babka , Johannes Weiner , Jonathan Corbet , Al Viro , Randy Dunlap , Kalesh Singh , Peter Xu , rppt@kernel.org, Peter Zijlstra , Catalin Marinas , vincenzo.frascino@arm.com, Chinwen Chang =?utf-8?B?KOW8temMpuaWhyk=?= , Axel Rasmussen , Andrea Arcangeli , Jann Horn , apopple@nvidia.com, John Hubbard , Yu Zhao , Will Deacon , fenghua.yu@intel.com, thunder.leizhen@huawei.com, Hugh Dickins , feng.tang@intel.com, Jason Gunthorpe , Roman Gushchin , Thomas Gleixner , krisman@collabora.com, chris.hyser@oracle.com, Peter Collingbourne , "Eric W. Biederman" , Jens Axboe , legion@kernel.org, Rolf Eike Beer , Cyrill Gorcunov , Muchun Song , Viresh Kumar , Thomas Cedeno , sashal@kernel.org, cxfcosmos@gmail.com, Rasmus Villemoes , LKML , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm , kernel-team Subject: Re: [PATCH v10 3/3] mm: add anonymous vma name refcounting Message-ID: <202110051220.FFD4C604EF@keescook> References: <20211001205657.815551-1-surenb@google.com> <20211001205657.815551-3-surenb@google.com> <20211005184211.GA19804@duo.ucw.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 05, 2021 at 12:14:59PM -0700, Suren Baghdasaryan wrote: > On Tue, Oct 5, 2021 at 11:42 AM Pavel Machek wrote: > > > > On Fri 2021-10-01 13:56:57, Suren Baghdasaryan wrote: > > > While forking a process with high number (64K) of named anonymous vmas the > > > overhead caused by strdup() is noticeable. Experiments with ARM64 > > Android > > > > I still believe you should simply use numbers and do the > > numbers->strings mapping in userspace. We should not need to optimize > > strdups in kernel... > > Here are complications with mapping numbers to strings in the userspace: > Approach 1: hardcode number->string in some header file and let all > tools use that mapping. The issue is that whenever that mapping > changes all the tools that are using it (including 3rd party ones) > have to be rebuilt. This is not really maintainable since we don't > control 3rd party tools and even for the ones we control, it will be a > maintenance issue figuring out which version of the tool used which > header file. > Approach 2: have a centralized facility (a process or a DB) > maintaining number->string mapping. This would require an additional > request to this facility whenever we want to make a number->string > conversion. Moreover, when we want to name a VMA, we would have to > register a new VMA name in that facility or check that one already > exists and get its ID. So each prctl() call to name a VMA will be > preceded by such a request (IPC call), maybe with some optimizations > to cache already known number->string pairs. This would be quite > expensive performance-wise. Additional issue with this approach is > that this mapping will have to be persistent to handle a case when the > facility crashes and has to be restored. > > As I said before, it complicates userspace quite a bit. Is that a good > enough reason to store the names in the kernel and pay a little more > memory for that? IMHO yes, but I might be wrong. FWIW, I prefer the strings. It's more human-readable, which is important for the kinds of cases where the maps are being used for diagnostics, etc. -- Kees Cook