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=-2.5 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 B4CD8C4360C for ; Fri, 4 Oct 2019 12:37:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 82CAF20862 for ; Fri, 4 Oct 2019 12:37:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82CAF20862 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2A6796B0003; Fri, 4 Oct 2019 08:37:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 256516B0005; Fri, 4 Oct 2019 08:37:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16BE68E0003; Fri, 4 Oct 2019 08:37:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id E3CA06B0003 for ; Fri, 4 Oct 2019 08:37:20 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 5EDD4824CA3F for ; Fri, 4 Oct 2019 12:37:20 +0000 (UTC) X-FDA: 76006052640.04.steam22_5d21c9181354b X-HE-Tag: steam22_5d21c9181354b X-Filterd-Recvd-Size: 2920 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Fri, 4 Oct 2019 12:37:19 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C5899B125; Fri, 4 Oct 2019 12:37:18 +0000 (UTC) Date: Fri, 4 Oct 2019 14:37:18 +0200 From: Michal Hocko To: Konstantin Khlebnikov Cc: Matthew Wilcox , linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/swap: piggyback lru_add_drain_all() calls Message-ID: <20191004123718.GI9578@dhcp22.suse.cz> References: <157018386639.6110.3058050375244904201.stgit@buzz> <20191004121017.GG32665@bombadil.infradead.org> <20191004122727.GA10845@dhcp22.suse.cz> <257f6172-971b-e0bd-0a74-30a0d143d6f9@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <257f6172-971b-e0bd-0a74-30a0d143d6f9@yandex-team.ru> User-Agent: Mutt/1.10.1 (2018-07-13) 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 Fri 04-10-19 15:32:01, Konstantin Khlebnikov wrote: > > > On 04/10/2019 15.27, Michal Hocko wrote: > > On Fri 04-10-19 05:10:17, Matthew Wilcox wrote: > > > On Fri, Oct 04, 2019 at 01:11:06PM +0300, Konstantin Khlebnikov wrote: > > > > This is very slow operation. There is no reason to do it again if somebody > > > > else already drained all per-cpu vectors after we waited for lock. > > > > + seq = raw_read_seqcount_latch(&seqcount); > > > > + > > > > mutex_lock(&lock); > > > > + > > > > + /* Piggyback on drain done by somebody else. */ > > > > + if (__read_seqcount_retry(&seqcount, seq)) > > > > + goto done; > > > > + > > > > + raw_write_seqcount_latch(&seqcount); > > > > + > > > > > > Do we really need the seqcount to do this? Wouldn't a mutex_trylock() > > > have the same effect? > > > > Yeah, this makes sense. From correctness point of view it should be ok > > because no caller can expect that per-cpu pvecs are empty on return. > > This might have some runtime effects that some paths might retry more - > > e.g. offlining path drains pcp pvces before migrating the range away, if > > there are pages still waiting for a worker to drain them then the > > migration would fail and we would retry. But this not a correctness > > issue. > > > > Caller might expect that pages added by him before are drained. > Exiting after mutex_trylock() will not guarantee that. > > For example POSIX_FADV_DONTNEED uses that. OK, I was not aware of this case. Please make sure to document that in the changelog and a comment in the code wouldn't hurt either. It would certainly explain more thatn "Piggyback on drain done by somebody else.". Thanks! -- Michal Hocko SUSE Labs