From patchwork Fri Apr 18 17:49:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 14057554 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 3636AC369AB for ; Fri, 18 Apr 2025 17:50:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 957C76B02A2; Fri, 18 Apr 2025 13:50:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 906366B02A3; Fri, 18 Apr 2025 13:50:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F5516B02A4; Fri, 18 Apr 2025 13:50:05 -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 63B156B02A2 for ; Fri, 18 Apr 2025 13:50:05 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AEBC080A99 for ; Fri, 18 Apr 2025 17:50:06 +0000 (UTC) X-FDA: 83347903212.09.4EEABD9 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) by imf19.hostedemail.com (Postfix) with ESMTP id 023A11A0003 for ; Fri, 18 Apr 2025 17:50:04 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=VECcIPSp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3y5ACaAYKCD4xzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.160.74 as permitted sender) smtp.mailfrom=3y5ACaAYKCD4xzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744998605; a=rsa-sha256; cv=none; b=ZU457uKf6XDYBeLobqI88h8g9TyV17N17UHNqpnBuI8zO+/Mbp4GO+IRC72KTJfBB6w2RU BMMMa4BefyIuMghewCE73ThlXDXezthoGV+lQr7HBqAorJ26ygxRdXP47Ryk6pgqgWpDiX tQ915E/8IuKK4jj48E43y+Ahq83m4d0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=VECcIPSp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3y5ACaAYKCD4xzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com designates 209.85.160.74 as permitted sender) smtp.mailfrom=3y5ACaAYKCD4xzwjsglttlqj.htrqnsz2-rrp0fhp.twl@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744998605; 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:in-reply-to: references:dkim-signature; bh=NChENxjYlbY+fearBpat5nnFIT5zlqPLQI15hZf3lPM=; b=DeJMyArW6ZiaxUg5y+skUavawPRqEgp/wc0QowKO0dKHTtlmuUguSVROEHEIXhSN76VB5b 7CG5uU3ENnADSADX+iTljZKXqDrNpG2Dv1Ztz0tbPtyvSDh9f5m1NgbIOGURQ2P7AvUq+F GYy91/78E05q2wi3XEZvXdRLRc4Wrtk= Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2c22c1d5d09so1367196fac.2 for ; Fri, 18 Apr 2025 10:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744998603; x=1745603403; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=NChENxjYlbY+fearBpat5nnFIT5zlqPLQI15hZf3lPM=; b=VECcIPSpseMPRy7gWigSo9r3Q1TdUZkRM3HfMIRC9LxL9w2GB7oaMBqp8P53A2Nq+W fbialGeo8xa4Rt0xHzT59niXanvT9BH1YVXqinVcYgvvuqfIlmHpWc9xzzO7lyhJZd5m LJVgP9wM9rZv5peaNdl72yhjVHP2DokTfCM2rtNXQgI8wlVPucCNuCPCgQ3ACApjr2p/ UHT3rgRT9l7bDGQeFZhU2fLPOO2QuICvS9pKnmmznundBBCePts/5z3/Qx/kTscQ7gp8 /URMzupdLerD95lKiesiWKeBF+qKP5knxMnlZHX7GrksFzxO5p+xqC6Do9H6YVhEcECQ EyMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744998603; x=1745603403; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NChENxjYlbY+fearBpat5nnFIT5zlqPLQI15hZf3lPM=; b=twoBpzrbpMk9g0EMrSSi0OWzFbUrcQbNFSHQdXo60C1FSjOp6gspF7T77c+6HKN5Zk QMnHUsSz5AUSRBp+eYzG73P+0nmk7EFQjXZaffegpTleFPh7yglgS8xTTgts1zFKMQnn sYNa3nlmsPLWq8uXAWC/mzdrOkdMBqJ4uwVqJqEc62cLwN7KI+XJfppB04OtKApaXH/S G7L2JABV3mEIe8xsHee58xpLi++MTwxYsCO0E5nqrzzlsjF2G5C8a4prQEyMnbj3PAtT S3gdMgVw8pVzRQJDAyuct3zzZfWS6LBX1eKXNhr6H36kZs75PZkRPfoVAL6mlTIDXI64 s0JQ== X-Forwarded-Encrypted: i=1; AJvYcCVC1fNtnKkxwN1U2g/C10Sw2RPhmyPcTf1KXBm82MxOSwpTsfSksvaFkBIKvq+Rujb4JpL4zJ9MQw==@kvack.org X-Gm-Message-State: AOJu0Yxpv3n0vmg4wbOZOFFZq2FezI45NHnm7l+oQYLgM1itiEqKsBj+ DU70n69llicyRCYqc0aH542U12pFdJ4P2OJ/S1ltIAz91BLcgL6t3/1HxuOj3zTAqwsmoZP/ShX Aug== X-Google-Smtp-Source: AGHT+IE3aftsn9hfNjPsF8qSwC5r3XHYkK9rjlStJcjhr+jAxmTp8vjQYXiW/ySOAL58Q0hdZgfr9P9bsm4= X-Received: from oabuz10.prod.google.com ([2002:a05:6870:af8a:b0:29f:d208:6db]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:ef83:b0:2d5:4f4:e24d with SMTP id 586e51a60fabf-2d5269799d4mr2188610fac.6.1744998603619; Fri, 18 Apr 2025 10:50:03 -0700 (PDT) Date: Fri, 18 Apr 2025 10:49:51 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.49.0.805.g082f7c87e0-goog Message-ID: <20250418174959.1431962-1-surenb@google.com> Subject: [PATCH v3 0/8] perform /proc/pid/maps read and PROCMAP_QUERY under RCU From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, david@redhat.com, vbabka@suse.cz, peterx@redhat.com, jannh@google.com, hannes@cmpxchg.org, mhocko@kernel.org, paulmck@kernel.org, shuah@kernel.org, adobriyan@gmail.com, brauner@kernel.org, josef@toxicpanda.com, yebin10@huawei.com, linux@weissschuh.net, willy@infradead.org, osalvador@suse.de, andrii@kernel.org, ryan.roberts@arm.com, christophe.leroy@csgroup.eu, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, surenb@google.com X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 023A11A0003 X-Stat-Signature: u1mrzn146ednbk8i4buect66ir9fw91f X-Rspam-User: X-HE-Tag: 1744998604-895799 X-HE-Meta: U2FsdGVkX1+Gp5Tn689bYr2hzRYCKm0m3aOqEJ3LrmD7fJI3BfdIvR88F+3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wLZJKSWLSTm2vMYiWjPLI48JQAxsJ+jrlpgwajDwv1hxhOkDEcp9qca8efT80rchI0N9JsIyT8JECyDw049ZF2KSOXIG07e+Zc4mYf+6swLjvlyPQWSK2dgaIA4BHcih3LwLixmeCbKq6J4NG8i9wPAxifofDUeCVcrf5ykn07YHMrUuev+jlNieXqmbAKkG0dHDTU9mLEzg7T378C6+6Lu0eo/ocdvZDErXliqut5bicTe6okyEoLAT0/P0vr8qlJPQfXcUzlmmO4WHJQRiUpjfw9QjVDw8KDq/fV3paBoYxmqneg8kzNPIZVkkL++PNL14WvKShecvqqz4zitpXMLMFJY8w4FfpMJy8hFMa6bzglqAE92KP6bVdAWbetq61cMXwkybk7lQmxjw7G/g0EuRwLsOM8CROJy/qIHxZ2GBauB1tJjtefTadbcUhG3A1NqrrrfEg9/jsCBJ9291cksmmwa5uDw= 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: After a long delay I'm posting next iteration of lockless /proc/pid/maps reading patchset. Differences from v2 [1]: - Add a set of tests concurrently modifying address space and checking for correct reading results; - Use new mmap_lock_speculate_xxx APIs for concurrent change detection and retries; - Add lockless PROCMAP_QUERY execution support; The new tests are designed to check for any unexpected data tearing while performing some common address space modifications (vma split, resize and remap). Even before these changes, reading /proc/pid/maps might have inconsistent data because the file is read page-by-page with mmap_lock being dropped between the pages. Such tearing is expected and userspace is supposed to deal with that possibility. An example of user-visible inconsistency can be that the same vma is printed twice: once before it was modified and then after the modifications. For example if vma was extended, it might be found and reported twice. Whan is not expected is to see a gap where there should have been a vma both before and after modification. This patchset increases the chances of such tearing, therefore it's event more important now to test for unexpected inconsistencies. Thanks to Paul McKenney who developed a benchmark to test performance of concurrent reads and updates, we also have data on performance benefits: The test has a pair of processes scanning /proc/PID/maps, and another process unmapping and remapping 4K pages from a 128MB range of anonymous memory. At the end of each 10-second run, the latency of each mmap() or munmap() operation is measured, and for each run the maximum and mean latency is printed. (Yes, the map/unmap process is started first, its PID is passed to the scanners, and then the map/unmap process waits until both scanners are running before starting its timed test. The scanners keep scanning until the specified /proc/PID/maps file disappears.) In summary, with stock mm, 78% of the runs had maximum latencies in excess of 0.5 milliseconds, and with more then half of the runs' latencies exceeding a full millisecond. In contrast, 98% of the runs with Suren's patch series applied had maximum latencies of less than 0.5 milliseconds. From a median-performance viewpoint, Suren's series also looks good, with stock mm weighing in at 13 microseconds and Suren's series at 10 microseconds, better than a 20% improvement. [1] https://lore.kernel.org/all/20240123231014.3801041-1-surenb@google.com/ Suren Baghdasaryan (8): selftests/proc: add /proc/pid/maps tearing from vma split test selftests/proc: extend /proc/pid/maps tearing test to include vma resizing selftests/proc: extend /proc/pid/maps tearing test to include vma remapping selftests/proc: test PROCMAP_QUERY ioctl while vma is concurrently modified selftests/proc: add verbose more for tests to facilitate debugging mm: make vm_area_struct anon_name field RCU-safe mm/maps: read proc/pid/maps under RCU mm/maps: execute PROCMAP_QUERY ioctl under RCU fs/proc/internal.h | 6 + fs/proc/task_mmu.c | 233 +++++- include/linux/mm_inline.h | 28 +- include/linux/mm_types.h | 3 +- mm/madvise.c | 30 +- tools/testing/selftests/proc/proc-pid-vm.c | 793 ++++++++++++++++++++- 6 files changed, 1061 insertions(+), 32 deletions(-) base-commit: 79f35c4125a9a3fd98efeed4cce1cd7ce5311a44