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=-3.5 required=3.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 3685EC433DF for ; Mon, 1 Jun 2020 14:38:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B101C2065C for ; Mon, 1 Jun 2020 14:37:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B101C2065C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3BA8D80007; Mon, 1 Jun 2020 10:37:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36AB78E0006; Mon, 1 Jun 2020 10:37:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25D0180007; Mon, 1 Jun 2020 10:37:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 0B8DB8E0006 for ; Mon, 1 Jun 2020 10:37:59 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C152A1812A475 for ; Mon, 1 Jun 2020 14:37:58 +0000 (UTC) X-FDA: 76880897436.08.drug49_2827061a26e41 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id A5C051819E643 for ; Mon, 1 Jun 2020 14:37:58 +0000 (UTC) X-HE-Tag: drug49_2827061a26e41 X-Filterd-Recvd-Size: 2976 Received: from r3-22.sinamail.sina.com.cn (r3-22.sinamail.sina.com.cn [202.108.3.22]) by imf37.hostedemail.com (Postfix) with SMTP for ; Mon, 1 Jun 2020 14:37:55 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([221.219.1.77]) by sina.com with ESMTP id 5ED512B800012F65; Mon, 1 Jun 2020 22:37:49 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 321509628868 From: Hillf Danton To: linux-mm Cc: LKML , Sebastian Andrzej Siewior , Konstantin Khlebnikov , Hillf Danton Subject: [RFC PATCH] mm: swap: remove lru drain waiters Date: Mon, 1 Jun 2020 22:37:34 +0800 Message-Id: <20200601143734.9572-1-hdanton@sina.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A5C051819E643 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.446658, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: After updating the lru drain sequence, new comers avoid waiting for the current drainer, because he is flushing works on each online CPU, by trying to lock the mutex; the drainer OTOH tries to do works for those who fail to acquire the lock by checking the lru drain sequence after releasing lock. See eef1a429f234 ("mm/swap.c: piggyback lru_add_drain_all() calls") for reasons why we can skip waiting for the lock. The memory barriers around the sequence and the lock come together to remove waiters without their drain works bandoned. Cc: Sebastian Andrzej Siewior Cc: Konstantin Khlebnikov Signed-off-by: Hillf Danton --- This is inspired by one of the works from Sebastian. --- a/mm/swap.c +++ b/mm/swap.c @@ -714,10 +714,11 @@ static void lru_add_drain_per_cpu(struct */ void lru_add_drain_all(void) { - static seqcount_t seqcount =3D SEQCNT_ZERO(seqcount); + static unsigned int lru_drain_seq; static DEFINE_MUTEX(lock); static struct cpumask has_work; - int cpu, seq; + int cpu; + unsigned int seq; =20 /* * Make sure nobody triggers this path before mm_percpu_wq is fully @@ -726,18 +727,16 @@ void lru_add_drain_all(void) if (WARN_ON(!mm_percpu_wq)) return; =20 - seq =3D raw_read_seqcount_latch(&seqcount); + lru_drain_seq++; + smp_mb(); =20 - mutex_lock(&lock); +more_work: =20 - /* - * Piggyback on drain started and finished while we waited for lock: - * all pages pended at the time of our enter were drained from vectors. - */ - if (__read_seqcount_retry(&seqcount, seq)) - goto done; + if (!mutex_trylock(&lock)) + return; =20 - raw_write_seqcount_latch(&seqcount); + smp_mb(); + seq =3D lru_drain_seq; =20 cpumask_clear(&has_work); =20 @@ -759,8 +758,11 @@ void lru_add_drain_all(void) for_each_cpu(cpu, &has_work) flush_work(&per_cpu(lru_add_drain_work, cpu)); =20 -done: mutex_unlock(&lock); + + smp_mb(); + if (seq !=3D lru_drain_seq) + goto more_work; } #else void lru_add_drain_all(void) --