Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp21431rdb; Wed, 14 Feb 2024 11:20:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUuR4SLS9MXx+UKBaGkiIp7fLQ9NvjznM+smq2v5iu7/gwdbXFklCLpEKwsa19Jx5jfWQbXvQBY5Mtr7jF6J9iqEYwxTsawebQK2QuRsA== X-Google-Smtp-Source: AGHT+IGFYWIcRz6eAzcxDECB/1kFpgYOpbyhbCZAxqGzpQNixFLP70p/zNY4FdvrZutBeORxkACH X-Received: by 2002:ac2:5f74:0:b0:511:a1b5:538a with SMTP id c20-20020ac25f74000000b00511a1b5538amr2331383lfc.69.1707938421709; Wed, 14 Feb 2024 11:20:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707938421; cv=pass; d=google.com; s=arc-20160816; b=FRkUGI6s646WO+ZLl4F06atUCBB0wfOpndamQ3KZGlA+1V/2HRbQ8UQt4w6uDlyPgO Aogiw11ChfpvtD+MrDsm+OQMKhvAWfES34P7o+3cPN+LYw74X31APAuVZWCv3CmRTD9C FrXbRJauZYlMCshmDsv4nBPmjgbuIomuqpCLa9b7MEs/xQyMVncAc11ZTsBtRjQ3FxH/ ZNi9/HRBa8YjLUckrysfDn8q6vaKwZlwETgZxokQBW1hYO284V7cl+HOsPX03LLKLJXW cpy4qyb+nflZX1Uh2/w3FUV8GQm85rDJUSVw+SvmIPW4N/5K/23JQw+iirJMXQ/wCQDZ 6AAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=BeLyV2BNkjBFN275c/stAXS4Zt5cMLEm0RT7xxWo7xU=; fh=6El6k0qdDUZr4vWHmuzDS+DB8/hagTxw+VYsetQnS7I=; b=lx9sShoDYUTN8fnksg8IujnvUceTaxBQlKHE9QEsydLXZWxNWUmWmwHIWKdyw20CMD NSJrb57zgIqIuzvwuEVSOiz52vqFhzPIr4F6Wj+G3PyfIto8fEHV1d0R4XZLSlyVNXh3 SoMOByFus3QLeQ6lbke6th+3gZZPvD/eDhTfkwF4ZlgDwQvrIxxiFYyU/Q8yeooPf+Yi fQNryroa+Ha+DlyfU0OiBtQ0kZYOrQc654b1DICLJgdmYuJBck8ISNgpPBJyCTBNgLY/ sY154wEFKCEezmO1pxBkJHjneXwRdvrIgLQR7vlGAxBQDSiAgyHn/theKfE6oz9JFeOQ Lngg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="vzsyc/dB"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-65874-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65874-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCVB7+7GH0SqsYcI2tkx4fdSIiW2bacqoFrBytbSNFbH3K8eye6taft1cP8DokNIjGxw42+hRaKibWW28BdEBub2KFpFVzkN48Kcqf6jsg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id nc33-20020a1709071c2100b00a3d440e278esi923666ejc.1009.2024.02.14.11.20.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 11:20:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65874-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="vzsyc/dB"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-65874-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65874-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3BF6B1F24CCB for ; Wed, 14 Feb 2024 19:20:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C385313B785; Wed, 14 Feb 2024 19:20:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vzsyc/dB" Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A819713A86A for ; Wed, 14 Feb 2024 19:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707938406; cv=none; b=hkK4zukpj8cw1K9Oa7nJL50rWVspmxQXVJcky6SonWfz9dSH+lloc2kVkL/lXA2kUfGPscokTZOUvWmh7oXFSLXTCaQv8RjApOfPObXFGdxu13gqdWYpyGqGNDxwsSxpPD+KyNv3rt6JicUe/Vr3Fv3eSox1X+c/h9H46ETPprc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707938406; c=relaxed/simple; bh=mthDvVI6cDtpS/5u1GLcBFHB8octCFvJ1gmdlmC2/g8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Ivb5RHCts7582t44N7SYE5CoiUSPJQKGegQyIy4VD6tuAzlLqspsMQrxgoIAHDqJ3m+4JGHZ0Yj7LRmsX3rTW3OVTuIQnxKRDs3Iu7G/MlBEAYr1qlpdm5wFi1ZbQ31tZVR+IenReVJxE/eqfsnVP52+5J64eQwwds+UaiK8aOI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vzsyc/dB; arc=none smtp.client-ip=209.85.219.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-dc74435c428so2869276.2 for ; Wed, 14 Feb 2024 11:20:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707938402; x=1708543202; darn=vger.kernel.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=BeLyV2BNkjBFN275c/stAXS4Zt5cMLEm0RT7xxWo7xU=; b=vzsyc/dBYTal5mdxOeGdp4NEX35TDKlH+6+R5osTjObyVOFPKmuOckvRCA0hdvduJ1 pzqdXW65WXwkrdQkOriu8rD+jDKQUvYGf8lsGtOO59xihRS0NyFLNZ5GUY+VLqt+Fzxy FZPzlfdh5Z7oQG7zCs1cn4HEOeGTZtyXMTij+JGAX5CjdG0AcTbvnOy4r/8bcyrhKv9A EvCOKzrZGOcpjHarSD/RShWRdIstGU0OoU62vBfKjk4695S0fTBPLPJFOlwKva/y15MH T0B8TsWnMiUa5Pbd/zKbwgXK5OIK5Dfkc7ApJIDV4xqpnfJS4q7EkFsjFRcsJVKvX5X2 r//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707938402; x=1708543202; 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=BeLyV2BNkjBFN275c/stAXS4Zt5cMLEm0RT7xxWo7xU=; b=m1DYWOJ43ieTrqboh5pwaAUMVFin0fVWId5dpNWDOlaavTvjx7YpBXqrrESSGO6xeF 2gFsQh9PAjdDdRNWqSov3OBPMj7Tllb+ScPoB/SlXvWsL7W2TajC+SdINrmEDlkqCJJe CXNe1BkgEVUM9TwYaDfk+WkBz+AS3gVaBGaBhl5+Ojq2kwxyfK/VKqVG8GUGzi2f7KFE 61Wybm4AF/cmayRLCXLT87c9TDCfQldD5HcMhBGPRFPu/rny/c+QOf6GeEPDAk+NhJXn 99SxxdQldU9ualoEQSH0b1pVaA0+Csmb2mnzOrKL9giP1OkY+nCz2F4dH7ayo3vy8+gh 9KkQ== X-Forwarded-Encrypted: i=1; AJvYcCXKnN8JWxL24Zd8EsaouwQULizuU2XFHDhoT32rQtbLLdD/OL4pl4QYvvbUF1LvQ7/H07yT0IWuLbsvVK86p6QNwrvMa338SCSZOuMY X-Gm-Message-State: AOJu0Yzvk6sN35PMehZ3WG6iMfzG5bW6kqeg4m3wVk5bnY8IYF4HOC8S PTnbKA/iQTaVkNk9n6AiThbhzRreC86yUwn5yiZeFxjpL0SdTyBkGidn2IvQvINlNvSvOIcNP3F mZXBK/ixUpCrQfSB5zDz+Vu9O1d85Qvk2ZrjJ X-Received: by 2002:a25:8708:0:b0:dc6:c617:7ca with SMTP id a8-20020a258708000000b00dc6c61707camr3594670ybl.29.1707938402225; Wed, 14 Feb 2024 11:20:02 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> <20240212213922.783301-6-surenb@google.com> <3cf2acae-cb8d-455a-b09d-a1fdc52f5774@suse.cz> In-Reply-To: <3cf2acae-cb8d-455a-b09d-a1fdc52f5774@suse.cz> From: Suren Baghdasaryan Date: Wed, 14 Feb 2024 11:19:51 -0800 Message-ID: Subject: Re: [PATCH v3 05/35] mm: introduce slabobj_ext to support slab object extensions To: Vlastimil Babka Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 14, 2024 at 9:59=E2=80=AFAM Vlastimil Babka wr= ote: > > On 2/12/24 22:38, Suren Baghdasaryan wrote: > > Currently slab pages can store only vectors of obj_cgroup pointers in > > page->memcg_data. Introduce slabobj_ext structure to allow more data > > to be stored for each slab object. Wrap obj_cgroup into slabobj_ext > > to support current functionality while allowing to extend slabobj_ext > > in the future. > > > > Signed-off-by: Suren Baghdasaryan > > ... > > > +static inline bool need_slab_obj_ext(void) > > +{ > > + /* > > + * CONFIG_MEMCG_KMEM creates vector of obj_cgroup objects conditi= onally > > + * inside memcg_slab_post_alloc_hook. No other users for now. > > + */ > > + return false; > > +} > > + > > +static inline struct slabobj_ext * > > +prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) > > +{ > > + struct slab *slab; > > + > > + if (!p) > > + return NULL; > > + > > + if (!need_slab_obj_ext()) > > + return NULL; > > + > > + slab =3D virt_to_slab(p); > > + if (!slab_obj_exts(slab) && > > + WARN(alloc_slab_obj_exts(slab, s, flags, false), > > + "%s, %s: Failed to create slab extension vector!\n", > > + __func__, s->name)) > > + return NULL; > > + > > + return slab_obj_exts(slab) + obj_to_index(s, slab, p); > > This is called in slab_post_alloc_hook() and the result stored to obj_ext= s > but unused. Maybe introduce this only in a later patch where it becomes > relevant? Ack. I'll move it into the patch where we start using obj_exts. > > > --- a/mm/slab_common.c > > +++ b/mm/slab_common.c > > @@ -201,6 +201,54 @@ struct kmem_cache *find_mergeable(unsigned int siz= e, unsigned int align, > > return NULL; > > } > > > > +#ifdef CONFIG_SLAB_OBJ_EXT > > +/* > > + * The allocated objcg pointers array is not accounted directly. > > + * Moreover, it should not come from DMA buffer and is not readily > > + * reclaimable. So those GFP bits should be masked off. > > + */ > > +#define OBJCGS_CLEAR_MASK (__GFP_DMA | __GFP_RECLAIMABLE | \ > > + __GFP_ACCOUNT | __GFP_NOFAIL) > > + > > +int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, > > + gfp_t gfp, bool new_slab) > > Since you're moving this function between files anyway, could you please > instead move it to mm/slub.c. I expect we'll eventually (maybe even soon) > move the rest of performance sensitive kmemcg hooks there as well to make > inlining possible. Will do. > > > +{ > > + unsigned int objects =3D objs_per_slab(s, slab); > > + unsigned long obj_exts; > > + void *vec; > > + > > + gfp &=3D ~OBJCGS_CLEAR_MASK; > > + vec =3D kcalloc_node(objects, sizeof(struct slabobj_ext), gfp, > > + slab_nid(slab)); > > + if (!vec) > > + return -ENOMEM; > > + > > + obj_exts =3D (unsigned long)vec; > > +#ifdef CONFIG_MEMCG > > + obj_exts |=3D MEMCG_DATA_OBJEXTS; > > +#endif > > + if (new_slab) { > > + /* > > + * If the slab is brand new and nobody can yet access its > > + * obj_exts, no synchronization is required and obj_exts = can > > + * be simply assigned. > > + */ > > + slab->obj_exts =3D obj_exts; > > + } else if (cmpxchg(&slab->obj_exts, 0, obj_exts)) { > > + /* > > + * If the slab is already in use, somebody can allocate a= nd > > + * assign slabobj_exts in parallel. In this case the exis= ting > > + * objcg vector should be reused. > > + */ > > + kfree(vec); > > + return 0; > > + } > > + > > + kmemleak_not_leak(vec); > > + return 0; > > +} > > +#endif /* CONFIG_SLAB_OBJ_EXT */ > > + > > static struct kmem_cache *create_cache(const char *name, > > unsigned int object_size, unsigned int align, > > slab_flags_t flags, unsigned int useroffset, > > diff --git a/mm/slub.c b/mm/slub.c > > index 2ef88bbf56a3..1eb1050814aa 100644 > > --- a/mm/slub.c > > +++ b/mm/slub.c > > @@ -683,10 +683,10 @@ static inline bool __slab_update_freelist(struct = kmem_cache *s, struct slab *sla > > > > if (s->flags & __CMPXCHG_DOUBLE) { > > ret =3D __update_freelist_fast(slab, freelist_old, counte= rs_old, > > - freelist_new, counters_new); > > + freelist_new, counters_new); > > } else { > > ret =3D __update_freelist_slow(slab, freelist_old, counte= rs_old, > > - freelist_new, counters_new); > > + freelist_new, counters_new); > > } > > if (likely(ret)) > > return true; > > @@ -710,13 +710,13 @@ static inline bool slab_update_freelist(struct km= em_cache *s, struct slab *slab, > > > > if (s->flags & __CMPXCHG_DOUBLE) { > > ret =3D __update_freelist_fast(slab, freelist_old, counte= rs_old, > > - freelist_new, counters_new); > > + freelist_new, counters_new); > > } else { > > unsigned long flags; > > > > local_irq_save(flags); > > ret =3D __update_freelist_slow(slab, freelist_old, counte= rs_old, > > - freelist_new, counters_new); > > + freelist_new, counters_new); > > I can see the mixing of tabs and spaces is wrong but perhaps not fix it a= s > part of the series? I'll fix them in the next version. > > > local_irq_restore(flags); > > } > > if (likely(ret)) > > @@ -1881,13 +1881,25 @@ static inline enum node_stat_item cache_vmstat_= idx(struct kmem_cache *s) > > NR_SLAB_RECLAIMABLE_B : NR_SLAB_UNRECLAIMABLE_B; > > } > > > > -#ifdef CONFIG_MEMCG_KMEM > > -static inline void memcg_free_slab_cgroups(struct slab *slab) > > +#ifdef CONFIG_SLAB_OBJ_EXT > > +static inline void free_slab_obj_exts(struct slab *slab) > > Right, freeing is already here, so makes sense put the allocation here as= well. > > > @@ -3817,6 +3820,7 @@ void slab_post_alloc_hook(struct kmem_cache *s, s= truct obj_cgroup *objcg, > > kmemleak_alloc_recursive(p[i], s->object_size, 1, > > s->flags, init_flags); > > kmsan_slab_alloc(s, p[i], init_flags); > > + obj_exts =3D prepare_slab_obj_exts_hook(s, flags, p[i]); > > Yeah here's the hook used. Doesn't it generate a compiler warning? Maybe = at > least postpone the call until the result is further used. Yes, I'll move that into the patch where we start using it. Thanks for the review, Vlastimil! > > > } > > > > memcg_slab_post_alloc_hook(s, objcg, flags, size, p); > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >