Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7309126ybi; Mon, 22 Jul 2019 10:44:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQIY/vscwEIMlER/gCRdtImAozlsjDbsji62KzJrwtgx6MIOLI2vLwWaBSUk5NPOlxt3hI X-Received: by 2002:a65:6815:: with SMTP id l21mr26461093pgt.146.1563817449020; Mon, 22 Jul 2019 10:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563817449; cv=none; d=google.com; s=arc-20160816; b=nA8IngFbshcajOLbsGYe3uwVckhD/R7BV3PqhxSH2OTZfK4XMRXAZ5NkJ/56D1DaLE ZlDGQb8SFUNnozOJSCcVx6XqgQyBMesSib81hA6pelstKm5lc6fH7sHohoMxRBOMZIQf 7gbOLxIl5PMYyr9CQC8Trs3LF8vnTUI5cwjEKHVSX5WvGq18ZRnq17GOCMm9QQLWPuB8 8+jj0Dt4m017jYMLfIJYB4NZ1a2PB5zQT3IZvSYiN2DpU1c78c10tdzeN1xyINYU728p +5dqrCspq7T9dszPPIY57C803mXoUB92L7HIL6W3v7UXYq9zqlDAZm2jt30JyM+kwI82 4IVg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=+/7np4FvOppMR9Hf/eQxNoXzqpdKSRbs1I6bZt2UJ40=; b=ikMWYpGYgAFkGCfdOfnPdJfaoJOGU/ipAyzmzzvlPdh5iBDy/ZiSj1Dc+vmS+gq27m THu8VavWVzxtK3pk4HSbf99aTh2WXB+oWmK51nHG9kbhmu9kmpWaaKCE+A8yhbNDGFX9 yhE70wXgnLIivEohFbJVHzYM9mPse+/rRPdfAi7v8xueVgEE7dE6SCO/3WD3MmNSR3bs d0cJpeGeiljXUeoVFrHSAPeweE1WcMXqN/dGL64LV6OOlLh/XVI949D8oUbM59nOexA/ /lbiF4PKm05HgsIi0YUKaes74BznAiAYkWRAd5cCnBm36c2kQjgsyGwyH9yxx1PY4coD B1gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=X6sWygAG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h63si8764668pjb.106.2019.07.22.10.43.52; Mon, 22 Jul 2019 10:44:09 -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; dkim=pass header.i=@aol.com header.s=a2048 header.b=X6sWygAG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730640AbfGVQwc (ORCPT + 99 others); Mon, 22 Jul 2019 12:52:32 -0400 Received: from sonic316-54.consmr.mail.gq1.yahoo.com ([98.137.69.30]:44605 "EHLO sonic316-54.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728752AbfGVQwb (ORCPT ); Mon, 22 Jul 2019 12:52:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1563814350; bh=+/7np4FvOppMR9Hf/eQxNoXzqpdKSRbs1I6bZt2UJ40=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=X6sWygAGuqfUgp75ROg5xSq7l5O2IjRks7AVIlvspODL2N9BhL1kDzaRObLFMlu8emxd2RL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KjD8wt.qczdyJ_L1MRZ2BI5EBkfEmfNpAI9cyDc9I bM3y6eg_w4vz4t9llHdpxVloO2nqvg5_W.X7C6kL.OzWepycJ9O0H8.cjrEqxbk5dXRyQCdvdj3o 6ZlcLeadJlxY0bAh6XSG7LYq1YstpiopTW5P0clR2P9KDlRKwf.1su7WasPLe8j0mt.QH_cbN1fy tw6_tyiUlI9GcNBrUV.b_lHdQd_9LIb8ss9HitVzA6PpXX6DwzL85wmMtjZ4XYfy8m7e0pKnSUxI epITVX5BALgw0ynLy1HXHEWw79qlBj9udhJ_l0ZnmGRhHDxRcQwOsRmbQjgeNwHAT.uXm2raNpyf vQkYb9Mm4r3Ko9x8IRG.Nyt4GfwPSQ1l7N599PvuP0sDCx1MFBRbgwiBDeXE2TNsrQsT_guJ1Uq0 NMWS7m1REosIvBs_QxPK4Sq22II3YEeVRvi3FFTbqk3PX5DhkoeeB7uPtloCJEw_HmrIEIKgupcU FctUVfufA Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Mon, 22 Jul 2019 16:52:30 +0000 Received: by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d88bfb998e3ead874cbe21f5d0ea57ed; Mon, 22 Jul 2019 16:52:26 +0000 (UTC) Subject: Re: [PATCH v3 12/24] erofs: introduce tagged pointer To: Steven Rostedt 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 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> <20190722123502.328cecb6@gandalf.local.home> From: Gao Xiang Message-ID: <25e5dd99-b110-45f8-f769-5372ff01510f@aol.com> Date: Tue, 23 Jul 2019 00:52:14 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190722123502.328cecb6@gandalf.local.home> Content-Type: text/plain; charset=gbk Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/23 ????12:35, Steven Rostedt wrote: > 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. Beyond my expectation, I think I will (could) learn some new knowledge from this topic, thanks you and Amir :) > >> >> 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. Considering one potential user, we could refold the tagged pointer. or we could refold the tagged pointer and update the value in atomic (like atomic_t does). a = tagptr_fold(ta, tagptr_unfold_tags(a), tag); > >> >> 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 current code supports cmpxchg as well, but I don't look into rb_head_page_set... (although I think it is not the critical thing if we decide to do some generic tagged pointer approach...) > > 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. Okay, that depends on your folks, actually... Thanks, Gao Xiang > > -- Steve >