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 87B1ED743F3 for ; Wed, 20 Nov 2024 23:44:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D231D6B007B; Wed, 20 Nov 2024 18:44:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD3566B0083; Wed, 20 Nov 2024 18:44:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9B2C6B0085; Wed, 20 Nov 2024 18:44:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9E4FF6B007B for ; Wed, 20 Nov 2024 18:44:44 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1A35B160218 for ; Wed, 20 Nov 2024 23:44:44 +0000 (UTC) X-FDA: 82808104050.10.1A1FA18 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf12.hostedemail.com (Postfix) with ESMTP id EE14C4000B for ; Wed, 20 Nov 2024 23:44:18 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=maQq7dCW; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of surenb@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732146097; 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=MxlIf7epPu0Gfnfexi0C2Kwjnv8g1AAJhtWmrHEoFGU=; b=DeeAQpifO859riDIH06aJ8c5MK/vTzw1RfSo9EE4Q/Fl1dAFn2B8Pl9gyB48WJYTE+h10s k/ZpgvFqt7QOywkIPfljcA9WwrbirqIVw38zs/CEwR3LgZL+ckKOIKkIwuuV3MJEc0j1sY 6egMq9WlLR+9UsC7xVdGdOk1ic2MhrM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=maQq7dCW; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of surenb@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732146097; a=rsa-sha256; cv=none; b=7S841CDJFqhCzZZi+Nx+faksEBkakZMQhUcloztsp7LoIFGhordm9C6IhyAtdwMM71THUv gIMdUYeaSAzo/eGxq+YEaXNxltIqI/+P81WqDj6DF2Xdt+PdOBmo3nqAqSAHc4zEb5F1kK 81l5AxDGp5zpUBZKMk9AFEj2ytY6Zhs= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-4608dddaa35so148241cf.0 for ; Wed, 20 Nov 2024 15:44:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732146281; x=1732751081; 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=MxlIf7epPu0Gfnfexi0C2Kwjnv8g1AAJhtWmrHEoFGU=; b=maQq7dCWCEmoOO/mXVSWGhKjfkxyZWJ5smALLJboPjeSRdTNmsLeh+TiABh/+2SxMy 6S5pk2XXZtuUnGClAiSlrrn5C5eOjjo6wArv3eDdwJxLEvGIuyLl4oD+Z78s31C3b5TF W50BR4vTH/LxkTE/ShsYW+IIigGbb/6YgIlkFUJZ4T25seBbzZkLBpVhkbhRA0KfE7lT wRxbHBt/FUHVueDKHUVnoyzRWt3WyRYLVwKA2STLB1ySBI/S1uSf2QPDwhybHSp0/NX2 7wmIcU6yOb5xKap6/b86EowA5TKuEmnBPq06YrcoPRnouUqhuqwNTxBpO65W9Z8rYNdX z+eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732146281; x=1732751081; 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=MxlIf7epPu0Gfnfexi0C2Kwjnv8g1AAJhtWmrHEoFGU=; b=W75AC8/mvrP+L+Jxnrv6EmZtuoR8Fq/4kNzMjfhgmGnsA6h/qFoR0nv3Tz3zcSDbzr 5E/97rNppDBlGF6fl9NVIY80+ZPtLEISWODxnriDwO4roz3QWgFJmBuPLAHOD1kUyZdj YHJMNK7o+mhIFSUYPRNjonOsl0ZG9Qfzxwz47Wv2y+fAslpVH+nX2vyrgfG5BapZzJsA sn91awpq3lx+Rc6azcQHHawWngYDjhUMfMlwSQmKSsOOgGQGUefwiaqc4MOHYnriGHtE un4cn5HG+Szw+clVradRjMEsORnStCrnQ1oFRMUGtFu6x2bvVGYiJg0cmQebmVw8rEmK c+dg== X-Forwarded-Encrypted: i=1; AJvYcCWUMNX38dAEMlOPzs4j4VVx5G2CUvnwgIsFy6GDiBzjkGppQqgyRnn4EXNBPWwpq5X3fXHDE4Rs0g==@kvack.org X-Gm-Message-State: AOJu0YztOaK20vS3RiTHkrJ+hxHRs8r5TI7rMBEFcivohEftZC5PDixK +UEAaA4X4yOs8xCtRK2x8fpatWtxmcQNGNJgXwNKt+4L/SfhmZW4jcKN2MdDjx2WnRaWmwRZxTc YLxFI03gYk0mh23NGSZKy+qtVDHd+7dddY8Cb X-Gm-Gg: ASbGncvnHpKkChoe/3Wnf8PxDDuJ+rVVhpJ+j2gSHkGv0Ax8O7c29TyjRxk7NcUp2Mz nr0tSmflXKgA16EPJRq5OKXs6vYJnVDE= X-Google-Smtp-Source: AGHT+IEe3+sA9ZC//JKUWhAcs4Y8+fxRca4+aY14pz1BRAB49A2SGTYA3dnT6lGqw0fmkJDYqZoIMrZMcDmmK2UU1uA= X-Received: by 2002:ac8:7d0c:0:b0:460:f093:f259 with SMTP id d75a77b69052e-465300c93f2mr1217201cf.22.1732146281054; Wed, 20 Nov 2024 15:44:41 -0800 (PST) MIME-Version: 1.0 References: <20241120000826.335387-1-surenb@google.com> <20241120000826.335387-3-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 20 Nov 2024 15:44:29 -0800 Message-ID: Subject: Re: [PATCH v4 2/5] mm: move per-vma lock into vm_area_struct To: Shakeel Butt Cc: akpm@linux-foundation.org, willy@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mjguzik@gmail.com, oliver.sang@intel.com, mgorman@techsingularity.net, david@redhat.com, peterx@redhat.com, oleg@redhat.com, dave@stgolabs.net, paulmck@kernel.org, brauner@kernel.org, dhowells@redhat.com, hdanton@sina.com, hughd@google.com, minchan@google.com, jannh@google.com, souravpanda@google.com, pasha.tatashin@soleen.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EE14C4000B X-Stat-Signature: ximnwuoewomsbnnaohf766iy4tibnumw X-Rspam-User: X-HE-Tag: 1732146258-845309 X-HE-Meta: U2FsdGVkX1+ElrqzlwwH6QPhVm6WZ/CRFl7taT/BSwbhFEAeSgjAaz3LornEhu078saYuRU8pxI+tZ/TPxM8Q9UB89aFpEPGVyOmMJcCUp9k/N0AJIC6ECLTd7m2hw++fiErmccDT48AhCo940jXdVQ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78KOeQg47XB9W03rGxfOT5rrN2fKPip2AoENOikhncTO/Ra6B/OOJBRt705R0sjDsB3osd3sEgKgYwtxwTuU9IsuSw93yklZjHUxVPdFwHoE0Q== 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 Wed, Nov 20, 2024 at 3:33=E2=80=AFPM Shakeel Butt wrote: > > On Tue, Nov 19, 2024 at 04:08:23PM -0800, Suren Baghdasaryan wrote: > > Back when per-vma locks were introduces, vm_lock was moved out of > > vm_area_struct in [1] because of the performance regression caused by > > false cacheline sharing. Recent investigation [2] revealed that the > > regressions is limited to a rather old Broadwell microarchitecture and > > even there it can be mitigated by disabling adjacent cacheline > > prefetching, see [3]. > > Splitting single logical structure into multiple ones leads to more > > complicated management, extra pointer dereferences and overall less > > maintainable code. When that split-away part is a lock, it complicates > > things even further. With no performance benefits, there are no reasons > > for this split. Merging the vm_lock back into vm_area_struct also allow= s > > vm_area_struct to use SLAB_TYPESAFE_BY_RCU later in this patchset. > > Move vm_lock back into vm_area_struct, aligning it at the cacheline > > boundary and changing the cache to be cacheline-aligned as well. > > With kernel compiled using defconfig, this causes VMA memory consumptio= n > > to grow from 160 (vm_area_struct) + 40 (vm_lock) bytes to 256 bytes: > > > > slabinfo before: > > ... : ... > > vma_lock ... 40 102 1 : ... > > vm_area_struct ... 160 51 2 : ... > > > > slabinfo after moving vm_lock: > > ... : ... > > vm_area_struct ... 256 32 2 : ... > > > > Aggregate VMA memory consumption per 1000 VMAs grows from 50 to 64 page= s, > > which is 5.5MB per 100000 VMAs. Note that the size of this structure is > > dependent on the kernel configuration and typically the original size i= s > > higher than 160 bytes. Therefore these calculations are close to the > > worst case scenario. A more realistic vm_area_struct usage before this > > change is: > > > > ... : ... > > vma_lock ... 40 102 1 : ... > > vm_area_struct ... 176 46 2 : ... > > > > Aggregate VMA memory consumption per 1000 VMAs grows from 54 to 64 page= s, > > which is 3.9MB per 100000 VMAs. > > This memory consumption growth can be addressed later by optimizing the > > vm_lock. > > > > [1] https://lore.kernel.org/all/20230227173632.3292573-34-surenb@google= .com/ > > [2] https://lore.kernel.org/all/ZsQyI%2F087V34JoIt@xsang-OptiPlex-9020/ > > [3] https://lore.kernel.org/all/CAJuCfpEisU8Lfe96AYJDZ+OM4NoPmnw9bP53cT= _kbfP_pR+-2g@mail.gmail.com/ > > > > Signed-off-by: Suren Baghdasaryan > > Reviewed-by: Lorenzo Stoakes > > Reviewed-by: Shakeel Butt Thanks! > > > One question below. > > > --- a/include/linux/mm_types.h > > +++ b/include/linux/mm_types.h > > @@ -716,8 +716,6 @@ struct vm_area_struct { > > * slowpath. > > */ > > unsigned int vm_lock_seq; > > - /* Unstable RCU readers are allowed to read this. */ > > - struct vma_lock *vm_lock; > > #endif > > > > /* > > @@ -770,6 +768,10 @@ struct vm_area_struct { > > struct vma_numab_state *numab_state; /* NUMA Balancing state *= / > > #endif > > struct vm_userfaultfd_ctx vm_userfaultfd_ctx; > > +#ifdef CONFIG_PER_VMA_LOCK > > + /* Unstable RCU readers are allowed to read this. */ > > + struct vma_lock vm_lock ____cacheline_aligned_in_smp; > > +#endif > > } __randomize_layout; > > Do we just want 'struct vm_area_struct' to be cacheline aligned or do we > want 'struct vma_lock vm_lock' to be on a separate cacheline as well? We want both to minimize cacheline sharing. >