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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E795CC77B6E for ; Wed, 12 Apr 2023 09:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjDLJp7 (ORCPT ); Wed, 12 Apr 2023 05:45:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbjDLJpz (ORCPT ); Wed, 12 Apr 2023 05:45:55 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 537B3170F for ; Wed, 12 Apr 2023 02:45:13 -0700 (PDT) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230412094442epoutp0297bed44e18494e0827b495e2a3ae09c4~VJslVlYxJ0041600416epoutp02k for ; Wed, 12 Apr 2023 09:44:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230412094442epoutp0297bed44e18494e0827b495e2a3ae09c4~VJslVlYxJ0041600416epoutp02k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1681292682; bh=GKdEwxZooKxsS+1teM/4vmQew0kof+r9nocu56V8y14=; h=Subject:Reply-To:From:To:CC:In-Reply-To:Date:References:From; b=QsZrAlO8SytiXKH2OkFUieVoWZHXaVKb//n6TSJce97V/md9uuzH/wxJ75oHv9utJ JBY3yojbmIgfMwbygfADL1Y89oe5FU1Iz34VdQANizJqEfREOxPB9hlUNmbjd5kJX6 ZmQUI1Xo90ylONJgXTLYH+0K1fzZLCy0Cd9yWoJc= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20230412094441epcas1p10967532508fb0544e5700874b619a669~VJskr9bBN3275032750epcas1p1G; Wed, 12 Apr 2023 09:44:41 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.36.226]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4PxHqX6kdbz4x9Q2; Wed, 12 Apr 2023 09:44:40 +0000 (GMT) X-AuditID: b6c32a37-c35ff7000000243f-b8-64367d888d55 Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id C1.29.09279.88D76346; Wed, 12 Apr 2023 18:44:40 +0900 (KST) Mime-Version: 1.0 Subject: RE: [PATCH v3] dma-buf/heaps: system_heap: avoid too much allocation Reply-To: jaewon31.kim@samsung.com Sender: Jaewon Kim From: Jaewon Kim To: Michal Hocko CC: "jstultz@google.com" , "tjmercier@google.com" , "sumit.semwal@linaro.org" , "daniel.vetter@ffwll.ch" , "akpm@linux-foundation.org" , "hannes@cmpxchg.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "jaewon31.kim@gmail.com" X-Priority: 3 X-Content-Kind-Code: NORMAL In-Reply-To: X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20230412094440epcms1p445319579ead0d0576bb616ebb07501b4@epcms1p4> Date: Wed, 12 Apr 2023 18:44:40 +0900 X-CMS-MailID: 20230412094440epcms1p445319579ead0d0576bb616ebb07501b4 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P X-CPGSPASS: Y X-CPGSPASS: Y X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrCJsWRmVeSWpSXmKPExsWy7bCmrm5HrVmKwYUJBhZz1q9hs3h5SNNi 4cO7zBarN/ladG+eyWjR+/4Vk8W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8P0zY2LmHH1hWyjxVd5yTz/+Z69LW973h/arX9RIZn929o 7VmW8K1dfPO8H92MOz+EfutYrpmpmbvrKZvjAaE971Qyvez7A//rz1VcHbZDiaU4I9FQi7mo OBEAVq3HGkcEAAA= DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230410073304epcas1p4cf3079b096994d69472b7801bd530bc7 References: <20230410073228.23043-1-jaewon31.kim@samsung.com> <20230412085726epcms1p7d2bec2526e47bd10a3b6ea6a113c9cc3@epcms1p7> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >On Wed 12-04-23 17:57:26, Jaewon Kim wrote: >> >Sorry for being late. I know there was some pre-existing discussion >> >around that but I didn't have time to participate. >> > >> >On Mon 10-04-23 16:32:28, Jaewon Kim wrote: >> >> @@ -350,6 +350,9 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, >> >> struct page *page, *tmp_page; >> >> int i, ret = -ENOMEM; >> >> >> >> + if (len / PAGE_SIZE > totalram_pages()) >> >> + return ERR_PTR(-ENOMEM); >> >> + >> > >> >This is an antipattern imho. Check 7661809d493b ("mm: don't allow >> >oversized kvmalloc() calls") how kvmalloc has dealt with a similar >> >> Hello Thank you for the information. >> >> I tried to search the macro of INT_MAX. >> >> include/vdso/limits.h >> #define INT_MAX ((int)(~0U >> 1)) >> >> AFAIK the dma-buf system heap user can request that huge size more than 2GB. > >Do you have any pointers? This all is unreclaimable memory, right? How >are those users constrained to not go overboard? Correct dma-buf system heap memory is unreclaimable. To avoid that huge request, this patch includes __GFP_RETRY_MAYFAIL. #define LOW_ORDER_GFP (GFP_HIGHUSER | __GFP_ZERO | __GFP_RETRY_MAYFAIL) > >> So >> I think totalram_pages() is better than INT_MAX in this case. >> >> >issue. totalram_pages doesn't really tell you anything about incorrect >> >users. You might be on a low memory system where the request size is >> >sane normally, it just doesn't fit into memory on that particular >> >machine. >> >> Sorry maybe I'm not fully understand what you meant. User may requested >> a huge size like 3GB on 2GB ram device. But I think that should be rejected >> because it is bigger than the device ram size. > >Even totalram_pages/10 can be just unfeasible amount of data to be >allocated without a major disruption. totalram_pages is no measure of >the memory availability. >If you want to have a ballpark estimation then si_mem_available might be >something you are looking for. But I thought the sole purpose of this >patch is to catch obviously buggy callers (like sign overflow lenght >etc) rather than any memory consumption sanity check. Yes if we want to avoid some big size, si_mem_available could be one option. Actually I tried to do totalram_pages() / 2 like the old ion system heap in the previous patch version. Anyway totalram_pages in this patch is used to avoid the buggy size. And as we discussed in v2 patch, __GFP_RETRY_MAYFAIL was added. And I think the gfp makes us feel better in memory perspective. > >-- >Michal Hocko >SUSE Labs