Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7307987ybi; Mon, 22 Jul 2019 10:42:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1z+5vuJl6a9lpAgZC5CMDpfZZkWudCp1X8ihDE6hicuH/MaLhL+NgVYUrquYAgHUFC41k X-Received: by 2002:aa7:9e9a:: with SMTP id p26mr1418647pfq.25.1563817366332; Mon, 22 Jul 2019 10:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563817366; cv=none; d=google.com; s=arc-20160816; b=qaa+Z9Ep2MDTRHNbWfgvEoxg0wkY5J+slRXdUKX1ZmU1yjK28hhellajO2TbZ2zQJo E+i1K/SVb9D1Af/ej43RSQMT92jaezIPxyaPhyLc5AC+Y8QM4kIj3C580+JggUGZjF6L 30K+TX9gE9ZsMXEnwwrXm83HuK1uulxIkiaa+JvFtUpFvm6hb2K9xVTd1SaqEvELSCYN 3ksx/P0uUlBCss8so99/2+5uEiU4hRDPo6q8IuLebkhiDdII51rJPk7KrpVwYNdg0mtG jb6BPQT+DW6MIJlVWPAFPHnWTyM488QrxJeztPDGhw2GJxfptXIUBSq8v7HJnt5XrDSf i2Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=cLGBuA4KHKCMbhXPXqyHBzqNhno+WhgLq+lt7rKPjk0=; b=jQk87MjVnEt3uVbw2zbydxdoOhegX0LOw/mC4xFscAzRY3vXwjTx0Whs64nJ1x5Gj8 9eldxpSBMDleJRrNv8YrkakagAfaFbJaYaZSxPm+5ceVNfB5xldrumAWThkWsVxEG2SE 46Gj1Itpv90o99jeju8B81T8+4f1OEiNOWQD/wFJAj+gQUPHGP160NSOvrCSJkzNjWTI a2aPk4GCgvsfQjIkn+doC0F4SdCR7JB2/hcqm+2MdqNCYIwTwT1i4GI7oIoFF1Cu/fkW +cK13J4ug3973J3WWZledX/gPch922VRqoRLs6EA4bMBEGidbsd9RQRCta0sQQ+/pT/K HtlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id go12si7964340plb.251.2019.07.22.10.42.30; Mon, 22 Jul 2019 10:42:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730965AbfGVQfI (ORCPT + 99 others); Mon, 22 Jul 2019 12:35:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:46106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728270AbfGVQfI (ORCPT ); Mon, 22 Jul 2019 12:35:08 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 441972190F; Mon, 22 Jul 2019 16:35:05 +0000 (UTC) Date: Mon, 22 Jul 2019 12:35:02 -0400 From: Steven Rostedt To: Gao Xiang Cc: Amir Goldstein , devel@driverdev.osuosl.org, Stephen Rothwell , Matthew Wilcox , Theodore Ts'o , Will Deacon , Peter Zijlstra , Greg Kroah-Hartman , Miao Xie , linux-erofs@lists.ozlabs.org, LKML , Ingo Molnar , Alexander Viro , linux-fsdevel , Andrew Morton , Linus Torvalds Subject: Re: [PATCH v3 12/24] erofs: introduce tagged pointer Message-ID: <20190722123502.328cecb6@gandalf.local.home> In-Reply-To: <0c2cdd4f-8fe7-6084-9c2d-c2e475e6806e@aol.com> References: <20190722025043.166344-1-gaoxiang25@huawei.com> <20190722025043.166344-13-gaoxiang25@huawei.com> <39fad3ab-c295-5f6f-0a18-324acab2f69e@huawei.com> <20190722104048.463397a0@gandalf.local.home> <0c2cdd4f-8fe7-6084-9c2d-c2e475e6806e@aol.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 22 Jul 2019 23:33:53 +0800 Gao Xiang wrote: > Hi Steven, > > On 2019/7/22 ????10:40, Steven Rostedt wrote: > >>> and I'm not sure Al could accept __fdget conversion (I just wanted to give a example then...) > >>> > >>> Therefore, I tend to keep silence and just promote EROFS... some better ideas?... > >>> > >> Writing example conversion patches to demonstrate cleaner code > >> and perhaps reduce LOC seems the best way. > > Yes, I would be more interested in seeing patches that clean up the > > code than just talking about it. > > > > I guess that is related to me, though I didn't plan to promote > a generic tagged pointer implementation in this series... I don't expect you to either. > > I try to describe what erofs met and my own implementation, > assume that we have 3 tagged pointers, a, b, c, and one > potential user only (no need to ACCESS_ONCE). > > One way is > > #define A_MASK 1 > #define B_MASK 1 > #define C_MASK 3 > > /* now we have 3 mask there, A, B, C is simple, > the real name could be long... */ > > void *a; > void *b; > void *c; /* and some pointers */ > > In order to decode the tag, we have to > ((unsigned long)a & A_MASK) > > to decode the ptr, we have to > ((unsigned long)a & ~A_MASK) > > In order to fold the tagged pointer... > (void *)((unsigned long)a | tag) And you need a way to clear the flag. > > You can see the only meaning of these masks is the bitlength of tags, > but there are many masks (or we have to do open-coded a & 3, > if bitlength is changed, we have to fix them all)... > > therefore my approach is > > typedef tagptr1_t ta; /* tagptr type a with 1-bit tag */ > typedef tagptr1_t tb; /* tagptr type b with 1-bit tag */ > typedef tagptr2_t tc; /* tagptr type c with 2-bit tag */ > > and ta a; tb b; tc c; > > the type will represent its bitlength of tags and we can use ta, tb, tc > to avoid masks or open-coded bitlength. > > In order to decode the tag, we can > tagptr_unfold_tags(a) > > In order to decode the ptr, we can > tagptr_unfold_ptr(a) > > In order to fold the tagged pointer... > a = tagptr_fold(ta, ptr, tag) > > > ACCESS_ONCE stuff is another thing... If my approach seems cleaner, > we could move to include/linux later after EROFS stuffs is done... > Or I could use a better tagptr approach later if any... Looking at the ring buffer code, it may be a bit too complex to try to use a generic infrastructure. Look at rb_head_page_set(), where it does a cmpxchg to set or clear the flags and then tests the previous flags to know what actions need to be done. The ring buffer tag code was added in 2009, the rtmutex tag code was added in 2006. It's been 10 years before we needed another tag operation. I'm not sure we benefit from making this generic. -- Steve