Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp259431pxb; Fri, 15 Jan 2021 12:18:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGaei17p4dx50XPQqhoiEsQGDyPYHpDln27YAa1CGeUfNw3YL2sPdrSiN9BF3iB9ekfi+U X-Received: by 2002:a50:9310:: with SMTP id m16mr11078210eda.94.1610741905784; Fri, 15 Jan 2021 12:18:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610741905; cv=none; d=google.com; s=arc-20160816; b=iJG116G2K00v1cH367Q/G/XmWf7lDpYVMu2QkRVr0kwpEfRmizcfhAWEsmcDJCsbc2 W9os4hcbxxuRFyW8+DYdc98G9DJC5oH11z799hvKejGPV2fFV5nDCu+aruebuG9SrNa/ gNcsDWCm+jAD91HSnvcGhJdPcC7+S/ZBjfdboqx+qijg7IGOyVdjKIFCLsUIFiCz5Qr4 nXmSBLCuPsrvWJQ0r2XP4LOBQzBCGTcIX3duyPWENQIcs1Qv/CaKK9i3uumUnvTOo8Qt HGePEVPDTOefpgg1qbL6+mZ958l9vFVZ8A3unkVPzsrmQ7QIsLuqIU3g9PursLjEJc7W s09w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ySs7CNTOqN5GXMFt8JleozKLbcnnMYl8h0GybHe3ovo=; b=d8jW9vdfcsMKc147Io+pKNNrP31fSD9T/JKHCMGMzVglkJCwFXA6gZkn8XMDS1GqDg m79W52OdtF3oov06PYeF5wgBoUR43tcqGCLJ7VqOUhlZitQKb8CF83YpZiEaT/su0+OH 5wuI88zuFDcD/AL2xNw7MzhJsQyHFFXyPJ8E+q8LDMXvEAdmYJ4tBXg9QY7i/nycwksk GN1Z4EcrQzuU4x+3ABnJ+7pnx+U040MV3QK9xuZlsgUhBIXWHNOxvpaDlaa+NiL/p98b 05L4dfmalVje+cLUQoa8kO/rDa0VRLLP5KCZbtS4aTmjDaGFFHxsXFOZubH4bCcbokB8 XvnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VlpCFPXB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si2918665edv.388.2021.01.15.12.18.02; Fri, 15 Jan 2021 12:18:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VlpCFPXB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732824AbhAOURM (ORCPT + 99 others); Fri, 15 Jan 2021 15:17:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726410AbhAOURK (ORCPT ); Fri, 15 Jan 2021 15:17:10 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86BCC061757 for ; Fri, 15 Jan 2021 12:16:29 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id u21so11770139lja.0 for ; Fri, 15 Jan 2021 12:16:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ySs7CNTOqN5GXMFt8JleozKLbcnnMYl8h0GybHe3ovo=; b=VlpCFPXBTVU5sv30ixD//eShTT4irKo27rhhyZGhIUsqmoxF6jwWVu3Quqs689I6zq AHsvmwosR39IZhN5Eb64huoTv/7f1b7rIr7ogsXWFqkSAtrtra6wKPFDL6OixkbiQyOL tz6ewYTX/eHAIBfWDy9YfcGq/ZxOFqTRMfA7TIhhouFbfaNN8gSJnq1BPNtLUwkdGfVC zKQn3z03aTQxD0M2gvdoU+OMjzL0Zw1RGwpVkKhlpRQ8F7yPXZEv3gkHy0YsIBBmw1UO 6eixhRzN2DUNoCHBBB0xIWIwl8uN/v1ZbP8Pn9IfkMZYMnAfzmIYZEvL6nQEv/s8LYPr OXSg== 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=ySs7CNTOqN5GXMFt8JleozKLbcnnMYl8h0GybHe3ovo=; b=bEoLH8ktiP7DjiOMj6cc82MGhijhacWvpZhAxR+zqTkCgINcGbB10MJ40iaoDtadD3 rLMzrExxhB0DvSLK4R6kGQxjwSHmlVVTRum52SWfDK/lj9W8OWEHg6sUzpYtxgwrOpb2 Lmpi4vEHJ+lm2bNk4gtJ1Gq9bbE5XahlabS05MhgH8AweFOonzv98x03Bn7axcGYbys6 CC+6zzjGqsCbrkzMNjlcaf/GYhXGwYHUoV0+Rtnj6QPIdtAboj1MdGOposDUGC7lsJwB rTNi36fRFb0bQkbYOs68svwkgZW34BMhrG4ESWTLwg+pe3LIhVDnr5aGDymqi13Gq9VB JYjg== X-Gm-Message-State: AOAM532L9ROHZCYxPqy9ext9ao/6WzibY84P+p2JKZsYHHD6/tHXbw1e eukHKQgnGB8FTMeBS3ggHkx1VuuxLzLt3w4npBh1Jw== X-Received: by 2002:a2e:9d87:: with SMTP id c7mr5897472ljj.43.1610741788004; Fri, 15 Jan 2021 12:16:28 -0800 (PST) MIME-Version: 1.0 References: <20210115183543.15097-1-vbabka@suse.cz> In-Reply-To: <20210115183543.15097-1-vbabka@suse.cz> From: Jann Horn Date: Fri, 15 Jan 2021 21:16:01 +0100 Message-ID: Subject: Re: [PATCH] mm, slub: splice cpu and page freelists in deactivate_slab() To: Vlastimil Babka Cc: Linux-MM , kernel list , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 7:35 PM Vlastimil Babka wrote: > In deactivate_slab() we currently move all but one objects on the cpu freelist > to the page freelist one by one using the costly cmpxchg_double() operation. > Then we unfreeze the page while moving the last object on page freelist, with > a final cmpxchg_double(). > > This can be optimized to avoid the cmpxchg_double() per object. Just count the > objects on cpu freelist (to adjust page->inuse properly) and also remember the > last object in the chain. Then splice page->freelist to the last object and > effectively add the whole cpu freelist to page->freelist while unfreezing the > page, with a single cmpxchg_double(). This might have some more (good) effects, although these might well be too minuscule to notice: - The old code inverted the direction of the freelist, while the new code preserves the direction. - We're no longer dirtying the cachelines of objects in the middle of the freelist. In the current code it probably doesn't really matter, since I think we basically only take this path when handling NUMA mismatches, PFMEMALLOC stuff, racing new_slab(), and flush_slab() for handling flushing IPIs? But yeah, if we want to start automatically sending flush IPIs, it might be a good idea, given that the next accesses to the page will probably come from a different CPU (unless the page is entirely unused, in which case it may be freed to the page allocator's percpu list) and we don't want to create unnecessary cache/memory traffic. (And it's a good cleanup regardless, I think.) > Signed-off-by: Vlastimil Babka Reviewed-by: Jann Horn [...] > /* > - * Stage two: Ensure that the page is unfrozen while the > - * list presence reflects the actual number of objects > - * during unfreeze. > + * Stage two: Unfreeze the page while splicing the per-cpu > + * freelist to the head of page's freelist. > + * > + * Ensure that the page is unfrozen while the list presence > + * reflects the actual number of objects during unfreeze. (my computer complains about trailing whitespace here) > * > * We setup the list membership and then perform a cmpxchg > * with the count. If there is a mismatch then the page