From patchwork Sat Sep 4 10:49:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12475521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACBE6C433F5 for ; Sat, 4 Sep 2021 10:50:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6186460FD7 for ; Sat, 4 Sep 2021 10:50:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6186460FD7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E08E56B0082; Sat, 4 Sep 2021 06:50:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22340940009; Sat, 4 Sep 2021 06:50:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4E6A94000E; Sat, 4 Sep 2021 06:50:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id 5B80494000C for ; Sat, 4 Sep 2021 06:50:14 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 25B012D3B4 for ; Sat, 4 Sep 2021 10:50:14 +0000 (UTC) X-FDA: 78549571548.39.B32FCAC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf23.hostedemail.com (Postfix) with ESMTP id D19D190000A7 for ; Sat, 4 Sep 2021 10:50:13 +0000 (UTC) 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-out2.suse.de (Postfix) with ESMTPS id E113320048; 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=oxcPbBzPCQgU+uBxjGU3z+1m86UNQhrPnhaw3+3WQVs=; b=YEicRP8FWRu89Ds49FJSO2Q/U1s9fXcVzebgy5vo/XD2Z4PuEsJEqWS7N23hb2yRotJ3mu yOIfGLPir+JDNcUag6OlIjiEXvLmQQ7ecg/nOGLZUBQiaSDl+BCFIEgBC5njjDsnC7HGdC MDFVA6JoCh8M7bBXvgPCam0JbVkvLBM= 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=oxcPbBzPCQgU+uBxjGU3z+1m86UNQhrPnhaw3+3WQVs=; b=5Wf/u8pEtzJKS2w8kuFE/iZhvg5zhpdIWdSkIWSMsG7RFGNg+ZfuwiGLkm49vT2Hz4FZWi qP/Kwv9pO8Sa0zCQ== 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 BA9BA1348A; 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 oIsBLWRPM2HoUQAAMHmgww (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 20/33] mm, slub: call deactivate_slab() without disabling irqs Date: Sat, 4 Sep 2021 12:49:50 +0200 Message-Id: <20210904105003.11688-21-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=1988; h=from:subject; bh=IqPKvbtKPB28IqQYKvtPPfxPfR0/j0o7jqdB9gktbf0=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhM084A0IrVxqUi/T2Tt3uE2aAXqGkNAiZJnnCyi04 zk5VpSOJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYTNPOAAKCRDgIcpz8YmpEMcFB/ 9W2hTCTffZBzGoVZIgWuJR+tOGvhJbiAQrCZYLjtIHgXoF2S9LjfOaz/deESoORgJAfYlrc7K/8ciE R4zRPTDroc+NaZV9CjB2pbnKscBQXzBzMejNEETXNI+jJMKao/JJSRZCTJIlb6vuStsit9CkUFsvZj E129Nsfql9wTP5+5GfMcDDPmQEkIE9kBaCqb3zw9y/VWo5u8f7m4LqfC045xZ7M7fngtk8QqJWzxSP lghgusjdSAaIKOtLXA749RtsIdVDtKf/SBWhI+Nzj/w/SXErcH7pHq/8yYkAdIoDs1QbZp11EUFXkK dgVVVBwLB7k8xJ0l2ytwna20GLxSsI X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=YEicRP8F; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="5Wf/u8pE"; spf=pass (imf23.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D19D190000A7 X-Stat-Signature: sxidq75itwcmot6eyhx8fonu5buq17m4 X-HE-Tag: 1630752613-888678 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: The function is now safe to be called with irqs enabled, so move the calls outside of irq disabled sections. When called from ___slab_alloc() -> flush_slab() we have irqs disabled, so to reenable them before deactivate_slab() we need to open-code flush_slab() in ___slab_alloc() and reenable irqs after modifying the kmem_cache_cpu fields. But that means a IRQ handler meanwhile might have assigned a new page to kmem_cache_cpu.page so we have to retry the whole check. The remaining callers of flush_slab() are the IPI handler which has disabled irqs anyway, and slub_cpu_dead() which will be dealt with in the following patch. Signed-off-by: Vlastimil Babka --- mm/slub.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 6deb4080ef54..cb12a077c61c 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2779,8 +2779,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, freelist = c->freelist; c->page = NULL; c->freelist = NULL; - deactivate_slab(s, page, freelist); local_irq_restore(flags); + deactivate_slab(s, page, freelist); new_slab: @@ -2848,18 +2848,32 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, */ goto return_single; +retry_load_page: + local_irq_save(flags); - if (unlikely(c->page)) - flush_slab(s, c); + if (unlikely(c->page)) { + void *flush_freelist = c->freelist; + struct page *flush_page = c->page; + + c->page = NULL; + c->freelist = NULL; + c->tid = next_tid(c->tid); + + local_irq_restore(flags); + + deactivate_slab(s, flush_page, flush_freelist); + + stat(s, CPUSLAB_FLUSH); + + goto retry_load_page; + } c->page = page; goto load_freelist; return_single: - local_irq_save(flags); deactivate_slab(s, page, get_freepointer(s, freelist)); - local_irq_restore(flags); return freelist; }