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 611C5C19F32 for ; Fri, 7 Mar 2025 13:35:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E6F06B0082; Fri, 7 Mar 2025 08:35:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 694976B0083; Fri, 7 Mar 2025 08:35:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 537186B0085; Fri, 7 Mar 2025 08:35:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3071B6B0082 for ; Fri, 7 Mar 2025 08:35:13 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 15AF3160B62 for ; Fri, 7 Mar 2025 13:35:14 +0000 (UTC) X-FDA: 83194851348.25.000265A Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by imf07.hostedemail.com (Postfix) with ESMTP id 323CE40007 for ; Fri, 7 Mar 2025 13:35:12 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hUWRQtgZ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.222.41 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741354512; 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=7d+R6+9QRbHOe69NMdbDCrWyNRLbx9LvgB+dGXyclrw=; b=B9v+Owgbwsb4QJxqXmJI4+wC1rFFYw2yAqTdxcgHCtnVXWBrnRviFUNr3poHSyJCalR5hf fcA/GncAVrk7TGW4Ro0obDUql/HZH6EJD2Ri2P4WWfcs6wEXsL/Z9nsDJDYiSLHV6oStCo 4XRDpl7DQwUsnMH/FetdIQ8xzmLU7Uc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741354512; a=rsa-sha256; cv=none; b=H0nGSW6cRs8a4kvveUL9iW7lPUOr0/s5Hby3OP4WqXycGW9A+In6WqZljhXFcYMKlX9jng sLopQjUL8sBXVXgLUydBYPG1iGJ5mFOv3sretziTGsvwyD/jOMiz0YoheY+3eHM2mNujfQ 8laiMuBWzuwBJ6jvXerXiZnRCYQeJH8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hUWRQtgZ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.222.41 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-86d3805a551so705958241.3 for ; Fri, 07 Mar 2025 05:35:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741354511; x=1741959311; 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=7d+R6+9QRbHOe69NMdbDCrWyNRLbx9LvgB+dGXyclrw=; b=hUWRQtgZdgPmbur+fz113zLgBnvyRNst6Cv6rw1EEJpcc+zFfTZjY05Y0gnHMMAVfF sn68Ohs1c7fQVAfyHUa76Y8eHSBRUqU+430nPcLU4wLfhssWM3TZMyDwuZWidQxFy37J EPeJpOTRkdmZ6M3gYksx1ZFwkCFylyGgbBi2zCWdgqvH+g6uF68W09z7rDV09/+0EUJG yXnB+62DSJEVFvufz5thZY2FwtWi1RIwqyJ/74Nv0nYGwtZmWUu5qrg3h6BCZ3tjmB/t vhIIfnPqPQ6340qz1tB6tpO1ICWlOVlFUb0D0ho6F7u7IO9cKSua/YV1evwSAjNrYqgH onjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741354511; x=1741959311; 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=7d+R6+9QRbHOe69NMdbDCrWyNRLbx9LvgB+dGXyclrw=; b=hOPO61Ld7eg51IFfBNPB2BVaPAh55WyQENA88Fcmq54oFkkiESlrKi8DnGCBMhqy/0 Qcs1n6OEeYWqqVx6EjiBig8S5qVsOJ9Jvr8lFTxt/eJ47WcehdkceUKR0Y1x6qZOQ85t fKde2qz086cGLz/+Pvr5aIAaMpK6P0RZcdT2+hXebMCJdomnpugutrQZ/vOIyG4TONNf irkhfebQOMAHBlm0brngC6Itf/Q2UO9uC/NBn3GlUknEkLWVJs6+fyCcFyKLYCd4chDS 2w7CWb+TDaibAooQskIIgXriOL7EDDtlC8TBJIjoQgFgyhHU73Pj0YxoXOC7Duxn+asC DFqg== X-Forwarded-Encrypted: i=1; AJvYcCV0rdZA76YOZbC0Rcfg+G6NJ8EYAkwX9y7XQUEg56DlpEDmQXBgClC7HVymX37O4iOoroPlXhAF1g==@kvack.org X-Gm-Message-State: AOJu0Yw4jEuG1Blm5Vvo/8Q8YZ8IfSyBOdJw/Qd+6FQqFy8vPvZBLHlb zO0BWBBER6aTlhXtEbdKFp7Y4kIz7rYhlXUXQ3dvPN6xG9fgTbkzPFlcBBUgeVLm/LIIxBTnuxu 1/9VRG/WEgLiTPaFpfX7mMkTHD7c= X-Gm-Gg: ASbGncuVezhbsAxogzVRAfS39n2zT9Vc9wGjhCQGe3pSjIlq306QxSDG3MCHKwXV+D1 5xs7fU5O5PKR3fW9OKHtaP/riaRT6AxQKs1GAmQsrT634sk9VF9yVDvo40Y5DqEt84z7pVHhTWt QJZzfQhY9QA5q5xy1GtVZ/XaM8wZUWzbWK3TTDc6uFFLnHvV7t9M1eIYnTpw== X-Google-Smtp-Source: AGHT+IEkZO8dAQmykN6hNMMyQP1GXA46jfVdXAgpT6xAUKZnPvfks06dX+OWRJ7CBhP0PhWT+OLQRoeCII1pXtLbc1g= X-Received: by 2002:a05:6102:cd3:b0:4c1:9780:3830 with SMTP id ada2fe7eead31-4c30a733b18mr1768213137.23.1741354511217; Fri, 07 Mar 2025 05:35:11 -0800 (PST) MIME-Version: 1.0 References: <20250306214948.2939043-1-yang@os.amperecomputing.com> <6f3cece7-4dc6-471c-978c-efcf4bbe64ce@lucifer.local> In-Reply-To: <6f3cece7-4dc6-471c-978c-efcf4bbe64ce@lucifer.local> From: Pedro Falcato Date: Fri, 7 Mar 2025 13:35:00 +0000 X-Gm-Features: AQ5f1JrW5M0MlO1Hs8HBHVa-tCdbr7o0box7gQiKi-i5Rvl74Y-7M6jz0SmBrCY Message-ID: Subject: Re: [PATCH] mm: vma: skip anonymous vma when inserting vma to file rmap tree To: Lorenzo Stoakes Cc: Yang Shi , Liam.Howlett@oracle.com, vbabka@suse.cz, jannh@google.com, oliver.sang@intel.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 323CE40007 X-Stat-Signature: otjg7rsyf87szxm6bufia4jidwdb81qq X-HE-Tag: 1741354512-563663 X-HE-Meta: U2FsdGVkX1+/RE7NC5HZDBs/HT4ijSWODyyd4vjf1Msqf61P77il/RZDehvdE7Er9sZ0VONzByNley3lJUugTmstACkCnsaWbyTIujnEZwjy00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g4ubv6MiUN7yLvuNseh6CMhnylFieSqgdhDETtN6D+tVCFyuNrNiwY9epUJpNGcKIppri0ZPmEfenL41zp5hCCINI93Ig6WkkUzBnDxHN7nvprV4Lq/p7Ro6MewVDW8vm89QB2cPbKBtSzuKfHe/iGJtpK1X+ezgO8osKJYp5iFk3WTICiCuc98dAXh22iWSwFMwrWi2wIHu7o7+IDwBl/unGHBCtgNE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000025, 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 Fri, Mar 7, 2025 at 1:12=E2=80=AFPM Lorenzo Stoakes wrote: > > On Thu, Mar 06, 2025 at 01:49:48PM -0800, Yang Shi wrote: > > LKP reported 800% performance improvement for small-allocs benchmark > > from vm-scalability [1] with patch ("/dev/zero: make private mapping > > full anonymous mapping") [2], but the patch was nack'ed since it change= s > > the output of smaps somewhat. > > Yeah sorry about that, but unfortunately something we really do have to > think about (among other things, the VMA edge cases are always the source > of weirdness...) > > > > > The profiling shows one of the major sources of the performance > > improvement is the less contention to i_mmap_rwsem. > > Great work tracking that down! Sorry I lost track of the other thread. > > > > > The small-allocs benchmark creates a lot of 40K size memory maps by > > mmap'ing private /dev/zero then triggers page fault on the mappings. > > When creating private mapping for /dev/zero, the anonymous VMA is > > created, but it has valid vm_file. Kernel basically assumes anonymous > > VMAs should have NULL vm_file, for example, mmap inserts VMA to the fil= e > > rmap tree if vm_file is not NULL. So the private /dev/zero mapping > > will be inserted to the file rmap tree, this resulted in the contention > > to i_mmap_rwsem. But it is actually anonymous VMA, so it is pointless > > to insert it to file rmap tree. > > Ughhhh god haha. > > > > > Skip anonymous VMA for this case. Over 400% performance improvement wa= s > > reported [3]. > > That's insane. Amazing work. > Ok, so the real question (to Yang) is: who are these /dev/zero users that require an insane degree of scalability, and why didn't they switch to regular MAP_ANONYMOUS? Are they in the room with us? > > > > It is not on par with the 800% improvement from the original patch. It= is > > because page fault handler needs to access some members of struct file > > if vm_file is not NULL, for example, f_mode and f_mapping. They are in > > the same cacheline with file refcount. When mmap'ing a file the file > > refcount is inc'ed and dec'ed, this caused bad cache false sharing > > problem. The further debug showed checking whether the VMA is anonymou= s > > or not can alleviate the problem. But I'm not sure whether it is the > > best way to handle it, maybe we should consider shuffle the layout of > > struct file. > > Interesting, I guess you'll take a look at this also? ... And this is probably a non-issue in 99% of !/dev/zero mmaps unless it's something like libc.so.6 at an insane rate of execs/second. This seems like a patch in search of a problem and I really don't see why we should wart up the mmap code otherwise. Not that I have a huge problem with this patch, which is somewhat simple and obvious. It'd be great if there was a real workload driving this rather than useless synthetic benchmarks. --=20 Pedro