From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 102F0C433E0 for ; Fri, 22 May 2020 14:57:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA16C207F9 for ; Fri, 22 May 2020 14:57:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Eec5LrVP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA16C207F9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 591F280008; Fri, 22 May 2020 10:57:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 541D280007; Fri, 22 May 2020 10:57:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 457F280008; Fri, 22 May 2020 10:57:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id 2A7F780007 for ; Fri, 22 May 2020 10:57:18 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E12C05DC5 for ; Fri, 22 May 2020 14:57:17 +0000 (UTC) X-FDA: 76844658114.19.table22_3f65dbc010d0a X-HE-Tag: table22_3f65dbc010d0a X-Filterd-Recvd-Size: 3988 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 14:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=erZ/JA17BuAFrecl0xoMrH0KQGWniu40sT1NX+tkDYE=; b=Eec5LrVPlqVvxH6htP3R0e0xB9 7pG1vNWYg54p64n9nca55RF2BVyBOwA5sHYwPXEKo36ykTKfXwf5tioO2WUxCPJqNKl8uT5N71sTv uNQM2qdNnAS0s0ADwlNTW6X56QEJPO+3aSEej5KQ1wrs46H7ntjUp2ntygdLQJNhD8Z6O42ZdCitH M5T0h3tsDqfO/IMqjxddRk9oEN7U+mgsrXjlSWBGuGwI/X8WPulK3s2T8oeNXNvWOSL7Vp+chP5eK g7yrELWQpTGzXeRslYDNyi6BAVxrCPLbUD2wSmdFyLz+yDVvXc894Pl2Sua0xhN8v3bi6XY2tHlQi VkOaX62g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jc96k-00024S-C3; Fri, 22 May 2020 14:57:10 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2CBE2307881; Fri, 22 May 2020 16:57:07 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D6C532B236866; Fri, 22 May 2020 16:57:07 +0200 (CEST) Date: Fri, 22 May 2020 16:57:07 +0200 From: Peter Zijlstra To: "Ahmed S. Darwish" Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , Andrew Morton , Konstantin Khlebnikov , linux-mm@kvack.org Subject: Re: [PATCH v1 02/25] mm/swap: Don't abuse the seqcount latching API Message-ID: <20200522145707.GO325280@hirez.programming.kicks-ass.net> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200519214547.352050-3-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200519214547.352050-3-a.darwish@linutronix.de> 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: On Tue, May 19, 2020 at 11:45:24PM +0200, Ahmed S. Darwish wrote: > @@ -713,10 +713,20 @@ static void lru_add_drain_per_cpu(struct work_struct *dummy) > */ > void lru_add_drain_all(void) > { > + static unsigned int lru_drain_gen; > static struct cpumask has_work; > + static DEFINE_MUTEX(lock); > + int cpu, this_gen; > > /* > * Make sure nobody triggers this path before mm_percpu_wq is fully > @@ -725,21 +735,48 @@ void lru_add_drain_all(void) > if (WARN_ON(!mm_percpu_wq)) > return; > > + this_gen = READ_ONCE(lru_drain_gen); > + smp_rmb(); this_gen = smp_load_acquire(&lru_drain_gen); > > mutex_lock(&lock); > > /* > + * (C) Exit the draining operation if a newer generation, from another > + * lru_add_drain_all(), was already scheduled for draining. Check (A). > */ > + if (unlikely(this_gen != lru_drain_gen)) > goto done; > > + WRITE_ONCE(lru_drain_gen, lru_drain_gen + 1); > + smp_wmb(); You can leave this smp_wmb() out and rely on the smp_mb() implied by queue_work_on()'s test_and_set_bit(). > cpumask_clear(&has_work); > - > for_each_online_cpu(cpu) { > struct work_struct *work = &per_cpu(lru_add_drain_work, cpu); > While you're here, do: s/cpumask_set_cpu/__&/ > @@ -766,7 +803,7 @@ void lru_add_drain_all(void) > { > lru_add_drain(); > } > -#endif > +#endif /* CONFIG_SMP */ > > /** > * release_pages - batched put_page()