From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BC0BC04FF8 for ; Fri, 19 Apr 2024 01:22:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B8E86B0082; Thu, 18 Apr 2024 21:22:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4699A6B0085; Thu, 18 Apr 2024 21:22:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 330986B0087; Thu, 18 Apr 2024 21:22:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 160DE6B0082 for ; Thu, 18 Apr 2024 21:22:32 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B08F8A1B78 for ; Fri, 19 Apr 2024 01:22:31 +0000 (UTC) X-FDA: 82024531302.16.825DE84 Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) by imf01.hostedemail.com (Postfix) with ESMTP id D40734000A for ; Fri, 19 Apr 2024 01:22:29 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=SGc6YZzg; spf=pass (imf01.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.41 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713489749; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v9ROGqlYMf4EWKkuF17eFEGeQPXT7Cmyk3kLJypWimE=; b=TLG7KJXT8RGHhKvHDupORF5fVe/4SLElUbn5TDbiDKJBF6wx5N0leMyTmVj+VzWi39pPjh aN89Fc7pp27piTYKU3D9VGih04opxAtD+uy7EHUiZNJBU6VXjiV/N37oyMIm1YpuCCFRhq 5oAc+DCWYuDeRN2TTFYXqNrlHR5GsKM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713489750; a=rsa-sha256; cv=none; b=Ni13l2CjPDtYkVNgUkbd/X2LGLgTTQMrETa88HR/juTiLZ391WRBIhuwWH72YojrmVP+tI i96nOUK729iwVUZhjRYk+/+GAyvCbHe1j138DyTYfQ3PmS1g5r1fGcCU0tZgsmbt/YbhhQ YnLeqdEt1dYyuZgDfIpt5agp4y8ysYY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=SGc6YZzg; spf=pass (imf01.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.41 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-233f389a61eso694462fac.3 for ; Thu, 18 Apr 2024 18:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713489748; x=1714094548; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=v9ROGqlYMf4EWKkuF17eFEGeQPXT7Cmyk3kLJypWimE=; b=SGc6YZzgo9lOdsV6nIzuZRuEzDBRmPO5gDRJ2f7P1duUjbw/ryOu0d/T9HQcByVium q81VTtFkvuXr98+a611nc2Qs2AvE/+tBE/4BPPZSu+u8Vg4AgQi4DPK4c21KFwdgLDAO rBpc5O1FI3yMRV16ZM7QctPGKuYhGFzccexY4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713489748; x=1714094548; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v9ROGqlYMf4EWKkuF17eFEGeQPXT7Cmyk3kLJypWimE=; b=mv5evByRGyzr1sxhPOf72BrmU2qrTf77kmNYdAlSdqn/h4upWN9fhS9va/ZirWyW6G avTJ4wUaja7r0AJ3snAsBMN66e+aZ3F7uY3VfSXhW9T74qintRWyyZMKDcK0W7I0V8WM zTXb+gpuyulfpThzxbHDS+zZV0XY/wVSNkzqXDaV5DJRCvOIGunbUKyPlOEWCoU172UQ B1ZFIleHpCfGufHipTizhxkIxVPwRVyabFOeEm090fe+oZIry3f87s4h9beduO5PTuX9 MDrUCTyxjIFsqwFdtnJtpiU7iYV/FTR+DgcTQ3icOX057KTfO1thrYy5HzP5wUZRkkJ3 o5yg== X-Forwarded-Encrypted: i=1; AJvYcCXsMFu6nnxaXW140kiOtHoZs/jIzscJv9uY+vZdS4oYL8rmgfPWtoy2ybFA+BvzYDu2FEU+sX+Y1Qah0d32sWw8/4o= X-Gm-Message-State: AOJu0YwXSHgiuogdrKJ07EpjVCbQ/Lbq1Rr2aum+DEgHoauzyvMuC1gJ dJBC7UchV2B275jBF/7RHmhvs4ky7448cQFU15V0JhEMQvTVSSjXrDwal0lijSfGBCy1YcOJua7 6hAuYR1yYORrYEKMCfxg7Xep2rwl3F4iuaI1I X-Google-Smtp-Source: AGHT+IEIBWNW7I5IBkSSrZoL3bQdbE0EnKQ5DMsc2OrG+K8cpwjoWbHljs2kaRoC/Lt0/1+1WBv43RrQh4SZC/NgzxY= X-Received: by 2002:a05:6870:cb8e:b0:21e:a957:efef with SMTP id ov14-20020a056870cb8e00b0021ea957efefmr870266oab.19.1713489748193; Thu, 18 Apr 2024 18:22:28 -0700 (PDT) MIME-Version: 1.0 References: <20240415163527.626541-1-jeffxu@chromium.org> In-Reply-To: From: Jeff Xu Date: Thu, 18 Apr 2024 18:22:16 -0700 Message-ID: Subject: Re: [PATCH v10 0/5] Introduce mseal To: Suren Baghdasaryan Cc: "Liam R. Howlett" , akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, willy@infradead.org, gregkh@linuxfoundation.org, torvalds@linux-foundation.org, usama.anjum@collabora.com, corbet@lwn.net, merimus@google.com, rdunlap@infradead.org, jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, pedro.falcato@gmail.com, dave.hansen@intel.com, linux-hardening@vger.kernel.org, deraadt@openbsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: D40734000A X-Stat-Signature: gogy45nhu685jiior87oh38yx3zk66ic X-Rspam-User: X-HE-Tag: 1713489749-961808 X-HE-Meta: U2FsdGVkX1/U13ui/U3bxNJYIwbE1cjICs40xHycqXKbyCcquCxBtAsWm57ypNyalmgXiv7UD16gPC42s/B+VNiIOgQ9KX04txQVq/VkPHAT7d3WilCIU9esMf8CDlJwGIdLu+AiARXhfPe1v+lF9Dbzs4yG2DI5HpXK9XxuDnuNIhq5fNlcbLua88vplsm/hOVfqPEWfaORuqNpsn4vxzKzV+FuXVKVs08IoXisc5rLFGE0ufoR74WY794mmS6ucxMnYeN3tw6+frJv19hA/UkpSA+5IKhpvhIxW4qtcO49AcGO2YRn/HnULsTZpXsySJ0Bv/QYQZ8Sq/fZKNJzaF0bAQ3Uqv5nhgmiGiiYxfoAUheg0U4tDqlC/mBGr63VsFprlPBzbUZxozm7zMr+L9fJjDjqsUoz6ZzQ3kxLaVtveOt1wcl77zdGscbSU4K0xSqd+h7paZBk8OkoD/dnS/XxXjHknzmceB5nK5/yhciQKeIlarPZjACUUupuxkBXsybtCoMTOrsypeeZNJjErCci+l09qgFXh3CUgIfGSt2fUsh8TYzCwocFhkT2IA361WmmsT7pAvaJDAEEh7WsOMUT/mon3JUy1S/2FuZCK/g0RmL3gpz8m9ZuMVZt84ZRuV2eAt0k2kUYrVVuoO7GQ9yri04W9WYiXuG5k+te82RkMrjvoFmucaDryz/SRV+rej9B470HELD5gqcL8hF+wp2xLwGs2QjjsUpPsFWa7ywvXWygrQXrLN7dukOywA633N6zAgN2T2Wn2G4FKPQkwfQ617EYQ1ccpets/GF1ulaa61A9zhziYMXPhVyra/9LJnoA4dtZ01YIybi5LagLnizrddfrWt6SJlhmhgdECr1/Gsq3OigHBbBVhup+9eVzcMFDjKpdDWofHkHx0rzszJL+18/T/8SYWwkfyJOouCz6Tklm9OMTObh/lebDx7T6wo2apR3/2aerfwP9DkT LDOG04jv 1s/dpD4OEhFBRsJ/TKhicmcO5hGhNmJs7iHfs0MDYMWAhDF7AvQ45Gzqat8VjhBxIVcN5b8OA17jsN3q3hmFpvB7oIB5l0LHtqUE4J7qQ6Wo18iTfMG1rNIHbW9gSAcv+Lf+e6MQrxKN3Rl5YORSwPxXw6KfcwF8ikaUVIWYctaLZgeYvI9LyT8ucUpgBlJckl4jjek4i8ut5DMP3LUtwg0cjTGhUp0I//lpmMUHXd0p5dZLXg0C1n23vaZDbxO5RUed8vApY4hWYm0/rMgyTGwrviVVGdEO8twHHIhmFNYxGiLgvLFjU82D4nEfObLQ0oYVeY0G46kTUjUFyS1a4B11o4gOyef2VoU0Yh2rVyfAzldjpWMgJ2SofWfFBuJZ3DxI0YM4wDGChsca8vV+xAiKiOQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Apr 18, 2024 at 1:19=E2=80=AFPM Suren Baghdasaryan wrote: > > On Tue, Apr 16, 2024 at 12:40=E2=80=AFPM Jeff Xu wr= ote: > > > > On Tue, Apr 16, 2024 at 8:13=E2=80=AFAM Liam R. Howlett wrote: > > > > > > * jeffxu@chromium.org [240415 12:35]: > > > > From: Jeff Xu > > > > > > > > This is V10 version, it rebases v9 patch to 6.9.rc3. > > > > We also applied and tested mseal() in chrome and chromebook. > > > > > > > > ------------------------------------------------------------------ > > > ... > > > > > > > MM perf benchmarks > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > > This patch adds a loop in the mprotect/munmap/madvise(DONTNEED) to > > > > check the VMAs=E2=80=99 sealing flag, so that no partial update can= be made, > > > > when any segment within the given memory range is sealed. > > > > > > > > To measure the performance impact of this loop, two tests are devel= oped. > > > > [8] > > > > > > > > The first is measuring the time taken for a particular system call, > > > > by using clock_gettime(CLOCK_MONOTONIC). The second is using > > > > PERF_COUNT_HW_REF_CPU_CYCLES (exclude user space). Both tests have > > > > similar results. > > > > > > > > The tests have roughly below sequence: > > > > for (i =3D 0; i < 1000, i++) > > > > create 1000 mappings (1 page per VMA) > > > > start the sampling > > > > for (j =3D 0; j < 1000, j++) > > > > mprotect one mapping > > > > stop and save the sample > > > > delete 1000 mappings > > > > calculates all samples. > > > > > > > > > Thank you for doing this performance testing. > > > > > > > > > > > Below tests are performed on Intel(R) Pentium(R) Gold 7505 @ 2.00GH= z, > > > > 4G memory, Chromebook. > > > > > > > > Based on the latest upstream code: > > > > The first test (measuring time) > > > > syscall__ vmas t t_mseal delta_ns per_vma % > > > > munmap__ 1 909 944 35 35 104% > > > > munmap__ 2 1398 1502 104 52 107% > > > > munmap__ 4 2444 2594 149 37 106% > > > > munmap__ 8 4029 4323 293 37 107% > > > > munmap__ 16 6647 6935 288 18 104% > > > > munmap__ 32 11811 12398 587 18 105% > > > > mprotect 1 439 465 26 26 106% > > > > mprotect 2 1659 1745 86 43 105% > > > > mprotect 4 3747 3889 142 36 104% > > > > mprotect 8 6755 6969 215 27 103% > > > > mprotect 16 13748 14144 396 25 103% > > > > mprotect 32 27827 28969 1142 36 104% > > > > madvise_ 1 240 262 22 22 109% > > > > madvise_ 2 366 442 76 38 121% > > > > madvise_ 4 623 751 128 32 121% > > > > madvise_ 8 1110 1324 215 27 119% > > > > madvise_ 16 2127 2451 324 20 115% > > > > madvise_ 32 4109 4642 534 17 113% > > > > > > > > The second test (measuring cpu cycle) > > > > syscall__ vmas cpu cmseal delta_cpu per_vma % > > > > munmap__ 1 1790 1890 100 100 106% > > > > munmap__ 2 2819 3033 214 107 108% > > > > munmap__ 4 4959 5271 312 78 106% > > > > munmap__ 8 8262 8745 483 60 106% > > > > munmap__ 16 13099 14116 1017 64 108% > > > > munmap__ 32 23221 24785 1565 49 107% > > > > mprotect 1 906 967 62 62 107% > > > > mprotect 2 3019 3203 184 92 106% > > > > mprotect 4 6149 6569 420 105 107% > > > > mprotect 8 9978 10524 545 68 105% > > > > mprotect 16 20448 21427 979 61 105% > > > > mprotect 32 40972 42935 1963 61 105% > > > > madvise_ 1 434 497 63 63 115% > > > > madvise_ 2 752 899 147 74 120% > > > > madvise_ 4 1313 1513 200 50 115% > > > > madvise_ 8 2271 2627 356 44 116% > > > > madvise_ 16 4312 4883 571 36 113% > > > > madvise_ 32 8376 9319 943 29 111% > > > > > > > > > > If I am reading this right, madvise() is affected more than the other > > > calls? Is that expected or do we need to have a closer look? > > > > > The madvise() has a bigger percentage (per_vma %), but it also has a > > smaller base value (cpu). > > Sorry, it's unclear to me what the "vmas" column denotes. Is that how > many VMAs were created before timing the syscall? If so, then 32 is > the max that you show here while you seem to have tested with 1000 > VMAs. What is the overhead with 1000 VMAs? The vmas column is the number of VMA used in one call. For example: for 32 and mprotect(ptr,size), the memory range used in mprotect has 32 VMAs. It also matters how many memory ranges are in-use at the time of the test, This is where 1000 comes in. The test creates 1000 memory ranges, each memory range has 32 vmas, then calls mprotect on the 1000 memory range. (the pseudocode was included in the original email) > My worry is that if the overhead grows linearly with the number of > VMAs then the effects will be quite noticeable on Android where an > application with a few thousand VMAs is not so unusual. > The overhead is likely to grow linearly with the number of VMA, since it takes time to retrieve VMA's metadata. Let's use one data sample to look at impact: Test: munmap 1000 memory range, each memory range has 1 VMA syscall__ vmas t t_mseal delta_ns per_vma % munmap__ 1 909 944 35 35 104% For those 1000 munmap calls, sealing adds 35000 ns in total, or 35 ns per c= all. The delta seems to be insignificant. e.g. it will take about 28571 munmap call to have 1 ms difference (1000000/35=3D28571) When I look at the data from 5.10 to 6.8, for the same munmap call, 6.8 adds 552 ns per call, which is 15 times bigger. syscall__ vmas t_5_10 t_6_8 delta_ns per_vma % munmap__ 1 357 909 552 552 254% > > > > -Jeff