From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751330AbdK3UtF (ORCPT ); Thu, 30 Nov 2017 15:49:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58640 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750964AbdK3UtE (ORCPT ); Thu, 30 Nov 2017 15:49:04 -0500 Subject: Re: [PATCH] list_lru: Prefetch neighboring list entries before acquiring lock To: Andrew Morton Cc: Dave Chinner , Vladimir Davydov , Johannes Weiner , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <1511965054-6328-1-git-send-email-longman@redhat.com> <20171129135319.ab078fbed566be8fc90c92ec@linux-foundation.org> <20171130004252.GR4094@dastard> <209d1aea-2951-9d4f-5638-8bc037a6676c@redhat.com> <20171130124736.e60c75d120b74314c049c02b@linux-foundation.org> From: Waiman Long Organization: Red Hat Message-ID: <377e9162-3d26-f553-c945-458738ebacf5@redhat.com> Date: Thu, 30 Nov 2017 15:49:03 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20171130124736.e60c75d120b74314c049c02b@linux-foundation.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 30 Nov 2017 20:49:04 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/30/2017 03:47 PM, Andrew Morton wrote: > On Thu, 30 Nov 2017 08:54:04 -0500 Waiman Long wrote: > >>> And, from that perspective, the racy shortcut in the proposed patch >>> is wrong, too. Prefetch is fine, but in general shortcutting list >>> empty checks outside the internal lock isn't. >> For the record, I add one more list_empty() check at the beginning of >> list_lru_del() in the patch for 2 purpose: >> 1. it allows the code to bail out early. >> 2. It make sure the cacheline of the list_head entry itself is loaded. >> >> Other than that, I only add a likely() qualifier to the existing >> list_empty() check within the lock critical region. > But it sounds like Dave thinks that unlocked check should be removed? > > How does this adendum look? > > From: Andrew Morton > Subject: list_lru-prefetch-neighboring-list-entries-before-acquiring-lock-fix > > include prefetch.h, remove unlocked list_empty() test, per Dave > > Cc: Dave Chinner > Cc: Johannes Weiner > Cc: Vladimir Davydov > Cc: Waiman Long > Signed-off-by: Andrew Morton > --- > > mm/list_lru.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff -puN mm/list_lru.c~list_lru-prefetch-neighboring-list-entries-before-acquiring-lock-fix mm/list_lru.c > --- a/mm/list_lru.c~list_lru-prefetch-neighboring-list-entries-before-acquiring-lock-fix > +++ a/mm/list_lru.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -135,13 +136,11 @@ bool list_lru_del(struct list_lru *lru, > /* > * Prefetch the neighboring list entries to reduce lock hold time. > */ > - if (unlikely(list_empty(item))) > - return false; > prefetchw(item->prev); > prefetchw(item->next); > > spin_lock(&nlru->lock); > - if (likely(!list_empty(item))) { > + if (!list_empty(item)) { > l = list_lru_from_kmem(nlru, item); > list_del_init(item); > l->nr_items--; > _ > Yes, that look good to me. Thanks for fixing that. Cheers, Longman