Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1224687pxb; Sat, 4 Sep 2021 03:59:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwllqAJRa4CQVC68TOKuKihlr+7rdL0OF4xGrkDCZCtcG2xRL6YlGgKBxLf4dbbrxhDTsMW X-Received: by 2002:a05:6638:bcf:: with SMTP id g15mr2841153jad.1.1630753148620; Sat, 04 Sep 2021 03:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630753148; cv=none; d=google.com; s=arc-20160816; b=iLpODuNwvIrXw1FpV1b56prGfFGYrNvFuK2THA+DXs445+gy9+yxajQwqpeEhvTL/Z 9nC9yJ+rTx8B/TGNef36TEUlfb0cWq6KGxQZkbDLmL+JW0w8PCSIzLcLbq2fg42V4PJe Xd8R5XP5NysKcv1V8molKseR1YHQJnLQnAH3RUCJQMrj+/mD8BXTK/Q/kO/ITeY26CaM LzwDakN2/N7inTtI+2w9+8BL7BpX98gb6bChfO6KOGIsFPL1LirG1KZNK48TNxGea8jQ ZocpFjcE2tgBzsPI0vkUKUx8WjzO488DOzsvBfaP7vCOS3nlpIGKX9Xg9e3ufow1+j+Q PYMQ== 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=yTWAKLmBnHJEgugHxPsV+ggOQdSrusqVnBL855yHn3I=; b=MHRhfjr1A6WZGf70bHS3a+qYUiBOlPc9VjhIcOZp9jZ8FeI948l+BtfcC/sYnyOvqs OnxNW8qPqDpQZe0xXM6YUZh1kSBdfHx/VjgrDzWrCg+cymEyeYlu7nN3CzkrZQZBp+kR 1kUzKoGTNKlyIDAZCs0mBXomC4q0J7bkOImUg+/A5GFW8wI4I3oe3YMMDbuWtQ/z8TL1 M/wRNNXT4637C4sxQaNa7eZ76WxyR8+JLtSN/bGLkS9Sn0ukqiEf88zD3IOQJT2h5vYh 8ScAsc8bSjG3NvecRTLKMW8lneFCt3QLWcju9qPSRa0EM4VmeWABpyuMyoy7VA0TDYhh CzlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1HGOkwfy; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=TU0mBrUk; 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 q128si2106108ioq.111.2021.09.04.03.58.57; Sat, 04 Sep 2021 03:59:08 -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=1HGOkwfy; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=TU0mBrUk; 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 S1351307AbhIDKwV (ORCPT + 99 others); Sat, 4 Sep 2021 06:52:21 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59728 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351117AbhIDKvO (ORCPT ); Sat, 4 Sep 2021 06:51:14 -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 8F9FC22697; Sat, 4 Sep 2021 10:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630752612; 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=yTWAKLmBnHJEgugHxPsV+ggOQdSrusqVnBL855yHn3I=; b=1HGOkwfyFpcDdYMO8NjN2Fi3dMfcB17e7lyImGrJ5QsOO4leNlqsHRasgP/9rpEPx66I6h /2c8ZjAruFxBYfafYxJQqRUIL9IAK3eek5dzt7uTWbJOS2SdGh4GEX/D6e5e86VF+MmtrL H9OS/ZZ86M8h4ZRrYrF+ymfx5Eff/mU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630752612; 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=yTWAKLmBnHJEgugHxPsV+ggOQdSrusqVnBL855yHn3I=; b=TU0mBrUkncQzJoN314ZySq7FYgDvlkqpFe/o0Pi42udw0z54b+wA5HaCAcg5COtHvPSHcS Zm7aplipNIozHmCw== 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 6AC4A1348A; Sat, 4 Sep 2021 10:50:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uPpRGWRPM2HoUQAAMHmgww (envelope-from ); Sat, 04 Sep 2021 10:50:12 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Vlastimil Babka Subject: [PATCH v6 18/33] mm, slub: move reset of c->page and freelist out of deactivate_slab() Date: Sat, 4 Sep 2021 12:49:48 +0200 Message-Id: <20210904105003.11688-19-vbabka@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210904105003.11688-1-vbabka@suse.cz> References: <20210904105003.11688-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2896; h=from:subject; bh=hjcH8xMrLWaUffLKkEsh3qXRSMtqDyM/+LlY5fXXiwM=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhM080e7i5aYvInkeI/gf6l7U8JqibXV+TakTvRvtD y7ZFzluJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYTNPNAAKCRDgIcpz8YmpEEFTB/ 0dw+e6VDTWgaK/zibVxnkLiIchrFDfWJDwS1E5sCIV4GY+GPTcznsFL8vrdpxdMUPxZzFs0BAwMzxC fZg5xNYlD9RhbP9GFoDnFyUdHSLo8FUeNOiQapDMgzQbGSNlmhdQKSEoiTPK9cvqPqroA9I35ygvjC m17znfL1YsKq3jJgUwsvYYech8/O+ANDRio75kXnyjybRb5RadKqsiXthB4F7gdsXzZKvjPoZ3NJQk a6KEjkA3csZfKZbrZy99wXdYKu+/HBsebzfyz4xlrtH51REnbZIKkeiuhEf1qy4iS1FyBM/QQB/1dR 1e8b/YEWds2pmibNEsK+MyYrxLHm+1 X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 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 8433e50d2c8e..cea7a2ad9e3e 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2209,10 +2209,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)); @@ -2341,9 +2344,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; } /* @@ -2468,10 +2468,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); } /* @@ -2769,7 +2775,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: @@ -2848,11 +2857,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.33.0