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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 01DADC33CAC for ; Thu, 6 Feb 2020 08:03:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C1AB220838 for ; Thu, 6 Feb 2020 08:03:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1AB220838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5491B6B0007; Thu, 6 Feb 2020 03:03:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FA1D6B0008; Thu, 6 Feb 2020 03:03:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E6C66B000A; Thu, 6 Feb 2020 03:03:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2573B6B0007 for ; Thu, 6 Feb 2020 03:03:10 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D3BBB180AD802 for ; Thu, 6 Feb 2020 08:03:09 +0000 (UTC) X-FDA: 76458961698.02.tax50_1b94a61765d58 X-HE-Tag: tax50_1b94a61765d58 X-Filterd-Recvd-Size: 3017 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 08:03:09 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6FD5FAF93; Thu, 6 Feb 2020 08:03:07 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 6FE6D1E0E31; Thu, 6 Feb 2020 09:03:07 +0100 (CET) Date: Thu, 6 Feb 2020 09:03:07 +0100 From: Jan Kara To: Jason Gunthorpe Cc: Jan Kara , Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 3/8] xarray: Explicitely set XA_FREE_MARK in __xa_cmpxchg() Message-ID: <20200206080307.GB14001@quack2.suse.cz> References: <20200204142514.15826-1-jack@suse.cz> <20200204142514.15826-4-jack@suse.cz> <20200205184512.GC28298@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200205184512.GC28298@ziepe.ca> 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 Wed 05-02-20 14:45:12, Jason Gunthorpe wrote: > On Tue, Feb 04, 2020 at 03:25:09PM +0100, Jan Kara wrote: > > __xa_cmpxchg() relies on xas_store() to set XA_FREE_MARK when storing > > NULL into xarray that has free tracking enabled. Make the setting of > > XA_FREE_MARK explicit similarly as its clearing currently it. > > > > Signed-off-by: Jan Kara > > lib/xarray.c | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/lib/xarray.c b/lib/xarray.c > > index ae8b7070e82c..4e32497c51bd 100644 > > +++ b/lib/xarray.c > > @@ -1477,8 +1477,12 @@ void *__xa_cmpxchg(struct xarray *xa, unsigned long index, > > curr = xas_load(&xas); > > if (curr == old) { > > xas_store(&xas, entry); > > - if (xa_track_free(xa) && entry && !curr) > > - xas_clear_mark(&xas, XA_FREE_MARK); > > + if (xa_track_free(xa)) { > > + if (entry && !curr) > > + xas_clear_mark(&xas, XA_FREE_MARK); > > + else if (!entry && curr) > > + xas_set_mark(&xas, XA_FREE_MARK); > > + } > > This feels like an optimization that should also happen for > __xa_store, which has very similar code: > > curr = xas_store(&xas, entry); > if (xa_track_free(xa)) > xas_clear_mark(&xas, XA_FREE_MARK); > > Something like > > if (xa_track_free(xa) && entry && !curr) > xas_clear_mark(&xas, XA_FREE_MARK); > > ? Yeah, entry != NULL is guaranteed for __xa_store() (see how it transforms NULL to XA_ZERO_ENTRY a few lines above) but !curr is probably a good condition to add to save some unnecessary clearing when overwriting existing values. It is unrelated to this patch though, just a separate optimization so I'll add that as a separate patch to the series. Thanks for the idea. Honza -- Jan Kara SUSE Labs, CR