Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6094946pxv; Thu, 29 Jul 2021 06:25:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLeiekcvDOm0cvogI33wlOmzNC+vDLsLZmwt3ZcMBQX5sWiFth9LD6KJGZjZEqNUva/OPO X-Received: by 2002:a02:c9c2:: with SMTP id c2mr4475731jap.98.1627565119728; Thu, 29 Jul 2021 06:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627565119; cv=none; d=google.com; s=arc-20160816; b=YdlUng1OsZ5FCEGPVqvTdyIiY1zdrnf+dNarsH3QUKaUpovU9ppxiEu1/hW/eANK4q JXBWSCXQ7v+tuyX/dBqa4cYJQSb4TYMUNqgZfEEhzNDpXIFTFYHu2NIYwBZaxifaVNpk MIxgplce3WDEV1ONzrIFZuyCelAO9Sk6TiieNFDmFFaMXLlUfqgeMwFT5BTttoL2HAxz JJBkz74MZ0sify8jPuLShv36kC3aUKpMrMpeeRgqxEaw9EVnVXs5wnXuGkGkl2fLaQtD 1JDt3T+Me/9CSFlDTvD/zTfCVKm1cfVL4ifRsP6admwUEieSfy6JGy0kuquOabFnM+qL r+wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=EttZbqFwae0pdlPSjAzhFml11J+ZB6/vwgMLD6ZmLNY=; b=w3qsqsuEubQkYSgxPhft/doz4iJuM4PLuBMaaYzy+XZFMlnU5rWx2NFzI2l3tEaz+c NOg3gpBFy9TWSuM/QW7z2P1o4VsEfY+eBWPLLOqz5Z6WzHxl+FDsToIDBQnt8+3a8VuO 4hYXFlRZytHXHnR4WED0Yb0kJON+vZJ4sWzpK5255g7sWfCRS+0E2ozb70UyGnQeDSg+ ND9p6A32Ezs5YsKX+QK9tVNTdTuvG9w1AuPQkM2UjNPLE32pBSLYf3gBOs238dy0fc3U e4TVjFZOIOBG1Z47pZpEIFmsN5cwbu+1wqQeYw5nUd/zCVzLU2wpikJyjjpFpNZ8T4xx FpsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=SSB9kfQq; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si4080456iow.65.2021.07.29.06.25.08; Thu, 29 Jul 2021 06:25:19 -0700 (PDT) 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=@suse.cz header.s=susede2_rsa header.b=SSB9kfQq; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237725AbhG2NWw (ORCPT + 99 others); Thu, 29 Jul 2021 09:22:52 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:38450 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237502AbhG2NVr (ORCPT ); Thu, 29 Jul 2021 09:21:47 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id F059F223AF; Thu, 29 Jul 2021 13:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1627564903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EttZbqFwae0pdlPSjAzhFml11J+ZB6/vwgMLD6ZmLNY=; b=SSB9kfQqJNQwzK/lj2YxZ3Kqrk5JvPexJwuErddaXnpBlbdk9XymcQ9U0qh0m6cC/FIFHb 0BOkAJpdoEVBCm2ZF1wGvmwaqm/P0/jkOaqh8ASBAGHOKtDlJzCepezzj1wOLgc+Igrczf 5y7gORQXjouEf+v0Y+wVnMjNtfND5xE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1627564903; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EttZbqFwae0pdlPSjAzhFml11J+ZB6/vwgMLD6ZmLNY=; b=svY3/oEmZ+PSu2aA6kmr3LCPpoYDtJLZ5NbqcXaSD9W1MtRnVB490EAmcPdtRGu00jm7Fv aArSeeYn6HaRUhDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C279313AF4; Thu, 29 Jul 2021 13:21:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aFrcLmerAmF9AwAAMHmgww (envelope-from ); Thu, 29 Jul 2021 13:21:43 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Jann Horn , Vlastimil Babka Subject: [PATCH v3 19/35] mm, slub: move reset of c->page and freelist out of deactivate_slab() Date: Thu, 29 Jul 2021 15:21:16 +0200 Message-Id: <20210729132132.19691-20-vbabka@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729132132.19691-1-vbabka@suse.cz> References: <20210729132132.19691-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org deactivate_slab() removes the cpu slab by merging the cpu freelist with slab's freelist and putting the slab on the proper node's list. It also sets the respective kmem_cache_cpu pointers to NULL. By extracting the kmem_cache_cpu operations from the function, we can make it not dependent on disabled irqs. Also if we return a single free pointer from ___slab_alloc, we no longer have to assign kmem_cache_cpu.page before deactivation or care if somebody preempted us and assigned a different page to our kmem_cache_cpu in the process. Signed-off-by: Vlastimil Babka --- mm/slub.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 50a4add8983d..7a8554eb3d96 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2192,10 +2192,13 @@ static void init_kmem_cache_cpus(struct kmem_cache *s) } /* - * Remove the cpu slab + * Finishes removing the cpu slab. Merges cpu's freelist with page's freelist, + * unfreezes the slabs and puts it on the proper list. + * Assumes the slab has been already safely taken away from kmem_cache_cpu + * by the caller. */ static void deactivate_slab(struct kmem_cache *s, struct page *page, - void *freelist, struct kmem_cache_cpu *c) + void *freelist) { enum slab_modes { M_NONE, M_PARTIAL, M_FULL, M_FREE }; struct kmem_cache_node *n = get_node(s, page_to_nid(page)); @@ -2324,9 +2327,6 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, discard_slab(s, page); stat(s, FREE_SLAB); } - - c->page = NULL; - c->freelist = NULL; } /* @@ -2451,10 +2451,16 @@ static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain) static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) { - stat(s, CPUSLAB_FLUSH); - deactivate_slab(s, c->page, c->freelist, c); + void *freelist = c->freelist; + struct page *page = c->page; + c->page = NULL; + c->freelist = NULL; c->tid = next_tid(c->tid); + + deactivate_slab(s, page, freelist); + + stat(s, CPUSLAB_FLUSH); } /* @@ -2739,7 +2745,10 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, local_irq_restore(flags); goto reread_page; } - deactivate_slab(s, page, c->freelist, c); + freelist = c->freelist; + c->page = NULL; + c->freelist = NULL; + deactivate_slab(s, page, freelist); local_irq_restore(flags); new_slab: @@ -2818,11 +2827,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, return_single: local_irq_save(flags); - if (unlikely(c->page)) - flush_slab(s, c); - c->page = page; - - deactivate_slab(s, page, get_freepointer(s, freelist), c); + deactivate_slab(s, page, get_freepointer(s, freelist)); local_irq_restore(flags); return freelist; } -- 2.32.0