Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3847830pxj; Mon, 24 May 2021 16:46:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKY3kmTec9Jy15fW/z6sFaoe1kwawIl/hr7SI+MypLiSuWlKUVrxlGOnUXi5I+pNsx2mqn X-Received: by 2002:a17:906:b74e:: with SMTP id fx14mr25671881ejb.104.1621899977254; Mon, 24 May 2021 16:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621899977; cv=none; d=google.com; s=arc-20160816; b=AZfs1TzwpCZ562IYIdm86UROY/UM4IdAcCsyZlpgqZ1dfcxe0KM3P/XobHsKuLrfL7 EtABD1ku5tuI8Eq0M5s9P95xvMULGAVH07QnIIBJ8V0gkcAgJf4DEZcTJcOJnA9nG1eV P8YYzL4CHPtHfiCpdvYnUkGgN9y6H1Lm1oCOl3e0hPuAiLmTJq0VaO82PjeVUoQYIWpv 2WVFdSugN+DpswZv1Rx9iX00KszfHNh1MLf67TI+vOgOKWCYZmTQNQ3KeWNzbKWAQv1f PjqIcrXSwQ79I165a1Zcw+RyKzcm+ex2P6ZDyTX2mAHQ0099+DQ2KgryGl/crdLWWvjR XFVA== 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=/KgxBTtzhGTK/VIVLMNo6aMrR/rwiEL/1FfFcxuOxMg=; b=ztc7vbmAaq7v+pXJ0o55xQOS3ohBLlxSB5FwT4PuT3p4mxaPGKVCRtQGeX0Ql4flVv 1WkvkX4hG4LxDxhPARl+uhlMXj4AP2iO2m7gwvTlRTaCWb/TsuFUS6Cxcupa7MSMoRSg KrQnrbvid7StPl/x4O2Df78/wSFjT8Zvu+GOjZ+y4og86E2yxjIiGs6rWAZ9Q4OZ+njX ljvv4rG1trCdLyaa+KAjSOU60JfATGtAYW3n9Jt/WpVzsmTCGkc2Q4b4zrKhTVozb3J0 CvH/+Xc5DA/Xj4aqgh8/99Ds2RRGfORYBxGtiwFsnpGcG2L6RwQKJeUSCxLcXt7Fj/a5 /Rsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=q2cgZiRR; dkim=neutral (no key) header.i=@suse.cz header.b=9npNbeO4; 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 y16si18671000eda.286.2021.05.24.16.45.54; Mon, 24 May 2021 16:46:17 -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=q2cgZiRR; dkim=neutral (no key) header.i=@suse.cz header.b=9npNbeO4; 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 S230248AbhEXXn7 (ORCPT + 99 others); Mon, 24 May 2021 19:43:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:50886 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbhEXXmW (ORCPT ); Mon, 24 May 2021 19:42:22 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1621899649; 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=/KgxBTtzhGTK/VIVLMNo6aMrR/rwiEL/1FfFcxuOxMg=; b=q2cgZiRRONUnvQz5BpUomDJo1FkmPKdCvZzP9oUNl8GQe0ffJ+0Jkfv3Zxz5ljCuYUHoJz 3zNBMDUsO2O3tHFrcpj0PMBcl1O7+gJ5s7jcGzuSenHlrAzEtBLqEzni8ejbi4rgZTP6Qk IXOo1+mVH8obnbim11QiwvMIEozZncw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1621899649; 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=/KgxBTtzhGTK/VIVLMNo6aMrR/rwiEL/1FfFcxuOxMg=; b=9npNbeO4WHoHF9BhDsqL5f24g4dwXZGhQYKiq26qhqB9ick767FUpQoh30NnFRgl5X7+ry baP87wDMtjVQtlAw== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DF289AF3B; Mon, 24 May 2021 23:40:48 +0000 (UTC) From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Peter Zijlstra , Jann Horn , Vlastimil Babka Subject: [RFC 18/26] mm, slub: call deactivate_slab() without disabling irqs Date: Tue, 25 May 2021 01:39:38 +0200 Message-Id: <20210524233946.20352-19-vbabka@suse.cz> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524233946.20352-1-vbabka@suse.cz> References: <20210524233946.20352-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 another irq might have assigned a new c->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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 0f58859165bf..01422c757f9b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2722,8 +2722,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: @@ -2792,18 +2792,31 @@ 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; } -- 2.31.1