Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2766841pxv; Sun, 18 Jul 2021 01:01:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhUJTdgLc7jvBwblRERdz4SZP79o2AVpK+H3B+dGB6WXRxcwRXhngN3aBhCquTp2cWs5SB X-Received: by 2002:a92:c0cc:: with SMTP id t12mr12508187ilf.47.1626595307635; Sun, 18 Jul 2021 01:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626595307; cv=none; d=google.com; s=arc-20160816; b=y4E8G8YV9wlZaKnPWq9p2q5GPkTBUmEw56X38VY4kd4T21/mqEHY8ZQNhUjkUR/VOF gqBkufQty2LGUPxj2xTOL/93Hdi/nSxjutDFOSHjjkj8u4cjsPpkDB2Qk4BnmWBVv6Yj xFxPG5uoUgm3s5XcIghz9MqIqLIpSg6axuAJuSeLeqbM1LpBd7sEfwecfDzEpCcuFWEG kmyrvaENhU9PsNj1SUaS6p3WrzVgYGtFog8lO7FTaKO8Behf58j1TqyQs+xcKcvPZ0lP lb0NBr1edimEuUoIUcRdEGQf+Yp/dG3FDDVAPLTReLiWAxJhRCqAbK0uo2T7iSmyHK1K 5Gwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-signature; bh=lFXsUKClt9utCJbeMYGbYEMZneK/Y9bderWwll5CPcs=; b=vddaJlINErMstV2YhRnhoHGRzPa4qhj9Bz0dh4CZSTk2ea0l1JBWOutLh/29o91bGa jr4F/pm97D4wn97QGUiMz/IcnKXero1FJgwhIK2GyEIgGUFLAxBNWwl91O19CGo8rEAQ sX6dS32U+4hpc1qSutYw+/5+ULNrImqlFNEUr4kHMJBWa+W/KoTfyNTO5DM8HSoY5SC+ hqOacAoAb1ZXZU5JLkkU084qB1MdrCK04YhxGNJuWnD1p3MXCLvj36/5jXuPEntPdag6 +Ir/d01zvKVRx+NLdqW2aYmF0XIk4qYgLWrG+RsX0QTLaAn/acPkW+ZpKu2ANeXvCysC tiSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="wKPZLk5/"; 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 u16si17355853jat.19.2021.07.18.01.01.34; Sun, 18 Jul 2021 01:01:47 -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="wKPZLk5/"; 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 S231300AbhGRIBf (ORCPT + 99 others); Sun, 18 Jul 2021 04:01:35 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:54098 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbhGRIBd (ORCPT ); Sun, 18 Jul 2021 04:01:33 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 B07C222253; Sun, 18 Jul 2021 07:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1626595114; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lFXsUKClt9utCJbeMYGbYEMZneK/Y9bderWwll5CPcs=; b=wKPZLk5/rmIzr6WECg4igKhcKud+egQh55TY46yLjRlD5LrtR0cJWqEQ25sWveaSQpF3rq l0Cd+807vUnSfnqPtmToLd/CTUpKWw9gwepNsau536tfhUWCJNBTZMk6gc5r8rpEFKoRCZ QgG+9Z66BcLsmwczjlQ0TX6xJX+d18w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1626595114; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lFXsUKClt9utCJbeMYGbYEMZneK/Y9bderWwll5CPcs=; b=0F0+yxWY5mWsKimkLVmjUA+WF7upqj1oyCRhpEPl92SbXvCLu05XQZhx8uGoGxfNDcsdJd k5HpLgX0/N8sokBw== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 7C07B13AD2; Sun, 18 Jul 2021 07:58:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id Hjd1HCrf82DBDwAAGKfGzw (envelope-from ); Sun, 18 Jul 2021 07:58:34 +0000 Subject: Re: [patch] v2 mm/slub: restore/expand unfreeze_partials() local exclusion scope To: Mike Galbraith , Thomas Gleixner , LKML Cc: linux-rt-users@vger.kernel.org, Mel Gorman , Sebastian Andrzej Siewior References: <87tul5p2fa.ffs@nanos.tec.linutronix.de> <8c0e0c486056b5185b58998f2cce62619ed3f05c.camel@gmx.de> <878s2fnv79.ffs@nanos.tec.linutronix.de> <6c0e20dd84084036d5068e445746c3ed7e82ec4b.camel@gmx.de> <7431ceb9761c566cf2d1f6f263247acd8d38c4b5.camel@gmx.de> <476d147ab6eec386a1e8b8e11cb09708377f8c3e.camel@gmx.de> From: Vlastimil Babka Message-ID: <725fe90b-4918-321e-ca88-6166bec0c131@suse.cz> Date: Sun, 18 Jul 2021 09:58:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <476d147ab6eec386a1e8b8e11cb09708377f8c3e.camel@gmx.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/17/21 4:58 PM, Mike Galbraith wrote: > On Thu, 2021-07-15 at 18:34 +0200, Mike Galbraith wrote: >> Greetings crickets, >> >> Methinks he problem is the hole these patches opened only for RT. >> >> static void put_cpu_partial(struct kmem_cache *s, struct page *page, >> int drain) >> { >> #ifdef CONFIG_SLUB_CPU_PARTIAL >> struct page *oldpage; >> int pages; >> int pobjects; >> >> slub_get_cpu_ptr(s->cpu_slab); >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > Bah, I'm tired of waiting to see what if anything mm folks do about > this little bugger, so I'm gonna step on it my damn self and be done > with it. Fly or die little patchlet. Sorry, Mike. Got some badly timed sickness. Will check ASAP. > mm/slub: restore/expand unfreeze_partials() local exclusion scope > > 2180da7ea70a ("mm, slub: use migrate_disable() on PREEMPT_RT") replaced > preempt_disable() in put_cpu_partial() with migrate_disable(), which when > combined with ___slab_alloc() having become preemptibile, leads to > kmem_cache_free()/kfree() blowing through ___slab_alloc() unimpeded, > and vice versa, resulting in PREMPT_RT exclusive explosions in both > paths while stress testing with both SLUB_CPU_PARTIAL/MEMCG enabled, > ___slab_alloc() during allocation (duh), and __unfreeze_partials() > during free, both while accessing an unmapped page->freelist. > > Serialize put_cpu_partial()/unfreeze_partials() on cpu_slab->lock to > ensure that alloc/free paths cannot pluck cpu_slab->partial out from > underneath each other unconstrained. > > Signed-off-by: Mike Galbraith > Fixes: 2180da7ea70a ("mm, slub: use migrate_disable() on PREEMPT_RT") > --- > mm/slub.c | 23 ++++++++++++++++++++++- > 1 file changed, 22 insertions(+), 1 deletion(-) > > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -2418,6 +2418,17 @@ static void __unfreeze_partials(struct k > if (n) > spin_unlock_irqrestore(&n->list_lock, flags); > > + /* > + * If we got here via __slab_free() -> put_cpu_partial(), > + * memcg_free_page_obj_cgroups() ->kfree() may send us > + * back to __slab_free() -> put_cpu_partial() for an > + * unfortunate second encounter with cpu_slab->lock. > + */ > + if (IS_ENABLED(CONFIG_PREEMPT_RT) && memcg_kmem_enabled()) { > + lockdep_assert_held(this_cpu_ptr(&s->cpu_slab->lock.lock)); > + local_unlock(&s->cpu_slab->lock); > + } > + > while (discard_page) { > page = discard_page; > discard_page = discard_page->next; > @@ -2426,6 +2437,9 @@ static void __unfreeze_partials(struct k > discard_slab(s, page); > stat(s, FREE_SLAB); > } > + > + if (IS_ENABLED(CONFIG_PREEMPT_RT) && memcg_kmem_enabled()) > + local_lock(&s->cpu_slab->lock); > } > > /* > @@ -2497,7 +2511,9 @@ static void put_cpu_partial(struct kmem_ > * partial array is full. Move the existing > * set to the per node partial list. > */ > + local_lock(&s->cpu_slab->lock); > unfreeze_partials(s); > + local_unlock(&s->cpu_slab->lock); > oldpage = NULL; > pobjects = 0; > pages = 0; > @@ -2579,7 +2595,9 @@ static void flush_cpu_slab(struct work_s > if (c->page) > flush_slab(s, c, true); > > + local_lock(&s->cpu_slab->lock); > unfreeze_partials(s); > + local_unlock(&s->cpu_slab->lock); > } > > static bool has_cpu_slab(int cpu, struct kmem_cache *s) > @@ -2632,8 +2650,11 @@ static int slub_cpu_dead(unsigned int cp > struct kmem_cache *s; > > mutex_lock(&slab_mutex); > - list_for_each_entry(s, &slab_caches, list) > + list_for_each_entry(s, &slab_caches, list) { > + local_lock(&s->cpu_slab->lock); > __flush_cpu_slab(s, cpu); > + local_unlock(&s->cpu_slab->lock); > + } > mutex_unlock(&slab_mutex); > return 0; > } >