Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5436519imm; Tue, 31 Jul 2018 10:51:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd6iz+HHm7bv3eVliW+3x3Cz6LPdpJMXz9B5bgpBQuGwJsnEr9pWZtg+dOLqb7LiSnaAECn X-Received: by 2002:a63:a347:: with SMTP id v7-v6mr20817649pgn.182.1533059494254; Tue, 31 Jul 2018 10:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533059494; cv=none; d=google.com; s=arc-20160816; b=yUGxaRZdhRV+DL2oGxekzQolsqAfwipsDDwFLA2xe+OgQhCvJXcpOaDjDnAKNahxyi MLf3acc7YXIgkrCExi0UXN0UXZBW6Olq+C3KJH8Zan3VlOPxS9Cjlc+V71gX1gBIUqID dwDOHsOBh4y0kGsCAUKBgota33ftulZwykilmXMiEuMo7U6oH9E4MtmTceNehmkYbUTd 5u3Szuf7jjzI/5wsJe4viER15+GEnmYbJYuZTrPB3EJUvLciSiI4vRf17BxIj+7C3frm qyBOSWVAfbYXGbxVbMHe35tDMO5qmJBBRpj9vCE+/WVtGlvH2iWpkIjN8d9GF6OfTPZo viGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=hMnhkj+uN1WyHd0klgsn6XEPLEkU9GzwvBGDs/L2sPs=; b=nQHrQgIw9T3K6MlhecVeGT5Y42KE2bqvwR0dEWMIvkW5dKbjYIMh9/IWThTjUc/5YL egeE6eZ/47WXjTFAGGvGk/32HexLRk8VmYu1z1JWldE2z4se94qNnm6rs7z9U72gTVZx BC65OWC+nNLEvSW1yoi62zrbvFKNauEITJ0mJp+eTJoLtGWKemaKgHFfugheIlOhrWqZ I7cFklJhH0EaAOgUhDOCtO1cUzHge3+bJomFB4qAmUMmjuut1aPHJ2JgEIYBvnzqAAvw OeV1O0zIE0CC0utbCjBXoEOy4xBjts1qWh2pP63CTQAwKNR4AE1+E/ZR94FPD7w6wEBQ IUcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QgrVH1YV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18-v6si13380670pgl.171.2018.07.31.10.51.19; Tue, 31 Jul 2018 10:51:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QgrVH1YV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731902AbeGaTb2 (ORCPT + 99 others); Tue, 31 Jul 2018 15:31:28 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:54666 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728750AbeGaTbF (ORCPT ); Tue, 31 Jul 2018 15:31:05 -0400 Received: by mail-it0-f66.google.com with SMTP id s7-v6so5720008itb.4; Tue, 31 Jul 2018 10:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hMnhkj+uN1WyHd0klgsn6XEPLEkU9GzwvBGDs/L2sPs=; b=QgrVH1YV+UFfWC3tyEcPFCgplvK17nX1cI2nQwFpDsC1kJT/xrSTbwS7BJ5wyzF37h hV1HEijvZiDlGvF8IcCP1PhE/8yqYHNhrOJWDiWpcRJ7+rv3HWbk1EFA7dG4TjTlJbR3 Ld4BTVz+kpDMM3r2BnHqppCVpjKqWTkyUXDjY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hMnhkj+uN1WyHd0klgsn6XEPLEkU9GzwvBGDs/L2sPs=; b=EbUevyA8FxgWav7jlyJCX+dNJTLbexfD2NCWRb3eC1jID3+H3vqAxNAW0ft4XM7GBi UpaLwHv/MpwnlVoP7lZ92jMJv31RYzzlBby/Q/HZTzMqUqCyIHltOCheWXAQMFRwPo5p pcCSqZ4NXxe+2WtxhGOR3IEoRz1wkGZQcbGFof63Bp7vVBjlxXI/EwTHyWoWstGN17cb dkYyTv/3Cz+ie1vdj958dIY0j/0nJ50xpZ3J3UJtGWCe2ENIMsZec7IsjcywossSDskk urXeEVP8L/Ufpy6ecj5BJFufd225mZgbEvsA6ex9MoTXZUXfEtl4rBuJwT+1XKljw7yV JjhA== X-Gm-Message-State: AOUpUlFShPkFpqNnXoo1LmL/l1U3MGEsxnaztl5wvFX7iSgTzSYXVqB8 M+8bnpu/1bPVkrt2hiS7OusHpnq/76MAo43mPAs= X-Received: by 2002:a24:5002:: with SMTP id m2-v6mr647617itb.16.1533059379396; Tue, 31 Jul 2018 10:49:39 -0700 (PDT) MIME-Version: 1.0 References: <01000164f169bc6b-c73a8353-d7d9-47ec-a782-90aadcb86bfb-000000@email.amazonses.com> In-Reply-To: <01000164f169bc6b-c73a8353-d7d9-47ec-a782-90aadcb86bfb-000000@email.amazonses.com> From: Linus Torvalds Date: Tue, 31 Jul 2018 10:49:28 -0700 Message-ID: Subject: Re: SLAB_TYPESAFE_BY_RCU without constructors (was Re: [PATCH v4 13/17] khwasan: add hooks implementation) To: Christoph Lameter Cc: Andrey Ryabinin , "Theodore Ts'o" , Jan Kara , linux-ext4@vger.kernel.org, Greg Kroah-Hartman , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , David Miller , NetFilter , coreteam@netfilter.org, Network Development , gerrit@erg.abdn.ac.uk, dccp@vger.kernel.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Dave Airlie , intel-gfx , DRI , Eric Dumazet , Alexey Kuznetsov , Hideaki YOSHIFUJI , Ursula Braun , linux-s390 , Linux Kernel Mailing List , Dmitry Vyukov , Andrew Morton , linux-mm , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 31, 2018 at 10:36 AM Christopher Lameter wrote: > > If there is refcounting going on then why use SLAB_TYPESAFE_BY_RCU? .. because the object can be accessed (by RCU) after the refcount has gone down to zero, and the thing has been released. That's the whole and only point of SLAB_TYPESAFE_BY_RCU. That flag basically says: "I may end up accessing this object *after* it has been free'd, because there may be RCU lookups in flight" This has nothing to do with constructors. It's ok if the object gets reused as an object of the same type and does *not* get re-initialized, because we're perfectly fine seeing old stale data. What it guarantees is that the slab isn't shared with any other kind of object, _and_ that the underlying pages are free'd after an RCU quiescent period (so the pages aren't shared with another kind of object either during an RCU walk). And it doesn't necessarily have to have a constructor, because the thing that a RCU walk will care about is (a) guaranteed to be an object that *has* been on some RCU list (so it's not a "new" object) (b) the RCU walk needs to have logic to verify that it's still the *same* object and hasn't been re-used as something else. So the re-use might initialize the fields lazily, not necessarily using a ctor. And the point of using SLAB_TYPESAFE_BY_RCU is that using the more traditional RCU freeing - where you free each object one by one with an RCU delay - can be prohibitively slow and have a huge memory overhead (because of big chunks of memory that are queued for freeing). In contrast, a SLAB_TYPESAFE_BY_RCU memory gets free'd and re-used immediately, but because it gets reused as the same kind of object, the RCU walker can "know" what parts have meaning for re-use, in a way it couidn't if the re-use was random. That said, it *is* subtle, and people should be careful. Linus