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 0AD37C433EF for ; Wed, 15 Jun 2022 11:10:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49A646B0071; Wed, 15 Jun 2022 07:10:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 422D56B0072; Wed, 15 Jun 2022 07:10:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 275176B0073; Wed, 15 Jun 2022 07:10:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 128276B0071 for ; Wed, 15 Jun 2022 07:10:07 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D2A8121666 for ; Wed, 15 Jun 2022 11:10:06 +0000 (UTC) X-FDA: 79580200812.13.F396516 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf29.hostedemail.com (Postfix) with ESMTP id 675AD120083 for ; Wed, 15 Jun 2022 11:10:06 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id o6so10132803plg.2 for ; Wed, 15 Jun 2022 04:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZUJvI2mIr0H2JT9klD7hj8v0XWBj/xmpouDexRiutpo=; b=OV4LbbvNTOubDxSR19tlDR0mEttMuH5P4gikDuK2pS/QDLgBmAheHCN7uEq/l64G52 uDODflgmce8H7AwH9CPZ3+TtpLNxB7+djP3CwLZIeX665l8xf1S5v3750tZ+DCkQNYL0 RYemDfImpY+bTbuO1hkowkRgJAHgFJHOa8cp3h27zJ2hZLbMbkBH8MYfoKXceOLUuz3d hwkZvQU9ciMB39aztUHTUAAIfgi8GDCoeUajKSoPZBnOpCLiV3dD0uoouavxQMILNTpZ YNXoXYfeig/0CUWZLzE5GiOEPjH2E2ZPNr28EBGPUm0omWoXlxAhulUUCiUVMfXdHZG1 MOjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZUJvI2mIr0H2JT9klD7hj8v0XWBj/xmpouDexRiutpo=; b=ZEsKlq+ZmWW+9etxsDHBDmHPWpN6zAOSECkgixp0S/mCWN0XqAAe7g/e6IImjdlR7b Gy9bg77GkZs25YTHtT/ll4FfaAIbkLGedV5wPK7fHQmt6p+ZpZkoi9mORWoBu2XUVymY xe8/D8NwHXeqvCtFFHZg3x4WvO/Ha1XsOBoSiF/yKTj+HIxtrvxvo0lXxI04rckBljvi ChNhiVmZrfqpuiwZ1pB5gfpVM98DGerSUcXPGZbkFRpPuR5LLcms8T0NKwMmEit+79Y1 c2/sFhGblqkvJ4y8ByDN83JtyNfbG4YuDx1QZ6MQUjaH0ETPc2dFW7H6zMdSnzhpwHAp KLiw== X-Gm-Message-State: AJIora+WZYC38o8t9/TbmAq7VYnwZX7Trq1SSQfzkZMy3E5z+gzJ+OkA DX1MeHG2Hje0e+EYFkOp7JTarBqyq5xMX5Ex1kQ= X-Google-Smtp-Source: AGRyM1vaEEy9OdnuCJeSwh9Eq+nU4S/rlxRNs8UiJJ5SLzphXZKdVr4TdMlMfALolZK1gUaADJBFIvt4+uC/qCigmhY= X-Received: by 2002:a17:903:11c6:b0:167:90e5:59c2 with SMTP id q6-20020a17090311c600b0016790e559c2mr9048263plh.50.1655291405303; Wed, 15 Jun 2022 04:10:05 -0700 (PDT) MIME-Version: 1.0 References: <20220603143555.41914-1-sxwjean@me.com> In-Reply-To: From: Xiongwei Song Date: Wed, 15 Jun 2022 19:09:38 +0800 Message-ID: Subject: Re: [PATCH v2] mm/slub: Simplify __kmem_cache_alias() To: Vlastimil Babka Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Xiongwei Song , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Muchun Song , "linux-mm @ kvack . org" , Linux Kernel Mailing List , Xiongwei Song Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655291406; a=rsa-sha256; cv=none; b=tZR094F+DOfkmyd+Ycuj3U9CNfmcbi3FceXyjOP0JDEjyjgEtTL7mtMivnOTDBe8wHj5sr yGKdJfShJ+zmdmuTJxMOqg1fdau2sugsn3Pdm4xvrgOIhEiOAldVNq1Q9R7cAokgU53f++ 7mO3mIzJBhINEHdhWpZhJTDvW6UtNw4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OV4LbbvN; spf=pass (imf29.hostedemail.com: domain of sxwjean@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=sxwjean@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655291406; 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:in-reply-to:references:references:dkim-signature; bh=ZUJvI2mIr0H2JT9klD7hj8v0XWBj/xmpouDexRiutpo=; b=WKxTngIrrJgkiR2IBw5HR9MaD68BKqmVlQRwt2ElTuPcKwM1okDQxVjfFXBGzXfH/4ILg1 9eqrqrU1ngH6vGjZ9XcP2YuK4nVrpoQBRozA3lc8sePJMMPZyQJXwn9zEWU+24ItTvhsJS Afbp8+oW+55NlCcY4UQMs1TB+kTK5ZI= X-Stat-Signature: 1nso9fnsrpp6p3p4itcakixc6xa36pzf X-Rspamd-Queue-Id: 675AD120083 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OV4LbbvN; spf=pass (imf29.hostedemail.com: domain of sxwjean@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=sxwjean@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1655291406-96950 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: On Wed, Jun 15, 2022 at 4:37 PM Vlastimil Babka wrote: > > On 6/5/22 09:04, Xiongwei Song wrote: > > On Sat, Jun 4, 2022 at 5:43 PM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > >> > >> On Fri, Jun 03, 2022 at 10:35:55PM +0800, sxwjean@me.com wrote: > >> > From: Xiongwei Song > >> > > >> > There is no need to do anything if sysfs_slab_alias() return nonzero > >> > value after getting a mergeable cache. > >> > > >> > Signed-off-by: Xiongwei Song > >> > Reviewed-by: Muchun Song > >> > --- > >> > v2: Collect Reviewed-by tag from Muchun. > > Hmm I added v1 (with the Reviewed tag) before getting to the v2 thread. But > I think it's fine, see below. > > >> > --- > >> > mm/slub.c | 8 +++----- > >> > 1 file changed, 3 insertions(+), 5 deletions(-) > >> > > >> > diff --git a/mm/slub.c b/mm/slub.c > >> > index d8d5abf49f5f..9444277d669a 100644 > >> > --- a/mm/slub.c > >> > +++ b/mm/slub.c > >> > @@ -4861,6 +4861,9 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, > >> > > >> > s = find_mergeable(size, align, flags, name, ctor); > >> > if (s) { > >> > + if (sysfs_slab_alias(s, name)) > >> > + return NULL; > >> > + > >> > s->refcount++; > >> > > >> > >> I think we should not expose sysfs attributes before initializing > >> what can be read via sysfs attribute (object_size). > > Hmm I don't think they are unitialized. They have an old value from the > cache we are merging with, which is updated if the new aliased cache has a > larger one. > So yeah we might briefly during creation expose an alias that will have an > incorrect value, but I doubt anything will break. The values are not stable > anyway as new aliases are added, as we are bumping them for the 'root' cache > and all aliases that share it already. > > >> > /* > >> > @@ -4869,11 +4872,6 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, > >> > */ > >> > s->object_size = max(s->object_size, size); > >> > >> this calculation should be done before sysfs_slab_alias(). > > > > Yeah, understood. Should we restore s->object_size and s->inuse if > > sysfs_slab_alias() returns non zero value? > > And by bailing out early this patch effectively achieves that, so I'd say > it's a better state than before the patch so I'll keep it unless proven > otherwise. Thanks! Thank you for your comments Vlastimil and Hyeonggon. Regards, Xiongwei > > > Regards, > > Xiongwwei > > > >> > >> Thanks, > >> Hyeonggon > >> > >> > s->inuse = max(s->inuse, ALIGN(size, sizeof(void *))); > >> > - > >> > - if (sysfs_slab_alias(s, name)) { > >> > - s->refcount--; > >> > - s = NULL; > >> > - } > >> > } > >> > > >> > return s; > >> > -- > >> > 2.30.2 > >> > > >> >