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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35205C3DA64 for ; Tue, 6 Aug 2024 11:37:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F2FD6B007B; Tue, 6 Aug 2024 07:37:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A3476B0082; Tue, 6 Aug 2024 07:37:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 642CF6B0083; Tue, 6 Aug 2024 07:37:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 46E8B6B007B for ; Tue, 6 Aug 2024 07:37:44 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A49E0C09DC for ; Tue, 6 Aug 2024 11:37:43 +0000 (UTC) X-FDA: 82421620806.06.D327E81 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf23.hostedemail.com (Postfix) with ESMTP id AA29C140014 for ; Tue, 6 Aug 2024 11:37:38 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722944199; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S0SiEONYRpxrZtR0HPzp22zIJEvfV4+9ZJaxARbtylc=; b=UfdQuK95ddqdHML3HSquO4PYhHZ6rngbDfvTRjaJuLrH/o41SWwHZAdDD7K0tQw95t/RoE h2Ic0zFKvEPdnlNpUjsrUS1DjJw2kgEgcabhSBq46d3MTbXW61F8pdzVEq1JgjphfDrWVK HTFCVaQGk7qaoan4ieCerCPxG0vH1/0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722944199; a=rsa-sha256; cv=none; b=nDRX8rUyOFpoumNYmyRu64Xhb9Owt8F8SGqd2zWe3GfT18Lu80ro60UC70eO6DoXGZ4lZu cGn6nkA8+mrMtfdwpKw1eXCl151ac9maDp0Z/eQIavxidAj2zoGdnW+qOQ5vxPScAJ3C9B uLjPyl8TTd19BXJXrhAhxCc48X75Mkw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WdWQD3tK9zQpC4; Tue, 6 Aug 2024 19:33:08 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 28868180102; Tue, 6 Aug 2024 19:37:34 +0800 (CST) Received: from [10.67.120.129] (10.67.120.129) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 6 Aug 2024 19:37:33 +0800 Message-ID: Date: Tue, 6 Aug 2024 19:37:33 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v12 04/14] mm: page_frag: add '_va' suffix to page_frag API To: Alexander Duyck , Yunsheng Lin CC: , , , , , Subbaraya Sundeep , Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , Eric Dumazet , Tony Nguyen , Przemek Kitszel , Sunil Goutham , Geetha sowjanya , hariprasad , Felix Fietkau , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , Andrew Morton , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , David Howells , Marc Dionne , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , , , , , , , , , , References: <20240731124505.2903877-1-linyunsheng@huawei.com> <20240731124505.2903877-5-linyunsheng@huawei.com> <22fda86c-d688-42e7-99e8-e2f8fcf1a5ba@huawei.com> <877efebe-f316-4192-aada-dd2657b74125@huawei.com> <2a29ce61-7136-4b9b-9940-504228b10cba@gmail.com> Content-Language: en-US From: Yunsheng Lin In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.120.129] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AA29C140014 X-Stat-Signature: exsncs46k6er1e67gonei8i11dt3qzjj X-HE-Tag: 1722944258-914945 X-HE-Meta: U2FsdGVkX18hvan4UXXDOxdKRBI7ek57eo2ITVCbns3LJk1nJYHjoYG8MYAmyriQLzcN7mT4Fcd/oxFUGdUD84O5OD1jMT5vNLBnLLnyrIP0XOyUv+mNZwOF0ayEaFuu8StR6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BZUrAWpUVlZeW//28n1cmFCPvSJr6mH/zk+uyKzvaeWxXoVbEAwktunE5+u+u9xAkxo0e50kXGOabcKVYZR752eK32kYdPhXghkCXIHNHzDFssY/nbz3WVXLTCh+9yaA+dPPLqc+mwqh8caBgjdpNITLz+EYIWBuhcqcZHPTpC5VzVYfGFM0yjxLiUBXqzuQZkJdhkkcowdwUboE7uUF9CS7bsbzR6iP3v/K0KIfhVbm8UgLZtfKUkKc8bnX7d1Yev4CYUK/DbK5PkPlzLwoaBmA/TTc= 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: List-Subscribe: List-Unsubscribe: On 2024/8/6 8:52, Alexander Duyck wrote: > On Sun, Aug 4, 2024 at 10:00 AM Yunsheng Lin wrote: >> >> On 8/3/2024 1:00 AM, Alexander Duyck wrote: >> >>>> >>>>> >>>>> As far as your API extension and naming maybe you should look like >>>>> something like bio_vec and borrow the naming from that since that is >>>>> essentially what you are passing back and forth is essentially that >>>>> instead of a page frag which is normally a virtual address. >>>> >>>> I thought about adding something like bio_vec before, but I am not sure >>>> what you have in mind is somthing like I considered before? >>>> Let's say that we reuse bio_vec like something below for the new APIs: >>>> >>>> struct bio_vec { >>>> struct page *bv_page; >>>> void *va; >>>> unsigned int bv_len; >>>> unsigned int bv_offset; >>>> }; >>> >>> I wasn't suggesting changing the bio_vec. I was suggesting that be >>> what you pass as a pointer reference instead of the offset. Basically >>> your use case is mostly just for populating bio_vec style structures >>> anyway. >> >> I wasn't trying/going to reuse/change bio_vec for page_frag, I was just >> having a hard time coming with a good new name for it. >> The best one I came up with is pfrag_vec, but I am not sure about the >> 'vec' as the "vec" portion of the name would suggest, iovec structures >> tend to come in arrays, mentioned in the below article: >> https://lwn.net/Articles/625077/ >> >> Anther one is page_frag, which is currently in use. >> >> Or any better one in your mind? > > I was suggesting using bio_vec, not some new structure. The general > idea is that almost all the values you are using are exposed by that > structure already in the case of the page based calls you were adding, > so it makes sense to use what is there rather than reinventing the > wheel. Through a quick look, there seems to be at least three structs which have similar values: struct bio_vec & struct skb_frag & struct page_frag. As your above agrument about using bio_vec, it seems it is ok to use any one of them as each one of them seems to have almost all the values we are using? Personally, my preference over them: 'struct page_frag' > 'struct skb_frag' > 'struct bio_vec', as the naming of 'struct page_frag' seems to best match the page_frag API, 'struct skb_frag' is the second preference because we mostly need to fill skb frag anyway, and 'struct bio_vec' is the last preference because it just happen to have almost all the values needed. Is there any specific reason other than the above "almost all the values you are using are exposed by that structure already " that you prefer bio_vec? > >>> >>>> It seems we have the below options for the new API: >>>> >>>> option 1, it seems like a better option from API naming point of view, but >>>> it needs to return a bio_vec pointer to the caller, it seems we need to have >>>> extra space for the pointer, I am not sure how we can avoid the memory waste >>>> for sk_page_frag() case in patch 12: >>>> struct bio_vec *page_frag_alloc_bio(struct page_frag_cache *nc, >>>> unsigned int fragsz, gfp_t gfp_mask); >>>> >>>> option 2, it need both the caller and callee to have a its own local space >>>> for 'struct bio_vec ', I am not sure if passing the content instead of >>>> the pointer of a struct through the function returning is the common pattern >>>> and if it has any performance impact yet: >>>> struct bio_vec page_frag_alloc_bio(struct page_frag_cache *nc, >>>> unsigned int fragsz, gfp_t gfp_mask); >>>> >>>> option 3, the caller passes the pointer of 'struct bio_vec ' to the callee, >>>> and page_frag_alloc_bio() fills in the data, I am not sure what is the point >>>> of indirect using 'struct bio_vec ' instead of passing 'va' & 'fragsz' & >>>> 'offset' through pointers directly: >>>> bool page_frag_alloc_bio(struct page_frag_cache *nc, >>>> unsigned int fragsz, gfp_t gfp_mask, struct bio_vec *bio); >>>> >>>> If one of the above option is something in your mind? Yes, please be more specific >>>> about which one is the prefer option, and why it is the prefer option than the one >>>> introduced in this patchset? >>>> >>>> If no, please be more specific what that is in your mind? >>> >>> Option 3 is more or less what I had in mind. Basically you would >>> return an int to indicate any errors and you would be populating a >>> bio_vec during your allocation. In addition you would use the bio_vec >> >> Actually using this new bio_vec style structures does not seem to solve >> the APIs naming issue this patch is trying to solve as my understanding, >> as the new struct is only about passing one pointer or multi-pointers >> from API naming perspective. It is part of the API naming, but not all >> of it. > > I have no idea what you are talking about. The issue was you were > splitting things page_frag_alloc_va and page_frag_alloc_pg. Now it > would be page_frag_alloc and page_frag_alloc_bio or maybe > page_frag_fill_bio which would better explain what you are doing with > this function. There are three types of API as proposed in this patchset instead of two types of API: 1. page_frag_alloc_va() returns [va]. 2. page_frag_alloc_pg() returns [page, offset]. 3. page_frag_alloc() returns [va] & [page, offset]. You seemed to miss that we need a third naming for the type 3 API. Do you see type 3 API as a valid API? if yes, what naming are you suggesting for it? if no, why it is not a valid API? > >>> as a tracker of the actual fragsz so when you commit you are >>> committing with the fragsz as it was determined at the time of putting >>> the bio_vec together so you can theoretically catch things like if the >>> underlying offset had somehow changed from the time you setup the >> >> I think we might need a stronger argument than the above to use the new >> *vec thing other than the above debugging feature. >> >> I looked throught the bio_vec related info, and come along somewhat not >> really related, but really helpful "What’s all this get us" section: >> https://docs.kernel.org/block/biovecs.html >> >> So the question seems to be: what is this new struct for page_frag get >> us? >> >> Generally, I am argeed with the new struct thing if it does bring us >> something other than the above debugging feature. Otherwise we should >> avoid introducing a new thing which is hard to argue about its existent. > > I don't want a new structure. I just want you to use the bio_vec for > spots where you are needing to use a page because you are populating a > bio_vec. > >>> allocation. It would fit well into your probe routines since they are >>> all essentially passing the page, offset, and fragsz throughout the >>> code. >> >> For the current probe routines, the 'va' need to be passed, do you >> expect the 'va' to be passed by function return, double pointer, or >> new the *_vec pointer? > > I would suggest doing so via the *_vec pointer. The problem as I see As your above suggestion, I can safely assume *_ve is 'struct bio_vec', right? I am really confused here, you just clarified that you wasn't suggesting changing the bio_vec, and now you are suggesting passing 'va' via the 'struct bio_vec' pointer? How is it possible with current definition of 'struct bio_vec'? struct bio_vec { struct page *bv_page; unsigned int bv_len; unsigned int bv_offset; }; Or am I mising something obvious here? > it is that the existing code is exposing too much of the internals and > setting up the possibility for a system to get corrupted really If most of the page_frag API callers doesn't access 'struct bio_vec' directly and use something like bvec_iter_* API to do the accessing, then I am agreed with the above argument. But right now, most of the page_frag API callers are accessing 'va' directly to do the memcpy'ing, and accessing 'page & off & len' directly to do skb frag filling, so I am not really sure what's the point of indirection using the 'struct bio_vec' here. And adding 'struct bio_vec' for page_frag and accessing the value of it directly may be against of the design choice of 'struct bio_vec', as there seems to be no inline helper defined to access the value of 'struct bio_vec' directly in bvec.h